diff Objects/codeobject.c @ 59694:22f589a8e3ab legacy-trunk

Add support for weak references to code objects. This will be used by an optimization in the incoming Python 3 JIT. Patch by Reid Kleckner!
author Collin Winter <collinw@gmail.com>
date Thu, 18 Mar 2010 21:54:01 +0000
parents dddf424bd669
children fd25030223b0
line wrap: on
line diff
--- a/Objects/codeobject.c	Thu Mar 18 21:50:06 2010 +0000
+++ b/Objects/codeobject.c	Thu Mar 18 21:54:01 2010 +0000
@@ -103,6 +103,7 @@
 		Py_INCREF(lnotab);
 		co->co_lnotab = lnotab;
                 co->co_zombieframe = NULL;
+		co->co_weakreflist = NULL;
 	}
 	return co;
 }
@@ -314,6 +315,8 @@
 	Py_XDECREF(co->co_lnotab);
         if (co->co_zombieframe != NULL)
                 PyObject_GC_Del(co->co_zombieframe);
+	if (co->co_weakreflist != NULL)
+		PyObject_ClearWeakRefs((PyObject*)co);
 	PyObject_DEL(co);
 }
 
@@ -490,8 +493,8 @@
 	code_doc,			/* tp_doc */
 	0,				/* tp_traverse */
 	0,				/* tp_clear */
-	code_richcompare,				/* tp_richcompare */
-	0,				/* tp_weaklistoffset */
+	code_richcompare,		/* tp_richcompare */
+	offsetof(PyCodeObject, co_weakreflist), /* tp_weaklistoffset */
 	0,				/* tp_iter */
 	0,				/* tp_iternext */
 	0,				/* tp_methods */