Message382284
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 :-) |
|
| Date |
User |
Action |
Args |
| 2020-12-01 23:47:46 | vstinner | set | recipients:
+ vstinner, ronaldoussoren, lazka, shihai1991 |
| 2020-12-01 23:47:46 | vstinner | set | messageid: <1606866466.24.0.118106509371.issue42522@roundup.psfhosted.org> |
| 2020-12-01 23:47:46 | vstinner | link | issue42522 messages |
| 2020-12-01 23:47:45 | vstinner | create | |
|