[Python-checkins] CVS: python/dist/src/Include object.h,2.92,2.93 objimpl.h,2.38,2.39
Guido van Rossum
gvanrossum@users.sourceforge.net
Tue, 02 Oct 2001 14:24:59 -0700
Update of /cvsroot/python/python/dist/src/Include
In directory usw-pr-cvs1:/tmp/cvs-serv30352/Include
Modified Files:
object.h objimpl.h
Log Message:
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.)
Index: object.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/object.h,v
retrieving revision 2.92
retrieving revision 2.93
diff -C2 -d -r2.92 -r2.93
*** object.h 2001/09/20 21:45:26 2.92
--- object.h 2001/10/02 21:24:56 2.93
***************
*** 286,289 ****
--- 286,290 ----
newfunc tp_new;
destructor tp_free; /* Low-level free-memory routine */
+ inquiry tp_is_gc; /* For PyObject_IS_GC */
PyObject *tp_bases;
PyObject *tp_mro; /* method resolution order */
Index: objimpl.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/objimpl.h,v
retrieving revision 2.38
retrieving revision 2.39
diff -C2 -d -r2.38 -r2.39
*** objimpl.h 2001/09/03 15:44:48 2.38
--- objimpl.h 2001/10/02 21:24:57 2.39
***************
*** 218,221 ****
--- 218,225 ----
* Garbage Collection Support
* ==========================
+ *
+ * Some of the functions and macros below are always defined; when
+ * WITH_CYCLE_GC is undefined, they simply don't do anything different
+ * than their non-GC counterparts.
*/
***************
*** 224,228 ****
/* Test if an object has a GC head */
! #define PyObject_IS_GC(o) PyType_IS_GC((o)->ob_type)
extern DL_IMPORT(PyObject *) _PyObject_GC_Malloc(PyTypeObject *, int);
--- 228,233 ----
/* Test if an object has a GC head */
! #define PyObject_IS_GC(o) (PyType_IS_GC((o)->ob_type) && \
! ((o)->ob_type->tp_is_gc == NULL || (o)->ob_type->tp_is_gc(o)))
extern DL_IMPORT(PyObject *) _PyObject_GC_Malloc(PyTypeObject *, int);
***************
*** 232,237 ****
( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) )
- #ifdef WITH_CYCLE_GC
-
extern DL_IMPORT(PyObject *) _PyObject_GC_New(PyTypeObject *);
extern DL_IMPORT(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, int);
--- 237,240 ----
***************
*** 239,242 ****
--- 242,247 ----
extern DL_IMPORT(void) _PyObject_GC_Track(PyObject *);
extern DL_IMPORT(void) _PyObject_GC_UnTrack(PyObject *);
+
+ #ifdef WITH_CYCLE_GC
/* GC information is stored BEFORE the object structure */