Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 3 additions & 2 deletions 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, void *dealloc);

#define PyTrash_UNWIND_LEVEL 50

Expand All @@ -537,8 +539,7 @@ PyAPI_FUNC(void) _PyTrash_end(struct _ts *tstate);
} while (0);

#define Py_TRASHCAN_BEGIN(op, dealloc) \
Py_TRASHCAN_BEGIN_CONDITION(op, \
Py_TYPE(op)->tp_dealloc == (destructor)(dealloc))
Py_TRASHCAN_BEGIN_CONDITION(op, _PyTrash_cond(_PyObject_CAST(op), 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.
7 changes: 7 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,13 @@ _PyTrash_end(PyThreadState *tstate)
}


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, void *dealloc)
{
return Py_TYPE(op)->tp_dealloc == (destructor)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