diff options
author | Raymond Hettinger <python@rcn.com> | 2004-05-31 03:09:25 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-05-31 03:09:25 (GMT) |
commit | 027bb633b6899a0847d81cb35cbccdff5a468766 (patch) | |
tree | 4d6694b894394f6dd73ed6eb7c8c47c1909f056d /Modules | |
parent | cb87bc8e7ee3a2ffd83dd1b12fcfa1c01aa740aa (diff) | |
download | cpython-027bb633b6899a0847d81cb35cbccdff5a468766.zip cpython-027bb633b6899a0847d81cb35cbccdff5a468766.tar.gz cpython-027bb633b6899a0847d81cb35cbccdff5a468766.tar.bz2 |
Add weakref support to sockets and re pattern objects.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sre.c | 25 | ||||
-rw-r--r-- | Modules/sre.h | 1 |
2 files changed, 25 insertions, 1 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c index 45139bc..4be33d0 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -1673,6 +1673,8 @@ _compile(PyObject* self_, PyObject* args) Py_XINCREF(indexgroup); self->indexgroup = indexgroup; + self->weakreflist = NULL; + return (PyObject*) self; } @@ -1985,6 +1987,8 @@ pattern_scanner(PatternObject* pattern, PyObject* args) static void pattern_dealloc(PatternObject* self) { + if (self->weakreflist != NULL) + PyObject_ClearWeakRefs((PyObject *) self); Py_XDECREF(self->pattern); Py_XDECREF(self->groupindex); Py_XDECREF(self->indexgroup); @@ -2632,6 +2636,7 @@ pattern_copy(PatternObject* self, PyObject* args) memcpy((char*) copy + offset, (char*) self + offset, sizeof(PatternObject) + self->codesize * sizeof(SRE_CODE) - offset); + copy->weakreflist = NULL; return (PyObject*) copy; #else @@ -2722,7 +2727,25 @@ statichere PyTypeObject Pattern_Type = { sizeof(PatternObject), sizeof(SRE_CODE), (destructor)pattern_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ - (getattrfunc)pattern_getattr /*tp_getattr*/ + (getattrfunc)pattern_getattr, /*tp_getattr*/ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ + 0, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + offsetof(PatternObject, weakreflist), /* tp_weaklistoffset */ }; /* -------------------------------------------------------------------- */ diff --git a/Modules/sre.h b/Modules/sre.h index 4502802..b07d210 100644 --- a/Modules/sre.h +++ b/Modules/sre.h @@ -29,6 +29,7 @@ typedef struct { /* compatibility */ PyObject* pattern; /* pattern source (or None) */ int flags; /* flags used when compiling pattern source */ + PyObject *weakreflist; /* List of weak references */ /* pattern code */ int codesize; SRE_CODE code[1]; |