Skip to content

bpo-40170: Hide implementation detail of Py_TRASHCAN_BEGIN macro #23235

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.

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
merged 6 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ struct _ts;
/* Python 3.9 private API, invoked by the macros below. */
PyAPI_FUNC(int) _PyTrash_begin(struct _ts *tstate, PyObject *op);
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

Expand All @@ -538,7 +540,7 @@ PyAPI_FUNC(void) _PyTrash_end(struct _ts *tstate);

#define Py_TRASHCAN_BEGIN(op, dealloc) \
Py_TRASHCAN_BEGIN_CONDITION(op, \
Py_TYPE(op)->tp_dealloc == (destructor)(dealloc))
_PyTrash_cond(_PyObject_CAST(op), (destructor)dealloc))

/* For backwards compatibility, these macros enable the trashcan
* unconditionally */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The ``Py_TRASHCAN_BEGIN`` macro no longer accesses PyTypeObject attributes,
but now can get the condition by calling the new private
:c:func:`_PyTrash_cond()` function which hides implementation details.
9 changes: 9 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,15 @@ _PyTrash_end(PyThreadState *tstate)
}


/* bpo-40170: It's only be used in Py_TRASHCAN_BEGIN macro to hide
implementation details. */
int
Copy link
Member

Choose a reason for hiding this comment

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

Please add comment explaining that it is used by the Py_TRASHCAN_BEGIN macro.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it, updated.

_PyTrash_cond(PyObject *op, destructor dealloc)
{
return Py_TYPE(op)->tp_dealloc == dealloc;
}


void _Py_NO_RETURN
_PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg,
const char *file, int line, const char *function)
Expand Down