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

[macOS, UNIX] prefer _SC_PAGESIZE over (partially) deprecated getpagesize() #1891

Merged
merged 2 commits into from
Dec 17, 2020

Conversation

giampaolo
Copy link
Owner

@giampaolo giampaolo commented Dec 17, 2020

Summary

Description

Add a reusable psutil_getpagesize() utility common to all UNIXes.

Related to #1885 (getpagesize() is deprecated on recent macOS, POSIX.1-2001 and possibly other UNIXes).

The problem emerged on macOS but getpagesize() is also used in FreeBSD, NetBSD, OpenBSD, AIX and sunOS, so it makes sense to do this in one place only, similarly to Windows which also provide a psutil_getpagesize() utility.

Follow cPython's mmapmodule.c and resourcemodule.c lead and rely on sysconf(_SC_PAGESIZE) instead, but leave getpagesize() in place as last resort/attempt since on some systems it appears it's not deprecated and/or they legitimately rely on it.

Also provide a python wrapper so we can test the return value of this C function against Python's stdlib modules.

Related to #1885. getpagesize() is deprecated on macOS, POSIX.1-2001 and
possibly other UNIXes.

The problem emerged on macOS but getpagesize() is also used in FreeBSD,
NetBSD, OpenBSD and AIX, so it makes sense to do this in one place only,
similarly to Windows which also provide a psutil_getpagesize() utility.

Follow cPython's mmapmodule.c and resourcemodule.c lead and rely on
`sysconf(_SC_PAGESIZE)` instead.

Leave getpagesize() in place as last resort/attemp for systems where it's
not deprecated or they still legitimately rely on it.

Also provide a python wrapper so we can test the return value of this C
function against Python's stdlib.

Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant