summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-01-25 18:29:30 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2020-01-25 18:29:30 +0100
commitb06141fc323f5b8211fa14786782610eebed666b (patch)
tree1fc7fd7515f9b6a6e41874b9fa1e268e5a018896
parent99f37f9f5d8a35c55baff584b4ad4a55640d4197 (diff)
downloadpsutil-b06141fc323f5b8211fa14786782610eebed666b.tar.gz
use _Py_PARSE_PID
-rw-r--r--psutil/_psutil_common.h18
-rw-r--r--psutil/_psutil_linux.c10
2 files changed, 23 insertions, 5 deletions
diff --git a/psutil/_psutil_common.h b/psutil/_psutil_common.h
index 7eb0e8bd..ed147469 100644
--- a/psutil/_psutil_common.h
+++ b/psutil/_psutil_common.h
@@ -25,6 +25,24 @@ static const int PSUTIL_CONN_NONE = 128;
PyObject *PyLong_FromPid(pid_t pid);
#endif
+// Python 2
+#ifndef _Py_PARSE_PID
+ #if !defined(SIZEOF_PID_T) || !defined(SIZEOF_INT) || !defined(SIZEOF_LONG)
+ #error "missing SIZEOF* definition"
+ #endif
+
+ #if SIZEOF_PID_T == SIZEOF_INT
+ #define _Py_PARSE_PID "i"
+ #elif SIZEOF_PID_T == SIZEOF_LONG
+ #define _Py_PARSE_PID "l"
+ #elif defined(SIZEOF_LONG_LONG) && SIZEOF_PID_T == SIZEOF_LONG_LONG
+ #define _Py_PARSE_PID "L"
+ #else
+ #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or "
+ "sizeof(long long)"
+ #endif
+#endif
+
// ====================================================================
// --- Custom exceptions
// ====================================================================
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
index 17835f1a..463e2d99 100644
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -99,7 +99,7 @@ static PyObject *
psutil_proc_ioprio_get(PyObject *self, PyObject *args) {
pid_t pid;
int ioprio, ioclass, iodata;
- if (! PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
+ if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
return NULL;
ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);
if (ioprio == -1)
@@ -122,7 +122,7 @@ psutil_proc_ioprio_set(PyObject *self, PyObject *args) {
int retval;
if (! PyArg_ParseTuple(
- args, "O&ii", Py_PidConverter, &pid, &ioclass, &iodata)) {
+ args, _Py_PARSE_PID "ii", &pid, &ioclass, &iodata)) {
return NULL;
}
ioprio = IOPRIO_PRIO_VALUE(ioclass, iodata);
@@ -149,7 +149,7 @@ psutil_linux_prlimit(PyObject *self, PyObject *args) {
PyObject *py_soft = NULL;
PyObject *py_hard = NULL;
- if (! PyArg_ParseTuple(args, "O&i|OO", Py_PidConverter, &pid, &resource,
+ if (! PyArg_ParseTuple(args, _Py_PARSE_PID "i|OO", &pid, &resource,
&py_soft, &py_hard)) {
return NULL;
}
@@ -299,7 +299,7 @@ psutil_proc_cpu_affinity_get(PyObject *self, PyObject *args) {
cpu_set_t *mask = NULL;
PyObject *py_list = NULL;
- if (!PyArg_ParseTuple(args, "O&", Py_PidConverter, &pid))
+ if (!PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
return NULL;
ncpus = NCPUS_START;
while (1) {
@@ -367,7 +367,7 @@ psutil_proc_cpu_affinity_set(PyObject *self, PyObject *args) {
PyObject *py_cpu_set;
PyObject *py_cpu_seq = NULL;
- if (!PyArg_ParseTuple(args, "O&O", Py_PidConverter, &pid, &py_cpu_set))
+ if (!PyArg_ParseTuple(args, _Py_PARSE_PID "O", &pid, &py_cpu_set))
return NULL;
if (!PySequence_Check(py_cpu_set)) {