diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-13 15:51:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-13 15:51:52 (GMT) |
commit | 38965ec5411da60d312b59be281f3510d58e0cf1 (patch) | |
tree | 337294fec36de620386a08d0a5e917f63a6ba0e3 /Objects | |
parent | 309d7cc5df4e2bf3086c49eb2b1b56b929554500 (diff) | |
download | cpython-38965ec5411da60d312b59be281f3510d58e0cf1.zip cpython-38965ec5411da60d312b59be281f3510d58e0cf1.tar.gz cpython-38965ec5411da60d312b59be281f3510d58e0cf1.tar.bz2 |
bpo-39947: Hide implementation detail of trashcan macros (GH-18971)
Py_TRASHCAN_BEGIN_CONDITION and Py_TRASHCAN_END macro no longer
access PyThreadState attributes, but call new private
_PyTrash_begin() and _PyTrash_end() functions which hide
implementation details.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c index 72c4189..e6d0da1 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -2116,6 +2116,30 @@ _PyTrash_thread_destroy_chain(void) } +int +_PyTrash_begin(PyThreadState *tstate, PyObject *op) +{ + 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); + return 1; + } + ++tstate->trash_delete_nesting; + return 0; +} + + +void +_PyTrash_end(PyThreadState *tstate) +{ + --tstate->trash_delete_nesting; + if (tstate->trash_delete_later && tstate->trash_delete_nesting <= 0) { + _PyTrash_thread_destroy_chain(); + } +} + + void _Py_NO_RETURN _PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg, const char *file, int line, const char *function) |