[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.104,2.105

Guido van Rossum gvanrossum@users.sourceforge.net
2001年10月15日 15:03:34 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv23185/Objects
Modified Files:
	typeobject.c 
Log Message:
Get rid of __defined__ and tp_defined -- there's no need to
distinguish __dict__ and __defined__ any more. In the C structure,
tp_cache takes its place -- but this hasn't been implemented yet.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.104
retrieving revision 2.105
diff -C2 -d -r2.104 -r2.105
*** typeobject.c	2001年10月15日 21:05:10	2.104
--- typeobject.c	2001年10月15日 22:03:32	2.105
***************
*** 45,49 ****
 	if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE))
 		return PyString_FromString("__builtin__");
! 	mod = PyDict_GetItemString(type->tp_defined, "__module__");
 	if (mod != NULL && PyString_Check(mod)) {
 		Py_INCREF(mod);
--- 45,49 ----
 	if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE))
 		return PyString_FromString("__builtin__");
! 	mod = PyDict_GetItemString(type->tp_dict, "__module__");
 	if (mod != NULL && PyString_Check(mod)) {
 		Py_INCREF(mod);
***************
*** 81,99 ****
 }
 
- static PyObject *
- type_defined(PyTypeObject *type, void *context)
- {
- 	if (type->tp_defined == NULL) {
- 		Py_INCREF(Py_None);
- 		return Py_None;
- 	}
- 	return PyDictProxy_New(type->tp_defined);
- }
- 
 PyGetSetDef type_getsets[] = {
 	{"__name__", (getter)type_name, NULL, NULL},
 	{"__module__", (getter)type_module, (setter)type_set_module, NULL},
 	{"__dict__", (getter)type_dict, NULL, NULL},
- 	{"__defined__", (getter)type_defined, NULL, NULL},
 	{0}
 };
--- 81,88 ----
***************
*** 839,844 ****
 	type->tp_base = base;
 
! 	/* Initialize tp_defined from passed-in dict */
! 	type->tp_defined = dict = PyDict_Copy(dict);
 	if (dict == NULL) {
 		Py_DECREF(type);
--- 828,833 ----
 	type->tp_base = base;
 
! 	/* Initialize tp_dict from passed-in dict */
! 	type->tp_dict = dict = PyDict_Copy(dict);
 	if (dict == NULL) {
 		Py_DECREF(type);
***************
*** 974,978 ****
 	PyObject *mro, *res, *dict;
 
! 	/* Look in tp_defined of types in MRO */
 	mro = type->tp_mro;
 	assert(PyTuple_Check(mro));
--- 963,967 ----
 	PyObject *mro, *res, *dict;
 
! 	/* Look in tp_dict of types in MRO */
 	mro = type->tp_mro;
 	assert(PyTuple_Check(mro));
***************
*** 981,985 ****
 		type = (PyTypeObject *) PyTuple_GET_ITEM(mro, i);
 		assert(PyType_Check(type));
! 		dict = type->tp_defined;
 		assert(dict && PyDict_Check(dict));
 		res = PyDict_GetItem(dict, name);
--- 970,974 ----
 		type = (PyTypeObject *) PyTuple_GET_ITEM(mro, i);
 		assert(PyType_Check(type));
! 		dict = type->tp_dict;
 		assert(dict && PyDict_Check(dict));
 		res = PyDict_GetItem(dict, name);
***************
*** 1015,1019 ****
 	}
 
! 	/* Look in tp_defined of this type and its bases */
 	res = _PyType_Lookup(type, name);
 	if (res != NULL) {
--- 1004,1008 ----
 	}
 
! 	/* Look in tp_dict of this type and its bases */
 	res = _PyType_Lookup(type, name);
 	if (res != NULL) {
***************
*** 1071,1075 ****
 	Py_XDECREF(type->tp_bases);
 	Py_XDECREF(type->tp_mro);
! 	Py_XDECREF(type->tp_defined);
 	Py_XDECREF(type->tp_subclasses);
 	Py_XDECREF(et->name);
--- 1060,1064 ----
 	Py_XDECREF(type->tp_bases);
 	Py_XDECREF(type->tp_mro);
! 	Py_XDECREF(type->tp_cache);
 	Py_XDECREF(type->tp_subclasses);
 	Py_XDECREF(et->name);
***************
*** 1137,1141 ****
 
 	VISIT(type->tp_dict);
! 	VISIT(type->tp_defined);
 	VISIT(type->tp_mro);
 	VISIT(type->tp_bases);
--- 1126,1130 ----
 
 	VISIT(type->tp_dict);
! 	VISIT(type->tp_cache);
 	VISIT(type->tp_mro);
 	VISIT(type->tp_bases);
***************
*** 1168,1172 ****
 
 	CLEAR(type->tp_dict);
! 	CLEAR(type->tp_defined);
 	CLEAR(type->tp_mro);
 	CLEAR(type->tp_bases);
--- 1157,1161 ----
 
 	CLEAR(type->tp_dict);
! 	CLEAR(type->tp_cache);
 	CLEAR(type->tp_mro);
 	CLEAR(type->tp_bases);
***************
*** 1456,1460 ****
 add_methods(PyTypeObject *type, PyMethodDef *meth)
 {
! 	PyObject *dict = type->tp_defined;
 
 	for (; meth->ml_name != NULL; meth++) {
--- 1445,1449 ----
 add_methods(PyTypeObject *type, PyMethodDef *meth)
 {
! 	PyObject *dict = type->tp_dict;
 
 	for (; meth->ml_name != NULL; meth++) {
***************
*** 1475,1479 ****
 add_members(PyTypeObject *type, PyMemberDef *memb)
 {
! 	PyObject *dict = type->tp_defined;
 
 	for (; memb->name != NULL; memb++) {
--- 1464,1468 ----
 add_members(PyTypeObject *type, PyMemberDef *memb)
 {
! 	PyObject *dict = type->tp_dict;
 
 	for (; memb->name != NULL; memb++) {
***************
*** 1494,1498 ****
 add_getset(PyTypeObject *type, PyGetSetDef *gsp)
 {
! 	PyObject *dict = type->tp_defined;
 
 	for (; gsp->name != NULL; gsp++) {
--- 1483,1487 ----
 add_getset(PyTypeObject *type, PyGetSetDef *gsp)
 {
! 	PyObject *dict = type->tp_dict;
 
 	for (; gsp->name != NULL; gsp++) {
***************
*** 1747,1751 ****
 	}
 	assert((type->tp_flags & Py_TPFLAGS_READYING) == 0);
- 	assert(type->tp_dict == NULL);
 
 	type->tp_flags |= Py_TPFLAGS_READYING;
--- 1736,1739 ----
***************
*** 1774,1787 ****
 	}
 
! 	/* Initialize tp_defined */
! 	dict = type->tp_defined;
 	if (dict == NULL) {
 		dict = PyDict_New();
 		if (dict == NULL)
 			goto error;
! 		type->tp_defined = dict;
 	}
 
! 	/* Add type-specific descriptors to tp_defined */
 	if (add_operators(type) < 0)
 		goto error;
--- 1762,1775 ----
 	}
 
! 	/* Initialize tp_dict */
! 	dict = type->tp_dict;
 	if (dict == NULL) {
 		dict = PyDict_New();
 		if (dict == NULL)
 			goto error;
! 		type->tp_dict = dict;
 	}
 
! 	/* Add type-specific descriptors to tp_dict */
 	if (add_operators(type) < 0)
 		goto error;
***************
*** 1799,1808 ****
 	}
 
- 	/* Temporarily make tp_dict the same object as tp_defined.
- 	 (This is needed to call mro(), and can stay this way for
- 	 dynamic types). */
- 	Py_INCREF(type->tp_defined);
- 	type->tp_dict = type->tp_defined;
- 
 	/* Calculate method resolution order */
 	if (mro_internal(type) < 0) {
--- 1787,1790 ----
***************
*** 2677,2686 ****
 	PyObject *func;
 
! 	if (PyDict_GetItemString(type->tp_defined, "__new__") != NULL)
 		return 0;
 	func = PyCFunction_New(tp_new_methoddef, (PyObject *)type);
 	if (func == NULL)
 		return -1;
! 	return PyDict_SetItemString(type->tp_defined, "__new__", func);
 }
 
--- 2659,2668 ----
 	PyObject *func;
 
! 	if (PyDict_GetItemString(type->tp_dict, "__new__") != NULL)
 		return 0;
 	func = PyCFunction_New(tp_new_methoddef, (PyObject *)type);
 	if (func == NULL)
 		return -1;
! 	return PyDict_SetItemString(type->tp_dict, "__new__", func);
 }
 
***************
*** 2688,2692 ****
 add_wrappers(PyTypeObject *type, struct wrapperbase *wraps, void *wrapped)
 {
! 	PyObject *dict = type->tp_defined;
 
 	for (; wraps->name != NULL; wraps++) {
--- 2670,2674 ----
 add_wrappers(PyTypeObject *type, struct wrapperbase *wraps, void *wrapped)
 {
! 	PyObject *dict = type->tp_dict;
 
 	for (; wraps->name != NULL; wraps++) {
***************
*** 2707,2711 ****
 dictionary with method descriptors for function slots. For each
 function slot (like tp_repr) that's defined in the type, one or
! more corresponding descriptors are added in the type's tp_defined
 dictionary under the appropriate name (like __repr__). Some
 function slots cause more than one descriptor to be added (for
--- 2689,2693 ----
 dictionary with method descriptors for function slots. For each
 function slot (like tp_repr) that's defined in the type, one or
! more corresponding descriptors are added in the type's tp_dict
 dictionary under the appropriate name (like __repr__). Some
 function slots cause more than one descriptor to be added (for
***************
*** 2714,2718 ****
 descriptor (for example both sq_item and mp_subscript generate a
 __getitem__ descriptor). This only adds new descriptors and
! doesn't overwrite entries in tp_defined that were previously
 defined. The descriptors contain a reference to the C function
 they must call, so that it's safe if they are copied into a
--- 2696,2700 ----
 descriptor (for example both sq_item and mp_subscript generate a
 __getitem__ descriptor). This only adds new descriptors and
! doesn't overwrite entries in tp_dict that were previously
 defined. The descriptors contain a reference to the C function
 they must call, so that it's safe if they are copied into a
***************
*** 3943,3947 ****
 				assert(PyType_Check(base));
 				descr = PyDict_GetItem(
! 					base->tp_defined, p->name_strobj);
 				if (descr != NULL)
 					break;
--- 3925,3929 ----
 				assert(PyType_Check(base));
 				descr = PyDict_GetItem(
! 					base->tp_dict, p->name_strobj);
 				if (descr != NULL)
 					break;
***************
*** 4056,4060 ****
 			assert(PyType_Check(tmp));
 			res = PyDict_GetItem(
! 				((PyTypeObject *)tmp)->tp_defined, name);
 			if (res != NULL) {
 				Py_INCREF(res);
--- 4038,4042 ----
 			assert(PyType_Check(tmp));
 			res = PyDict_GetItem(
! 				((PyTypeObject *)tmp)->tp_dict, name);
 			if (res != NULL) {
 				Py_INCREF(res);

AltStyle によって変換されたページ (->オリジナル) /