Skip to content
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: Remove private C API functions (move them to the internal C API) #106320

Closed
vstinner opened this issue Jul 1, 2023 · 55 comments
Closed

C API: Remove private C API functions (move them to the internal C API) #106320

vstinner opened this issue Jul 1, 2023 · 55 comments

Comments

@vstinner
Copy link
Member

vstinner commented Jul 1, 2023

Over the years, we accumulated many private functions as part of the public C API header files. I propose to remove them: move them to the internal C API.

If many C extensions are affected by these removals, it's a sign that we should consider promoted used private functions as public functions: provide a better API, add error handling, write documentation, write tests.


Summary: My plan to clarify private vs public functions in Python 3.13


Linked PRs

vstinner added a commit to vstinner/cpython that referenced this issue Jul 1, 2023
Replace calls to the (removed) slow _PyInterpreterState_Get() with
fast inlined _PyInterpreterState_GET() function.
vstinner added a commit to vstinner/cpython that referenced this issue Jul 1, 2023
Replace calls to the (removed) slow _PyInterpreterState_Get() with
fast inlined _PyInterpreterState_GET() function.
vstinner added a commit to vstinner/cpython that referenced this issue Jul 1, 2023
Replace calls to the (removed) slow _PyInterpreterState_Get() with
fast inlined _PyInterpreterState_GET() function.
@vstinner
Copy link
Member Author

vstinner commented Jul 1, 2023

See also issue #106316: remove pytime.h header file (_PyTime functions).

@vstinner
Copy link
Member Author

vstinner commented Jul 1, 2023

See also issue #106084: C API: Remove private functions from abstract.h.

@vstinner
Copy link
Member Author

vstinner commented Jul 1, 2023

See also commit 0b51463:

Remove the following private functions of the C API:

* _PyCodecInfo_GetIncrementalDecoder()
* _PyCodecInfo_GetIncrementalEncoder()
* _PyCodec_DecodeText()
* _PyCodec_EncodeText()
* _PyCodec_Forget()
* _PyCodec_Lookup()
* _PyCodec_LookupTextEncoding()

vstinner added a commit to vstinner/cpython that referenced this issue Jul 1, 2023
Replace calls to the (removed) slow _PyInterpreterState_Get() with
fast inlined _PyInterpreterState_GET() function.
vstinner added a commit that referenced this issue Jul 1, 2023
Replace calls to the (removed) slow _PyInterpreterState_Get() with
fast inlined _PyInterpreterState_GET() function.
vstinner added a commit to vstinner/cpython that referenced this issue Jul 2, 2023
* Remove private _PyTracemalloc C API functions: move them to the
  internal C API.
* Rename Include/tracemalloc.h to Include/cpython/tracemalloc.h
vstinner added a commit to vstinner/cpython that referenced this issue Jul 2, 2023
* Remove private _PyTracemalloc C API functions: move them to the
  internal C API.
* Don't export private _PyTracemalloc functions anymore.
* Rename Include/tracemalloc.h to Include/cpython/tracemalloc.h
vstinner added a commit to vstinner/cpython that referenced this issue Jul 2, 2023
* Remove private _PyTraceMalloc C API functions: move them to the
  internal C API.
* Don't export most of these functions anymore, but still export
  _PyTraceMalloc_GetTraceback() used by tests.
* Rename Include/tracemalloc.h to Include/cpython/tracemalloc.h
vstinner added a commit to vstinner/cpython that referenced this issue Jul 2, 2023
Remove private _PyThreadState and _PyInterpreterState C API
functions: move them to the internal C API (pycore_pystate.h and
pycore_interp.h). Don't export most of these functions anymore, but
still export functions used by tests.

Remove _PyThreadState_Prealloc() and _PyThreadState_Init() from the C
API, but keep it in the stable API.
vstinner added a commit that referenced this issue Jul 2, 2023
* Remove private _PyTraceMalloc C API functions: move them to the
  internal C API.
* Don't export most of these functions anymore, but still export
  _PyTraceMalloc_GetTraceback() used by tests.
* Rename Include/tracemalloc.h to Include/cpython/tracemalloc.h
vstinner added a commit to vstinner/cpython that referenced this issue Jul 2, 2023
Remove private _PyThreadState and _PyInterpreterState C API
functions: move them to the internal C API (pycore_pystate.h and
pycore_interp.h). Don't export most of these functions anymore, but
still export functions used by tests.

Remove _PyThreadState_Prealloc() and _PyThreadState_Init() from the C
API, but keep it in the stable API.
vstinner added a commit that referenced this issue Jul 2, 2023
Remove private _PyThreadState and _PyInterpreterState C API
functions: move them to the internal C API (pycore_pystate.h and
pycore_interp.h). Don't export most of these functions anymore, but
still export functions used by tests.

Remove _PyThreadState_Prealloc() and _PyThreadState_Init() from the C
API, but keep it in the stable API.
vstinner added a commit to vstinner/cpython that referenced this issue Jul 2, 2023
Remove private _PyThreadState and _PyInterpreterState C API
functions: move them to the internal C API (pycore_pystate.h and
pycore_interp.h). Don't export most of these functions anymore, but
still export functions used by tests.

Remove _PyThreadState_Prealloc() and _PyThreadState_Init() from the C
API, but keep it in the stable API.
vstinner added a commit to vstinner/cpython that referenced this issue Jul 2, 2023
Replace PyInterpreterState_Get() with inlined
_PyInterpreterState_GET().
vstinner added a commit to vstinner/cpython that referenced this issue Jul 2, 2023
Replace PyInterpreterState_Get() with inlined
_PyInterpreterState_GET().
vstinner added a commit that referenced this issue Jul 2, 2023
Remove private _PyThreadState and _PyInterpreterState C API
functions: move them to the internal C API (pycore_pystate.h and
pycore_interp.h). Don't export most of these functions anymore, but
still export functions used by tests.

Remove _PyThreadState_Prealloc() and _PyThreadState_Init() from the C
API, but keep it in the stable API.
vstinner added a commit to vstinner/cpython that referenced this issue Jul 2, 2023
Replace PyInterpreterState_Get() with inlined
_PyInterpreterState_GET().
vstinner added a commit that referenced this issue Jul 2, 2023
Replace PyInterpreterState_Get() with inlined
_PyInterpreterState_GET().
vstinner added a commit to vstinner/cpython that referenced this issue Jul 2, 2023
Add internal pycore_complexobject.h header file.

Move _Py_c_xxx() functions and _PyComplex_FormatAdvancedWriter()
function to this new header file.
vstinner added a commit to vstinner/cpython that referenced this issue Jul 2, 2023
…ng()

Replace private _PyUnicode_EqualToASCIIString() with public
PyUnicode_CompareWithASCIIString().
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
…#111162)

* pythongh-106320: Re-add _PyLong_FromByteArray(), _PyLong_AsByteArray() and _PyLong_GCD() to the public header files since they are used by third-party packages and there is no efficient replacement.

See python#111140
See python#111139

* pythongh-111262: Re-add _PyDict_Pop() to have a C-API until a new public one is designed.
lachbr pushed a commit to toontownretro/panda that referenced this issue Feb 17, 2024
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
…#106335)

Remove private _PyThreadState and _PyInterpreterState C API
functions: move them to the internal C API (pycore_pystate.h and
pycore_interp.h). Don't export most of these functions anymore, but
still export functions used by tests.

Remove _PyThreadState_Prealloc() and _PyThreadState_Init() from the C
API, but keep it in the stable API.
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 27, 2024
…#106335)

Remove private _PyThreadState and _PyInterpreterState C API
functions: move them to the internal C API (pycore_pystate.h and
pycore_interp.h). Don't export most of these functions anymore, but
still export functions used by tests.

Remove _PyThreadState_Prealloc() and _PyThreadState_Init() from the C
API, but keep it in the stable API.
adorilson pushed a commit to adorilson/cpython that referenced this issue Jun 26, 2024
…#106335)

Remove private _PyThreadState and _PyInterpreterState C API
functions: move them to the internal C API (pycore_pystate.h and
pycore_interp.h). Don't export most of these functions anymore, but
still export functions used by tests.

Remove _PyThreadState_Prealloc() and _PyThreadState_Init() from the C
API, but keep it in the stable API.
arthurzam added a commit to arthurzam/py-tree-sitter that referenced this issue Aug 28, 2024
The `_PyErr_FormatFromCause` function is a private function, which was
never documented. While it existed for a long time, it was removed in
Python 3.13 [1].

Use instead the public function `PyErr_Format`, which is also part of
the stable API.

[1] python/cpython#106320

Signed-off-by: Arthur Zamarin <[email protected]>
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
…#111162)

* pythongh-106320: Re-add _PyLong_FromByteArray(), _PyLong_AsByteArray() and _PyLong_GCD() to the public header files since they are used by third-party packages and there is no efficient replacement.

See python#111140
See python#111139

* pythongh-111262: Re-add _PyDict_Pop() to have a C-API until a new public one is designed.
ludwigschwardt added a commit to ludwigschwardt/python-gnureadline that referenced this issue Oct 17, 2024
Python 3.13 moved some private C API functions to internal header files.
See python/cpython#106320 for a general discussion on this (glad to see
that gnureadline was at least listed as an affected PyPI package :-) ).

These private functions affect us:
  - _Py_SetLocaleFromEnv -> pycore_pylifecycle.h
    (see python/cpython#106400)
  - _PyArg_CheckPositional, _PyArg_BadArgument -> pycore_modsupport.h
    (see python/cpython#110964)

Since we can't include these anymore, patch the relevant declarations into
the module code. The alternative (add the internal headers to this package)
is much messier, as we would have to pull in most of those headers.
@clin1234
Copy link

@vstinner Given the number of commits in various projects affected by this, perhaps there should a comprehensive list of replacement functions for each corresponding private function included in the What's New section within 3.13's documentation.

@vstinner
Copy link
Member Author

@clin1234:

@vstinner Given the number of commits in various projects affected by this, perhaps there should a comprehensive list of replacement functions for each corresponding private function included in the What's New section within 3.13's documentation.

Good idea: I created #128787 for that.

vstinner added a commit to vstinner/cpython that referenced this issue Jan 13, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 14, 2025
vstinner added a commit that referenced this issue Jan 14, 2025
…128837)

gh-106320: Document replacement for removed C API (GH-128787)
(cherry picked from commit 43ef958)

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants