STINNER Victor <vstin...@python.org> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42522>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to