diff options
author | Matthieu Darbois <mayeut@users.noreply.github.com> | 2022-10-21 01:02:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-21 01:02:23 +0200 |
commit | 614e91158ced7a65aabbe7244d52de1cebfc494b (patch) | |
tree | e69c295da7ebf41d4f6a11db6378e37916625f1a /psutil | |
parent | 1b09c1b54cb2ae46145de7f710e9b990cd264016 (diff) | |
download | psutil-614e91158ced7a65aabbe7244d52de1cebfc494b.tar.gz |
feature: use ABI3 for cp36+ (#2102)
Diffstat (limited to 'psutil')
-rw-r--r-- | psutil/_psutil_linux.c | 32 | ||||
-rw-r--r-- | psutil/arch/windows/process_info.c | 2 |
2 files changed, 14 insertions, 20 deletions
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c index 64cdf0b5..1ed1f91a 100644 --- a/psutil/_psutil_linux.c +++ b/psutil/_psutil_linux.c @@ -296,52 +296,46 @@ psutil_proc_cpu_affinity_set(PyObject *self, PyObject *args) { cpu_set_t cpu_set; size_t len; pid_t pid; - int i, seq_len; + Py_ssize_t i, seq_len; PyObject *py_cpu_set; - PyObject *py_cpu_seq = NULL; if (!PyArg_ParseTuple(args, _Py_PARSE_PID "O", &pid, &py_cpu_set)) return NULL; if (!PySequence_Check(py_cpu_set)) { - PyErr_Format(PyExc_TypeError, "sequence argument expected, got %s", - Py_TYPE(py_cpu_set)->tp_name); - goto error; + return PyErr_Format(PyExc_TypeError, "sequence argument expected, got %R", Py_TYPE(py_cpu_set)); } - py_cpu_seq = PySequence_Fast(py_cpu_set, "expected a sequence or integer"); - if (!py_cpu_seq) - goto error; - seq_len = PySequence_Fast_GET_SIZE(py_cpu_seq); + seq_len = PySequence_Size(py_cpu_set); + if (seq_len < 0) { + return NULL; + } CPU_ZERO(&cpu_set); for (i = 0; i < seq_len; i++) { - PyObject *item = PySequence_Fast_GET_ITEM(py_cpu_seq, i); + PyObject *item = PySequence_GetItem(py_cpu_set, i); + if (!item) { + return NULL; + } #if PY_MAJOR_VERSION >= 3 long value = PyLong_AsLong(item); #else long value = PyInt_AsLong(item); #endif + Py_XDECREF(item); if ((value == -1) || PyErr_Occurred()) { if (!PyErr_Occurred()) PyErr_SetString(PyExc_ValueError, "invalid CPU value"); - goto error; + return NULL; } CPU_SET(value, &cpu_set); } len = sizeof(cpu_set); if (sched_setaffinity(pid, len, &cpu_set)) { - PyErr_SetFromErrno(PyExc_OSError); - goto error; + return PyErr_SetFromErrno(PyExc_OSError); } - Py_DECREF(py_cpu_seq); Py_RETURN_NONE; - -error: - if (py_cpu_seq != NULL) - Py_DECREF(py_cpu_seq); - return NULL; } #endif /* PSUTIL_HAVE_CPU_AFFINITY */ diff --git a/psutil/arch/windows/process_info.c b/psutil/arch/windows/process_info.c index d44c4eb7..1981d306 100644 --- a/psutil/arch/windows/process_info.c +++ b/psutil/arch/windows/process_info.c @@ -578,7 +578,7 @@ psutil_get_cmdline(DWORD pid, int use_peb) { wcslen(szArglist[i])); if (py_unicode == NULL) goto out; - PyList_SET_ITEM(py_retlist, i, py_unicode); + PyList_SetItem(py_retlist, i, py_unicode); py_unicode = NULL; } ret = py_retlist; |