]> granicus.if.org Git - python/commitdiff
Add support for weak references to the function and method types.
authorFred Drake <fdrake@acm.org>
Fri, 23 Mar 2001 04:19:27 +0000 (04:19 +0000)
committerFred Drake <fdrake@acm.org>
Fri, 23 Mar 2001 04:19:27 +0000 (04:19 +0000)
Objects/classobject.c
Objects/funcobject.c

index d7b4c1e5a6c491dc40d47623bdf93366dc0482fb..fa71c4ea3a74fa187150a8f1146d00c8b674f060 100644 (file)
@@ -1805,6 +1805,7 @@ PyMethod_New(PyObject *func, PyObject *self, PyObject *class)
                if (im == NULL)
                        return NULL;
        }
+       im->im_weakreflist = NULL;
        Py_INCREF(func);
        im->im_func = func;
        Py_XINCREF(self);
@@ -1902,6 +1903,7 @@ instancemethod_getattro(register PyMethodObject *im, PyObject *name)
 static void
 instancemethod_dealloc(register PyMethodObject *im)
 {
+       PyObject_ClearWeakRefs((PyObject *)im);
        PyObject_GC_Fini(im);
        Py_DECREF(im->im_func);
        Py_XDECREF(im->im_self);
@@ -2019,9 +2021,12 @@ PyTypeObject PyMethod_Type = {
        (getattrofunc)instancemethod_getattro,  /* tp_getattro */
        (setattrofunc)instancemethod_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)instancemethod_traverse,  /* tp_traverse */
+       0,                                      /* tp_clear */
+       0,                                      /* tp_richcompare */
+       offsetof(PyMethodObject, im_weakreflist) /* tp_weaklistoffset */
 };
 
 /* Clear out the free list */
index 8871e0ac1fa35158ae32f3a997d818371c1bfa00..78c968c2b462a35171c8ab4ff61a877fbea5f28e 100644 (file)
@@ -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 */
 };