File: pygi-util.h

package info (click to toggle)
pygobject 3.55.3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 5,728 kB
  • sloc: ansic: 39,419; python: 26,856; sh: 114; makefile: 81; xml: 35; cpp: 1
file content (62 lines) | stat: -rw-r--r-- 2,914 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef __PYGI_UTIL_H__
#define __PYGI_UTIL_H__

#include <glib.h>
#include <pythoncapi_compat.h>

G_BEGIN_DECLS

PyObject *pyg_ptr_richcompare (void *a, void *b, int op);
const gchar *pyg_constant_strip_prefix (const gchar *name,
                                        const gchar *strip_prefix);

gboolean pygi_guint_from_pyssize (Py_ssize_t pyval, guint *result);

PyObject *pyg_is_python_keyword (const gchar *name);

void pyg_destroy_notify (gpointer user_data);

#if PY_VERSION_HEX < 0x030900A4
#define Py_SET_TYPE(obj, type) ((Py_TYPE (obj) = (type)), (void)0)
#endif

#if PY_VERSION_HEX >= 0x03080000
#define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN (op, dealloc)
#define CPy_TRASHCAN_END(op)            Py_TRASHCAN_END
#else
#define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_SAFE_BEGIN (op)
#define CPy_TRASHCAN_END(op)            Py_TRASHCAN_SAFE_END (op)
#endif

#define PYGI_DEFINE_TYPE(typename, symbol, csymbol)                           \
    PyTypeObject symbol = { PyVarObject_HEAD_INIT (NULL, 0) typename,         \
                            sizeof (csymbol) };

#define _PyGI_ERROR_PREFIX(format, ...)                                       \
    G_STMT_START                                                              \
    {                                                                         \
        PyObject *py_error_prefix;                                            \
        py_error_prefix = PyUnicode_FromFormat (format, ##__VA_ARGS__);       \
        if (py_error_prefix != NULL) {                                        \
            PyObject *py_error_type, *py_error_value, *py_error_traceback;    \
            PyErr_Fetch (&py_error_type, &py_error_value,                     \
                         &py_error_traceback);                                \
            if (PyUnicode_Check (py_error_value)) {                           \
                PyObject *new;                                                \
                new = PyUnicode_Concat (py_error_prefix, py_error_value);     \
                Py_DECREF (py_error_value);                                   \
                if (new != NULL) {                                            \
                    py_error_value = new;                                     \
                }                                                             \
            }                                                                 \
            PyErr_Restore (py_error_type, py_error_value,                     \
                           py_error_traceback);                               \
            Py_DECREF (py_error_prefix);                                      \
        }                                                                     \
    }                                                                         \
    G_STMT_END


G_END_DECLS

#endif /* __PYGI_UTIL_H__ */