| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | /* Descriptors -- a new, flexible way to describe attributes */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Python.h"
 | 
					
						
							|  |  |  | #include "structmember.h" /* Why is this not included in Python.h? */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | descr_dealloc(PyDescrObject *descr) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	_PyObject_GC_UNTRACK(descr); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	Py_XDECREF(descr->d_type); | 
					
						
							|  |  |  | 	Py_XDECREF(descr->d_name); | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	PyObject_GC_Del(descr); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char * | 
					
						
							|  |  |  | descr_name(PyDescrObject *descr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (descr->d_name != NULL && PyString_Check(descr->d_name)) | 
					
						
							|  |  |  | 		return PyString_AS_STRING(descr->d_name); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return "?"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | descr_repr(PyDescrObject *descr, char *format) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2001-08-24 18:34:26 +00:00
										 |  |  | 	return PyString_FromFormat(format, descr_name(descr), | 
					
						
							|  |  |  | 				   descr->d_type->tp_name); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | method_repr(PyMethodDescrObject *descr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return descr_repr((PyDescrObject *)descr,  | 
					
						
							| 
									
										
										
										
											2001-08-24 18:34:26 +00:00
										 |  |  | 			  "<method '%s' of '%s' objects>"); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | member_repr(PyMemberDescrObject *descr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return descr_repr((PyDescrObject *)descr,  | 
					
						
							| 
									
										
										
										
											2001-08-24 18:34:26 +00:00
										 |  |  | 			  "<member '%s' of '%s' objects>"); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | getset_repr(PyGetSetDescrObject *descr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return descr_repr((PyDescrObject *)descr,  | 
					
						
							| 
									
										
										
										
											2001-08-24 18:34:26 +00:00
										 |  |  | 			  "<attribute '%s' of '%s' objects>"); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | wrapper_repr(PyWrapperDescrObject *descr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return descr_repr((PyDescrObject *)descr,  | 
					
						
							| 
									
										
										
										
											2001-08-24 18:34:26 +00:00
										 |  |  | 			  "<slot wrapper '%s' of '%s' objects>"); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | descr_check(PyDescrObject *descr, PyObject *obj, PyTypeObject *type, | 
					
						
							| 
									
										
										
										
											2001-08-16 08:27:33 +00:00
										 |  |  | 	    PyObject **pres) | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2001-08-16 08:27:33 +00:00
										 |  |  | 	if (obj == NULL || (obj == Py_None && type != Py_None->ob_type)) { | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 		Py_INCREF(descr); | 
					
						
							|  |  |  | 		*pres = (PyObject *)descr; | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-08-19 16:02:33 +00:00
										 |  |  | 	if (!PyObject_TypeCheck(obj, descr->d_type)) { | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2001-08-24 18:34:26 +00:00
										 |  |  | 			     "descriptor '%s' for '%s' objects " | 
					
						
							|  |  |  | 			     "doesn't apply to '%s' object", | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 			     descr_name((PyDescrObject *)descr), | 
					
						
							|  |  |  | 			     descr->d_type->tp_name, | 
					
						
							|  |  |  | 			     obj->ob_type->tp_name); | 
					
						
							|  |  |  | 		*pres = NULL; | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-09 22:56:13 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | classmethod_get(PyMethodDescrObject *descr, PyObject *obj, | 
					
						
							|  |  |  | 		PyTypeObject *type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyCFunction_New(descr->d_method, (PyObject *)type); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | method_get(PyMethodDescrObject *descr, PyObject *obj, PyTypeObject *type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (descr_check((PyDescrObject *)descr, obj, type, &res)) | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 	return PyCFunction_New(descr->d_method, obj); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | member_get(PyMemberDescrObject *descr, PyObject *obj, PyTypeObject *type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (descr_check((PyDescrObject *)descr, obj, type, &res)) | 
					
						
							|  |  |  | 		return res; | 
					
						
							| 
									
										
										
										
											2001-09-20 20:46:19 +00:00
										 |  |  | 	return PyMember_GetOne((char *)obj, descr->d_member); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | getset_get(PyGetSetDescrObject *descr, PyObject *obj, PyTypeObject *type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (descr_check((PyDescrObject *)descr, obj, type, &res)) | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 	if (descr->d_getset->get != NULL) | 
					
						
							|  |  |  | 		return descr->d_getset->get(obj, descr->d_getset->closure); | 
					
						
							|  |  |  | 	PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2001-12-15 05:00:30 +00:00
										 |  |  | 		     "attribute '%.300s' of '%.100s' objects is not readable", | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 		     descr_name((PyDescrObject *)descr), | 
					
						
							|  |  |  | 		     descr->d_type->tp_name); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | wrapper_get(PyWrapperDescrObject *descr, PyObject *obj, PyTypeObject *type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (descr_check((PyDescrObject *)descr, obj, type, &res)) | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 	return PyWrapper_New((PyObject *)descr, obj); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | descr_setcheck(PyDescrObject *descr, PyObject *obj, PyObject *value, | 
					
						
							|  |  |  | 	       int *pres) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	assert(obj != NULL); | 
					
						
							|  |  |  | 	if (!PyObject_IsInstance(obj, (PyObject *)(descr->d_type))) { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 			     "descriptor '%.200s' for '%.100s' objects " | 
					
						
							|  |  |  | 			     "doesn't apply to '%.100s' object", | 
					
						
							|  |  |  | 			     descr_name(descr), | 
					
						
							|  |  |  | 			     descr->d_type->tp_name, | 
					
						
							|  |  |  | 			     obj->ob_type->tp_name); | 
					
						
							|  |  |  | 		*pres = -1; | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | member_set(PyMemberDescrObject *descr, PyObject *obj, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (descr_setcheck((PyDescrObject *)descr, obj, value, &res)) | 
					
						
							|  |  |  | 		return res; | 
					
						
							| 
									
										
										
										
											2001-09-20 20:46:19 +00:00
										 |  |  | 	return PyMember_SetOne((char *)obj, descr->d_member, value); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | getset_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (descr_setcheck((PyDescrObject *)descr, obj, value, &res)) | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 	if (descr->d_getset->set != NULL) | 
					
						
							|  |  |  | 		return descr->d_getset->set(obj, value, | 
					
						
							|  |  |  | 					    descr->d_getset->closure); | 
					
						
							|  |  |  | 	PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2001-12-15 05:00:30 +00:00
										 |  |  | 		     "attribute '%.300s' of '%.100s' objects is not writable", | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 		     descr_name((PyDescrObject *)descr), | 
					
						
							|  |  |  | 		     descr->d_type->tp_name); | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int argc; | 
					
						
							|  |  |  | 	PyObject *self, *func, *result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Make sure that the first argument is acceptable as 'self' */ | 
					
						
							|  |  |  | 	assert(PyTuple_Check(args)); | 
					
						
							|  |  |  | 	argc = PyTuple_GET_SIZE(args); | 
					
						
							|  |  |  | 	if (argc < 1) { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 			     "descriptor '%.300s' of '%.100s' " | 
					
						
							|  |  |  | 			     "object needs an argument", | 
					
						
							|  |  |  | 			     descr_name((PyDescrObject *)descr), | 
					
						
							|  |  |  | 			     descr->d_type->tp_name); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	self = PyTuple_GET_ITEM(args, 0); | 
					
						
							|  |  |  | 	if (!PyObject_IsInstance(self, (PyObject *)(descr->d_type))) { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 			     "descriptor '%.200s' " | 
					
						
							|  |  |  | 			     "requires a '%.100s' object " | 
					
						
							|  |  |  | 			     "but received a '%.100s'", | 
					
						
							|  |  |  | 			     descr_name((PyDescrObject *)descr), | 
					
						
							|  |  |  | 			     descr->d_type->tp_name, | 
					
						
							|  |  |  | 			     self->ob_type->tp_name); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	func = PyCFunction_New(descr->d_method, self); | 
					
						
							|  |  |  | 	if (func == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	args = PyTuple_GetSlice(args, 1, argc); | 
					
						
							|  |  |  | 	if (args == NULL) { | 
					
						
							|  |  |  | 		Py_DECREF(func); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	result = PyEval_CallObjectWithKeywords(func, args, kwds); | 
					
						
							|  |  |  | 	Py_DECREF(args); | 
					
						
							|  |  |  | 	Py_DECREF(func); | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-09 22:56:13 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, | 
					
						
							|  |  |  | 		      PyObject *kwds) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *func, *result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	func = PyCFunction_New(descr->d_method, (PyObject *)descr->d_type); | 
					
						
							|  |  |  | 	if (func == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	result = PyEval_CallObjectWithKeywords(func, args, kwds); | 
					
						
							|  |  |  | 	Py_DECREF(func); | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int argc; | 
					
						
							|  |  |  | 	PyObject *self, *func, *result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Make sure that the first argument is acceptable as 'self' */ | 
					
						
							|  |  |  | 	assert(PyTuple_Check(args)); | 
					
						
							|  |  |  | 	argc = PyTuple_GET_SIZE(args); | 
					
						
							|  |  |  | 	if (argc < 1) { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 			     "descriptor '%.300s' of '%.100s' " | 
					
						
							|  |  |  | 			     "object needs an argument", | 
					
						
							|  |  |  | 			     descr_name((PyDescrObject *)descr), | 
					
						
							|  |  |  | 			     descr->d_type->tp_name); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	self = PyTuple_GET_ITEM(args, 0); | 
					
						
							|  |  |  | 	if (!PyObject_IsInstance(self, (PyObject *)(descr->d_type))) { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 			     "descriptor '%.200s' " | 
					
						
							|  |  |  | 			     "requires a '%.100s' object " | 
					
						
							|  |  |  | 			     "but received a '%.100s'", | 
					
						
							|  |  |  | 			     descr_name((PyDescrObject *)descr), | 
					
						
							|  |  |  | 			     descr->d_type->tp_name, | 
					
						
							|  |  |  | 			     self->ob_type->tp_name); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	func = PyWrapper_New((PyObject *)descr, self); | 
					
						
							|  |  |  | 	if (func == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	args = PyTuple_GetSlice(args, 1, argc); | 
					
						
							|  |  |  | 	if (args == NULL) { | 
					
						
							|  |  |  | 		Py_DECREF(func); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	result = PyEval_CallObjectWithKeywords(func, args, kwds); | 
					
						
							|  |  |  | 	Py_DECREF(args); | 
					
						
							|  |  |  | 	Py_DECREF(func); | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-09-20 20:46:19 +00:00
										 |  |  | method_get_doc(PyMethodDescrObject *descr, void *closure) | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (descr->d_method->ml_doc == NULL) { | 
					
						
							|  |  |  | 		Py_INCREF(Py_None); | 
					
						
							|  |  |  | 		return Py_None; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return PyString_FromString(descr->d_method->ml_doc); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-20 20:46:19 +00:00
										 |  |  | static PyMemberDef descr_members[] = { | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	{"__objclass__", T_OBJECT, offsetof(PyDescrObject, d_type), READONLY}, | 
					
						
							|  |  |  | 	{"__name__", T_OBJECT, offsetof(PyDescrObject, d_name), READONLY}, | 
					
						
							|  |  |  | 	{0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-20 21:45:26 +00:00
										 |  |  | static PyGetSetDef method_getset[] = { | 
					
						
							| 
									
										
										
										
											2001-09-20 20:46:19 +00:00
										 |  |  | 	{"__doc__", (getter)method_get_doc}, | 
					
						
							|  |  |  | 	{0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | member_get_doc(PyMemberDescrObject *descr, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (descr->d_member->doc == NULL) { | 
					
						
							|  |  |  | 		Py_INCREF(Py_None); | 
					
						
							|  |  |  | 		return Py_None; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return PyString_FromString(descr->d_member->doc); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-20 21:45:26 +00:00
										 |  |  | static PyGetSetDef member_getset[] = { | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	{"__doc__", (getter)member_get_doc}, | 
					
						
							|  |  |  | 	{0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-20 21:45:26 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | getset_get_doc(PyGetSetDescrObject *descr, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (descr->d_getset->doc == NULL) { | 
					
						
							|  |  |  | 		Py_INCREF(Py_None); | 
					
						
							|  |  |  | 		return Py_None; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return PyString_FromString(descr->d_getset->doc); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyGetSetDef getset_getset[] = { | 
					
						
							|  |  |  | 	{"__doc__", (getter)getset_get_doc}, | 
					
						
							|  |  |  | 	{0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | wrapper_get_doc(PyWrapperDescrObject *descr, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (descr->d_base->doc == NULL) { | 
					
						
							|  |  |  | 		Py_INCREF(Py_None); | 
					
						
							|  |  |  | 		return Py_None; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return PyString_FromString(descr->d_base->doc); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-20 21:45:26 +00:00
										 |  |  | static PyGetSetDef wrapper_getset[] = { | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	{"__doc__", (getter)wrapper_get_doc}, | 
					
						
							|  |  |  | 	{0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | descr_traverse(PyObject *self, visitproc visit, void *arg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyDescrObject *descr = (PyDescrObject *)self; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (descr->d_type) { | 
					
						
							|  |  |  | 		err = visit((PyObject *)(descr->d_type), arg); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | static PyTypeObject PyMethodDescr_Type = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	"method_descriptor", | 
					
						
							|  |  |  | 	sizeof(PyMethodDescrObject), | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	(destructor)descr_dealloc,		/* tp_dealloc */ | 
					
						
							|  |  |  | 	0,					/* tp_print */ | 
					
						
							|  |  |  | 	0,					/* tp_getattr */ | 
					
						
							|  |  |  | 	0,					/* tp_setattr */ | 
					
						
							|  |  |  | 	0,					/* tp_compare */ | 
					
						
							|  |  |  | 	(reprfunc)method_repr,			/* tp_repr */ | 
					
						
							|  |  |  | 	0,					/* tp_as_number */ | 
					
						
							|  |  |  | 	0,					/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,					/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,					/* tp_hash */ | 
					
						
							|  |  |  | 	(ternaryfunc)methoddescr_call,		/* tp_call */ | 
					
						
							|  |  |  | 	0,					/* tp_str */ | 
					
						
							|  |  |  | 	PyObject_GenericGetAttr,		/* tp_getattro */ | 
					
						
							|  |  |  | 	0,					/* tp_setattro */ | 
					
						
							|  |  |  | 	0,					/* tp_as_buffer */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_doc */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	descr_traverse,				/* tp_traverse */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_clear */ | 
					
						
							|  |  |  | 	0,					/* tp_richcompare */ | 
					
						
							|  |  |  | 	0,					/* tp_weaklistoffset */ | 
					
						
							|  |  |  | 	0,					/* tp_iter */ | 
					
						
							|  |  |  | 	0,					/* tp_iternext */ | 
					
						
							|  |  |  | 	0,					/* tp_methods */ | 
					
						
							|  |  |  | 	descr_members,				/* tp_members */ | 
					
						
							| 
									
										
										
										
											2001-09-20 20:46:19 +00:00
										 |  |  | 	method_getset,				/* tp_getset */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_base */ | 
					
						
							|  |  |  | 	0,					/* tp_dict */ | 
					
						
							|  |  |  | 	(descrgetfunc)method_get,		/* tp_descr_get */ | 
					
						
							|  |  |  | 	0,					/* tp_descr_set */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-09 22:56:13 +00:00
										 |  |  | static PyTypeObject PyClassMethodDescr_Type = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	"special_method_descriptor", | 
					
						
							|  |  |  | 	sizeof(PyMethodDescrObject), | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	(destructor)descr_dealloc,		/* tp_dealloc */ | 
					
						
							|  |  |  | 	0,					/* tp_print */ | 
					
						
							|  |  |  | 	0,					/* tp_getattr */ | 
					
						
							|  |  |  | 	0,					/* tp_setattr */ | 
					
						
							|  |  |  | 	0,					/* tp_compare */ | 
					
						
							|  |  |  | 	(reprfunc)method_repr,			/* tp_repr */ | 
					
						
							|  |  |  | 	0,					/* tp_as_number */ | 
					
						
							|  |  |  | 	0,					/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,					/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,					/* tp_hash */ | 
					
						
							|  |  |  | 	(ternaryfunc)classmethoddescr_call,		/* tp_call */ | 
					
						
							|  |  |  | 	0,					/* tp_str */ | 
					
						
							|  |  |  | 	PyObject_GenericGetAttr,		/* tp_getattro */ | 
					
						
							|  |  |  | 	0,					/* tp_setattro */ | 
					
						
							|  |  |  | 	0,					/* tp_as_buffer */ | 
					
						
							|  |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ | 
					
						
							|  |  |  | 	0,					/* tp_doc */ | 
					
						
							|  |  |  | 	descr_traverse,				/* tp_traverse */ | 
					
						
							|  |  |  | 	0,					/* tp_clear */ | 
					
						
							|  |  |  | 	0,					/* tp_richcompare */ | 
					
						
							|  |  |  | 	0,					/* tp_weaklistoffset */ | 
					
						
							|  |  |  | 	0,					/* tp_iter */ | 
					
						
							|  |  |  | 	0,					/* tp_iternext */ | 
					
						
							|  |  |  | 	0,					/* tp_methods */ | 
					
						
							|  |  |  | 	descr_members,				/* tp_members */ | 
					
						
							|  |  |  | 	method_getset,				/* tp_getset */ | 
					
						
							|  |  |  | 	0,					/* tp_base */ | 
					
						
							|  |  |  | 	0,					/* tp_dict */ | 
					
						
							|  |  |  | 	(descrgetfunc)classmethod_get,		/* tp_descr_get */ | 
					
						
							|  |  |  | 	0,					/* tp_descr_set */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | static PyTypeObject PyMemberDescr_Type = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	"member_descriptor", | 
					
						
							|  |  |  | 	sizeof(PyMemberDescrObject), | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	(destructor)descr_dealloc,		/* tp_dealloc */ | 
					
						
							|  |  |  | 	0,					/* tp_print */ | 
					
						
							|  |  |  | 	0,					/* tp_getattr */ | 
					
						
							|  |  |  | 	0,					/* tp_setattr */ | 
					
						
							|  |  |  | 	0,					/* tp_compare */ | 
					
						
							|  |  |  | 	(reprfunc)member_repr,			/* tp_repr */ | 
					
						
							|  |  |  | 	0,					/* tp_as_number */ | 
					
						
							|  |  |  | 	0,					/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,					/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,					/* tp_hash */ | 
					
						
							|  |  |  | 	(ternaryfunc)0,				/* tp_call */ | 
					
						
							|  |  |  | 	0,					/* tp_str */ | 
					
						
							|  |  |  | 	PyObject_GenericGetAttr,		/* tp_getattro */ | 
					
						
							|  |  |  | 	0,					/* tp_setattro */ | 
					
						
							|  |  |  | 	0,					/* tp_as_buffer */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_doc */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	descr_traverse,				/* tp_traverse */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_clear */ | 
					
						
							|  |  |  | 	0,					/* tp_richcompare */ | 
					
						
							|  |  |  | 	0,					/* tp_weaklistoffset */ | 
					
						
							|  |  |  | 	0,					/* tp_iter */ | 
					
						
							|  |  |  | 	0,					/* tp_iternext */ | 
					
						
							|  |  |  | 	0,					/* tp_methods */ | 
					
						
							|  |  |  | 	descr_members,				/* tp_members */ | 
					
						
							| 
									
										
										
										
											2001-09-20 20:46:19 +00:00
										 |  |  | 	member_getset,				/* tp_getset */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_base */ | 
					
						
							|  |  |  | 	0,					/* tp_dict */ | 
					
						
							|  |  |  | 	(descrgetfunc)member_get,		/* tp_descr_get */ | 
					
						
							|  |  |  | 	(descrsetfunc)member_set,		/* tp_descr_set */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyTypeObject PyGetSetDescr_Type = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	"getset_descriptor", | 
					
						
							|  |  |  | 	sizeof(PyGetSetDescrObject), | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	(destructor)descr_dealloc,		/* tp_dealloc */ | 
					
						
							|  |  |  | 	0,					/* tp_print */ | 
					
						
							|  |  |  | 	0,					/* tp_getattr */ | 
					
						
							|  |  |  | 	0,					/* tp_setattr */ | 
					
						
							|  |  |  | 	0,					/* tp_compare */ | 
					
						
							|  |  |  | 	(reprfunc)getset_repr,			/* tp_repr */ | 
					
						
							|  |  |  | 	0,					/* tp_as_number */ | 
					
						
							|  |  |  | 	0,					/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,					/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,					/* tp_hash */ | 
					
						
							|  |  |  | 	(ternaryfunc)0,				/* tp_call */ | 
					
						
							|  |  |  | 	0,					/* tp_str */ | 
					
						
							|  |  |  | 	PyObject_GenericGetAttr,		/* tp_getattro */ | 
					
						
							|  |  |  | 	0,					/* tp_setattro */ | 
					
						
							|  |  |  | 	0,					/* tp_as_buffer */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_doc */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	descr_traverse,				/* tp_traverse */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_clear */ | 
					
						
							|  |  |  | 	0,					/* tp_richcompare */ | 
					
						
							|  |  |  | 	0,					/* tp_weaklistoffset */ | 
					
						
							|  |  |  | 	0,					/* tp_iter */ | 
					
						
							|  |  |  | 	0,					/* tp_iternext */ | 
					
						
							|  |  |  | 	0,					/* tp_methods */ | 
					
						
							|  |  |  | 	descr_members,				/* tp_members */ | 
					
						
							| 
									
										
										
										
											2001-09-20 21:45:26 +00:00
										 |  |  | 	getset_getset,				/* tp_getset */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_base */ | 
					
						
							|  |  |  | 	0,					/* tp_dict */ | 
					
						
							|  |  |  | 	(descrgetfunc)getset_get,		/* tp_descr_get */ | 
					
						
							|  |  |  | 	(descrsetfunc)getset_set,		/* tp_descr_set */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-03 12:09:30 +00:00
										 |  |  | PyTypeObject PyWrapperDescr_Type = { | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	"wrapper_descriptor", | 
					
						
							|  |  |  | 	sizeof(PyWrapperDescrObject), | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	(destructor)descr_dealloc,		/* tp_dealloc */ | 
					
						
							|  |  |  | 	0,					/* tp_print */ | 
					
						
							|  |  |  | 	0,					/* tp_getattr */ | 
					
						
							|  |  |  | 	0,					/* tp_setattr */ | 
					
						
							|  |  |  | 	0,					/* tp_compare */ | 
					
						
							|  |  |  | 	(reprfunc)wrapper_repr,			/* tp_repr */ | 
					
						
							|  |  |  | 	0,					/* tp_as_number */ | 
					
						
							|  |  |  | 	0,					/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,					/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,					/* tp_hash */ | 
					
						
							|  |  |  | 	(ternaryfunc)wrapperdescr_call,		/* tp_call */ | 
					
						
							|  |  |  | 	0,					/* tp_str */ | 
					
						
							|  |  |  | 	PyObject_GenericGetAttr,		/* tp_getattro */ | 
					
						
							|  |  |  | 	0,					/* tp_setattro */ | 
					
						
							|  |  |  | 	0,					/* tp_as_buffer */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_doc */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	descr_traverse,				/* tp_traverse */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_clear */ | 
					
						
							|  |  |  | 	0,					/* tp_richcompare */ | 
					
						
							|  |  |  | 	0,					/* tp_weaklistoffset */ | 
					
						
							|  |  |  | 	0,					/* tp_iter */ | 
					
						
							|  |  |  | 	0,					/* tp_iternext */ | 
					
						
							|  |  |  | 	0,					/* tp_methods */ | 
					
						
							|  |  |  | 	descr_members,				/* tp_members */ | 
					
						
							|  |  |  | 	wrapper_getset,				/* tp_getset */ | 
					
						
							|  |  |  | 	0,					/* tp_base */ | 
					
						
							|  |  |  | 	0,					/* tp_dict */ | 
					
						
							|  |  |  | 	(descrgetfunc)wrapper_get,		/* tp_descr_get */ | 
					
						
							|  |  |  | 	0,					/* tp_descr_set */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyDescrObject * | 
					
						
							|  |  |  | descr_new(PyTypeObject *descrtype, PyTypeObject *type, char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyDescrObject *descr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	descr = (PyDescrObject *)PyType_GenericAlloc(descrtype, 0); | 
					
						
							|  |  |  | 	if (descr != NULL) { | 
					
						
							|  |  |  | 		Py_XINCREF(type); | 
					
						
							|  |  |  | 		descr->d_type = type; | 
					
						
							|  |  |  | 		descr->d_name = PyString_InternFromString(name); | 
					
						
							|  |  |  | 		if (descr->d_name == NULL) { | 
					
						
							|  |  |  | 			Py_DECREF(descr); | 
					
						
							|  |  |  | 			descr = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return descr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyDescr_NewMethod(PyTypeObject *type, PyMethodDef *method) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyMethodDescrObject *descr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	descr = (PyMethodDescrObject *)descr_new(&PyMethodDescr_Type, | 
					
						
							|  |  |  | 						 type, method->ml_name); | 
					
						
							|  |  |  | 	if (descr != NULL) | 
					
						
							|  |  |  | 		descr->d_method = method; | 
					
						
							|  |  |  | 	return (PyObject *)descr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-09 22:56:13 +00:00
										 |  |  | PyObject * | 
					
						
							|  |  |  | PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyMethodDescrObject *descr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	descr = (PyMethodDescrObject *)descr_new(&PyClassMethodDescr_Type, | 
					
						
							|  |  |  | 						 type, method->ml_name); | 
					
						
							|  |  |  | 	if (descr != NULL) | 
					
						
							|  |  |  | 		descr->d_method = method; | 
					
						
							|  |  |  | 	return (PyObject *)descr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | PyObject * | 
					
						
							| 
									
										
										
										
											2001-09-20 20:46:19 +00:00
										 |  |  | PyDescr_NewMember(PyTypeObject *type, PyMemberDef *member) | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	PyMemberDescrObject *descr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	descr = (PyMemberDescrObject *)descr_new(&PyMemberDescr_Type, | 
					
						
							|  |  |  | 						 type, member->name); | 
					
						
							|  |  |  | 	if (descr != NULL) | 
					
						
							|  |  |  | 		descr->d_member = member; | 
					
						
							|  |  |  | 	return (PyObject *)descr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject * | 
					
						
							| 
									
										
										
										
											2001-09-20 21:45:26 +00:00
										 |  |  | PyDescr_NewGetSet(PyTypeObject *type, PyGetSetDef *getset) | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	PyGetSetDescrObject *descr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	descr = (PyGetSetDescrObject *)descr_new(&PyGetSetDescr_Type, | 
					
						
							|  |  |  | 						 type, getset->name); | 
					
						
							|  |  |  | 	if (descr != NULL) | 
					
						
							|  |  |  | 		descr->d_getset = getset; | 
					
						
							|  |  |  | 	return (PyObject *)descr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *base, void *wrapped) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyWrapperDescrObject *descr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	descr = (PyWrapperDescrObject *)descr_new(&PyWrapperDescr_Type, | 
					
						
							|  |  |  | 						 type, base->name); | 
					
						
							|  |  |  | 	if (descr != NULL) { | 
					
						
							|  |  |  | 		descr->d_base = base; | 
					
						
							|  |  |  | 		descr->d_wrapped = wrapped; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return (PyObject *)descr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* --- Readonly proxy for dictionaries (actually any mapping) --- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* This has no reason to be in this file except that adding new files is a
 | 
					
						
							|  |  |  |    bit of a pain */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  | 	PyObject_HEAD | 
					
						
							|  |  |  | 	PyObject *dict; | 
					
						
							|  |  |  | } proxyobject; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | proxy_len(proxyobject *pp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyObject_Size(pp->dict); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | proxy_getitem(proxyobject *pp, PyObject *key) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyObject_GetItem(pp->dict, key); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMappingMethods proxy_as_mapping = { | 
					
						
							|  |  |  | 	(inquiry)proxy_len,			/* mp_length */ | 
					
						
							|  |  |  | 	(binaryfunc)proxy_getitem,		/* mp_subscript */ | 
					
						
							|  |  |  | 	0,					/* mp_ass_subscript */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | proxy_contains(proxyobject *pp, PyObject *key) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PySequence_Contains(pp->dict, key); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PySequenceMethods proxy_as_sequence = { | 
					
						
							|  |  |  | 	0,					/* sq_length */ | 
					
						
							|  |  |  | 	0,					/* sq_concat */ | 
					
						
							|  |  |  | 	0,					/* sq_repeat */ | 
					
						
							|  |  |  | 	0,					/* sq_item */ | 
					
						
							|  |  |  | 	0,					/* sq_slice */ | 
					
						
							|  |  |  | 	0,					/* sq_ass_item */ | 
					
						
							|  |  |  | 	0,					/* sq_ass_slice */ | 
					
						
							|  |  |  | 	(objobjproc)proxy_contains,		/* sq_contains */ | 
					
						
							|  |  |  | 	0,					/* sq_inplace_concat */ | 
					
						
							|  |  |  | 	0,					/* sq_inplace_repeat */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-16 13:15:00 +00:00
										 |  |  | proxy_has_key(proxyobject *pp, PyObject *key) | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return PyInt_FromLong(PySequence_Contains(pp->dict, key)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | proxy_get(proxyobject *pp, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *key, *def = Py_None; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-29 16:33:45 +00:00
										 |  |  | 	if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &def)) | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	return PyObject_CallMethod(pp->dict, "get", "(OO)", key, def); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-16 13:15:00 +00:00
										 |  |  | proxy_keys(proxyobject *pp) | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return PyMapping_Keys(pp->dict); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-16 13:15:00 +00:00
										 |  |  | proxy_values(proxyobject *pp) | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return PyMapping_Values(pp->dict); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-16 13:15:00 +00:00
										 |  |  | proxy_items(proxyobject *pp) | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return PyMapping_Items(pp->dict); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-03-25 17:43:22 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | proxy_iterkeys(proxyobject *pp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyObject_CallMethod(pp->dict, "iterkeys", NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | proxy_itervalues(proxyobject *pp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyObject_CallMethod(pp->dict, "itervalues", NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | proxy_iteritems(proxyobject *pp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyObject_CallMethod(pp->dict, "iteritems", NULL); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-16 13:15:00 +00:00
										 |  |  | proxy_copy(proxyobject *pp) | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return PyObject_CallMethod(pp->dict, "copy", NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMethodDef proxy_methods[] = { | 
					
						
							| 
									
										
										
										
											2002-04-13 14:06:36 +00:00
										 |  |  | 	{"has_key",   (PyCFunction)proxy_has_key,    METH_O, | 
					
						
							| 
									
										
										
										
											2002-08-13 22:19:13 +00:00
										 |  |  | 	 PyDoc_STR("D.has_key(k) -> 1 if D has a key k, else 0")}, | 
					
						
							| 
									
										
										
										
											2002-04-13 14:06:36 +00:00
										 |  |  | 	{"get",       (PyCFunction)proxy_get,        METH_VARARGS, | 
					
						
							| 
									
										
										
										
											2002-08-13 22:19:13 +00:00
										 |  |  | 	 PyDoc_STR("D.get(k[,d]) -> D[k] if D.has_key(k), else d." | 
					
						
							|  |  |  | 	 				"  d defaults to None.")}, | 
					
						
							| 
									
										
										
										
											2002-04-13 14:06:36 +00:00
										 |  |  | 	{"keys",      (PyCFunction)proxy_keys,       METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2002-08-13 22:19:13 +00:00
										 |  |  | 	 PyDoc_STR("D.keys() -> list of D's keys")}, | 
					
						
							| 
									
										
										
										
											2002-04-13 14:06:36 +00:00
										 |  |  | 	{"values",    (PyCFunction)proxy_values,     METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2002-08-13 22:19:13 +00:00
										 |  |  | 	 PyDoc_STR("D.values() -> list of D's values")}, | 
					
						
							| 
									
										
										
										
											2002-04-13 14:06:36 +00:00
										 |  |  | 	{"items",     (PyCFunction)proxy_items,      METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2002-08-13 22:19:13 +00:00
										 |  |  | 	 PyDoc_STR("D.items() -> list of D's (key, value) pairs, as 2-tuples")}, | 
					
						
							| 
									
										
										
										
											2002-04-13 14:06:36 +00:00
										 |  |  | 	{"iterkeys",  (PyCFunction)proxy_iterkeys,   METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2002-08-13 22:19:13 +00:00
										 |  |  | 	 PyDoc_STR("D.iterkeys() -> an iterator over the keys of D")}, | 
					
						
							| 
									
										
										
										
											2002-04-13 14:06:36 +00:00
										 |  |  | 	{"itervalues",(PyCFunction)proxy_itervalues, METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2002-08-13 22:19:13 +00:00
										 |  |  | 	 PyDoc_STR("D.itervalues() -> an iterator over the values of D")}, | 
					
						
							| 
									
										
										
										
											2002-04-13 14:06:36 +00:00
										 |  |  | 	{"iteritems", (PyCFunction)proxy_iteritems,  METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2002-08-13 22:19:13 +00:00
										 |  |  | 	 PyDoc_STR("D.iteritems() ->" | 
					
						
							|  |  |  | 	 	   " an iterator over the (key, value) items of D")}, | 
					
						
							| 
									
										
										
										
											2002-04-13 14:06:36 +00:00
										 |  |  | 	{"copy",      (PyCFunction)proxy_copy,       METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2002-08-13 22:19:13 +00:00
										 |  |  | 	 PyDoc_STR("D.copy() -> a shallow copy of D")}, | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	{0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | proxy_dealloc(proxyobject *pp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	_PyObject_GC_UNTRACK(pp); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	Py_DECREF(pp->dict); | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	PyObject_GC_Del(pp); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | proxy_getiter(proxyobject *pp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyObject_GetIter(pp->dict); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-21 22:26:43 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | proxy_str(proxyobject *pp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyObject_Str(pp->dict); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | proxy_traverse(PyObject *self, visitproc visit, void *arg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	proxyobject *pp = (proxyobject *)self; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (pp->dict) { | 
					
						
							|  |  |  | 		err = visit(pp->dict, arg); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-08-31 15:51:04 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | proxy_compare(proxyobject *v, PyObject *w) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyObject_Compare(v->dict, w); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | proxy_richcompare(proxyobject *v, PyObject *w, int op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyObject_RichCompare(v->dict, w, op); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-21 22:26:43 +00:00
										 |  |  | static PyTypeObject proxytype = { | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0,					/* ob_size */ | 
					
						
							| 
									
										
										
										
											2002-06-14 20:41:17 +00:00
										 |  |  | 	"dictproxy",				/* tp_name */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	sizeof(proxyobject),			/* tp_basicsize */ | 
					
						
							|  |  |  | 	0,					/* tp_itemsize */ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	(destructor)proxy_dealloc, 		/* tp_dealloc */ | 
					
						
							|  |  |  | 	0,					/* tp_print */ | 
					
						
							|  |  |  | 	0,					/* tp_getattr */ | 
					
						
							|  |  |  | 	0,					/* tp_setattr */ | 
					
						
							| 
									
										
										
										
											2002-08-31 15:51:04 +00:00
										 |  |  | 	(cmpfunc)proxy_compare,			/* tp_compare */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_repr */ | 
					
						
							|  |  |  | 	0,					/* tp_as_number */ | 
					
						
							|  |  |  | 	&proxy_as_sequence,			/* tp_as_sequence */ | 
					
						
							|  |  |  | 	&proxy_as_mapping,			/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,					/* tp_hash */ | 
					
						
							|  |  |  | 	0,					/* tp_call */ | 
					
						
							|  |  |  | 	(reprfunc)proxy_str,			/* tp_str */ | 
					
						
							|  |  |  | 	PyObject_GenericGetAttr,		/* tp_getattro */ | 
					
						
							|  |  |  | 	0,					/* tp_setattro */ | 
					
						
							|  |  |  | 	0,					/* tp_as_buffer */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  |  	0,					/* tp_doc */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	proxy_traverse,				/* tp_traverse */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  |  	0,					/* tp_clear */ | 
					
						
							| 
									
										
										
										
											2002-08-31 15:51:04 +00:00
										 |  |  | 	(richcmpfunc)proxy_richcompare,		/* tp_richcompare */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	0,					/* tp_weaklistoffset */ | 
					
						
							|  |  |  | 	(getiterfunc)proxy_getiter,		/* tp_iter */ | 
					
						
							|  |  |  | 	0,					/* tp_iternext */ | 
					
						
							|  |  |  | 	proxy_methods,				/* tp_methods */ | 
					
						
							|  |  |  | 	0,					/* tp_members */ | 
					
						
							|  |  |  | 	0,					/* tp_getset */ | 
					
						
							|  |  |  | 	0,					/* tp_base */ | 
					
						
							|  |  |  | 	0,					/* tp_dict */ | 
					
						
							|  |  |  | 	0,					/* tp_descr_get */ | 
					
						
							|  |  |  | 	0,					/* tp_descr_set */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyDictProxy_New(PyObject *dict) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	proxyobject *pp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	pp = PyObject_GC_New(proxyobject, &proxytype); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	if (pp != NULL) { | 
					
						
							|  |  |  | 		Py_INCREF(dict); | 
					
						
							|  |  |  | 		pp->dict = dict; | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 		_PyObject_GC_TRACK(pp); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return (PyObject *)pp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* --- Wrapper object for "slot" methods --- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* This has no reason to be in this file except that adding new files is a
 | 
					
						
							|  |  |  |    bit of a pain */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  | 	PyObject_HEAD | 
					
						
							|  |  |  | 	PyWrapperDescrObject *descr; | 
					
						
							|  |  |  | 	PyObject *self; | 
					
						
							|  |  |  | } wrapperobject; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | wrapper_dealloc(wrapperobject *wp) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	_PyObject_GC_UNTRACK(wp); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	Py_XDECREF(wp->descr); | 
					
						
							|  |  |  | 	Py_XDECREF(wp->self); | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	PyObject_GC_Del(wp); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMethodDef wrapper_methods[] = { | 
					
						
							|  |  |  | 	{0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | wrapper_name(wrapperobject *wp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *s = wp->descr->d_base->name; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return PyString_FromString(s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | wrapper_doc(wrapperobject *wp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *s = wp->descr->d_base->doc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (s == NULL) { | 
					
						
							|  |  |  | 		Py_INCREF(Py_None); | 
					
						
							|  |  |  | 		return Py_None; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		return PyString_FromString(s); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-20 21:45:26 +00:00
										 |  |  | static PyGetSetDef wrapper_getsets[] = { | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	{"__name__", (getter)wrapper_name}, | 
					
						
							|  |  |  | 	{"__doc__", (getter)wrapper_doc}, | 
					
						
							|  |  |  | 	{0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | wrapper_call(wrapperobject *wp, PyObject *args, PyObject *kwds) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	wrapperfunc wrapper = wp->descr->d_base->wrapper; | 
					
						
							|  |  |  | 	PyObject *self = wp->self; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-22 00:43:43 +00:00
										 |  |  | 	if (wp->descr->d_base->flags & PyWrapperFlag_KEYWORDS) { | 
					
						
							|  |  |  | 		wrapperfunc_kwds wk = (wrapperfunc_kwds)wrapper; | 
					
						
							|  |  |  | 		return (*wk)(self, args, wp->descr->d_wrapped, kwds); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (kwds != NULL && (!PyDict_Check(kwds) || PyDict_Size(kwds) != 0)) { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 			     "wrapper %s doesn't take keyword arguments", | 
					
						
							|  |  |  | 			     wp->descr->d_base->name); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	return (*wrapper)(self, args, wp->descr->d_wrapped); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | wrapper_traverse(PyObject *self, visitproc visit, void *arg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	wrapperobject *wp = (wrapperobject *)self; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wp->descr) { | 
					
						
							|  |  |  | 		err = visit((PyObject *)(wp->descr), arg); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (wp->self) { | 
					
						
							|  |  |  | 		err = visit(wp->self, arg); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-21 22:26:43 +00:00
										 |  |  | static PyTypeObject wrappertype = { | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0,					/* ob_size */ | 
					
						
							|  |  |  | 	"method-wrapper",			/* tp_name */ | 
					
						
							|  |  |  | 	sizeof(wrapperobject),			/* tp_basicsize */ | 
					
						
							|  |  |  | 	0,					/* tp_itemsize */ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	(destructor)wrapper_dealloc, 		/* tp_dealloc */ | 
					
						
							|  |  |  | 	0,					/* tp_print */ | 
					
						
							|  |  |  | 	0,					/* tp_getattr */ | 
					
						
							|  |  |  | 	0,					/* tp_setattr */ | 
					
						
							|  |  |  | 	0,					/* tp_compare */ | 
					
						
							|  |  |  | 	0,					/* tp_repr */ | 
					
						
							|  |  |  | 	0,					/* tp_as_number */ | 
					
						
							|  |  |  | 	0,					/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,		       			/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,					/* tp_hash */ | 
					
						
							|  |  |  | 	(ternaryfunc)wrapper_call,		/* tp_call */ | 
					
						
							|  |  |  | 	0,					/* tp_str */ | 
					
						
							|  |  |  | 	PyObject_GenericGetAttr,		/* tp_getattro */ | 
					
						
							|  |  |  | 	0,					/* tp_setattro */ | 
					
						
							|  |  |  | 	0,					/* tp_as_buffer */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  |  	0,					/* tp_doc */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	wrapper_traverse,			/* tp_traverse */ | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  |  	0,					/* tp_clear */ | 
					
						
							|  |  |  | 	0,					/* tp_richcompare */ | 
					
						
							|  |  |  | 	0,					/* tp_weaklistoffset */ | 
					
						
							|  |  |  | 	0,					/* tp_iter */ | 
					
						
							|  |  |  | 	0,					/* tp_iternext */ | 
					
						
							|  |  |  | 	wrapper_methods,			/* tp_methods */ | 
					
						
							|  |  |  | 	0,					/* tp_members */ | 
					
						
							|  |  |  | 	wrapper_getsets,			/* tp_getset */ | 
					
						
							|  |  |  | 	0,					/* tp_base */ | 
					
						
							|  |  |  | 	0,					/* tp_dict */ | 
					
						
							|  |  |  | 	0,					/* tp_descr_get */ | 
					
						
							|  |  |  | 	0,					/* tp_descr_set */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject * | 
					
						
							|  |  |  | PyWrapper_New(PyObject *d, PyObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	wrapperobject *wp; | 
					
						
							|  |  |  | 	PyWrapperDescrObject *descr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	assert(PyObject_TypeCheck(d, &PyWrapperDescr_Type)); | 
					
						
							|  |  |  | 	descr = (PyWrapperDescrObject *)d; | 
					
						
							|  |  |  | 	assert(PyObject_IsInstance(self, (PyObject *)(descr->d_type))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	wp = PyObject_GC_New(wrapperobject, &wrappertype); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	if (wp != NULL) { | 
					
						
							|  |  |  | 		Py_INCREF(descr); | 
					
						
							|  |  |  | 		wp->descr = descr; | 
					
						
							|  |  |  | 		Py_INCREF(self); | 
					
						
							|  |  |  | 		wp->self = self; | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 		_PyObject_GC_TRACK(wp); | 
					
						
							| 
									
										
										
										
											2001-08-02 04:15:00 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return (PyObject *)wp; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | /* A built-in 'property' type */ | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  |     class property(object): | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-12-10 18:03:34 +00:00
										 |  |  |         def __init__(self, fget=None, fset=None, fdel=None, doc=None): | 
					
						
							|  |  |  |             self.__get = fget | 
					
						
							|  |  |  |             self.__set = fset | 
					
						
							|  |  |  |             self.__del = fdel | 
					
						
							|  |  |  |             self.__doc__ = doc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def __get__(self, inst, type=None): | 
					
						
							|  |  |  |             if inst is None: | 
					
						
							|  |  |  |                 return self | 
					
						
							| 
									
										
										
										
											2001-12-10 18:06:21 +00:00
										 |  |  |             if self.__get is None: | 
					
						
							|  |  |  |                 raise AttributeError, "unreadable attribute" | 
					
						
							| 
									
										
										
										
											2001-12-10 18:03:34 +00:00
										 |  |  |             return self.__get(inst) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def __set__(self, inst, value): | 
					
						
							|  |  |  |             if self.__set is None: | 
					
						
							|  |  |  |                 raise AttributeError, "can't set attribute" | 
					
						
							|  |  |  |             return self.__set(inst, value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def __delete__(self, inst): | 
					
						
							|  |  |  |             if self.__del is None: | 
					
						
							|  |  |  |                 raise AttributeError, "can't delete attribute" | 
					
						
							|  |  |  |             return self.__del(inst) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  | 	PyObject_HEAD | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | 	PyObject *prop_get; | 
					
						
							|  |  |  | 	PyObject *prop_set; | 
					
						
							|  |  |  | 	PyObject *prop_del; | 
					
						
							|  |  |  | 	PyObject *prop_doc; | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | } propertyobject; | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | static PyMemberDef property_members[] = { | 
					
						
							|  |  |  | 	{"fget", T_OBJECT, offsetof(propertyobject, prop_get), READONLY}, | 
					
						
							|  |  |  | 	{"fset", T_OBJECT, offsetof(propertyobject, prop_set), READONLY}, | 
					
						
							|  |  |  | 	{"fdel", T_OBJECT, offsetof(propertyobject, prop_del), READONLY}, | 
					
						
							|  |  |  | 	{"__doc__",  T_OBJECT, offsetof(propertyobject, prop_doc), READONLY}, | 
					
						
							|  |  |  | 	{0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | property_dealloc(PyObject *self) | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | 	propertyobject *gs = (propertyobject *)self; | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	_PyObject_GC_UNTRACK(self); | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | 	Py_XDECREF(gs->prop_get); | 
					
						
							|  |  |  | 	Py_XDECREF(gs->prop_set); | 
					
						
							|  |  |  | 	Py_XDECREF(gs->prop_del); | 
					
						
							|  |  |  | 	Py_XDECREF(gs->prop_doc); | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 	self->ob_type->tp_free(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | property_descr_get(PyObject *self, PyObject *obj, PyObject *type) | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | 	propertyobject *gs = (propertyobject *)self; | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (obj == NULL || obj == Py_None) { | 
					
						
							|  |  |  | 		Py_INCREF(self); | 
					
						
							|  |  |  | 		return self; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-12-10 18:00:15 +00:00
										 |  |  | 	if (gs->prop_get == NULL) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_AttributeError, "unreadable attribute"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | 	return PyObject_CallFunction(gs->prop_get, "(O)", obj); | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | property_descr_set(PyObject *self, PyObject *obj, PyObject *value) | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | 	propertyobject *gs = (propertyobject *)self; | 
					
						
							| 
									
										
										
										
											2001-08-24 15:23:20 +00:00
										 |  |  | 	PyObject *func, *res; | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-24 15:23:20 +00:00
										 |  |  | 	if (value == NULL) | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | 		func = gs->prop_del; | 
					
						
							| 
									
										
										
										
											2001-08-24 15:23:20 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | 		func = gs->prop_set; | 
					
						
							| 
									
										
										
										
											2001-08-24 15:23:20 +00:00
										 |  |  | 	if (func == NULL) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  | 				value == NULL ? | 
					
						
							|  |  |  | 				"can't delete attribute" : | 
					
						
							|  |  |  | 				"can't set attribute"); | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-08-24 10:17:36 +00:00
										 |  |  | 	if (value == NULL) | 
					
						
							| 
									
										
										
										
											2001-08-24 15:23:20 +00:00
										 |  |  | 		res = PyObject_CallFunction(func, "(O)", obj); | 
					
						
							| 
									
										
										
										
											2001-08-24 10:17:36 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2001-08-24 15:23:20 +00:00
										 |  |  | 		res = PyObject_CallFunction(func, "(OO)", obj, value); | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 	if (res == NULL) | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	Py_DECREF(res); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | property_init(PyObject *self, PyObject *args, PyObject *kwds) | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | 	PyObject *get = NULL, *set = NULL, *del = NULL, *doc = NULL; | 
					
						
							|  |  |  | 	static char *kwlist[] = {"fget", "fset", "fdel", "doc", 0}; | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | 	propertyobject *gs = (propertyobject *)self; | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO:property", | 
					
						
							|  |  |  | 	     				 kwlist, &get, &set, &del, &doc)) | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 	if (get == Py_None) | 
					
						
							|  |  |  | 		get = NULL; | 
					
						
							|  |  |  | 	if (set == Py_None) | 
					
						
							|  |  |  | 		set = NULL; | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | 	if (del == Py_None) | 
					
						
							|  |  |  | 		del = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 	Py_XINCREF(get); | 
					
						
							|  |  |  | 	Py_XINCREF(set); | 
					
						
							| 
									
										
										
										
											2001-08-24 15:23:20 +00:00
										 |  |  | 	Py_XINCREF(del); | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | 	Py_XINCREF(doc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gs->prop_get = get; | 
					
						
							|  |  |  | 	gs->prop_set = set; | 
					
						
							|  |  |  | 	gs->prop_del = del; | 
					
						
							|  |  |  | 	gs->prop_doc = doc; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  | PyDoc_STRVAR(property_doc, | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | "property(fget=None, fset=None, fdel=None, doc=None) -> property attribute\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "fget is a function to be used for getting an attribute value, and likewise\n" | 
					
						
							|  |  |  | "fset is a function for setting, and fdel a function for del'ing, an\n" | 
					
						
							|  |  |  | "attribute.  Typical use is to define a managed attribute x:\n" | 
					
						
							| 
									
										
										
										
											2001-08-24 09:55:51 +00:00
										 |  |  | "class C(object):\n" | 
					
						
							|  |  |  | "    def getx(self): return self.__x\n" | 
					
						
							|  |  |  | "    def setx(self, value): self.__x = value\n" | 
					
						
							| 
									
										
										
										
											2001-08-24 15:23:20 +00:00
										 |  |  | "    def delx(self): del self.__x\n" | 
					
						
							| 
									
										
										
										
											2002-06-13 20:33:02 +00:00
										 |  |  | "    x = property(getx, setx, delx, \"I'm the 'x' property.\")"); | 
					
						
							| 
									
										
										
										
											2001-08-24 09:55:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | property_traverse(PyObject *self, visitproc visit, void *arg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	propertyobject *pp = (propertyobject *)self; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define VISIT(SLOT) \
 | 
					
						
							|  |  |  | 	if (pp->SLOT) { \ | 
					
						
							|  |  |  | 		err = visit((PyObject *)(pp->SLOT), arg); \ | 
					
						
							|  |  |  | 		if (err) \ | 
					
						
							|  |  |  | 			return err; \ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VISIT(prop_get); | 
					
						
							|  |  |  | 	VISIT(prop_set); | 
					
						
							|  |  |  | 	VISIT(prop_del); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | PyTypeObject PyProperty_Type = { | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0,					/* ob_size */ | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | 	"property",				/* tp_name */ | 
					
						
							|  |  |  | 	sizeof(propertyobject),			/* tp_basicsize */ | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 	0,					/* tp_itemsize */ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | 	property_dealloc,	 		/* tp_dealloc */ | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 	0,					/* tp_print */ | 
					
						
							|  |  |  | 	0,					/* tp_getattr */ | 
					
						
							|  |  |  | 	0,					/* tp_setattr */ | 
					
						
							|  |  |  | 	0,					/* tp_compare */ | 
					
						
							|  |  |  | 	0,					/* tp_repr */ | 
					
						
							|  |  |  | 	0,					/* tp_as_number */ | 
					
						
							|  |  |  | 	0,					/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,		       			/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,					/* tp_hash */ | 
					
						
							|  |  |  | 	0,					/* tp_call */ | 
					
						
							|  |  |  | 	0,					/* tp_str */ | 
					
						
							|  |  |  | 	PyObject_GenericGetAttr,		/* tp_getattro */ | 
					
						
							|  |  |  | 	0,					/* tp_setattro */ | 
					
						
							|  |  |  | 	0,					/* tp_as_buffer */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | | 
					
						
							|  |  |  | 		Py_TPFLAGS_BASETYPE,		/* tp_flags */ | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  |  	property_doc,				/* tp_doc */ | 
					
						
							| 
									
										
											  
											
												Add Garbage Collection support to new-style classes (not yet to their
instances).
Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)
One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).
I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
											
										 
											2001-10-02 21:24:57 +00:00
										 |  |  | 	property_traverse,			/* tp_traverse */ | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  |  	0,					/* tp_clear */ | 
					
						
							|  |  |  | 	0,					/* tp_richcompare */ | 
					
						
							|  |  |  | 	0,					/* tp_weaklistoffset */ | 
					
						
							|  |  |  | 	0,					/* tp_iter */ | 
					
						
							|  |  |  | 	0,					/* tp_iternext */ | 
					
						
							|  |  |  | 	0,					/* tp_methods */ | 
					
						
							| 
									
										
										
										
											2001-09-24 21:17:50 +00:00
										 |  |  | 	property_members,			/* tp_members */ | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 	0,					/* tp_getset */ | 
					
						
							|  |  |  | 	0,					/* tp_base */ | 
					
						
							|  |  |  | 	0,					/* tp_dict */ | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | 	property_descr_get,			/* tp_descr_get */ | 
					
						
							|  |  |  | 	property_descr_set,			/* tp_descr_set */ | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 	0,					/* tp_dictoffset */ | 
					
						
							| 
									
										
										
										
											2001-09-06 21:56:42 +00:00
										 |  |  | 	property_init,				/* tp_init */ | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | 	PyType_GenericAlloc,			/* tp_alloc */ | 
					
						
							|  |  |  | 	PyType_GenericNew,			/* tp_new */ | 
					
						
							| 
									
										
										
										
											2002-04-12 02:44:22 +00:00
										 |  |  | 	PyObject_GC_Del,               		/* tp_free */ | 
					
						
							| 
									
										
										
										
											2001-08-23 21:40:38 +00:00
										 |  |  | }; |