aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLumir Balhar <lbalhar@redhat.com>2017-11-10 09:27:30 +0100
committerJiri Kastner <jkastner@redhat.com>2017-11-20 13:53:13 +0100
commit53aff14ad4b0f7913fec1398d072de01684296ca (patch)
tree49012a0a9c42cc892f22719fab69845e52ca61e4
parent76cbbd195fbd57cbea4a871b52c0747a1822ee11 (diff)
downloadpython-schedutils-53aff14ad4b0f7913fec1398d072de01684296ca.tar.gz
python3: Add compatibility header file with necessary macros
Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Signed-off-by: Jiri Kastner <jkastner@redhat.com>
-rw-r--r--python-schedutils/py3compat.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/python-schedutils/py3compat.h b/python-schedutils/py3compat.h
new file mode 100644
index 0000000..625cddf
--- /dev/null
+++ b/python-schedutils/py3compat.h
@@ -0,0 +1,60 @@
+/*
+ Python 3 compatibility macros
+ Copyright (C) Petr Viktorin <pviktori@redhat.com> 2015
+*/
+
+#include <Python.h>
+
+#if PY_MAJOR_VERSION >= 3
+
+/***** Python 3 *****/
+
+#define IS_PY3 1
+
+/* Ints */
+
+#define PyInt_AsLong PyLong_AsLong
+
+/* Strings */
+
+#define PyStr_FromString PyUnicode_FromString
+
+/* Module init */
+
+#define MODULE_INIT_FUNC(name) \
+ PyMODINIT_FUNC PyInit_ ## name(void); \
+ PyMODINIT_FUNC PyInit_ ## name(void)
+
+#else
+
+/***** Python 2 *****/
+
+#define IS_PY3 0
+
+/* Strings */
+
+#define PyStr_FromString PyString_FromString
+
+/* Module init */
+
+#define PyModuleDef_HEAD_INIT 0
+
+typedef struct PyModuleDef {
+ int m_base;
+ const char* m_name;
+ const char* m_doc;
+ Py_ssize_t m_size;
+ PyMethodDef *m_methods;
+} PyModuleDef;
+
+#define PyModule_Create(def) \
+ Py_InitModule3((def)->m_name, (def)->m_methods, (def)->m_doc)
+
+#define MODULE_INIT_FUNC(name) \
+ static PyObject *PyInit_ ## name(void); \
+ void init ## name(void); \
+ void init ## name(void) { PyInit_ ## name(); } \
+ static PyObject *PyInit_ ## name(void)
+
+
+#endif