summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-10-17 20:27:56 +0800
committerGiampaolo Rodola <g.rodola@gmail.com>2019-10-17 20:27:56 +0800
commit0522e80461c8c984b824e257287c655616f4703d (patch)
treef224f695af9614d36e7c2913e12ee18fab9e5eb3
parentcdae54a8307d690ecf48454a47619b02a507c635 (diff)
downloadpsutil-0522e80461c8c984b824e257287c655616f4703d.tar.gz
check return value of PyModule_AddIntConstant
-rw-r--r--psutil/_psutil_linux.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
index 05e52673..d6cb8719 100644
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -625,7 +625,7 @@ PsutilMethods[] = {
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
- "psutil_linux",
+ "_psutil_linux",
NULL,
-1,
PsutilMethods,
@@ -644,26 +644,26 @@ PsutilMethods[] = {
{
PyObject *v;
#if PY_MAJOR_VERSION >= 3
- PyObject *module = PyModule_Create(&moduledef);
+ PyObject *mod = PyModule_Create(&moduledef);
#else
- PyObject *module = Py_InitModule("_psutil_linux", PsutilMethods);
+ PyObject *mod = Py_InitModule("_psutil_linux", PsutilMethods);
#endif
- if (module == NULL)
+ if (mod == NULL)
INITERR;
- PyModule_AddIntConstant(module, "version", PSUTIL_VERSION);
+ if (PyModule_AddIntConstant(mod, "version", PSUTIL_VERSION)) INITERR;
#if PSUTIL_HAVE_PRLIMIT
- PyModule_AddIntConstant(module, "RLIMIT_AS", RLIMIT_AS);
- PyModule_AddIntConstant(module, "RLIMIT_CORE", RLIMIT_CORE);
- PyModule_AddIntConstant(module, "RLIMIT_CPU", RLIMIT_CPU);
- PyModule_AddIntConstant(module, "RLIMIT_DATA", RLIMIT_DATA);
- PyModule_AddIntConstant(module, "RLIMIT_FSIZE", RLIMIT_FSIZE);
- PyModule_AddIntConstant(module, "RLIMIT_LOCKS", RLIMIT_LOCKS);
- PyModule_AddIntConstant(module, "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK);
- PyModule_AddIntConstant(module, "RLIMIT_NOFILE", RLIMIT_NOFILE);
- PyModule_AddIntConstant(module, "RLIMIT_NPROC", RLIMIT_NPROC);
- PyModule_AddIntConstant(module, "RLIMIT_RSS", RLIMIT_RSS);
- PyModule_AddIntConstant(module, "RLIMIT_STACK", RLIMIT_STACK);
+ if (PyModule_AddIntConstant(mod, "RLIMIT_AS", RLIMIT_AS)) INITERR;
+ if (PyModule_AddIntConstant(mod, "RLIMIT_CORE", RLIMIT_CORE)) INITERR;
+ if (PyModule_AddIntConstant(mod, "RLIMIT_CPU", RLIMIT_CPU)) INITERR;
+ if (PyModule_AddIntConstant(mod, "RLIMIT_DATA", RLIMIT_DATA)) INITERR;
+ if (PyModule_AddIntConstant(mod, "RLIMIT_FSIZE", RLIMIT_FSIZE)) INITERR;
+ if (PyModule_AddIntConstant(mod, "RLIMIT_LOCKS", RLIMIT_LOCKS)) INITERR;
+ if (PyModule_AddIntConstant(mod, "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK)) INITERR;
+ if (PyModule_AddIntConstant(mod, "RLIMIT_NOFILE", RLIMIT_NOFILE)) INITERR;
+ if (PyModule_AddIntConstant(mod, "RLIMIT_NPROC", RLIMIT_NPROC)) INITERR;
+ if (PyModule_AddIntConstant(mod, "RLIMIT_RSS", RLIMIT_RSS)) INITERR;
+ if (PyModule_AddIntConstant(mod, "RLIMIT_STACK", RLIMIT_STACK)) INITERR;
#if defined(HAVE_LONG_LONG)
if (sizeof(RLIM_INFINITY) > sizeof(long)) {
@@ -674,32 +674,33 @@ PsutilMethods[] = {
v = PyLong_FromLong((long) RLIM_INFINITY);
}
if (v) {
- PyModule_AddObject(module, "RLIM_INFINITY", v);
+ PyModule_AddObject(mod, "RLIM_INFINITY", v);
}
#ifdef RLIMIT_MSGQUEUE
- PyModule_AddIntConstant(module, "RLIMIT_MSGQUEUE", RLIMIT_MSGQUEUE);
+ if (PyModule_AddIntConstant(mod, "RLIMIT_MSGQUEUE", RLIMIT_MSGQUEUE)) INITERR;
#endif
#ifdef RLIMIT_NICE
- PyModule_AddIntConstant(module, "RLIMIT_NICE", RLIMIT_NICE);
+ if (PyModule_AddIntConstant(mod, "RLIMIT_NICE", RLIMIT_NICE)) INITERR;
#endif
#ifdef RLIMIT_RTPRIO
- PyModule_AddIntConstant(module, "RLIMIT_RTPRIO", RLIMIT_RTPRIO);
+ if (PyModule_AddIntConstant(mod, "RLIMIT_RTPRIO", RLIMIT_RTPRIO)) INITERR;
#endif
#ifdef RLIMIT_RTTIME
- PyModule_AddIntConstant(module, "RLIMIT_RTTIME", RLIMIT_RTTIME);
+ if (PyModule_AddIntConstant(mod, "RLIMIT_RTTIME", RLIMIT_RTTIME)) INITERR;
#endif
#ifdef RLIMIT_SIGPENDING
- PyModule_AddIntConstant(module, "RLIMIT_SIGPENDING", RLIMIT_SIGPENDING);
+ if (PyModule_AddIntConstant(mod, "RLIMIT_SIGPENDING", RLIMIT_SIGPENDING))
+ INITERR;
#endif
#endif
- PyModule_AddIntConstant(module, "DUPLEX_HALF", DUPLEX_HALF);
- PyModule_AddIntConstant(module, "DUPLEX_FULL", DUPLEX_FULL);
- PyModule_AddIntConstant(module, "DUPLEX_UNKNOWN", DUPLEX_UNKNOWN);
+ if (PyModule_AddIntConstant(mod, "DUPLEX_HALF", DUPLEX_HALF)) INITERR;
+ if (PyModule_AddIntConstant(mod, "DUPLEX_FULL", DUPLEX_FULL)) INITERR;
+ if (PyModule_AddIntConstant(mod, "DUPLEX_UNKNOWN", DUPLEX_UNKNOWN)) INITERR;
- if (module == NULL)
+ if (mod == NULL)
INITERR;
#if PY_MAJOR_VERSION >= 3
- return module;
+ return mod;
#endif
}