[Patches] GC infrastructure patch 2 (type changes)

Neil Schemenauer nascheme@enme.ucalgary.ca
Wed, 14 Jun 2000 13:15:07 -0600


--VbJkn9YxBvnuCH5J
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

This patch modifies the type structures of objects that
participate in GC.  The object's tp_basicsize is increased when
GC is enabled.  GC information is prefixed to the object to
maintain binary compatibility.  GC objects also define the
tp_flag Py_TPFLAGS_GC.

Can someone think of a better alternative for the name
WITH_CYCLE_GC?  I don't like it.

    Neil

--VbJkn9YxBvnuCH5J
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="type.diff"

Index: recurse.1/Include/object.h
*** recurse.1/Include/object.h Wed, 14 Jun 2000 12:32:15 -0600 nas (python/o/18_object.h 1.1.2.1 644)
--- recurse.1(w)/Include/object.h Wed, 14 Jun 2000 12:46:50 -0600 nas (python/o/18_object.h 1.1.2.1 644)
***************
*** 325,330 ****
--- 325,337 ----
  /* PySequenceMethods contains sq_contains */
  #define Py_TPFLAGS_HAVE_SEQUENCE_IN (1L<<1)
  
+ /* Objects which participate in garbage collection (see objimp.h) */
+ #ifdef WITH_CYCLE_GC
+ #define Py_TPFLAGS_GC (1L<<2)
+ #else
+ #define Py_TPFLAGS_GC 0
+ #endif
+ 
  #define Py_TPFLAGS_DEFAULT  (Py_TPFLAGS_HAVE_GETCHARBUFFER | \
                               Py_TPFLAGS_HAVE_SEQUENCE_IN)
  
Index: recurse.1/Include/objimpl.h
*** recurse.1/Include/objimpl.h Mon, 08 May 2000 12:24:03 -0600 nas (python/o/19_objimpl.h 1.1.2.1 644)
--- recurse.1(w)/Include/objimpl.h Wed, 14 Jun 2000 12:47:39 -0600 nas (python/o/19_objimpl.h 1.1.2.1 644)
***************
*** 234,239 ****
--- 234,245 ----
     the 1st step is performed automatically for you, so in a C++ class
     constructor you would start directly with PyObject_Init/InitVar. */
  
+ 
+ 
+ #ifndef WITH_CYCLE_GC
+ #define PyGC_INFO_SIZE 0
+ #endif
+ 
  #ifdef __cplusplus
  }
  #endif
Index: recurse.1/Objects/classobject.c
*** recurse.1/Objects/classobject.c Wed, 14 Jun 2000 12:32:15 -0600 nas (python/E/16_classobjec 1.1.2.2.1.1 644)
--- recurse.1(w)/Objects/classobject.c Wed, 14 Jun 2000 12:46:30 -0600 nas (python/E/16_classobjec 1.1.2.2.1.1 644)
***************
*** 403,409 ****
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"class",
! 	sizeof(PyClassObject),
  	0,
  	(destructor)class_dealloc, /*tp_dealloc*/
  	0,		/*tp_print*/
--- 403,409 ----
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"class",
! 	sizeof(PyClassObject) + PyGC_INFO_SIZE,
  	0,
  	(destructor)class_dealloc, /*tp_dealloc*/
  	0,		/*tp_print*/
***************
*** 420,426 ****
  	(getattrofunc)class_getattr, /*tp_getattro*/
  	(setattrofunc)class_setattr, /*tp_setattro*/
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT, /*tp_flags*/
  	0,		/* tp_doc */
  	(recurseproc)class_recurse,	/* tp_recurse */
  };
--- 420,426 ----
  	(getattrofunc)class_getattr, /*tp_getattro*/
  	(setattrofunc)class_setattr, /*tp_setattro*/
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /*tp_flags*/
  	0,		/* tp_doc */
  	(recurseproc)class_recurse,	/* tp_recurse */
  };
***************
*** 1479,1485 ****
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"instance",
! 	sizeof(PyInstanceObject),
  	0,
  	(destructor)instance_dealloc, /*tp_dealloc*/
  	0,			/*tp_print*/
--- 1479,1485 ----
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"instance",
! 	sizeof(PyInstanceObject) + PyGC_INFO_SIZE,
  	0,
  	(destructor)instance_dealloc, /*tp_dealloc*/
  	0,			/*tp_print*/
***************
*** 1496,1502 ****
  	(getattrofunc)instance_getattr, /*tp_getattro*/
  	(setattrofunc)instance_setattr, /*tp_setattro*/
          0, /* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT, /*tp_flags*/
  	0,		/* tp_doc */
  	(recurseproc)instance_recurse,	/* tp_recurse */
  };
--- 1496,1502 ----
  	(getattrofunc)instance_getattr, /*tp_getattro*/
  	(setattrofunc)instance_setattr, /*tp_setattro*/
          0, /* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /*tp_flags*/
  	0,		/* tp_doc */
  	(recurseproc)instance_recurse,	/* tp_recurse */
  };
***************
*** 1701,1707 ****
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"instance method",
! 	sizeof(PyMethodObject),
  	0,
  	(destructor)instancemethod_dealloc, /*tp_dealloc*/
  	0,			/*tp_print*/
--- 1701,1707 ----
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"instance method",
! 	sizeof(PyMethodObject) + PyGC_INFO_SIZE,
  	0,
  	(destructor)instancemethod_dealloc, /*tp_dealloc*/
  	0,			/*tp_print*/
***************
*** 1718,1724 ****
  	(getattrofunc)instancemethod_getattr, /*tp_getattro*/
  	0,			/*tp_setattro*/
  	0,			/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT, /*tp_flags*/
  	0,			/* tp_doc */
  	(recurseproc)instancemethod_recurse,	/* tp_recurse */
  };
--- 1718,1724 ----
  	(getattrofunc)instancemethod_getattr, /*tp_getattro*/
  	0,			/*tp_setattro*/
  	0,			/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /*tp_flags*/
  	0,			/* tp_doc */
  	(recurseproc)instancemethod_recurse,	/* tp_recurse */
  };
Index: recurse.1/Objects/dictobject.c
*** recurse.1/Objects/dictobject.c Wed, 14 Jun 2000 12:32:15 -0600 nas (python/E/19_dictobject 1.1.2.1.1.1 644)
--- recurse.1(w)/Objects/dictobject.c Wed, 14 Jun 2000 12:46:30 -0600 nas (python/E/19_dictobject 1.1.2.1.1.1 644)
***************
*** 1087,1093 ****
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"dictionary",
! 	sizeof(dictobject),
  	0,
  	(destructor)dict_dealloc, /*tp_dealloc*/
  	(printfunc)dict_print, /*tp_print*/
--- 1087,1093 ----
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"dictionary",
! 	sizeof(dictobject) + PyGC_INFO_SIZE,
  	0,
  	(destructor)dict_dealloc, /*tp_dealloc*/
  	(printfunc)dict_print, /*tp_print*/
***************
*** 1104,1110 ****
  	0,		/* tp_getattro */
  	0,		/* tp_setattro */
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT, /*tp_flags*/
  	0,		/* tp_doc */
  	(recurseproc)dict_recurse,	/* tp_recurse */
  	(inquiry)dict_tp_clear,		/* tp_clear */
--- 1104,1110 ----
  	0,		/* tp_getattro */
  	0,		/* tp_setattro */
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /*tp_flags*/
  	0,		/* tp_doc */
  	(recurseproc)dict_recurse,	/* tp_recurse */
  	(inquiry)dict_tp_clear,		/* tp_clear */
Index: recurse.1/Objects/funcobject.c
*** recurse.1/Objects/funcobject.c Wed, 14 Jun 2000 12:32:15 -0600 nas (python/E/23_funcobject 1.1.2.2.1.1 644)
--- recurse.1(w)/Objects/funcobject.c Wed, 14 Jun 2000 12:46:30 -0600 nas (python/E/23_funcobject 1.1.2.2.1.1 644)
***************
*** 254,260 ****
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"function",
! 	sizeof(PyFunctionObject),
  	0,
  	(destructor)func_dealloc, /*tp_dealloc*/
  	0,		/*tp_print*/
--- 254,260 ----
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"function",
! 	sizeof(PyFunctionObject) + PyGC_INFO_SIZE,
  	0,
  	(destructor)func_dealloc, /*tp_dealloc*/
  	0,		/*tp_print*/
***************
*** 271,277 ****
  	0,		/*tp_getattro*/
  	0,		/*tp_setattro*/
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT, /*tp_flags*/
  	0,		/* tp_doc */
  	(recurseproc)func_recurse,	/* tp_recurse */
  };
--- 271,277 ----
  	0,		/*tp_getattro*/
  	0,		/*tp_setattro*/
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /*tp_flags*/
  	0,		/* tp_doc */
  	(recurseproc)func_recurse,	/* tp_recurse */
  };
Index: recurse.1/Objects/listobject.c
*** recurse.1/Objects/listobject.c Wed, 14 Jun 2000 12:32:15 -0600 nas (python/E/25_listobject 1.1.2.3.1.1 644)
--- recurse.1(w)/Objects/listobject.c Wed, 14 Jun 2000 13:01:53 -0600 nas (python/E/25_listobject 1.1.2.3.1.1 644)
***************
*** 71,77 ****
  		return PyErr_NoMemory();
  	}
  	/* PyObject_NewVar is inlined */
! 	op = (PyListObject *) PyObject_MALLOC(sizeof(PyListObject));
  	if (op == NULL) {
  		return PyErr_NoMemory();
  	}
--- 71,78 ----
  		return PyErr_NoMemory();
  	}
  	/* PyObject_NewVar is inlined */
! 	op = (PyListObject *) PyObject_MALLOC(sizeof(PyListObject)
! 						+ PyGC_INFO_SIZE);
  	if (op == NULL) {
  		return PyErr_NoMemory();
  	}
***************
*** 1499,1505 ****
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"list",
! 	sizeof(PyListObject),
  	0,
  	(destructor)list_dealloc, /*tp_dealloc*/
  	(printfunc)list_print, /*tp_print*/
--- 1500,1506 ----
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"list",
! 	sizeof(PyListObject) + PyGC_INFO_SIZE,
  	0,
  	(destructor)list_dealloc, /*tp_dealloc*/
  	(printfunc)list_print, /*tp_print*/
***************
*** 1516,1522 ****
  	0,		/* tp_getattro */
  	0,		/* tp_setattro */
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT,	/* tp_flags */
  	0,		/* tp_doc */
  	(recurseproc)list_recurse,	/* tp_recurse */
  	(inquiry)list_clear,	/* tp_clear */
--- 1517,1523 ----
  	0,		/* tp_getattro */
  	0,		/* tp_setattro */
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC,	/* tp_flags */
  	0,		/* tp_doc */
  	(recurseproc)list_recurse,	/* tp_recurse */
  	(inquiry)list_clear,	/* tp_clear */
***************
*** 1577,1583 ****
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"list (immutable, during sort)",
! 	sizeof(PyListObject),
  	0,
  	0,		/*tp_dealloc*/ /* Cannot happen */
  	(printfunc)list_print, /*tp_print*/
--- 1578,1584 ----
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"list (immutable, during sort)",
! 	sizeof(PyListObject) + PyGC_INFO_SIZE,
  	0,
  	0,		/*tp_dealloc*/ /* Cannot happen */
  	(printfunc)list_print, /*tp_print*/
***************
*** 1594,1600 ****
  	0,		/* tp_getattro */
  	0,		/* tp_setattro */
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT,	/* tp_flags */
  	0,		/* tp_doc */
  	(recurseproc)list_recurse,	/* tp_recurse */
  };
--- 1595,1601 ----
  	0,		/* tp_getattro */
  	0,		/* tp_setattro */
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC,	/* tp_flags */
  	0,		/* tp_doc */
  	(recurseproc)list_recurse,	/* tp_recurse */
  };
Index: recurse.1/Objects/tupleobject.c
*** recurse.1/Objects/tupleobject.c Wed, 14 Jun 2000 12:32:15 -0600 nas (python/E/33_tupleobjec 1.1.2.3.1.1 644)
--- recurse.1(w)/Objects/tupleobject.c Wed, 14 Jun 2000 13:13:03 -0600 nas (python/E/33_tupleobjec 1.1.2.3.1.1 644)
***************
*** 93,99 ****
  		int nbytes = size * sizeof(PyObject *);
  		/* Check for overflow */
  		if (nbytes / sizeof(PyObject *) != (size_t)size ||
! 		    (nbytes += sizeof(PyTupleObject) - sizeof(PyObject *))
  		    <= 0)
  		{
  			return PyErr_NoMemory();
--- 93,100 ----
  		int nbytes = size * sizeof(PyObject *);
  		/* Check for overflow */
  		if (nbytes / sizeof(PyObject *) != (size_t)size ||
! 		    (nbytes += sizeof(PyTupleObject) - sizeof(PyObject *)
! 		     		+ PyGC_INFO_SIZE)
  		    <= 0)
  		{
  			return PyErr_NoMemory();
***************
*** 449,455 ****
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"tuple",
! 	sizeof(PyTupleObject) - sizeof(PyObject *),
  	sizeof(PyObject *),
  	(destructor)tupledealloc, /*tp_dealloc*/
  	(printfunc)tupleprint, /*tp_print*/
--- 450,456 ----
  	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"tuple",
! 	sizeof(PyTupleObject) - sizeof(PyObject *) + PyGC_INFO_SIZE,
  	sizeof(PyObject *),
  	(destructor)tupledealloc, /*tp_dealloc*/
  	(printfunc)tupleprint, /*tp_print*/
***************
*** 466,472 ****
  	0,		/* tp_getattro */
  	0,		/* tp_setattro */
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT,	/* tp_flags */
  	0,		/* tp_doc */
  	(recurseproc)tuplerecurse,	/* tp_recurse */
  };
--- 467,473 ----
  	0,		/* tp_getattro */
  	0,		/* tp_setattro */
  	0,		/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC,	/* tp_flags */
  	0,		/* tp_doc */
  	(recurseproc)tuplerecurse,	/* tp_recurse */
  };
***************
*** 554,561 ****
  #endif		
  	{
  		sv = (PyTupleObject *)
! 			PyObject_REALLOC((char *)v,
! 				sizeof(PyTupleObject) + newsize * sizeof(PyObject *));
  		*pv = (PyObject *) sv;
  		if (sv == NULL) {
  			PyObject_DEL(v);
--- 555,563 ----
  #endif		
  	{
  		sv = (PyTupleObject *)
! 			PyObject_REALLOC((char *)v, sizeof(PyTupleObject) 
! 					+ PyGC_INFO_SIZE
! 					+ newsize * sizeof(PyObject *));
  		*pv = (PyObject *) sv;
  		if (sv == NULL) {
  			PyObject_DEL(v);

--VbJkn9YxBvnuCH5J--