Skip to content

Commit 9a61914

Browse files
committed
Invoke trashcan earlier to avoid hitting C recursion limit during object finalization.
1 parent 78ceefb commit 9a61914

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

Include/cpython/object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,15 @@ PyAPI_FUNC(void) PyTrash_thread_destroy_chain(PyThreadState *tstate);
471471
#define Py_TRASHCAN_BEGIN(op, dealloc) \
472472
do { \
473473
PyThreadState *tstate = PyThreadState_Get(); \
474-
if (tstate->c_recursion_remaining <= 0 && Py_TYPE(op)->tp_dealloc == (destructor)dealloc) { \
474+
if (tstate->c_recursion_remaining <= 50 && Py_TYPE(op)->tp_dealloc == (destructor)dealloc) { \
475475
PyTrash_thread_deposit_object(tstate, (PyObject *)op); \
476476
break; \
477477
} \
478478
tstate->c_recursion_remaining--;
479479
/* The body of the deallocator is here. */
480480
#define Py_TRASHCAN_END \
481481
tstate->c_recursion_remaining++; \
482-
if (tstate->delete_later && tstate->c_recursion_remaining > 50) { \
482+
if (tstate->delete_later && tstate->c_recursion_remaining > 100) { \
483483
PyTrash_thread_destroy_chain(tstate); \
484484
} \
485485
} while (0);

Lib/test/test_ordered_dict.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ def replaced_module(name, replacement):
3131

3232
class OrderedDictTests:
3333

34-
maxDiff = None
35-
3634
def test_init(self):
3735
OrderedDict = self.OrderedDict
3836
with self.assertRaises(TypeError):

Objects/object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2723,7 +2723,7 @@ PyTrash_thread_destroy_chain(PyThreadState *tstate)
27232723
tups = [(tup,) for tup in tups]
27242724
del tups
27252725
*/
2726-
assert(tstate->c_recursion_remaining > 50);
2726+
assert(tstate->c_recursion_remaining > 100);
27272727
tstate->c_recursion_remaining--;
27282728
while (tstate->delete_later) {
27292729
PyObject *op = tstate->delete_later;

0 commit comments

Comments
 (0)