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

Include <unistd.h> to avoid implicit-function-declaration for close and syscall #2321

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

hroncok
Copy link
Contributor

@hroncok hroncok commented Oct 23, 2023

Summary

  • OS: Linux
  • Bug fix: yes
  • Type: core
  • Fixes: build failure on Python 3.13 with -Werror=implicit-function-declaration

Description

See 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().

@giampaolo
Copy link
Owner

Can you paste the compilation error? We don't use those functions in _psutil_linux.c, but perhaps we do in arch/linux/*.c files, so that should be added to those files, not _psutil_linux.c (and perhaps other files in arch/{OS}/*.c).

@hroncok
Copy link
Contributor Author

hroncok commented Oct 23, 2023

Ah, sorry, should have pasted that in the first place:

Those were the errors I started with in 5.9.6:

      psutil/_psutil_linux.c: In function ‘ioprio_get’:
      psutil/_psutil_linux.c:73:12: error: implicit declaration of function ‘syscall’ [-Werror=implicit-function-declaration]
         73 |     return syscall(__NR_ioprio_get, which, who);
            |            ^~~~~~~
      psutil/_psutil_linux.c: In function ‘psutil_net_if_duplex_speed’:
      psutil/_psutil_linux.c:488:5: error: implicit declaration of function ‘close’; did you mean ‘clone’? [-Werror=implicit-function-declaration]
        488 |     close(sock);
            |     ^~~~~
            |     clone

Then I checked on the master branch and haven't noticed the error is a tad different:

      psutil/arch/linux/net.c: In function ‘psutil_net_if_duplex_speed’:
      psutil/arch/linux/net.c:112:5: error: implicit declaration of function ‘close’; did you mean ‘pclose’? [-Werror=implicit-function-declaration]
        112 |     close(sock);
            |     ^~~~~
            |     pclose

Will move the include to psutil/arch/linux/net.c and amend the commit message.

@hroncok
Copy link
Contributor Author

hroncok commented Oct 23, 2023

And the other one is:

      psutil/arch/linux/proc.c: In function ‘ioprio_get’:
      psutil/arch/linux/proc.c:22:12: error: implicit declaration of function ‘syscall’ [-Werror=implicit-function-declaration]
         22 |     return syscall(__NR_ioprio_get, which, who);
            |            ^~~~~~~

@giampaolo
Copy link
Owner

While you're at it, can you also update these guys?

psutil/arch/solaris/environ.c
psutil/_psutil_sunos.c

…nd syscall

See 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().
"""

(I have not tested the additions to non-linux files.)
@hroncok
Copy link
Contributor Author

hroncok commented Oct 23, 2023

Done.

@giampaolo giampaolo merged commit e9dabbb into giampaolo:master Oct 24, 2023
11 of 14 checks passed
@hroncok hroncok deleted the unistd branch October 24, 2023 20:38
@hroncok
Copy link
Contributor Author

hroncok commented Oct 24, 2023

Thanks for merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants