summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-02-12 13:16:20 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2020-02-12 13:16:20 +0100
commit205f213dd5f548d19873a55ee1a7dc28a77d46e1 (patch)
tree6ad6cd6b9019682e3d97713704930495c6d85c05
parent3e2ee4f26f171e05b9b38a270c6baab63edb3f7e (diff)
downloadpsutil-205f213dd5f548d19873a55ee1a7dc28a77d46e1.tar.gz
fix pypy on Linux
-rw-r--r--psutil/_psutil_common.c82
-rw-r--r--psutil/_psutil_common.h2
-rwxr-xr-xpsutil/tests/test_system.py4
3 files changed, 42 insertions, 46 deletions
diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c
index 9bfaf92c..b8c6b5e5 100644
--- a/psutil/_psutil_common.c
+++ b/psutil/_psutil_common.c
@@ -10,55 +10,13 @@
#include "_psutil_common.h"
// ====================================================================
-// --- Global vars / constants
+// --- Global vars
// ====================================================================
-
int PSUTIL_DEBUG = 0;
int PSUTIL_TESTING = 0;
// PSUTIL_CONN_NONE
-
-// ====================================================================
-// --- Backward compatibility with missing Python.h APIs
-// ====================================================================
-
-// PyPy on Windows
-#if defined(PYPY_VERSION) && !defined(PyErr_SetFromWindowsErrWithFilename)
-PyObject *
-PyErr_SetFromWindowsErrWithFilename(int winerr, const char *filename) {
- PyObject *py_exc = NULL;
- PyObject *py_winerr = NULL;
-
- if (winerr == 0)
- winerr = GetLastError();
- if (filename == NULL) {
- py_exc = PyObject_CallFunction(PyExc_OSError, "(is)", winerr,
- strerror(winerr));
- }
- else {
- py_exc = PyObject_CallFunction(PyExc_OSError, "(iss)", winerr,
- strerror(winerr), filename);
- }
- if (py_exc == NULL)
- return NULL;
-
- py_winerr = Py_BuildValue("i", winerr);
- if (py_winerr == NULL)
- goto error;
- if (PyObject_SetAttrString(py_exc, "winerror", py_winerr) != 0)
- goto error;
- PyErr_SetObject(PyExc_OSError, py_exc);
- Py_XDECREF(py_exc);
- return NULL;
-
-error:
- Py_XDECREF(py_exc);
- Py_XDECREF(py_winerr);
- return NULL;
-}
-#endif
-
// ====================================================================
// --- Custom exceptions
// ====================================================================
@@ -84,6 +42,7 @@ PyErr_SetFromOSErrnoWithSyscall(const char *syscall) {
return NULL;
}
+
/*
* Set OSError(errno=ESRCH, strerror="No such process (originated from")
* Python exception.
@@ -185,6 +144,43 @@ CRITICAL_SECTION PSUTIL_CRITICAL_SECTION;
#define WIN32_FROM_NTSTATUS(Status) (((ULONG)(Status)) & 0xffff)
+// PyPy on Windows
+#if defined(PYPY_VERSION) && !defined(PyErr_SetFromWindowsErrWithFilename)
+PyObject *
+PyErr_SetFromWindowsErrWithFilename(int winerr, const char *filename) {
+ PyObject *py_exc = NULL;
+ PyObject *py_winerr = NULL;
+
+ if (winerr == 0)
+ winerr = GetLastError();
+ if (filename == NULL) {
+ py_exc = PyObject_CallFunction(PyExc_OSError, "(is)", winerr,
+ strerror(winerr));
+ }
+ else {
+ py_exc = PyObject_CallFunction(PyExc_OSError, "(iss)", winerr,
+ strerror(winerr), filename);
+ }
+ if (py_exc == NULL)
+ return NULL;
+
+ py_winerr = Py_BuildValue("i", winerr);
+ if (py_winerr == NULL)
+ goto error;
+ if (PyObject_SetAttrString(py_exc, "winerror", py_winerr) != 0)
+ goto error;
+ PyErr_SetObject(PyExc_OSError, py_exc);
+ Py_XDECREF(py_exc);
+ return NULL;
+
+error:
+ Py_XDECREF(py_exc);
+ Py_XDECREF(py_winerr);
+ return NULL;
+}
+#endif
+
+
// A wrapper around GetModuleHandle and GetProcAddress.
PVOID
psutil_GetProcAddress(LPCSTR libname, LPCSTR procname) {
diff --git a/psutil/_psutil_common.h b/psutil/_psutil_common.h
index 2886d611..b072e357 100644
--- a/psutil/_psutil_common.h
+++ b/psutil/_psutil_common.h
@@ -32,7 +32,7 @@ static const int PSUTIL_CONN_NONE = 128;
// SIZEOF_INT|LONG is missing on Linux + PyPy (only?).
// SIZEOF_PID_T is missing on Windows + Python2.
// In we can't determine pid_t size we assume it's an (int).
-// On major UNIX platforms I've seen pid_t is treated as int.
+// On all UNIX platforms I've seen pid_t is defined as an int.
// _getpid() on Windows returns an int. We can't be 100% sure though,
// (in that case we'd probably get compiler warnings).
#if !defined(SIZEOF_INT)
diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py
index 223f91a2..2d606be4 100755
--- a/psutil/tests/test_system.py
+++ b/psutil/tests/test_system.py
@@ -535,7 +535,7 @@ class TestSystemAPIs(unittest.TestCase):
ls = psutil.disk_partitions(all=True)
self.assertTrue(ls, msg=ls)
for disk in psutil.disk_partitions(all=True):
- if not WINDOWS:
+ if not WINDOWS and disk.mountpoint:
try:
os.stat(disk.mountpoint)
except OSError as err:
@@ -558,7 +558,7 @@ class TestSystemAPIs(unittest.TestCase):
mount = find_mount_point(__file__)
mounts = [x.mountpoint.lower() for x in
- psutil.disk_partitions(all=True)]
+ psutil.disk_partitions(all=True) if x.mountpoint]
self.assertIn(mount, mounts)
psutil.disk_usage(mount)