Skip to content

Make PY_SSIZE_T_CLEAN not mandatory again #104922

Description

@methane

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

Activity

  1. changed the title [-]Make PY_SSIZE_T_CLEAN not mandatolly again[/-] [+]Make PY_SSIZE_T_CLEAN not mandatory again[/+] on May 25, 2023
  2. added a commit that references this issue on May 31, 2023
  3. vstinner commented on Jul 1, 2023

    @vstinner
    Member

    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.
    
  4. methane commented on Jul 1, 2023

    @methane
    MemberAuthor

    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.

  5. vstinner commented on Jul 1, 2023

    @vstinner
    Member

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

  6. added 2 commits that reference this issue on Jul 2, 2023
  7. added a commit that references this issue on Jul 3, 2023
  8. vstinner commented on Jan 16, 2024

    @vstinner
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions