Skip to content

gh-136823: Update documentation on excluded headers in Python.h #136824

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SZeltaat
Copy link
Contributor

@SZeltaat SZeltaat commented Jul 19, 2025

This part of the documentation from https://docs.python.org/3/extending/extending.html#a-simple-example is currently outdated:

All user-visible symbols defined by Python.h have a prefix of Py or PY, except those defined in standard header files. For convenience, and since they are used extensively by the Python interpreter, "Python.h" includes a few standard header files: <stdio.h>, <string.h>, <errno.h>, and <stdlib.h>. If the latter header file does not exist on your system, it declares the functions malloc(), free() and realloc() directly.

This PR aligns the documentation with the code and the comments provided by the original author that implemented the changes.


📚 Documentation preview 📚: https://cpython-previews--136824.org.readthedocs.build/

@SZeltaat
Copy link
Contributor Author

Hi @AA-Turner, could you please take a look at this PR?
#EuroPython2025

``PY``, except those defined in standard header files.

Note that :file:`Python.h` excludes ``<stdio.h>``, ``<string.h>``, ``<errno.h>``, and ``<stdlib.h>`` as they are not used by
Python anymore. For backward compatibility of existing third party C extensions, they will

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we write down since which version they are no longer used, as we did for <ctype.h> and <unistd.h>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the right thing to do, but I couldn't find since which version they are no longer used. @vstinner, you seem to have added that comment to the code 4 years ago. Do you happen to know since which version?

@AA-Turner AA-Turner added sprint needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jul 19, 2025
Comment on lines 80 to 83
Note that :file:`Python.h` excludes ``<stdio.h>``, ``<string.h>``, ``<errno.h>``, and ``<stdlib.h>`` as they are not used by
Python anymore. For backward compatibility of existing third party C extensions, they will
be included if Py_LIMITED_API is not defined and for limited C API version 3.10 and older.
The ``<ctype.h>`` and ``<unistd.h>`` headers are also not included for limited C API version 3.13 and newer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Note that :file:`Python.h` excludes ``<stdio.h>``, ``<string.h>``, ``<errno.h>``, and ``<stdlib.h>`` as they are not used by
Python anymore. For backward compatibility of existing third party C extensions, they will
be included if Py_LIMITED_API is not defined and for limited C API version 3.10 and older.
The ``<ctype.h>`` and ``<unistd.h>`` headers are also not included for limited C API version 3.13 and newer.
For backward compatibility of existing third party C extensions, :file:`Python.h`
includes ``<stdio.h>``, ``<string.h>``, ``<errno.h>``, and ``<stdlib.h>`` iff
:c:macro:`Py_LIMITED_API` is not defined or for limited C API version 3.10 and older.
The ``<ctype.h>`` and ``<unistd.h>`` headers are also not included for limited C API version 3.13 and newer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news sprint
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

5 participants