1 #ifndef __PYGI_UTIL_H__
2 #define __PYGI_UTIL_H__
6 #include "pygobject-internal.h"
7 #include "pygi-python-compat.h"
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)) { \
29 new = PyUnicode_Concat(py_error_prefix, py_error_value); \
30 Py_DECREF(py_error_value); \
32 py_error_value = new; \
35 PyErr_Restore(py_error_type, py_error_value, py_error_traceback); \
36 Py_DECREF(py_error_prefix); \
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; \
54 PyErr_Restore(py_error_type, py_error_value, py_error_traceback); \
62 #endif /* __PYGI_UTIL_H__ */