functions: revert the function init order to make pylint happy again. See #217
[pygobject.git] / gi / pygi-util.h
blob2f9847e61eb9699bd3f4ea3b9aa0c359c7b776cf
1 #ifndef __PYGI_UTIL_H__
2 #define __PYGI_UTIL_H__
4 #include <Python.h>
5 #include <glib.h>
6 #include "pygobject-internal.h"
7 #include "pygi-python-compat.h"
9 G_BEGIN_DECLS
11 PyObject * pyg_integer_richcompare(PyObject *v, PyObject *w, int op);
12 PyObject * pyg_ptr_richcompare(void* a, void *b, int op);
13 const gchar * pyg_constant_strip_prefix(const gchar *name, const gchar *strip_prefix);
14 PyObject * pygi_import_module (const char *name);
15 PyObject * pygi_pyerr_format (PyObject *exception, const char *format, ...);
17 gboolean pygi_guint_from_pyssize (Py_ssize_t pyval, guint *result);
19 #if PY_VERSION_HEX >= 0x03000000
21 #define _PyGI_ERROR_PREFIX(format, ...) G_STMT_START { \
22 PyObject *py_error_prefix; \
23 py_error_prefix = PyUnicode_FromFormat(format, ## __VA_ARGS__); \
24 if (py_error_prefix != NULL) { \
25 PyObject *py_error_type, *py_error_value, *py_error_traceback; \
26 PyErr_Fetch(&py_error_type, &py_error_value, &py_error_traceback); \
27 if (PyUnicode_Check(py_error_value)) { \
28 PyObject *new; \
29 new = PyUnicode_Concat(py_error_prefix, py_error_value); \
30 Py_DECREF(py_error_value); \
31 if (new != NULL) { \
32 py_error_value = new; \
33 } \
34 } \
35 PyErr_Restore(py_error_type, py_error_value, py_error_traceback); \
36 Py_DECREF(py_error_prefix); \
37 } \
38 } G_STMT_END
40 #else
42 #define _PyGI_ERROR_PREFIX(format, ...) G_STMT_START { \
43 PyObject *py_error_prefix; \
44 py_error_prefix = PyString_FromFormat(format, ## __VA_ARGS__); \
45 if (py_error_prefix != NULL) { \
46 PyObject *py_error_type, *py_error_value, *py_error_traceback; \
47 PyErr_Fetch(&py_error_type, &py_error_value, &py_error_traceback); \
48 if (PyString_Check(py_error_value)) { \
49 PyString_ConcatAndDel(&py_error_prefix, py_error_value); \
50 if (py_error_prefix != NULL) { \
51 py_error_value = py_error_prefix; \
52 } \
53 } \
54 PyErr_Restore(py_error_type, py_error_value, py_error_traceback); \
55 } \
56 } G_STMT_END
58 #endif
60 G_END_DECLS
62 #endif /* __PYGI_UTIL_H__ */