New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C API] Functions not exported with PyAPI_FUNC() #89479
Comments
The Python C API contains multiple functions which are not exported with PyAPI_FUNC() and so are not usable. Public functions: void PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range);
int PyLineTable_NextAddressRange(PyCodeAddressRange *range);
int PyLineTable_PreviousAddressRange(PyCodeAddressRange *range); => Either make this functions private ("_Py" prefix) and move them to the internal C API, or add PyAPI_FUNC(). Private functions: int _PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds);
int _PyCode_InitEndAddressRange(PyCodeObject* co, PyCodeAddressRange* bounds);
PyDictKeysObject *_PyDict_NewKeysForClass(void);
Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys);
uint32_t _PyDictKeys_GetVersionForCurrentState(PyDictKeysObject *dictkeys);
Py_ssize_t _PyDictKeys_StringLookup(PyDictKeysObject* dictkeys, PyObject *key);
PyObject *_PyDict_Pop_KnownHash(PyObject *, PyObject *, Py_hash_t, PyObject *);
PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value);
PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
Py_ssize_t _PyDict_GetItemHint(PyDictObject *, PyObject *, Py_ssize_t, PyObject **);
PyFrameObject* _PyFrame_New_NoTrack(struct _interpreter_frame *, int);
int PySignal_SetWakeupFd(int fd);
uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func);
PyObject *_PyGen_yf(PyGenObject *);
PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
PyObject *_PyAsyncGenValueWrapperNew(PyObject *);
void _PyArg_Fini(void);
int _Py_CheckPython3(void); => I suggest to move all these declarations to the internal C API. Moreover, Include/moduleobject.h contains: #ifdef Py_BUILD_CORE
extern int _PyModule_IsExtension(PyObject *obj);
#endif IMO this declaration should be moved to the internal C API. See also bpo-45201 about PySignal_SetWakeupFd(). |
Agree. We should also review all recently added functions with PyAPI_FUNC(). If they are not intended to be public API, PyAPI_FUNC() should be removed and declarations moved. |
Regarding these three functions: void PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range);
int PyLineTable_NextAddressRange(PyCodeAddressRange *range);
int PyLineTable_PreviousAddressRange(PyCodeAddressRange *range); They are explicitly not part of the C API (limited or otherwise): https://www.python.org/dev/peps/pep-0626/#out-of-process-debuggers-and-profilers |
See also bpo-45431: [C API] Rename CFrame or hide it to only export names starting with Py. |
Update: only two remaining functions are not exported by the public C API: int PySignal_SetWakeupFd(int fd);
int _Py_CheckPython3(void); |
Thanks for working on this, Victor. |
@vstinner hello, I find #31576 cause the
Maybe this declaration should be written to another file |
Please open a new issue for your build error. It's unrelated to this issue. |
I close this issue. I don't know how to handle PySignal_SetWakeupFd() and _Py_CheckPython3(). |
Oh wait, I misunderstood the issue. You're right, it's a regression caused by commit 4a0c7a1. I wrote PR #92011 to fix it. I didn't notice that this function is actually used by a C extension built as a shared library, but only for a special build. |
Thanks |
When Python is built with "./configure --enable-pystats" (if the Py_STATS macro is defined), the _Py_GetSpecializationStats() function must be exported, since it's used by the _opcode extension which is built as a shared library.
Merged. I close again the issue. |
How are you supposed to use these functions than? |
They are not public on purpose. If you consider that they should be public, please open a feature request (a new issue). This issue is now closed, it's a bad place to discuss it. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: