summaryrefslogtreecommitdiffstats
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-05-31 00:35:52 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-05-31 00:35:52 (GMT)
commitcb87bc8e7ee3a2ffd83dd1b12fcfa1c01aa740aa (patch)
treef9e95a569fd2b935cccbdd0a2ba2ea88d8348276 /Modules/arraymodule.c
parent691d80532b0a0204e92de35ecba1472d87af6e94 (diff)
downloadcpython-cb87bc8e7ee3a2ffd83dd1b12fcfa1c01aa740aa.zip
cpython-cb87bc8e7ee3a2ffd83dd1b12fcfa1c01aa740aa.tar.gz
cpython-cb87bc8e7ee3a2ffd83dd1b12fcfa1c01aa740aa.tar.bz2
Add weakref support to array.array and file objects.
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index ed2ea9d..ab904bd 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -4,6 +4,7 @@
The item type is restricted to simple C types like int or float */
#include "Python.h"
+#include "structmember.h"
#ifdef STDC_HEADERS
#include <stddef.h>
@@ -32,6 +33,7 @@ typedef struct arrayobject {
char *ob_item;
int allocated;
struct arraydescr *ob_descr;
+ PyObject *weakreflist; /* List of weak references */
} arrayobject;
static PyTypeObject Arraytype;
@@ -442,6 +444,7 @@ newarrayobject(PyTypeObject *type, int size, struct arraydescr *descr)
}
op->ob_descr = descr;
op->allocated = size;
+ op->weakreflist = NULL;
return (PyObject *) op;
}
@@ -490,6 +493,8 @@ ins1(arrayobject *self, int where, PyObject *v)
static void
array_dealloc(arrayobject *op)
{
+ if (op->weakreflist != NULL)
+ PyObject_ClearWeakRefs((PyObject *) op);
if (op->ob_item != NULL)
PyMem_DEL(op->ob_item);
op->ob_type->tp_free((PyObject *)op);
@@ -1950,12 +1955,12 @@ static PyTypeObject Arraytype = {
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
&array_as_buffer, /* tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
arraytype_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
array_richcompare, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
+ offsetof(arrayobject, weakreflist), /* tp_weaklistoffset */
(getiterfunc)array_iter, /* tp_iter */
0, /* tp_iternext */
array_methods, /* tp_methods */