GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-39947: Remove old private trashcan C API functions by vstinner · Pull Request #26869 · python/cpython

bpo-39947: Remove old private trashcan C API functions #26869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
vstinner merged 1 commit into python:main from vstinner:trashcan
Jun 23, 2021

Uh oh!

There was an error while loading. Please reload this page.

Merged

bpo-39947: Remove old private trashcan C API functions #26869

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
fa3b514
bpo-39947: Remove old private trashcan C API functions
vstinner Jun 23, 2021
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

16 changes: 2 additions & 14 deletions 16 Include/cpython/object.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ without deallocating anything (and so unbounded call-stack depth is avoided).
When the call stack finishes unwinding again, code generated by the END macro
notices this, and calls another routine to deallocate all the objects that
may have been added to the list of deferred deallocations. In effect, a
chain of N deallocations is broken into (N-1)/(PyTrash_UNWIND_LEVEL-1) pieces,
with the call stack never exceeding a depth of PyTrash_UNWIND_LEVEL.
chain of N deallocations is broken into (N-1)/(_PyTrash_UNWIND_LEVEL-1) pieces,
with the call stack never exceeding a depth of _PyTrash_UNWIND_LEVEL.

Since the tp_dealloc of a subclass typically calls the tp_dealloc of the base
class, we need to ensure that the trashcan is only triggered on the tp_dealloc
Expand All @@ -503,16 +503,6 @@ partially-deallocated object. To check this, the tp_dealloc function must be
passed as second argument to Py_TRASHCAN_BEGIN().
*/

/* This is the old private API, invoked by the macros before 3.2.4.
Kept for binary compatibility of extensions using the stable ABI. */
PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*);
PyAPI_FUNC(void) _PyTrash_destroy_chain(void);

/* This is the old private API, invoked by the macros before 3.9.
Kept for binary compatibility of extensions using the stable ABI. */
PyAPI_FUNC(void) _PyTrash_thread_deposit_object(PyObject*);
PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void);

/* Forward declarations for PyThreadState */
struct _ts;

Expand All @@ -522,8 +512,6 @@ PyAPI_FUNC(void) _PyTrash_end(struct _ts *tstate);
/* Python 3.10 private API, invoked by the Py_TRASHCAN_BEGIN(). */
PyAPI_FUNC(int) _PyTrash_cond(PyObject *op, destructor dealloc);

#define PyTrash_UNWIND_LEVEL 50

#define Py_TRASHCAN_BEGIN_CONDITION(op, cond) \
do { \
PyThreadState *_tstate = NULL; \
Expand Down
20 changes: 20 additions & 0 deletions 20 Misc/NEWS.d/next/C API/2021-06-23-10-31-45.bpo-39947.je_HMo.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Remove 4 private trashcan C API 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.
Comment thread Outdated
Comment on lines 1 to 4

@encukou encukou Jun 23, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you say which ones?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Jun 23, 2021

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

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 :c:type:`PyThreadState` members like
``_tstate->trash_delete_nesting``, whereas the :c:type:`PyThreadState`
structure is opaque in the limited C API.

Exclude also the the ``PyTrash_UNWIND_LEVEL`` constant from the C API.

Patch by Victor Stinner.
12 changes: 0 additions & 12 deletions 12 Misc/stable_abi.txt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1602,12 +1602,6 @@ function _PyThreadState_Init
function _PyThreadState_Prealloc
added 3.2
abi_only
function _PyTrash_deposit_object
added 3.2
abi_only
function _PyTrash_destroy_chain
added 3.2
abi_only
data _PyWeakref_CallableProxyType
added 3.2
abi_only
Expand Down Expand Up @@ -1920,12 +1914,6 @@ function Py_EncodeLocale
added 3.7 # (and 3.6.1 and 3.5.3)
function Py_SetPath
added 3.7 # (and 3.6.1 and 3.5.3)
function _PyTrash_thread_deposit_object
added 3.7 # (and 3.6.1 and 3.5.3)
abi_only
function _PyTrash_thread_destroy_chain
added 3.7 # (and 3.6.1 and 3.5.3)
abi_only
function PyErr_SetExcFromWindowsErr
added 3.7 # (and 3.6.1 and 3.5.3)
ifdef MS_WINDOWS
Expand Down
56 changes: 8 additions & 48 deletions 56 Objects/object.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2092,25 +2092,13 @@ Py_ReprLeave(PyObject *obj)

/* 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();
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions 4 PC/python3dll.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ EXPORT_FUNC(_PyObject_NewVar)
EXPORT_FUNC(_PyState_AddModule)
EXPORT_FUNC(_PyThreadState_Init)
EXPORT_FUNC(_PyThreadState_Prealloc)
EXPORT_FUNC(_PyTrash_deposit_object)
EXPORT_FUNC(_PyTrash_destroy_chain)
EXPORT_FUNC(_PyTrash_thread_deposit_object)
EXPORT_FUNC(_PyTrash_thread_destroy_chain)
EXPORT_FUNC(Py_AddPendingCall)
EXPORT_FUNC(Py_AtExit)
EXPORT_FUNC(Py_BuildValue)
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.