Removal of _Py_ForgetReference from public header in 3.9 issue

Please excuse if this is the wrong mailing list. I couldn't find one for module maintainers. I maintain an open source Python module in C. I'm trying to verify for the first time that the module still works with cpython 3.9. This module does *not* use the "limited" C API. In building my module against 3.9b3, I'm getting a missing declaration warning on _Py_ForgetReference. My module builds and passes test fine, this is just a compiler warning issue. The change that caused this was made in: commit f58bd7c1693fe041f7296a5778d0a11287895648 Author: Victor Stinner <vstinner@python.org> Date: Wed Feb 5 13:12:19 2020 +0100 bpo-39542: Make PyObject_INIT() opaque in limited C API (GH-18363) ... I definitely need the _Py_ForgetReference call for a particularly hairy error condition (https://github.com/jnwatson/py-lmdb/blob/master/lmdb/cpython.c#L888 if you're curious). In fact, my tests will seg fault if I don't have that call and trace refs is enabled. Should I put an #ifdef Py_TRACE_REFS around the call? Ignore it? What do you think is the proper resolution? Nic Watson

On 2020-06-14 22:10, cpython@nicwatson.org wrote:
Please excuse if this is the wrong mailing list. I couldn't find one for module maintainers.
This is relevant to capi-sig@python.org; let's continue here.
I maintain an open source Python module in C. I'm trying to verify for the first time that the module still works with cpython 3.9. This module does *not* use the "limited" C API.
In building my module against 3.9b3, I'm getting a missing declaration warning on _Py_ForgetReference. My module builds and passes test fine, this is just a compiler warning issue.
What does the _Py_ForgetReference function do? The [documentation] says it's only for use in the interpereter core, so I'd assume it's . [documentation]: https://docs.python.org/3/c-api/refcounting.html
The change that caused this was made in:
commit f58bd7c1693fe041f7296a5778d0a11287895648 Author: Victor Stinner <vstinner@python.org> Date: Wed Feb 5 13:12:19 2020 +0100
bpo-39542: Make PyObject_INIT() opaque in limited C API (GH-18363) ...
I definitely need the _Py_ForgetReference call for a particularly hairy error condition (https://github.com/jnwatson/py-lmdb/blob/master/lmdb/cpython.c#L888 if you're curious). In fact, my tests will seg fault if I don't have that call and trace refs is enabled.
I can't follow the reasoning behind the code easily. Why do you use _Py_ForgetReference and PyObject_Del, instead of Py_DECREF(self)?
Should I put an #ifdef Py_TRACE_REFS around the call? Ignore it? What do you think is the proper resolution?

On 15.06.2020 11:02, Petr Viktorin wrote:
On 2020-06-14 22:10, cpython@nicwatson.org wrote:
I maintain an open source Python module in C. I'm trying to verify for the first time that the module still works with cpython 3.9. This module does *not* use the "limited" C API.
In building my module against 3.9b3, I'm getting a missing declaration warning on _Py_ForgetReference. My module builds and passes test fine, this is just a compiler warning issue.
What does the _Py_ForgetReference function do? The [documentation] says it's only for use in the interpereter core, so I'd assume it's .
[documentation]: https://docs.python.org/3/c-api/refcounting.html
This is typically used in error handlers of constructors where you want to avoid having the deallocator run as result of the DECREF, e.g. because the object has not been full initialized yet. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Jun 15 2020)
Python Projects, Coaching and Support ... https://www.egenix.com/ Python Product Development ... https://consulting.egenix.com/
::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/
participants (3)
-
cpython@nicwatson.org
-
M.-A. Lemburg
-
Petr Viktorin