diff options
| author | Mark Shannon <mark@hotpy.org> | 2025-04-30 10:37:53 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-30 10:37:53 (GMT) |
| commit | 44e4c479fbf2c28605bd39303b1ce484753f6177 (patch) | |
| tree | e81f9ef8e6d43f8900f7264d2e2fde708bcdaf72 /Python | |
| parent | 0f23e84cda6a53a5db7a70f1e48f9773c335a9bd (diff) | |
| download | cpython-44e4c479fbf2c28605bd39303b1ce484753f6177.zip cpython-44e4c479fbf2c28605bd39303b1ce484753f6177.tar.gz cpython-44e4c479fbf2c28605bd39303b1ce484753f6177.tar.bz2 | |
GH-124715: Move trashcan mechanism into `Py_Dealloc` (GH-132280)
Diffstat (limited to 'Python')
| -rw-r--r-- | Python/bltinmodule.c | 2 | ||||
| -rw-r--r-- | Python/ceval.c | 6 | ||||
| -rw-r--r-- | Python/gc.c | 5 | ||||
| -rw-r--r-- | Python/gc_free_threading.c | 5 | ||||
| -rw-r--r-- | Python/hamt.c | 6 | ||||
| -rw-r--r-- | Python/instruction_sequence.c | 2 | ||||
| -rw-r--r-- | Python/pylifecycle.c | 4 | ||||
| -rw-r--r-- | Python/pystate.c | 5 | ||||
| -rw-r--r-- | Python/traceback.c | 2 |
9 files changed, 12 insertions, 25 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 8ed0a96..3221d5a 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -566,11 +566,9 @@ filter_dealloc(PyObject *self) { filterobject *lz = _filterobject_CAST(self); PyObject_GC_UnTrack(lz); - Py_TRASHCAN_BEGIN(lz, filter_dealloc) Py_XDECREF(lz->func); Py_XDECREF(lz->it); Py_TYPE(lz)->tp_free(lz); - Py_TRASHCAN_END } static int diff --git a/Python/ceval.c b/Python/ceval.c index c3a7a27..4a75b60 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -482,12 +482,6 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where) _PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate; uintptr_t here_addr = _Py_get_machine_stack_pointer(); assert(_tstate->c_stack_soft_limit != 0); - if (_tstate->c_stack_hard_limit == 0) { - _Py_InitializeRecursionLimits(tstate); - } - if (here_addr >= _tstate->c_stack_soft_limit) { - return 0; - } assert(_tstate->c_stack_hard_limit != 0); if (here_addr < _tstate->c_stack_hard_limit) { /* Overflowing while handling an overflow. Give up. */ diff --git a/Python/gc.c b/Python/gc.c index 58224ac..b7b48c8 100644 --- a/Python/gc.c +++ b/Python/gc.c @@ -2207,9 +2207,8 @@ void PyObject_GC_UnTrack(void *op_raw) { PyObject *op = _PyObject_CAST(op_raw); - /* Obscure: the Py_TRASHCAN mechanism requires that we be able to - * call PyObject_GC_UnTrack twice on an object. - */ + /* The code for some objects, such as tuples, is a bit + * sloppy about when the object is tracked and untracked. */ if (_PyObject_GC_IS_TRACKED(op)) { _PyObject_GC_UNTRACK(op); } diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c index d22307a..2db75e0 100644 --- a/Python/gc_free_threading.c +++ b/Python/gc_free_threading.c @@ -2511,9 +2511,8 @@ void PyObject_GC_UnTrack(void *op_raw) { PyObject *op = _PyObject_CAST(op_raw); - /* Obscure: the Py_TRASHCAN mechanism requires that we be able to - * call PyObject_GC_UnTrack twice on an object. - */ + /* The code for some objects, such as tuples, is a bit + * sloppy about when the object is tracked and untracked. */ if (_PyObject_GC_IS_TRACKED(op)) { _PyObject_GC_UNTRACK(op); } diff --git a/Python/hamt.c b/Python/hamt.c index e4d1e16..f9bbf63 100644 --- a/Python/hamt.c +++ b/Python/hamt.c @@ -1118,7 +1118,6 @@ hamt_node_bitmap_dealloc(PyObject *self) } PyObject_GC_UnTrack(self); - Py_TRASHCAN_BEGIN(self, hamt_node_bitmap_dealloc) if (len > 0) { i = len; @@ -1128,7 +1127,6 @@ hamt_node_bitmap_dealloc(PyObject *self) } Py_TYPE(self)->tp_free(self); - Py_TRASHCAN_END } #ifdef Py_DEBUG @@ -1508,7 +1506,6 @@ hamt_node_collision_dealloc(PyObject *self) /* Collision's tp_dealloc */ Py_ssize_t len = Py_SIZE(self); PyObject_GC_UnTrack(self); - Py_TRASHCAN_BEGIN(self, hamt_node_collision_dealloc) if (len > 0) { PyHamtNode_Collision *node = _PyHamtNode_Collision_CAST(self); while (--len >= 0) { @@ -1516,7 +1513,6 @@ hamt_node_collision_dealloc(PyObject *self) } } Py_TYPE(self)->tp_free(self); - Py_TRASHCAN_END } #ifdef Py_DEBUG @@ -1878,13 +1874,11 @@ hamt_node_array_dealloc(PyObject *self) { /* Array's tp_dealloc */ PyObject_GC_UnTrack(self); - Py_TRASHCAN_BEGIN(self, hamt_node_array_dealloc) PyHamtNode_Array *obj = _PyHamtNode_Array_CAST(self); for (Py_ssize_t i = 0; i < HAMT_ARRAY_NODE_SIZE; i++) { Py_XDECREF(obj->a_array[i]); } Py_TYPE(self)->tp_free(self); - Py_TRASHCAN_END } #ifdef Py_DEBUG diff --git a/Python/instruction_sequence.c b/Python/instruction_sequence.c index b068e4f..e2db46b 100644 --- a/Python/instruction_sequence.c +++ b/Python/instruction_sequence.c @@ -419,10 +419,8 @@ inst_seq_dealloc(PyObject *op) { _PyInstructionSequence *seq = (_PyInstructionSequence *)op; PyObject_GC_UnTrack(seq); - Py_TRASHCAN_BEGIN(seq, inst_seq_dealloc) PyInstructionSequence_Fini(seq); PyObject_GC_Del(seq); - Py_TRASHCAN_END } static int diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 9eaf493..c4c1d9f 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -854,6 +854,10 @@ error: static PyStatus pycore_interp_init(PyThreadState *tstate) { + _PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate; + if (_tstate->c_stack_hard_limit == 0) { + _Py_InitializeRecursionLimits(tstate); + } PyInterpreterState *interp = tstate->interp; PyStatus status; PyObject *sysmod = NULL; diff --git a/Python/pystate.c b/Python/pystate.c index b0c79ba..5685957 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -2168,7 +2168,10 @@ _PyThreadState_Attach(PyThreadState *tstate) if (current_fast_get() != NULL) { Py_FatalError("non-NULL old thread state"); } - + _PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate; + if (_tstate->c_stack_hard_limit == 0) { + _Py_InitializeRecursionLimits(tstate); + } while (1) { _PyEval_AcquireLock(tstate); diff --git a/Python/traceback.c b/Python/traceback.c index 0ac0b28..c06cb1a 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -236,11 +236,9 @@ tb_dealloc(PyObject *op) { PyTracebackObject *tb = _PyTracebackObject_CAST(op); PyObject_GC_UnTrack(tb); - Py_TRASHCAN_BEGIN(tb, tb_dealloc) Py_XDECREF(tb->tb_next); Py_XDECREF(tb->tb_frame); PyObject_GC_Del(tb); - Py_TRASHCAN_END } static int |
