mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-35983: skip trashcan for subclasses (GH-11841)
Add new trashcan macros to deal with a double deallocation that could occur when the `tp_dealloc` of a subclass calls the `tp_dealloc` of a base class and that base class uses the trashcan mechanism. Patch by Jeroen Demeyer.
This commit is contained in:
parent
a2fedd8c91
commit
351c67416b
15 changed files with 189 additions and 121 deletions
|
@ -1176,7 +1176,7 @@ hamt_node_bitmap_dealloc(PyHamtNode_Bitmap *self)
|
|||
Py_ssize_t i;
|
||||
|
||||
PyObject_GC_UnTrack(self);
|
||||
Py_TRASHCAN_SAFE_BEGIN(self)
|
||||
Py_TRASHCAN_BEGIN(self, hamt_node_bitmap_dealloc)
|
||||
|
||||
if (len > 0) {
|
||||
i = len;
|
||||
|
@ -1186,7 +1186,7 @@ hamt_node_bitmap_dealloc(PyHamtNode_Bitmap *self)
|
|||
}
|
||||
|
||||
Py_TYPE(self)->tp_free((PyObject *)self);
|
||||
Py_TRASHCAN_SAFE_END(self)
|
||||
Py_TRASHCAN_END
|
||||
}
|
||||
|
||||
#ifdef Py_DEBUG
|
||||
|
@ -1584,7 +1584,7 @@ hamt_node_collision_dealloc(PyHamtNode_Collision *self)
|
|||
Py_ssize_t len = Py_SIZE(self);
|
||||
|
||||
PyObject_GC_UnTrack(self);
|
||||
Py_TRASHCAN_SAFE_BEGIN(self)
|
||||
Py_TRASHCAN_BEGIN(self, hamt_node_collision_dealloc)
|
||||
|
||||
if (len > 0) {
|
||||
|
||||
|
@ -1594,7 +1594,7 @@ hamt_node_collision_dealloc(PyHamtNode_Collision *self)
|
|||
}
|
||||
|
||||
Py_TYPE(self)->tp_free((PyObject *)self);
|
||||
Py_TRASHCAN_SAFE_END(self)
|
||||
Py_TRASHCAN_END
|
||||
}
|
||||
|
||||
#ifdef Py_DEBUG
|
||||
|
@ -1969,14 +1969,14 @@ hamt_node_array_dealloc(PyHamtNode_Array *self)
|
|||
Py_ssize_t i;
|
||||
|
||||
PyObject_GC_UnTrack(self);
|
||||
Py_TRASHCAN_SAFE_BEGIN(self)
|
||||
Py_TRASHCAN_BEGIN(self, hamt_node_array_dealloc)
|
||||
|
||||
for (i = 0; i < HAMT_ARRAY_NODE_SIZE; i++) {
|
||||
Py_XDECREF(self->a_array[i]);
|
||||
}
|
||||
|
||||
Py_TYPE(self)->tp_free((PyObject *)self);
|
||||
Py_TRASHCAN_SAFE_END(self)
|
||||
Py_TRASHCAN_END
|
||||
}
|
||||
|
||||
#ifdef Py_DEBUG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue