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 lazka, ronaldoussoren, shihai1991, vstinner
Date 2020-12-01.23:47:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1606866466.24.0.118106509371.issue42522@roundup.psfhosted.org>
In-reply-to
Content
I had more time to think about this issue.

First, I decided to always include "pythoncapi_compat.h" and so there is no strict requirement to add new C API functions to Python.

Second, the _Py_Borrow() function looked nice, but there is a practical issue: its return type is always PyObject* which makes it not convenient to "convert" a function returning a different type.

For example, I replaced "frame->f_code" with "((PyCodeObject *)_Py_Borrow(PyFrame_GetCode(frame)))", but this expression requires 3 levels of parenthesis, it's long and it's hard to read :-( The outter parenthesis is needed if the modified expresion is used to get a code member, like: "frame->f_code->co_name".

I chose another approach: add a "Borrow" variant of the functions that I need.

For example, add _PyFrameGetCodeBorrow() variant of PyFrameGetCode(). This function is only added to pythoncapi_compat.h, and so Python doesn't have to be modified.

I reject my issue :-)
History
Date User Action Args
2020-12-01 23:47:46vstinnersetrecipients: + vstinner, ronaldoussoren, lazka, shihai1991
2020-12-01 23:47:46vstinnersetmessageid: <1606866466.24.0.118106509371.issue42522@roundup.psfhosted.org>
2020-12-01 23:47:46vstinnerlinkissue42522 messages
2020-12-01 23:47:45vstinnercreate