diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-10-17 20:10:43 +0800 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-10-17 20:10:43 +0800 |
commit | cdae54a8307d690ecf48454a47619b02a507c635 (patch) | |
tree | 0dc424f04682be0c91d5b9f151dc430fdb218f6f | |
parent | ad0f2d200e2d0bb061bf20045126bf8aa87d289e (diff) | |
download | psutil-cdae54a8307d690ecf48454a47619b02a507c635.tar.gz |
port _psutil_linux
-rw-r--r-- | psutil/_psutil_linux.c | 69 |
1 files changed, 22 insertions, 47 deletions
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c index 4bf53b85..05e52673 100644 --- a/psutil/_psutil_linux.c +++ b/psutil/_psutil_linux.c @@ -612,7 +612,6 @@ PsutilMethods[] = { {"linux_prlimit", psutil_linux_prlimit, METH_VARARGS, "Get or set process resource limits."}, #endif - // --- others {"set_testing", psutil_set_testing, METH_NOARGS, "Set psutil in testing mode"}, @@ -620,52 +619,28 @@ PsutilMethods[] = { {NULL, NULL, 0, NULL} }; -struct module_state { - PyObject *error; -}; #if PY_MAJOR_VERSION >= 3 -#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m)) -#else -#define GETSTATE(m) (&_state) -#endif - -#if PY_MAJOR_VERSION >= 3 - -static int -psutil_linux_traverse(PyObject *m, visitproc visit, void *arg) { - Py_VISIT(GETSTATE(m)->error); - return 0; -} - -static int -psutil_linux_clear(PyObject *m) { - Py_CLEAR(GETSTATE(m)->error); - return 0; -} - -static struct PyModuleDef - moduledef = { - PyModuleDef_HEAD_INIT, - "psutil_linux", - NULL, - sizeof(struct module_state), - PsutilMethods, - NULL, - psutil_linux_traverse, - psutil_linux_clear, - NULL -}; - -#define INITERROR return NULL - -PyMODINIT_FUNC PyInit__psutil_linux(void) - -#else -#define INITERROR return - -void init_psutil_linux(void) -#endif + #define INITERR return NULL + + static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "psutil_linux", + NULL, + -1, + PsutilMethods, + NULL, + NULL, + NULL, + NULL + }; + + PyObject *PyInit__psutil_linux(void) +#else /* PY_MAJOR_VERSION */ + #define INITERR return + + void init_psutil_linux(void) +#endif /* PY_MAJOR_VERSION */ { PyObject *v; #if PY_MAJOR_VERSION >= 3 @@ -674,7 +649,7 @@ void init_psutil_linux(void) PyObject *module = Py_InitModule("_psutil_linux", PsutilMethods); #endif if (module == NULL) - INITERROR; + INITERR; PyModule_AddIntConstant(module, "version", PSUTIL_VERSION); #if PSUTIL_HAVE_PRLIMIT @@ -723,7 +698,7 @@ void init_psutil_linux(void) PyModule_AddIntConstant(module, "DUPLEX_UNKNOWN", DUPLEX_UNKNOWN); if (module == NULL) - INITERROR; + INITERR; #if PY_MAJOR_VERSION >= 3 return module; #endif |