diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-02-01 03:06:18 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-02-01 03:06:18 +0100 |
commit | 795c1e1dcc5f6965370070c1dd77642ba80387f8 (patch) | |
tree | af146f9d32ca7c319184731a113b9e2d2886c0ca | |
parent | dfb522f43f07baa67794cb418e7368664c77a4f3 (diff) | |
download | psutil-795c1e1dcc5f6965370070c1dd77642ba80387f8.tar.gz |
small C refactoring
-rw-r--r-- | psutil/_psutil_common.c | 19 | ||||
-rw-r--r-- | psutil/_psutil_common.h | 7 |
2 files changed, 5 insertions, 21 deletions
diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c index 0c86a4e6..990d59a6 100644 --- a/psutil/_psutil_common.c +++ b/psutil/_psutil_common.c @@ -24,25 +24,6 @@ int PSUTIL_TESTING = 0; // ==================================================================== /* - * Backport of unicode FS APIs from Python 3. - * On Python 2 we just return a plain byte string - * which is never supposed to raise decoding errors. - * See: https://github.com/giampaolo/psutil/issues/1040 - */ -#if PY_MAJOR_VERSION < 3 -PyObject * -PyUnicode_DecodeFSDefault(char *s) { - return PyString_FromString(s); -} - - -PyObject * -PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size) { - return PyString_FromStringAndSize(s, size); -} -#endif - -/* * Same as PyErr_SetFromErrno(0) but adds the syscall to the exception * message. */ diff --git a/psutil/_psutil_common.h b/psutil/_psutil_common.h index d45cf56b..60ea6298 100644 --- a/psutil/_psutil_common.h +++ b/psutil/_psutil_common.h @@ -20,8 +20,11 @@ static const int PSUTIL_CONN_NONE = 128; // ==================================================================== #if PY_MAJOR_VERSION < 3 - PyObject* PyUnicode_DecodeFSDefault(char *s); - PyObject* PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size); + // On Python 2 we just return a plain byte string, which is never + // supposed to raise decoding errors, see: + // https://github.com/giampaolo/psutil/issues/1040 + #define PyUnicode_DecodeFSDefault PyString_FromString + #define PyUnicode_DecodeFSDefaultAndSize PyString_FromStringAndSize #endif // Python 2: SIZEOF_PID_T not defined but _getpid() returns an int. |