mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
bpo-39947: Remove old private trashcan C API functions (GH-26869)
Remove 4 C API private trashcan functions which were only kept for the backward compatibility of the stable ABI with Python 3.8 and older, since the trashcan API was not usable with the limited C API on Python 3.8 and older. The trashcan API was excluded from the limited C API in Python 3.9. Removed functions: * _PyTrash_deposit_object() * _PyTrash_destroy_chain() * _PyTrash_thread_deposit_object() * _PyTrash_thread_destroy_chain() The trashcan C API was never usable with the limited C API, since old trashcan macros accessed directly PyThreadState members like "_tstate->trash_delete_nesting", whereas the PyThreadState structure is opaque in the limited C API. Exclude also the PyTrash_UNWIND_LEVEL constant from the C API. The trashcan C API was modified in Python 3.9 by commit38965ec541and in Python 3.10 by commited1a5a5bacto hide implementation details.
This commit is contained in:
parent
2a396d65b8
commit
db532a0999
5 changed files with 30 additions and 78 deletions
|
|
@ -2092,25 +2092,13 @@ finally:
|
|||
|
||||
/* Trashcan support. */
|
||||
|
||||
/* Add op to the _PyTrash_delete_later list. Called when the current
|
||||
#define _PyTrash_UNWIND_LEVEL 50
|
||||
|
||||
/* Add op to the gcstate->trash_delete_later list. Called when the current
|
||||
* call-stack depth gets large. op must be a currently untracked gc'ed
|
||||
* object, with refcount 0. Py_DECREF must already have been called on it.
|
||||
*/
|
||||
void
|
||||
_PyTrash_deposit_object(PyObject *op)
|
||||
{
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
struct _gc_runtime_state *gcstate = &interp->gc;
|
||||
|
||||
_PyObject_ASSERT(op, _PyObject_IS_GC(op));
|
||||
_PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op));
|
||||
_PyObject_ASSERT(op, Py_REFCNT(op) == 0);
|
||||
_PyGCHead_SET_PREV(_Py_AS_GC(op), gcstate->trash_delete_later);
|
||||
gcstate->trash_delete_later = op;
|
||||
}
|
||||
|
||||
/* The equivalent API, using per-thread state recursion info */
|
||||
void
|
||||
static void
|
||||
_PyTrash_thread_deposit_object(PyObject *op)
|
||||
{
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
|
|
@ -2121,37 +2109,9 @@ _PyTrash_thread_deposit_object(PyObject *op)
|
|||
tstate->trash_delete_later = op;
|
||||
}
|
||||
|
||||
/* Deallocate all the objects in the _PyTrash_delete_later list. Called when
|
||||
* the call-stack unwinds again.
|
||||
*/
|
||||
void
|
||||
_PyTrash_destroy_chain(void)
|
||||
{
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
struct _gc_runtime_state *gcstate = &interp->gc;
|
||||
|
||||
while (gcstate->trash_delete_later) {
|
||||
PyObject *op = gcstate->trash_delete_later;
|
||||
destructor dealloc = Py_TYPE(op)->tp_dealloc;
|
||||
|
||||
gcstate->trash_delete_later =
|
||||
(PyObject*) _PyGCHead_PREV(_Py_AS_GC(op));
|
||||
|
||||
/* Call the deallocator directly. This used to try to
|
||||
* fool Py_DECREF into calling it indirectly, but
|
||||
* Py_DECREF was already called on this object, and in
|
||||
* assorted non-release builds calling Py_DECREF again ends
|
||||
* up distorting allocation statistics.
|
||||
*/
|
||||
_PyObject_ASSERT(op, Py_REFCNT(op) == 0);
|
||||
++gcstate->trash_delete_nesting;
|
||||
(*dealloc)(op);
|
||||
--gcstate->trash_delete_nesting;
|
||||
}
|
||||
}
|
||||
|
||||
/* The equivalent API, using per-thread state recursion info */
|
||||
void
|
||||
/* Deallocate all the objects in the gcstate->trash_delete_later list.
|
||||
* Called when the call-stack unwinds again. */
|
||||
static void
|
||||
_PyTrash_thread_destroy_chain(void)
|
||||
{
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
|
|
@ -2192,7 +2152,7 @@ _PyTrash_thread_destroy_chain(void)
|
|||
int
|
||||
_PyTrash_begin(PyThreadState *tstate, PyObject *op)
|
||||
{
|
||||
if (tstate->trash_delete_nesting >= PyTrash_UNWIND_LEVEL) {
|
||||
if (tstate->trash_delete_nesting >= _PyTrash_UNWIND_LEVEL) {
|
||||
/* Store the object (to be deallocated later) and jump past
|
||||
* Py_TRASHCAN_END, skipping the body of the deallocator */
|
||||
_PyTrash_thread_deposit_object(op);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue