Gilchrist Dadaglo | 3e235d3 | 2020-05-06 12:25:31 +0000 | [diff] [blame] | 1 | /* ps_python.h: SPOA Python processing includes |
| 2 | * |
| 3 | * Copyright (C) 2020 Gilchrist Dadaglo <gilchrist@dadaglo.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version |
| 8 | * 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is provided in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #ifndef __PS_PYTHON_H__ |
| 18 | #define __PS_PYTHON_H__ |
| 19 | |
| 20 | #include <Python.h> |
| 21 | |
| 22 | #if PY_MAJOR_VERSION >= 3 |
| 23 | #define IS_PYTHON_3K 1 |
| 24 | #define IS_PYTHON_27 0 |
| 25 | #elif PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7 |
| 26 | #define IS_PYTHON_3K 0 |
| 27 | #define IS_PYTHON_27 1 |
| 28 | #else |
| 29 | #error "Unsupported Python Version - Please use Python 3" |
| 30 | #endif /* PY_MAJOR_VERSION */ |
| 31 | |
| 32 | #if IS_PYTHON_3K |
| 33 | #define PY_INIT_MODULE(instance, name, methods, moduledef) \ |
| 34 | (instance = PyModule_Create(moduledef)) |
| 35 | #define PY_STRING_FROM_STRING PyUnicode_FromString |
| 36 | #define PY_STRING_FROM_STRING_AND_SIZE PyUnicode_FromStringAndSize |
| 37 | #define PY_BYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize |
| 38 | #define PY_STRING_GET_SIZE PyBytes_Size |
| 39 | #define PY_STRING_AS_STRING PyBytes_AsString |
| 40 | #elif IS_PYTHON_27 |
| 41 | #define PY_INIT_MODULE(instance, name, methods, moduledef) \ |
| 42 | (instance = Py_InitModule(name, methods)) |
| 43 | #define PY_STRING_FROM_STRING PyString_FromString |
| 44 | #define PY_STRING_FROM_STRING_AND_SIZE PyString_FromStringAndSize |
| 45 | #define PY_BYTES_FROM_STRING_AND_SIZE PyString_FromStringAndSize |
| 46 | #define PY_STRING_GET_SIZE PyString_GET_SIZE |
| 47 | #define PY_STRING_AS_STRING PyString_AS_STRING |
| 48 | #endif /* IS_PYTHON_3K */ |
| 49 | |
| 50 | #endif /* __PS_PYTHON_H__ */ |
| 51 | |
| 52 | /* EOF */ |