@@ -42,6 +42,7 @@ static const char copyright[] =
4242#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION
4343#include "pycore_dict.h" // _PyDict_Next()
4444#include "pycore_long.h" // _PyLong_GetZero()
45+ #include "pycore_list.h" // _PyList_AppendTakeRef()
4546#include "pycore_moduleobject.h" // _PyModule_GetState()
4647#include "pycore_tuple.h" // _PyTuple_FromPairSteal
4748#include "pycore_unicodeobject.h" // _PyUnicode_Copy
@@ -986,8 +987,7 @@ _sre_SRE_Pattern_findall_impl(PatternObject *self, PyObject *string,
986987 break ;
987988 }
988989
989- status = PyList_Append (list , item );
990- Py_DECREF (item );
990+ status = _PyList_AppendTakeRef ((PyListObject * )list , item );
991991 if (status < 0 )
992992 goto error ;
993993
@@ -1333,8 +1333,7 @@ pattern_subx(_sremodulestate* module_state,
13331333 string , i , b );
13341334 if (!item )
13351335 goto error ;
1336- status = PyList_Append (list , item );
1337- Py_DECREF (item );
1336+ status = _PyList_AppendTakeRef ((PyListObject * )list , item );
13381337 if (status < 0 )
13391338 goto error ;
13401339
@@ -1363,8 +1362,7 @@ pattern_subx(_sremodulestate* module_state,
13631362
13641363 /* add to list */
13651364 if (item != Py_None ) {
1366- status = PyList_Append (list , item );
1367- Py_DECREF (item );
1365+ status = _PyList_AppendTakeRef ((PyListObject * )list , item );
13681366 if (status < 0 )
13691367 goto error ;
13701368 }
@@ -1381,8 +1379,7 @@ pattern_subx(_sremodulestate* module_state,
13811379 string , i , state .endpos );
13821380 if (!item )
13831381 goto error ;
1384- status = PyList_Append (list , item );
1385- Py_DECREF (item );
1382+ status = _PyList_AppendTakeRef ((PyListObject * )list , item );
13861383 if (status < 0 )
13871384 goto error ;
13881385 }
0 commit comments