summaryrefslogtreecommitdiffstats
path: root/Objects/funcobject.c
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-03-23 04:19:27 (GMT)
committerFred Drake <fdrake@acm.org>2001-03-23 04:19:27 (GMT)
commitdb81e8ddf8953359e8c2ed9569dd2e774d78ae95 (patch)
treeee907202cd30873818f01817b57f1652631af918 /Objects/funcobject.c
parent6a1c87ddf9033570bb773ffec5190d44e70bd5a1 (diff)
downloadcpython-db81e8ddf8953359e8c2ed9569dd2e774d78ae95.zip
cpython-db81e8ddf8953359e8c2ed9569dd2e774d78ae95.tar.gz
cpython-db81e8ddf8953359e8c2ed9569dd2e774d78ae95.tar.bz2
Add support for weak references to the function and method types.
Diffstat (limited to 'Objects/funcobject.c')
-rw-r--r--Objects/funcobject.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 8871e0a..78c968c 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -13,6 +13,7 @@ PyFunction_New(PyObject *code, PyObject *globals)
if (op != NULL) {
PyObject *doc;
PyObject *consts;
+ op->func_weakreflist = NULL;
Py_INCREF(code);
op->func_code = code;
Py_INCREF(globals);
@@ -245,6 +246,7 @@ func_setattro(PyFunctionObject *op, PyObject *name, PyObject *value)
static void
func_dealloc(PyFunctionObject *op)
{
+ PyObject_ClearWeakRefs((PyObject *) op);
PyObject_GC_Fini(op);
Py_DECREF(op->func_code);
Py_DECREF(op->func_globals);
@@ -327,13 +329,16 @@ PyTypeObject PyFunction_Type = {
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
- 0, /*tp_hash*/
+ 0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
(getattrofunc)func_getattro, /*tp_getattro*/
(setattrofunc)func_setattro, /*tp_setattro*/
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /*tp_flags*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC | Py_TPFLAGS_HAVE_WEAKREFS,
0, /* tp_doc */
(traverseproc)func_traverse, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ offsetof(PyFunctionObject, func_weakreflist), /* tp_weaklistoffset */
};