@@ -1673,6 +1673,8 @@ _compile(PyObject* self_, PyObject* args)
16731673 Py_XINCREF (indexgroup );
16741674 self -> indexgroup = indexgroup ;
16751675
1676+ self -> weakreflist = NULL ;
1677+
16761678 return (PyObject * ) self ;
16771679}
16781680
@@ -1985,6 +1987,8 @@ pattern_scanner(PatternObject* pattern, PyObject* args)
19851987static void
19861988pattern_dealloc (PatternObject * self )
19871989{
1990+ if (self -> weakreflist != NULL )
1991+ PyObject_ClearWeakRefs ((PyObject * ) self );
19881992 Py_XDECREF (self -> pattern );
19891993 Py_XDECREF (self -> groupindex );
19901994 Py_XDECREF (self -> indexgroup );
@@ -2632,6 +2636,7 @@ pattern_copy(PatternObject* self, PyObject* args)
26322636
26332637 memcpy ((char * ) copy + offset , (char * ) self + offset ,
26342638 sizeof (PatternObject ) + self -> codesize * sizeof (SRE_CODE ) - offset );
2639+ copy -> weakreflist = NULL ;
26352640
26362641 return (PyObject * ) copy ;
26372642#else
@@ -2722,7 +2727,25 @@ statichere PyTypeObject Pattern_Type = {
27222727 sizeof (PatternObject ), sizeof (SRE_CODE ),
27232728 (destructor )pattern_dealloc , /*tp_dealloc*/
27242729 0 , /*tp_print*/
2725- (getattrfunc )pattern_getattr /*tp_getattr*/
2730+ (getattrfunc )pattern_getattr , /*tp_getattr*/
2731+ 0 , /* tp_setattr */
2732+ 0 , /* tp_compare */
2733+ 0 , /* tp_repr */
2734+ 0 , /* tp_as_number */
2735+ 0 , /* tp_as_sequence */
2736+ 0 , /* tp_as_mapping */
2737+ 0 , /* tp_hash */
2738+ 0 , /* tp_call */
2739+ 0 , /* tp_str */
2740+ 0 , /* tp_getattro */
2741+ 0 , /* tp_setattro */
2742+ 0 , /* tp_as_buffer */
2743+ Py_TPFLAGS_HAVE_WEAKREFS , /* tp_flags */
2744+ 0 , /* tp_doc */
2745+ 0 , /* tp_traverse */
2746+ 0 , /* tp_clear */
2747+ 0 , /* tp_richcompare */
2748+ offsetof(PatternObject , weakreflist ), /* tp_weaklistoffset */
27262749};
27272750
27282751/* -------------------------------------------------------------------- */
0 commit comments