Imported Upstream version 3.7.3
[platform/upstream/python-gobject.git] / gi / pygi-private.h
1 /* -*- Mode: C; c-basic-offset: 4 -*-
2  * vim: tabstop=4 shiftwidth=4 expandtab
3  */
4 #ifndef __PYGI_PRIVATE_H__
5 #define __PYGI_PRIVATE_H__
6
7 #ifdef __PYGI_H__
8 #   error "Import pygi.h or pygi-private.h, but not both"
9 #endif
10
11 #ifdef HAVE_CONFIG_H
12 #   include <config.h>
13 #endif
14
15 #include <Python.h>
16
17 #include "pygi.h"
18
19 #include "pygobject-external.h"
20
21 #include "pygi-repository.h"
22 #include "pygi-info.h"
23 #include "pygi-struct.h"
24 #include "pygi-boxed.h"
25 #include "pygi-argument.h"
26 #include "pygi-type.h"
27 #include "pygi-foreign.h"
28 #include "pygi-closure.h"
29 #include "pygi-ccallback.h"
30 #include "pygi-property.h"
31 #include "pygi-signal-closure.h"
32 #include "pygi-invoke.h"
33 #include "pygi-cache.h"
34 #include "pygi-source.h"
35
36 G_BEGIN_DECLS
37 #if PY_VERSION_HEX >= 0x03000000
38
39 #define _PyGI_ERROR_PREFIX(format, ...) G_STMT_START { \
40     PyObject *py_error_prefix; \
41     py_error_prefix = PyUnicode_FromFormat(format, ## __VA_ARGS__); \
42     if (py_error_prefix != NULL) { \
43         PyObject *py_error_type, *py_error_value, *py_error_traceback; \
44         PyErr_Fetch(&py_error_type, &py_error_value, &py_error_traceback); \
45         if (PyUnicode_Check(py_error_value)) { \
46             PyObject *new; \
47             new = PyUnicode_Concat(py_error_prefix, py_error_value); \
48             Py_DECREF(py_error_value); \
49             if (new != NULL) { \
50                 py_error_value = new; \
51             } \
52         } \
53         PyErr_Restore(py_error_type, py_error_value, py_error_traceback); \
54     } \
55 } G_STMT_END
56
57 #else
58
59 #define _PyGI_ERROR_PREFIX(format, ...) G_STMT_START { \
60     PyObject *py_error_prefix; \
61     py_error_prefix = PyString_FromFormat(format, ## __VA_ARGS__); \
62     if (py_error_prefix != NULL) { \
63         PyObject *py_error_type, *py_error_value, *py_error_traceback; \
64         PyErr_Fetch(&py_error_type, &py_error_value, &py_error_traceback); \
65         if (PyString_Check(py_error_value)) { \
66             PyString_ConcatAndDel(&py_error_prefix, py_error_value); \
67             if (py_error_prefix != NULL) { \
68                 py_error_value = py_error_prefix; \
69             } \
70         } \
71         PyErr_Restore(py_error_type, py_error_value, py_error_traceback); \
72     } \
73 } G_STMT_END
74
75 #endif
76
77 /* Redefine g_array_index because we want it to return the i-th element, casted
78  * to the type t, of the array a, and not the i-th element of the array a
79  * casted to the type t. */
80 #define _g_array_index(a,t,i) \
81     *(t *)((a)->data + g_array_get_element_size(a) * (i))
82
83
84 G_END_DECLS
85
86 #endif /* __PYGI_PRIVATE_H__ */