Skip to content

Commit

Permalink
#1672, #1682: SIZEOF_INT is not available on pypy3; assume that on sy…
Browse files Browse the repository at this point in the history
…stems where pid_t size can't be determined at runtime pid_t is an int
  • Loading branch information
giampaolo committed Feb 9, 2020
1 parent 796b2dd commit 05758f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions psutil/_psutil_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@ static const int PSUTIL_CONN_NONE = 128;
#define PyUnicode_DecodeFSDefaultAndSize PyString_FromStringAndSize
#endif

// Python 2: SIZEOF_PID_T not defined but _getpid() returns an int.
#if defined(PSUTIL_WINDOWS) && !defined(SIZEOF_PID_T)
#define SIZEOF_PID_T SIZEOF_INT
// --- _Py_PARSE_PID

// SIZEOF_INT|LONG is missing on Linux + PyPy (only?)
// SIZEOF_PID_T is missing on Windows + Python2
// In we can't determine we assume PID is an (int).
// On major UNIX platforms I've seen pid_t is treated as int.
// On Windows _getpid() returns an int. We can't be 100% certain though,
// (in that case we'd probably get compiler warnings).
#if !defined(SIZEOF_INT)
#define SIZEOF_INT 4
#endif

#if !defined(_Py_PARSE_PID) || PY_MAJOR_VERSION < 3
#if !defined(SIZEOF_PID_T) || !defined(SIZEOF_INT) || !defined(SIZEOF_LONG)
#error "missing SIZEOF* definition"
#endif
#if !defined(SIZEOF_LONG)
#define SIZEOF_LONG 8
#endif
#if !defined(SIZEOF_PID_T)
#define SIZEOF_PID_T 4 // assume int
#endif

// _Py_PARSE_PID is Python 3 only, but since it's private make sure it's
Expand Down
2 changes: 1 addition & 1 deletion psutil/_psutil_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static PyObject *
psutil_disk_partitions(PyObject *self, PyObject *args) {
FILE *file = NULL;
struct mntent *entry;
const char *mtab_path;
char *mtab_path;
PyObject *py_dev = NULL;
PyObject *py_mountp = NULL;
PyObject *py_tuple = NULL;
Expand Down

0 comments on commit 05758f6

Please sign in to comment.