| 1 |
#ifndef __PYGI_UTIL_H__ |
| 2 |
#define __PYGI_UTIL_H__ |
| 3 |
|
| 4 |
#include <glib.h> |
| 5 |
#include <pythoncapi_compat.h> |
| 6 |
|
| 7 |
G_BEGIN_DECLS |
| 8 |
|
| 9 |
PyObject *pyg_ptr_richcompare (void *a, void *b, int op); |
| 10 |
const gchar *pyg_constant_strip_prefix (const gchar *name, |
| 11 |
const gchar *strip_prefix); |
| 12 |
|
| 13 |
gboolean pygi_guint_from_pyssize (Py_ssize_t pyval, guint *result); |
| 14 |
|
| 15 |
PyObject *pyg_is_python_keyword (const gchar *name); |
| 16 |
|
| 17 |
void pyg_destroy_notify (gpointer user_data); |
| 18 |
|
| 19 |
#if PY_VERSION_HEX < 0x030900A4 |
| 20 |
#define Py_SET_TYPE(obj, type) ((Py_TYPE (obj) = (type)), (void)0) |
| 21 |
#endif |
| 22 |
|
| 23 |
#if PY_VERSION_HEX >= 0x03080000 |
| 24 |
#define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN (op, dealloc) |
| 25 |
#define CPy_TRASHCAN_END(op) Py_TRASHCAN_END |
| 26 |
#else |
| 27 |
#define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_SAFE_BEGIN (op) |
| 28 |
#define CPy_TRASHCAN_END(op) Py_TRASHCAN_SAFE_END (op) |
| 29 |
#endif |
| 30 |
|
| 31 |
#define PYGI_DEFINE_TYPE(typename, symbol, csymbol) \ |
| 32 |
PyTypeObject symbol = { PyVarObject_HEAD_INIT (NULL, 0) typename, \ |
| 33 |
sizeof (csymbol) }; |
| 34 |
|
| 35 |
#define _PyGI_ERROR_PREFIX(format, ...) \ |
| 36 |
G_STMT_START \ |
| 37 |
{ \ |
| 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, \ |
| 43 |
&py_error_traceback); \ |
| 44 |
if (PyUnicode_Check (py_error_value)) { \ |
| 45 |
PyObject *new; \ |
| 46 |
new = PyUnicode_Concat (py_error_prefix, py_error_value); \ |
| 47 |
Py_DECREF (py_error_value); \ |
| 48 |
if (new != NULL) { \ |
| 49 |
py_error_value = new; \ |
| 50 |
} \ |
| 51 |
} \ |
| 52 |
PyErr_Restore (py_error_type, py_error_value, \ |
| 53 |
py_error_traceback); \ |
| 54 |
Py_DECREF (py_error_prefix); \ |
| 55 |
} \ |
| 56 |
} \ |
| 57 |
G_STMT_END |
| 58 |
|
| 59 |
|
| 60 |
G_END_DECLS |
| 61 |
|
| 62 |
#endif /* __PYGI_UTIL_H__ */ |