|
4 | 4 | The item type is restricted to simple C types like int or float */ |
5 | 5 |
|
6 | 6 | #include "Python.h" |
| 7 | +#include "structmember.h" |
7 | 8 |
|
8 | 9 | #ifdef STDC_HEADERS |
9 | 10 | #include <stddef.h> |
@@ -32,6 +33,7 @@ typedef struct arrayobject { |
32 | 33 | char *ob_item; |
33 | 34 | int allocated; |
34 | 35 | struct arraydescr *ob_descr; |
| 36 | + PyObject *weakreflist; /* List of weak references */ |
35 | 37 | } arrayobject; |
36 | 38 |
|
37 | 39 | static PyTypeObject Arraytype; |
@@ -442,6 +444,7 @@ newarrayobject(PyTypeObject *type, int size, struct arraydescr *descr) |
442 | 444 | } |
443 | 445 | op->ob_descr = descr; |
444 | 446 | op->allocated = size; |
| 447 | + op->weakreflist = NULL; |
445 | 448 | return (PyObject *) op; |
446 | 449 | } |
447 | 450 |
|
@@ -490,6 +493,8 @@ ins1(arrayobject *self, int where, PyObject *v) |
490 | 493 | static void |
491 | 494 | array_dealloc(arrayobject *op) |
492 | 495 | { |
| 496 | + if (op->weakreflist != NULL) |
| 497 | + PyObject_ClearWeakRefs((PyObject *) op); |
493 | 498 | if (op->ob_item != NULL) |
494 | 499 | PyMem_DEL(op->ob_item); |
495 | 500 | op->ob_type->tp_free((PyObject *)op); |
@@ -1950,12 +1955,12 @@ static PyTypeObject Arraytype = { |
1950 | 1955 | PyObject_GenericGetAttr, /* tp_getattro */ |
1951 | 1956 | 0, /* tp_setattro */ |
1952 | 1957 | &array_as_buffer, /* tp_as_buffer*/ |
1953 | | - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 1958 | + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ |
1954 | 1959 | arraytype_doc, /* tp_doc */ |
1955 | 1960 | 0, /* tp_traverse */ |
1956 | 1961 | 0, /* tp_clear */ |
1957 | 1962 | array_richcompare, /* tp_richcompare */ |
1958 | | - 0, /* tp_weaklistoffset */ |
| 1963 | + offsetof(arrayobject, weakreflist), /* tp_weaklistoffset */ |
1959 | 1964 | (getiterfunc)array_iter, /* tp_iter */ |
1960 | 1965 | 0, /* tp_iternext */ |
1961 | 1966 | array_methods, /* tp_methods */ |
|
0 commit comments