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

Make PY_SSIZE_T_CLEAN not mandatory again #104922

Closed
methane opened this issue May 25, 2023 · 4 comments
Closed

Make PY_SSIZE_T_CLEAN not mandatory again #104922

methane opened this issue May 25, 2023 · 4 comments
Labels
topic-C-API type-feature A feature request or enhancement

Comments

@methane
Copy link
Member

methane commented May 25, 2023

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

@methane methane added type-feature A feature request or enhancement topic-C-API labels May 25, 2023
@AlexWaygood AlexWaygood changed the title Make PY_SSIZE_T_CLEAN not mandatolly again Make PY_SSIZE_T_CLEAN not mandatory again May 25, 2023
@methane methane closed this as completed May 31, 2023
@vstinner
Copy link
Member

vstinner commented Jul 1, 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.

@methane
Copy link
Member Author

methane commented Jul 1, 2023

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.

@vstinner
Copy link
Member

vstinner commented Jul 1, 2023

The (extension) doc should just explain that the macro was needed on Python 3.12 and older.

methane added a commit that referenced this issue Jul 2, 2023
Add note about PY_SSIZE_T_CLEAN in extending and embedding document.
carljm added a commit to carljm/cpython that referenced this issue Jul 3, 2023
* main: (167 commits)
  pythongh-91053: make func watcher tests resilient to other func watchers (python#106286)
  pythongh-104050: Add more type hints to Argument Clinic DSLParser() (python#106354)
  pythongh-106359: Fix corner case bugs in Argument Clinic converter parser (python#106361)
  pythongh-104146: Remove unused attr 'parameter_indent' from clinic.DLParser (python#106358)
  pythongh-106320: Remove private _PyErr C API functions (python#106356)
  pythongh-104050: Annotate Argument Clinic DSLParser attributes (python#106357)
  pythongh-106320: Create pycore_modsupport.h header file (python#106355)
  pythongh-106320: Move _PyUnicodeWriter to the internal C API (python#106342)
  pythongh-61215: New mock to wait for multi-threaded events to happen (python#16094)
  Document PYTHONSAFEPATH along side -P (python#106122)
  Replace the esoteric term 'datum' when describing dict comprehensions (python#106119)
  pythongh-104050: Add more type hints to Argument Clinic DSLParser() (python#106343)
  pythongh-106320: _testcapi avoids private _PyUnicode_EqualToASCIIString() (python#106341)
  pythongh-106320: Add pycore_complexobject.h header file (python#106339)
  pythongh-106078: Move DecimalException to _decimal state (python#106301)
  pythongh-106320: Use _PyInterpreterState_GET() (python#106336)
  pythongh-106320: Remove private _PyInterpreterState functions (python#106335)
  pythongh-104922: Doc: add note about PY_SSIZE_T_CLEAN (python#106314)
  pythongh-106217: Truncate the issue body size of `new-bugs-announce-notifier` (python#106329)
  pythongh-104922: remove PY_SSIZE_T_CLEAN (python#106315)
  ...
@vstinner
Copy link
Member

As a side effect, this change fixed the stable ABI: #71686. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-C-API type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants