Repository navigation
Make PY_SSIZE_T_CLEAN not mandatory again #104922
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancement
on May 25, 2023 - changed the title
[-]Make PY_SSIZE_T_CLEAN not mandatolly again[/-][+]Make PY_SSIZE_T_CLEAN not mandatory again[/+]on May 25, 2023 After Python 3.12 become EOL, extension developers can forget about PY_SSIZE_T_CLEAN completely.
Python stdlib extensions still define the PY_SSIZE_T_CLEAN macro. Is it still useful? It's unclear to me.
Also, the official documentation also requires to define the PY_SSIZE_T_CLEAN macro: https://docs.python.org/dev/extending/extending.html
The first two lines of our file can be: #define PY_SSIZE_T_CLEAN #include <Python.h> (...) It is recommended to always define PY_SSIZE_T_CLEAN before including Python.h.See right after the doc. I added the link to https://docs.python.org/dev/c-api/arg.html#arg-parsing-string-and-buffers
And there is a note about it at link target.
Note On Python 3.12 and older, the macro PY_SSIZE_T_CLEAN must be defined before including Python.h to use all # variants of formats (s#, y#, etc.) explained below. This is not necessary on Python 3.13 and later.
I didn't remove the recommendation because user may want to support older Pythons.
Python stdlib extensions still define the PY_SSIZE_T_CLEAN macro. Is it still useful? It's unclear to me.
I didn't remove them to ease review and avoid conflicts. But I will remove them all.
The (extension) doc should just explain that the macro was needed on Python 3.12 and older.
- added a commit that references this issue
on Jul 3, 2023 As a side effect, this change fixed the stable ABI: #71686. Thanks!
Reacted by Erlend E. Aasland- added 11 commits that reference this issue
on Nov 28, 2024 - added 2 commits that reference this issue
on Dec 30, 2024 - added a commit that references this issue
on Aug 2, 2026
Feature or enhancement
Use ssize_t version API regardless PY_SSIZE_T_CLEAN is defined.
No change to ABI.
Pitch
After Python 3.12 become EOL, extension developers can forget about PY_SSIZE_T_CLEAN completely.
Previous discussion
https://mail.python.org/archives/list/python-dev@python.org/thread/KSREO43D6GQWO5LMVIU2LF7CP4IBYT2C/#FG44N6RL5CT5O3XQ6UV6LBLUCET7IF6I
Linked PRs
PY_SSIZE_T_CLEANnot mandatory #104923PY_SSIZE_T_CLEANnot mandatory again #105051