Skip to content

Commit

Permalink
#1672: warning pre-processor directive don't work on win + py2; also …
Browse files Browse the repository at this point in the history
…if struct.calcsize('l') < 8 assume int
  • Loading branch information
giampaolo committed Feb 13, 2020
1 parent f0b87e1 commit 573886f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions psutil/_psutil_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,17 @@ 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 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).
// In this case we guess it from setup.py. It's not 100% bullet proof,
// If wrong we'll probably get compiler warnings.
// FWIW on all UNIX platforms I've seen pid_t is defined as an int.
// _getpid() on Windows also returns an int.
#if !defined(SIZEOF_INT)
#define SIZEOF_INT 4
#endif
#if !defined(SIZEOF_LONG)
#define SIZEOF_LONG 8
#endif
#if !defined(SIZEOF_PID_T)
#if PSUTIL_SIZEOF_PID_T != 4
#warning "SIZEOF_PID_T was guessed"
#endif
#define SIZEOF_PID_T PSUTIL_SIZEOF_PID_T // set as a macro in setup.py
#endif

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# Needed to determine _Py_PARSE_PID in case it's missing (Python 2, PyPy).
# Taken from Lib/test/test_fcntl.py.
# XXX: not bullet proof as the (long long) case is missing.
if struct.calcsize('l') == 8:
if struct.calcsize('l') <= 8:
macros.append(('PSUTIL_SIZEOF_PID_T', '4')) # int
else:
macros.append(('PSUTIL_SIZEOF_PID_T', '8')) # long
Expand Down

0 comments on commit 573886f

Please sign in to comment.