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.

classification
Title: [C API] Functions not exported with PyAPI_FUNC()
Type: Stage: patch review
Components: C API Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, corona10, eric.snow, serhiy.storchaka, shihai1991, vstinner
Priority: normal Keywords: patch

Created on 2021-09-29 08:18 by vstinner, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 31576 merged vstinner, 2022-02-25 14:13
PR 31577 merged vstinner, 2022-02-25 14:22
PR 31579 merged vstinner, 2022-02-25 14:43
PR 31580 merged vstinner, 2022-02-25 14:49
Messages (10)
msg402827 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-09-29 08:18
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().
msg402831 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-09-29 08:36
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.
msg402844 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-09-29 10:15
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
msg403641 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-11 09:50
See also bpo-45431: [C API] Rename CFrame or hide it to only export names starting with Py.
msg413995 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 14:41
New changeset 4a0c7a1aacd08cead7717479620e62359c828e88 by Victor Stinner in branch 'main':
bpo-45316: Move private PyCode C API to internal C API (GH-31576)
https://github.com/python/cpython/commit/4a0c7a1aacd08cead7717479620e62359c828e88
msg413996 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 14:41
New changeset 8ddbdd9e96e64b42c87dcfe4e38383cf0694988a by Victor Stinner in branch 'main':
bpo-45316: Move private PyDict functions to internal C API (GH-31577)
https://github.com/python/cpython/commit/8ddbdd9e96e64b42c87dcfe4e38383cf0694988a
msg414001 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 15:07
New changeset 8f2a337a80a283c66e1a4252839792fa229d2763 by Victor Stinner in branch 'main':
bpo-45316: Move private functions to internal C API (GH-31579)
https://github.com/python/cpython/commit/8f2a337a80a283c66e1a4252839792fa229d2763
msg414007 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 15:19
New changeset f780d9690f1a009a56ac0c653ec9608e6b2aeff4 by Victor Stinner in branch 'main':
bpo-45316: Move _PyArg_Fini() to internal C API (GH-31580)
https://github.com/python/cpython/commit/f780d9690f1a009a56ac0c653ec9608e6b2aeff4
msg414008 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-25 15:21
Update: only two remaining functions are not exported by the public C API:

int PySignal_SetWakeupFd(int fd);
int _Py_CheckPython3(void);
msg414019 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2022-02-25 16:49
Thanks for working on this, Victor.
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89479
2022-02-25 16:49:14eric.snowsetnosy: + eric.snow
messages: + msg414019
2022-02-25 15:21:28vstinnersetmessages: + msg414008
2022-02-25 15:19:34vstinnersetmessages: + msg414007
2022-02-25 15:07:18vstinnersetmessages: + msg414001
2022-02-25 14:49:45vstinnersetpull_requests: + pull_request29703
2022-02-25 14:43:25vstinnersetpull_requests: + pull_request29702
2022-02-25 14:41:59vstinnersetmessages: + msg413996
2022-02-25 14:41:40vstinnersetmessages: + msg413995
2022-02-25 14:22:12vstinnersetpull_requests: + pull_request29699
2022-02-25 14:13:13vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request29698
2021-10-11 09:50:40vstinnersetmessages: + msg403641
2021-10-07 02:10:16shihai1991setnosy: + shihai1991
2021-09-29 12:47:04corona10setnosy: + corona10
2021-09-29 10:15:35Mark.Shannonsetmessages: + msg402844
2021-09-29 09:51:46pablogsalsetnosy: + Mark.Shannon
2021-09-29 08:36:54serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg402831
2021-09-29 08:18:04vstinnercreate