summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-01-06 14:54:45 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2020-01-06 14:54:45 -0800
commit4b12537e250e6b46c0cd2f48e6d178bc1aae6532 (patch)
treef7463ac292b184df7ad2b168eea3dd9d78430e72
parent6c07f48a874754f472f6c3beb7e1184ab8dab39a (diff)
downloadpsutil-4b12537e250e6b46c0cd2f48e6d178bc1aae6532.tar.gz
just move stuff around
-rw-r--r--psutil/_psutil_common.c55
-rw-r--r--psutil/_psutil_common.h24
2 files changed, 53 insertions, 26 deletions
diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c
index c6e37bc2..30633c59 100644
--- a/psutil/_psutil_common.c
+++ b/psutil/_psutil_common.c
@@ -7,17 +7,27 @@
*/
#include <Python.h>
-#ifdef _WIN32
+#ifdef PSUTIL_WINDOWS
#include <windows.h>
-#endif
+#endif // !PSUTIL_WINDOWS
#include "_psutil_common.h"
-// Global vars.
+
+// ====================================================================
+// --- Global vars / constants
+// ====================================================================
+
+
int PSUTIL_DEBUG = 0;
int PSUTIL_TESTING = 0;
+// PSUTIL_CONN_NONE
+// ====================================================================
+// --- Python functions and backward compatibility
+// ====================================================================
+
/*
* Backport of unicode FS APIs from Python 3.
* On Python 2 we just return a plain byte string
@@ -37,22 +47,6 @@ PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size) {
}
#endif
-
-/*
- * Set OSError(errno=ESRCH, strerror="No such process") Python exception.
- * If msg != "" the exception message will change in accordance.
- */
-PyObject *
-NoSuchProcess(const char *msg) {
- PyObject *exc;
- exc = PyObject_CallFunction(
- PyExc_OSError, "(is)", ESRCH, strlen(msg) ? msg : strerror(ESRCH));
- PyErr_SetObject(PyExc_OSError, exc);
- Py_XDECREF(exc);
- return NULL;
-}
-
-
/*
* Same as PyErr_SetFromErrno(0) but adds the syscall to the exception
* message.
@@ -75,6 +69,25 @@ PyErr_SetFromOSErrnoWithSyscall(const char *syscall) {
}
+// ====================================================================
+// --- Custom exceptions
+// ====================================================================
+
+/*
+ * Set OSError(errno=ESRCH, strerror="No such process") Python exception.
+ * If msg != "" the exception message will change in accordance.
+ */
+PyObject *
+NoSuchProcess(const char *msg) {
+ PyObject *exc;
+ exc = PyObject_CallFunction(
+ PyExc_OSError, "(is)", ESRCH, strlen(msg) ? msg : strerror(ESRCH));
+ PyErr_SetObject(PyExc_OSError, exc);
+ Py_XDECREF(exc);
+ return NULL;
+}
+
+
/*
* Set OSError(errno=EACCES, strerror="Permission denied") Python exception.
* If msg != "" the exception message will change in accordance.
@@ -90,6 +103,10 @@ AccessDenied(const char *msg) {
}
+// ====================================================================
+// --- Global utils
+// ====================================================================
+
/*
* Enable testing mode. This has the same effect as setting PSUTIL_TESTING
* env var. This dual method exists because updating os.environ on
diff --git a/psutil/_psutil_common.h b/psutil/_psutil_common.h
index 7f58ad17..8b069d9f 100644
--- a/psutil/_psutil_common.h
+++ b/psutil/_psutil_common.h
@@ -4,28 +4,38 @@
* found in the LICENSE file.
*/
-#ifndef PSUTIL_PSUTIL_COMMON_H
-#define PSUTIL_PSUTIL_COMMON_H
-
#include <Python.h>
+// ====================================================================
+// --- Global vars / constants
+// ====================================================================
+
extern int PSUTIL_TESTING;
extern int PSUTIL_DEBUG;
-
// a signaler for connections without an actual status
static const int PSUTIL_CONN_NONE = 128;
+// ====================================================================
+// --- Python functions and backward compatibility
+// ====================================================================
+
#if PY_MAJOR_VERSION < 3
PyObject* PyUnicode_DecodeFSDefault(char *s);
PyObject* PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size);
#endif
+PyObject* PyErr_SetFromOSErrnoWithSyscall(const char *syscall);
+
+// ====================================================================
+// --- Custom exceptions
+// ====================================================================
PyObject* AccessDenied(const char *msg);
PyObject* NoSuchProcess(const char *msg);
-PyObject* PyErr_SetFromOSErrnoWithSyscall(const char *syscall);
+
+// ====================================================================
+// --- Global utils
+// ====================================================================
PyObject* psutil_set_testing(PyObject *self, PyObject *args);
void psutil_debug(const char* format, ...);
int psutil_setup(void);
-
-#endif // PSUTIL_PSUTIL_COMMON_H