GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-108765: Python.h no longer includes <unistd.h> by vstinner · Pull Request #108783 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Sep 1, 2023 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: C API: Cleanup header files #108765

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner vstinner added the skip news label Sep 1, 2023
@bedevere-bot bedevere-bot mentioned this pull request Sep 1, 2023
C API: Cleanup header files #108765
Closed
@vstinner vstinner mentioned this pull request Sep 1, 2023
gh-108765: [TEST] Test combined Python.h changes #108784
Closed
@vstinner
pythongh-108765: Python.h no longer includes <unistd.h>
f2f1abe
@vstinner
vstinner force-pushed the remove_unistd_h branch from 543f991 to f2f1abe Compare September 2, 2023 14:11
@vstinner
vstinner marked this pull request as ready for review September 2, 2023 14:11
@vstinner
vstinner requested a review from gpshead as a code owner September 2, 2023 14:11
@bedevere-bot bedevere-bot added the awaiting core review label Sep 2, 2023
@vstinner
vstinner merged commit 594b000 into python:main Sep 2, 2023
@vstinner
vstinner deleted the remove_unistd_h branch September 2, 2023 14:50
@bedevere-bot bedevere-bot removed the awaiting core review label Sep 2, 2023
@vstinner

vstinner commented Sep 2, 2023

Copy link
Copy Markdown
Member Author

I merged my PR.

If it causes too many trouble in 3rd party C extensions (require to update too many C extensions before Python 3.13 beta1), I can make this change conditional only in the limited C API version 3.13, as I did for other headers in Python.h:

// errno.h, stdio.h, stdlib.h and string.h headers are no longer used by Python
// headers, but kept for backward compatibility (no introduce new compiler
// warnings). They are not included by the limited C API version 3.11 and
// above.
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
#  include <errno.h>              // errno
#  include <stdio.h>              // FILE*
#  include <stdlib.h>             // getenv()
#  include <string.h>             // memcpy()
#endif

I consider that <unistd.h> is less commonly used by than the very common <errno.h>, <stdio.h>, <stdlib.h> and <string.h>. Again, if it causes too much burden, I can make the change conditional.

gpshead reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Sep 2, 2023
gh-108765: Python.h no longer includes <sys/time.h> #108775
Merged
gh-108765: Python.h no longer includes <ctype.h> #108831
Merged
@rgommers rgommers mentioned this pull request Oct 20, 2023
MAINT: fix a few issues with CPython main/3.13.0a1 numpy/numpy#24969
Merged
@jibal

jibal commented Oct 22, 2023

Copy link
Copy Markdown

breaks signalmodule.c

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Oct 22, 2023

Copy link
Copy Markdown
Member Author

breaks signalmodule.c

Would you mind to elaborate your comment "a little bit"? What is broken? Is it a build issue? On which Python version? On which OS (name, version) and compiler (name, version)?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jibal

jibal commented Oct 22, 2023

Copy link
Copy Markdown

signalmodule.c calls pause() and alarm() (under #ifdef HAVE_{PAUSE,ALARM} guards), which are defined in unistd.h

On the Python version where you deleted unistd.h from Python.h, of course.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Oct 27, 2023

Copy link
Copy Markdown
Member Author

signalmodule.c calls pause() and alarm() (under #ifdef HAVE_{PAUSE,ALARM} guards), which are defined in unistd.h

Hum, in fact, <unistd.h> is included indirectly by pycore_pythread.h. But well, I wrote PR #111402 to make it extra clear.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jibal

jibal commented Oct 27, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Hum, in fact, <unistd.h> is included indirectly by pycore_pythread.h.

Which is not necessarily included when signalmodule.c is compiled ... it wasn't in my build. (Which I've abandoned ... I never actually intended to build the top of tree.)

But well, I wrote PR #111402 to make it extra clear.

Seems like the right thing to do.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Oct 27, 2023

Copy link
Copy Markdown
Member Author

Which is not necessarily included when signalmodule.c is compiled ... it wasn't in my build. (Which I've abandoned ... I never actually intended to build the top of tree.)

You didn't reply to my question about OS and compiler... Also, pycore_pythread.h was modified recently.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner mentioned this pull request Nov 13, 2023
gh-112026: Add again <unistd.h> include in Python.h #112046
Merged
rathann added a commit to rathann/python-zstandard that referenced this pull request Nov 25, 2023
@rathann
add explicit <unistd.h> include
572ef4a
This fixes the following compilation error with Python 3.13.0a1:
```
c-ext/backend_c.c:275:13: error: implicit declaration of function ‘sysconf’; did you mean ‘sscanf’? [-Werror=implicit-function-declaration]
  275 |     count = sysconf(_SC_NPROCESSORS_ONLN);
      |             ^~~~~~~
      |             sscanf
```

According to https://docs.python.org/3.13/whatsnew/3.13.html:

Python.h no longer includes the <unistd.h> standard header file.
If needed, it should now be included explicitly.
For example, it provides the functions: read(), write(), close(), isatty(), lseek(), getpid(), getcwd(), sysconf() and getpagesize().
As a consequence, _POSIX_SEMAPHORES and _POSIX_THREADS macros are no longer defined by Python.h.
The HAVE_UNISTD_H and HAVE_PTHREAD_H macros defined by Python.h can be used to decide if <unistd.h> and <pthread.h> header files can be included.

See python/cpython#108783 .
@rathann rathann mentioned this pull request Nov 28, 2023
add explicit <unistd.h> include indygreg/python-zstandard#209
Closed
rathann added a commit to rathann/python-zstandard that referenced this pull request Mar 28, 2025
@rathann
add explicit <unistd.h> include
2e26bbf
This fixes the following compilation error with Python 3.13.0a1:
```
c-ext/backend_c.c:275:13: error: implicit declaration of function ‘sysconf’; did you mean ‘sscanf’? [-Werror=implicit-function-declaration]
  275 |     count = sysconf(_SC_NPROCESSORS_ONLN);
      |             ^~~~~~~
      |             sscanf
```

According to https://docs.python.org/3.13/whatsnew/3.13.html:

Python.h no longer includes the <unistd.h> standard header file.
If needed, it should now be included explicitly.
For example, it provides the functions: read(), write(), close(), isatty(), lseek(), getpid(), getcwd(), sysconf() and getpagesize().
As a consequence, _POSIX_SEMAPHORES and _POSIX_THREADS macros are no longer defined by Python.h.
The HAVE_UNISTD_H and HAVE_PTHREAD_H macros defined by Python.h can be used to decide if <unistd.h> and <pthread.h> header files can be included.

See python/cpython#108783 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gpshead gpshead Awaiting requested review from gpshead gpshead is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@vstinner @jibal @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.