mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
Make sets and deques weak referencable.
This commit is contained in:
parent
d70ad8a9d9
commit
691d80532b
5 changed files with 32 additions and 6 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue