diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2021-08-18 19:50:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-18 19:50:19 (GMT) |
commit | 31ee985db86c1339d00bd0d3cc1712019460670a (patch) | |
tree | 866b4e8377c49defb03247f5070ea7983533c344 /Doc/whatsnew | |
parent | a3a4d20d6798aa2975428d51f3a4f890248810cb (diff) | |
download | cpython-31ee985db86c1339d00bd0d3cc1712019460670a.zip cpython-31ee985db86c1339d00bd0d3cc1712019460670a.tar.gz cpython-31ee985db86c1339d00bd0d3cc1712019460670a.tar.bz2 |
bpo-44874: deprecate Py_TRASHCAN_SAFE_BEGIN and Py_TRASHCAN_SAFE_END (GH-27693)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/3.11.rst | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index c546ec0..49b4364 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -307,6 +307,47 @@ New Features Porting to Python 3.11 ---------------------- +* The old trashcan macros (``Py_TRASHCAN_SAFE_BEGIN``/``Py_TRASHCAN_SAFE_END``) + are now deprecated. They should be replaced by the new macros + ``Py_TRASHCAN_BEGIN`` and ``Py_TRASHCAN_END``. + + A tp_dealloc function that has the old macros, such as:: + + static void + mytype_dealloc(mytype *p) + { + PyObject_GC_UnTrack(p); + Py_TRASHCAN_SAFE_BEGIN(p); + ... + Py_TRASHCAN_SAFE_END + } + + should migrate to the new macros as follows:: + + static void + mytype_dealloc(mytype *p) + { + PyObject_GC_UnTrack(p); + Py_TRASHCAN_BEGIN(p, mytype_dealloc) + ... + Py_TRASHCAN_END + } + + Note that ``Py_TRASHCAN_BEGIN`` has a second argument which + should be the deallocation function it is in. + + To support older Python versions in the same codebase, you + can define the following macros and use them throughout + the code (credit: these were copied from the ``mypy`` codebase):: + + #if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 8 + # define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN(op, dealloc) + # define CPy_TRASHCAN_END(op) Py_TRASHCAN_END + #else + # define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_SAFE_BEGIN(op) + # define CPy_TRASHCAN_END(op) Py_TRASHCAN_SAFE_END(op) + #endif + * The :c:func:`PyType_Ready` function now raises an error if a type is defined with the :const:`Py_TPFLAGS_HAVE_GC` flag set but has no traverse function (:c:member:`PyTypeObject.tp_traverse`). |