mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
GH-124715: Move trashcan mechanism into Py_Dealloc
(GH-132280)
This commit is contained in:
parent
0f23e84cda
commit
44e4c479fb
26 changed files with 88 additions and 196 deletions
|
@ -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
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue