Imported Upstream version 3.21.91
[platform/upstream/python-gobject.git] / gi / pygi-util.h
1 #ifndef __PYGI_UTIL_H__
2 #define __PYGI_UTIL_H__
3
4 #include <glib.h>
5 #include "pygobject-internal.h"
6 #include <pyglib-python-compat.h>
7
8 G_BEGIN_DECLS
9
10 PyObject * pyg_integer_richcompare(PyObject *v, PyObject *w, int op);
11
12 #if PY_VERSION_HEX >= 0x03000000
13
14 #define _PyGI_ERROR_PREFIX(format, ...) G_STMT_START { \
15     PyObject *py_error_prefix; \
16     py_error_prefix = PyUnicode_FromFormat(format, ## __VA_ARGS__); \
17     if (py_error_prefix != NULL) { \
18         PyObject *py_error_type, *py_error_value, *py_error_traceback; \
19         PyErr_Fetch(&py_error_type, &py_error_value, &py_error_traceback); \
20         if (PyUnicode_Check(py_error_value)) { \
21             PyObject *new; \
22             new = PyUnicode_Concat(py_error_prefix, py_error_value); \
23             Py_DECREF(py_error_value); \
24             if (new != NULL) { \
25                 py_error_value = new; \
26             } \
27         } \
28         PyErr_Restore(py_error_type, py_error_value, py_error_traceback); \
29         Py_DECREF(py_error_prefix); \
30     } \
31 } G_STMT_END
32
33 #else
34
35 #define _PyGI_ERROR_PREFIX(format, ...) G_STMT_START { \
36     PyObject *py_error_prefix; \
37     py_error_prefix = PyString_FromFormat(format, ## __VA_ARGS__); \
38     if (py_error_prefix != NULL) { \
39         PyObject *py_error_type, *py_error_value, *py_error_traceback; \
40         PyErr_Fetch(&py_error_type, &py_error_value, &py_error_traceback); \
41         if (PyString_Check(py_error_value)) { \
42             PyString_ConcatAndDel(&py_error_prefix, py_error_value); \
43             if (py_error_prefix != NULL) { \
44                 py_error_value = py_error_prefix; \
45             } \
46         } \
47         PyErr_Restore(py_error_type, py_error_value, py_error_traceback); \
48     } \
49 } G_STMT_END
50
51 #endif
52
53 G_END_DECLS
54
55 #endif /* __PYGI_UTIL_H__ */