diff options
author | Raymond Hettinger <python@rcn.com> | 2004-05-30 07:26:47 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-05-30 07:26:47 (GMT) |
commit | 691d80532b0a0204e92de35ecba1472d87af6e94 (patch) | |
tree | 25297599e68d9c19c3ea51d145c9a12a60ebc190 /Modules | |
parent | d70ad8a9d9c8212af6d83d2d7d08d21760829b17 (diff) | |
download | cpython-691d80532b0a0204e92de35ecba1472d87af6e94.zip cpython-691d80532b0a0204e92de35ecba1472d87af6e94.tar.gz cpython-691d80532b0a0204e92de35ecba1472d87af6e94.tar.bz2 |
Make sets and deques weak referencable.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/collectionsmodule.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Modules/collectionsmodule.c b/Modules/collectionsmodule.c index 368f0b6..62b43aa 100644 --- a/Modules/collectionsmodule.c +++ b/Modules/collectionsmodule.c @@ -1,4 +1,5 @@ #include "Python.h" +#include "structmember.h" /* collections module implementation of a deque() datatype Written and maintained by Raymond D. Hettinger <python@rcn.com> @@ -32,6 +33,7 @@ typedef struct { int leftindex; int rightindex; int len; + PyObject *weakreflist; /* List of weak references */ } dequeobject; static PyTypeObject deque_type; @@ -58,6 +60,7 @@ deque_new(PyTypeObject *type, PyObject *args, PyObject *kwds) deque->leftindex = BLOCKLEN / 2 + 1; deque->rightindex = BLOCKLEN / 2; deque->len = 0; + deque->weakreflist = NULL; return (PyObject *)deque; } @@ -439,6 +442,8 @@ static void deque_dealloc(dequeobject *deque) { PyObject_GC_UnTrack(deque); + if (deque->weakreflist != NULL) + PyObject_ClearWeakRefs((PyObject *) deque); if (deque->leftblock != NULL) { int err = deque_clear(deque); assert(err == 0); @@ -744,12 +749,13 @@ static PyTypeObject deque_type = { PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | + Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ deque_doc, /* tp_doc */ (traverseproc)deque_traverse, /* tp_traverse */ (inquiry)deque_clear, /* tp_clear */ (richcmpfunc)deque_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset*/ + offsetof(dequeobject, weakreflist), /* tp_weaklistoffset*/ (getiterfunc)deque_iter, /* tp_iter */ 0, /* tp_iternext */ deque_methods, /* tp_methods */ |