[Python-Dev] Re: last minute GC questions

Neil Schemenauer nascheme@enme.ucalgary.ca
Fri, 30 Jun 2000 15:12:06 -0600


On Fri, Jun 30, 2000 at 04:57:44PM -0400, Jeremy Hylton wrote:
> I've got two last minute questions.
> 
> Does it look to you like I checked in all of the changes that you and
> Vladimir discussed?

Nope.

  Neil


Index: 0.13/Include/objimpl.h
*** 0.13/Include/objimpl.h Fri, 30 Jun 2000 13:05:40 -0600 nas (python/o/19_objimpl.h 1.1.2.1.2.1.2.1 644)
--- 0.13(w)/Include/objimpl.h Fri, 30 Jun 2000 15:09:51 -0600 nas (python/o/19_objimpl.h 1.1.2.1.2.1.2.1 644)
***************
*** 204,209 ****
--- 204,211 ----
  	(PyVarObject *) PyObject_MALLOC( _PyObject_VAR_SIZE((typeobj),(n)) ),\
  	(typeobj), (n)) )
  
+ #define PyObject_DEL(op) PyObject_FREE(op)
+ 
  /* This example code implements an object constructor with a custom
     allocator, where PyObject_New is inlined, and shows the important
     distinction between two steps (at least):
***************
*** 242,248 ****
     PyObject_{New, VarNew, Del} to manage the memory.  Set the type flag
     Py_TPFLAGS_GC and define the type method tp_recurse.  You should also
     add the method tp_clear if your object is mutable.  Include
!    PyGC_INFO_SIZE in the calculation of tp_basicsize.  Call
     PyObject_GC_Init after the pointers followed by tp_recurse become
     valid (usually just before returning the object from the allocation
     method.  Call PyObject_GC_Fini before those pointers become invalid
--- 244,250 ----
     PyObject_{New, VarNew, Del} to manage the memory.  Set the type flag
     Py_TPFLAGS_GC and define the type method tp_recurse.  You should also
     add the method tp_clear if your object is mutable.  Include
!    PyGC_HEAD_SIZE in the calculation of tp_basicsize.  Call
     PyObject_GC_Init after the pointers followed by tp_recurse become
     valid (usually just before returning the object from the allocation
     method.  Call PyObject_GC_Fini before those pointers become invalid
***************
*** 255,261 ****
  #define PyObject_GC_Fini(op)
  #define PyObject_AS_GC(op) (op)
  #define PyObject_FROM_GC(op) (op)
- #define PyObject_DEL(op) PyObject_FREE(op)
   
  #else
  
--- 257,262 ----
***************
*** 289,295 ****
  /* Get the object given the PyGC_Head */
  #define PyObject_FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1))
  
! #define PyObject_DEL(op) PyObject_FREE( PyObject_IS_GC(op) ? \
  					(ANY *)PyObject_AS_GC(op) : \
  					(ANY *)(op) )
  
--- 290,297 ----
  /* Get the object given the PyGC_Head */
  #define PyObject_FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1))
  
! #undef PyObject_DEL
! #define PyObject_DEL(op) PyObject_FREE( (op && PyObject_IS_GC(op)) ? \
  					(ANY *)PyObject_AS_GC(op) : \
  					(ANY *)(op) )
  
Index: 0.13/Objects/object.c
*** 0.13/Objects/object.c Fri, 30 Jun 2000 13:05:40 -0600 nas (python/E/29_object.c 1.1.1.1.1.1.1.1.1.1.1.1 644)
--- 0.13(w)/Objects/object.c Fri, 30 Jun 2000 15:05:26 -0600 nas (python/E/29_object.c 1.1.1.1.1.1.1.1.1.1.1.1 644)
***************
*** 192,205 ****
  	PyObject *op;
  {
  #ifdef WITH_CYCLE_GC
! 	if (PyType_IS_GC(op->ob_type)) {
! 		PyGC_Head *g = PyObject_AS_GC(op);
! 		PyObject_FREE(g);
! 	} else
! #endif
! 	{
! 		PyObject_FREE(op);
  	}
  }
  
  #ifndef WITH_CYCLE_GC
--- 192,202 ----
  	PyObject *op;
  {
  #ifdef WITH_CYCLE_GC
! 	if (op && PyType_IS_GC(op->ob_type)) {
! 		op = (PyObject *) PyObject_AS_GC(op);
  	}
+ #endif
+ 	PyObject_FREE(op);
  }
  
  #ifndef WITH_CYCLE_GC