This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients ronaldoussoren, shihai1991, vstinner
Date 2020-12-01.12:30:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1606825839.97.0.851573126173.issue42522@roundup.psfhosted.org>
In-reply-to
Content
Ronald Oussoren: "I'm -1 on adding this API as it is inherently unsafe and is bound to be used in locations where its contract is not honoured (especially outside of the core)."

I'm trying to update old C extensions which already rely on borrowed references.

I expect that only my script will use this function. Developers should not call it directly, but use strong references. I explained it in the function documentation.

Obviously, using strong references is safer, but it's not possible to automate the conversion of borrowed references to strong references. Maybe it's possible on simple functions, but not in the general code (long functions with loops, function calls, goto, etc.).


> Note that the pre-condition on the argument is that you now only own a reference to the object, but that there's also someone else that owns a reference.

Py_Borrow() is unsafe by design and should not be used :-)

Replacing frame->f_code with Py_Borrow(PyFrame_GetCode(frame)) doesn't make the code worse nor better in term of reference counting.


> It is better to bite the bullet and go for correct reference count updates when converting to the new PyFrame_GetCode API.

My goal is to automate conversion to new C API. Using strong references is really challenging and I expect that it would be done manually.

--

Once a code base is updated to use Py_Borrow(), it might become possible to replace automatically some simple patterns to use strong references.
History
Date User Action Args
2020-12-01 12:30:39vstinnersetrecipients: + vstinner, ronaldoussoren, shihai1991
2020-12-01 12:30:39vstinnersetmessageid: <1606825839.97.0.851573126173.issue42522@roundup.psfhosted.org>
2020-12-01 12:30:39vstinnerlinkissue42522 messages
2020-12-01 12:30:39vstinnercreate