bpo-40170: Hide impl detail of Py_TRASHCAN_BEGIN macro (GH-23235) · python/cpython@ed1a5a5 (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -516,6 +516,8 @@ struct _ts; | ||
516 | 516 | /* Python 3.9 private API, invoked by the macros below. */ |
517 | 517 | PyAPI_FUNC(int) _PyTrash_begin(struct _ts *tstate, PyObject *op); |
518 | 518 | PyAPI_FUNC(void) _PyTrash_end(struct _ts *tstate); |
519 | +/* Python 3.10 private API, invoked by the Py_TRASHCAN_BEGIN(). */ | |
520 | +PyAPI_FUNC(int) _PyTrash_cond(PyObject *op, destructor dealloc); | |
519 | 521 | |
520 | 522 | #define PyTrash_UNWIND_LEVEL 50 |
521 | 523 | |
@@ -539,7 +541,7 @@ PyAPI_FUNC(void) _PyTrash_end(struct _ts *tstate); | ||
539 | 541 | |
540 | 542 | #define Py_TRASHCAN_BEGIN(op, dealloc) \ |
541 | 543 | Py_TRASHCAN_BEGIN_CONDITION(op, \ |
542 | -Py_TYPE(op)->tp_dealloc == (destructor)(dealloc)) | |
544 | +_PyTrash_cond(_PyObject_CAST(op), (destructor)dealloc)) | |
543 | 545 | |
544 | 546 | /* For backwards compatibility, these macros enable the trashcan |
545 | 547 | * unconditionally */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
1 | +The ``Py_TRASHCAN_BEGIN`` macro no longer accesses PyTypeObject attributes, | |
2 | +but now can get the condition by calling the new private | |
3 | +:c:func:`_PyTrash_cond()` function which hides implementation details. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2134,6 +2134,15 @@ _PyTrash_end(PyThreadState *tstate) | ||
2134 | 2134 | } |
2135 | 2135 | |
2136 | 2136 | |
2137 | +/* bpo-40170: It's only be used in Py_TRASHCAN_BEGIN macro to hide | |
2138 | + implementation details. */ | |
2139 | +int | |
2140 | +_PyTrash_cond(PyObject *op, destructor dealloc) | |
2141 | +{ | |
2142 | +return Py_TYPE(op)->tp_dealloc == dealloc; | |
2143 | +} | |
2144 | + | |
2145 | + | |
2137 | 2146 | void _Py_NO_RETURN |
2138 | 2147 | _PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg, |
2139 | 2148 | const char *file, int line, const char *function) |