If the macro is deprecated, please provide an detailed explanation how to port existing C code to the new C API, in What's New In Python 3.X (version where the macro is deprecated, Python 3.11 if I understood correctly). Also, is there a way to write a single code base working on Python 3.6-Python 3.11? It seems like mypy uses macros to support Python < 3.8 and Python >= 3.8: #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) A search in PyPI top 1000 project gives me 8 projects (I was too lazy to check the full top 5000). It would be great to help these projects (propose pull requests) to migrate to the new C API. (*) pyrsistent-0.18.0.tar.gz
./pvectorcmodule.c: Py_TRASHCAN_SAFE_BEGIN(self); ./pvectorcmodule.c: Py_TRASHCAN_SAFE_BEGIN(self);
(*) PyGObject-3.40.1.tar.gz
./gi/pygi-resulttuple.c: Py_TRASHCAN_SAFE_BEGIN (self)
(*) pycurl-7.44.1.tar.gz
./src/easy.c: Py_TRASHCAN_SAFE_BEGIN(self); ./src/multi.c: Py_TRASHCAN_SAFE_BEGIN(self); ./src/share.c: Py_TRASHCAN_SAFE_BEGIN(self);
(*) mypy-0.910.tar.gz
./mypyc/lib-rt/CPy.h:
#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 --- (*) pypi-top-1000_2021-08-17/multidict-5.1.0.tar.gz
./multidict/_multidict.c: Py_TRASHCAN_SAFE_BEGIN(self);
(*) pypi-top-1000_2021-08-17/immutables-0.16.tar.gz
./immutables/_map.c: Py_TRASHCAN_SAFE_BEGIN(self) ./immutables/_map.c: Py_TRASHCAN_SAFE_BEGIN(self) ./immutables/_map.c: Py_TRASHCAN_SAFE_BEGIN(self)
(*) guppy3-3.1.1.tar.gz
./src/sets/nodeset.c: Py_TRASHCAN_SAFE_BEGIN(v) ./src/sets/immnodeset.c: Py_TRASHCAN_SAFE_BEGIN(it) ./src/sets/immnodeset.c: Py_TRASHCAN_SAFE_BEGIN(v) ./src/heapy/hv.c: Py_TRASHCAN_SAFE_BEGIN(v) ./src/heapy/classifier.c: Py_TRASHCAN_SAFE_BEGIN(op) ./src/heapy/nodegraph.c: Py_TRASHCAN_SAFE_BEGIN(v) ./src/heapy/hv_cli_rel.c: Py_TRASHCAN_SAFE_BEGIN(op)
(*) frozendict-2.0.6.tar.gz
<many files using the macro>
Victor On Tue, Aug 17, 2021 at 12:02 PM Łukasz Langa <lukasz@langa.pl> wrote:
Hi everybody, I'd like to revive this thread as I feel like we have to do something here but some consensus is needed first.
To recap, the current state of things is as follows: - in March 2000 (d724b23420f) Christian Tismer contributed the "trashcan" patch that added Py_TRASHCAN_SAFE_BEGIN and Py_TRASHCAN_SAFE_END macros which allow destroying nested objects non-recursively. - in May 2019 (GH-11841 of BPO-35983) Antoine Pitrou merged a change by Jeroen Demeyer which made Py_TRASHCAN_SAFE_BEGIN/END (unintentionally?) backwards incompatible; this was released in Python 3.8.0. - by the way, GH-11841 introduced a new pair of macros (because they have different signatures) called simply Py_TRASHCAN_BEGIN and Py_TRASHCAN_END. - by that time there was already a follow-up PR open (GH-12607) to improve backwards compatibility of the macros, as well as introduce tests for them; this was never merged. - in Feb 2020 (0fa4f43db08) Victor Stinner removed the trashcan mechanism from the limited C API (note: not ABI, those are macros) since it accesses fields of structs not exposed in the limited C API; this was released in Python 3.9.0. - in May 2020 Irit noticed that the backwards incompatibility (BPO-40608) causes segfaults for C API code that worked fine with Python 3.7. Using the new macros requires code changes but doesn't crash.
Now, there are a couple of things we can do here: Option 1: Finish GH-12607 to fix the old macros, keeping in mind this will restore compatibility lost with Python 3.8 - 3.10 only for users of 3.11+ Option 2: Review and merge GH-20104 that reverts the macro changes that make old client code segfault -- unclear what else this needs and again, that would only fix it for users of 3.11+ Option 3: Abandon GH-12607 and GH-20104, instead declaring the old macros deprecated for 3.11 and remove them in 3.13
I personally agree with Irit, voting +1 for Option 3 since the old macros were soft-deprecated already by introducing new macros in 3.8, and more importantly made incompatible with pre-3.8 usage.
Let's talk on how to proceed.
- Ł
On 26 Apr 2021, at 23:55, Irit Katriel via Python-Dev <python-dev@python.org> wrote:
Re https://bugs.python.org/issue40608.
I think it will be an act of kindness to deprecate Py_TRASHCAN_SAFE_BEGIN/END in 3.10 and tell people to use Py_TRASHCAN_BEGIN/END instead.
TL;DR: There was a change in 3.8 that introduced the latter while leaving the former for backwards compatibility, but also inadvertently breaking them. This is not an easy bug to deal with in the wild, we found it because we have a unit test in our codebase referencing https://bugs.python.org/issue16602. A deprecation note pointing to the new macros would have made it easier.
Is there any reason not to deprecate the old macros?
Irit _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/LWP6MOLP... Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/TH4NILYO... Code of Conduct: http://python.org/psf/codeofconduct/
-- Night gathers, and now my watch begins. It shall not end until my death.