1 /* -*- Mode: C; c-basic-offset: 4 -*- 2 * vim: tabstop=4 shiftwidth=4 expandtab 3 */ 4 #ifndef __PYGI_PRIVATE_H__ 5 #define __PYGI_PRIVATE_H__ 6 7 #ifdef __PYGI_H__ 8 # error "Import pygi.h or pygi-private.h, but not both" 9 #endif 10 11 #ifdef HAVE_CONFIG_H 12 # include <config.h> 13 #endif 14 15 #include <Python.h> 16 17 #include "pygi.h" 18 19 #include "pygobject-external.h" 20 21 #include "pygi-repository.h" 22 #include "pygi-info.h" 23 #include "pygi-struct.h" 24 #include "pygi-boxed.h" 25 #include "pygi-argument.h" 26 #include "pygi-type.h" 27 #include "pygi-foreign.h" 28 #include "pygi-closure.h" 29 #include "pygi-callbacks.h" 30 #include "pygi-invoke.h" 31 #include "pygi-property.h" 32 #include "pygi-signal-closure.h" 33 34 G_BEGIN_DECLS 35 #if PY_VERSION_HEX >= 0x03000000 36 37 #define _PyGI_ERROR_PREFIX(format, ...) G_STMT_START { \ 38 PyObject *py_error_prefix; \ 39 py_error_prefix = PyUnicode_FromFormat(format, ## __VA_ARGS__); \ 40 if (py_error_prefix != NULL) { \ 41 PyObject *py_error_type, *py_error_value, *py_error_traceback; \ 42 PyErr_Fetch(&py_error_type, &py_error_value, &py_error_traceback); \ 43 if (PyUnicode_Check(py_error_value)) { \ 44 PyObject *new; \ 45 new = PyUnicode_Concat(py_error_prefix, py_error_value); \ 46 Py_DECREF(py_error_value); \ 47 if (new != NULL) { \ 48 py_error_value = new; \ 49 } \ 50 } \ 51 PyErr_Restore(py_error_type, py_error_value, py_error_traceback); \ 52 } \ 53 } G_STMT_END 54 55 #else 56 57 #define _PyGI_ERROR_PREFIX(format, ...) G_STMT_START { \ 58 PyObject *py_error_prefix; \ 59 py_error_prefix = PyString_FromFormat(format, ## __VA_ARGS__); \ 60 if (py_error_prefix != NULL) { \ 61 PyObject *py_error_type, *py_error_value, *py_error_traceback; \ 62 PyErr_Fetch(&py_error_type, &py_error_value, &py_error_traceback); \ 63 if (PyString_Check(py_error_value)) { \ 64 PyString_ConcatAndDel(&py_error_prefix, py_error_value); \ 65 if (py_error_prefix != NULL) { \ 66 py_error_value = py_error_prefix; \ 67 } \ 68 } \ 69 PyErr_Restore(py_error_type, py_error_value, py_error_traceback); \ 70 } \ 71 } G_STMT_END 72 73 #endif 74 75 /* Redefine g_array_index because we want it to return the i-th element, casted 76 * to the type t, of the array a, and not the i-th element of the array a 77 * casted to the type t. */ 78 #define _g_array_index(a,t,i) \ 79 *(t *)((a)->data + g_array_get_element_size(a) * (i)) 80 81 82 G_END_DECLS 83 84 #endif /* __PYGI_PRIVATE_H__ */ 85