summaryrefslogtreecommitdiff
path: root/psutil/_psutil_aix.c
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-12-17 18:59:13 +0100
committerGitHub <noreply@github.com>2020-12-17 18:59:13 +0100
commit6bdde37049ba9fae31ccf83620468f77a6b9f396 (patch)
tree33875d40066b6b48b5ed5161d230288d968f6cc1 /psutil/_psutil_aix.c
parentc39fef497f0c2c963a9db03ef80cdb156f64a425 (diff)
downloadpsutil-6bdde37049ba9fae31ccf83620468f77a6b9f396.tar.gz
[macOS, UNIX] prefer _SC_PAGESIZE over (partially) deprecated getpagesize() (#1891)
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 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, but leave `getpagesize()` in place as last resort/attempt for systems where it's not deprecated and/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 modules. Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
Diffstat (limited to 'psutil/_psutil_aix.c')
-rw-r--r--psutil/_psutil_aix.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/psutil/_psutil_aix.c b/psutil/_psutil_aix.c
index 791e831e..a80bed70 100644
--- a/psutil/_psutil_aix.c
+++ b/psutil/_psutil_aix.c
@@ -876,7 +876,7 @@ error:
static PyObject *
psutil_virtual_mem(PyObject *self, PyObject *args) {
int rc;
- int pagesize = getpagesize();
+ long pagesize = psutil_getpagesize();
perfstat_memory_total_t memory;
rc = perfstat_memory_total(
@@ -902,7 +902,7 @@ psutil_virtual_mem(PyObject *self, PyObject *args) {
static PyObject *
psutil_swap_mem(PyObject *self, PyObject *args) {
int rc;
- int pagesize = getpagesize();
+ long pagesize = psutil_getpagesize();
perfstat_memory_total_t memory;
rc = perfstat_memory_total(