Debian Codegraph @

gi/pygobject-types.h

raw
1 /* -*- Mode: C; c-basic-offset: 4 -*-
2 * vim: tabstop=4 shiftwidth=4 expandtab
3 *
4 * Copyright (C) 2000 James Henstridge <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __PYGOBJECT_TYPES_H__
21 #define __PYGOBJECT_TYPES_H__
22
23 #include <glib.h>
24 #include <glib-object.h>
25 #include <Python.h>
26
27 G_BEGIN_DECLS
28
29 /* PyGClosure is a _private_ structure */
30 typedef void (*PyClosureExceptionHandler) (GValue *ret, guint n_param_values,
31 const GValue *params);
32 typedef struct _PyGClosure PyGClosure;
33 typedef struct _PyGObjectData PyGObjectData;
34
35 struct _PyGClosure {
36 GClosure closure;
37 PyObject *callback;
38 PyObject *extra_args; /* tuple of extra args to pass to callback */
39 PyObject *swap_data; /* other object for gtk_signal_connect__object */
40 PyClosureExceptionHandler exception_handler;
41 };
42
43 typedef enum {
44 PYGOBJECT_USING_TOGGLE_REF = 1 << 0, /* No longer used DO_NOT_USE! */
45 } PyGObjectFlags;
46
47 /* closures is just an alias for what is found in the
48 * PyGObjectData */
49 typedef struct {
50 PyObject_HEAD
51 GObject *obj;
52 PyObject *inst_dict; /* the instance dictionary -- must be last */
53 PyObject *weakreflist; /* list of weak references */
54
55 /*< private >*/
56 /* using union to preserve ABI compatibility (structure size
57 * must not change) */
58 union {
59 GSList *closures; /* stale field; no longer updated DO-NOT-USE! */
60 PyGObjectFlags flags; /* stale field; no longer updated DO-NOT-USE! */
61 } private_flags;
62
63 } PyGObject;
64
65 #define pygobject_get(v) (((PyGObject *)(v))->obj)
66 #define pygobject_check(v, base) (PyObject_TypeCheck (v, base))
67
68 typedef struct {
69 PyObject_HEAD
70 gpointer boxed;
71 GType gtype;
72 gboolean free_on_dealloc;
73 } PyGBoxed;
74
75 #define pyg_boxed_get(v, t) ((t *)((PyGBoxed *)(v))->boxed)
76 #define pyg_boxed_get_ptr(v) (((PyGBoxed *)(v))->boxed)
77 #define pyg_boxed_set_ptr(v, p) (((PyGBoxed *)(v))->boxed = (gpointer)p)
78 #define pyg_boxed_check(v, typecode) \
79 (PyObject_TypeCheck (v, &PyGBoxed_Type) \
80 && ((PyGBoxed *)(v))->gtype == (typecode))
81
82 typedef struct {
83 PyObject_HEAD
84 gpointer pointer;
85 GType gtype;
86 } PyGPointer;
87
88 #define pyg_pointer_get(v, t) ((t *)((PyGPointer *)(v))->pointer)
89 #define pyg_pointer_get_ptr(v) (((PyGPointer *)(v))->pointer)
90 #define pyg_pointer_set_ptr(v, p) (((PyGPointer *)(v))->pointer = (gpointer)p)
91 #define pyg_pointer_check(v, typecode) \
92 (PyObject_TypeCheck (v, &PyGPointer_Type) \
93 && ((PyGPointer *)(v))->gtype == (typecode))
94
95 typedef void (*PyGFatalExceptionFunc) (void);
96 typedef void (*PyGThreadBlockFunc) (void);
97
98 typedef int (*PyGClassInitFunc) (gpointer gclass, PyTypeObject *pyclass);
99 typedef PyTypeObject *(*PyGTypeRegistrationFunction) (const gchar *name,
100 gpointer data);
101
102 struct _PyGObject_Functions {
103 /*
104 * All field names in here are considered private,
105 * use the macros below instead, which provides stability
106 */
107 void (*register_class) (PyObject *dict, const gchar *class_name,
108 GType gtype, PyTypeObject *type, PyObject *bases);
109 void (*register_wrapper) (PyObject *self);
110 PyTypeObject *(*lookup_class) (GType type);
111 PyObject *(*newgobj) (GObject *obj);
112
113 GClosure *(*closure_new) (PyObject *callback, PyObject *extra_args,
114 PyObject *swap_data);
115 void (*object_watch_closure) (PyObject *self, GClosure *closure);
116 GDestroyNotify destroy_notify;
117
118 GType (*type_from_object) (PyObject *obj);
119 PyObject *(*type_wrapper_new) (GType type);
120
121 gint (*enum_get_value) (GType enum_type, PyObject *obj, gint *val);
122 gint (*flags_get_value) (GType flag_type, PyObject *obj, guint *val);
123 void (*register_gtype_custom) (
124 GType gtype, PyObject *(*from_func) (const GValue *value),
125 int (*to_func) (GValue *value, PyObject *obj));
126 int (*value_from_pyobject) (GValue *value, PyObject *obj);
127 PyObject *(*value_as_pyobject) (const GValue *value, gboolean copy_boxed);
128
129 void (*register_interface) (PyObject *dict, const gchar *class_name,
130 GType gtype, PyTypeObject *type);
131
132 PyTypeObject *boxed_type;
133 void (*register_boxed) (PyObject *dict, const gchar *class_name,
134 GType boxed_type, PyTypeObject *type);
135 PyObject *(*boxed_new) (GType boxed_type, gpointer boxed,
136 gboolean copy_boxed, gboolean own_ref);
137
138 PyTypeObject *pointer_type;
139 void (*register_pointer) (PyObject *dict, const gchar *class_name,
140 GType pointer_type, PyTypeObject *type);
141 PyObject *(*pointer_new) (GType boxed_type, gpointer pointer);
142
143 void (*enum_add_constants) (PyObject *module, GType enum_type,
144 const gchar *strip_prefix);
145 void (*flags_add_constants) (PyObject *module, GType flags_type,
146 const gchar *strip_prefix);
147
148 const gchar *(*constant_strip_prefix) (const gchar *name,
149 const gchar *strip_prefix);
150
151 gboolean (*error_check) (GError **error);
152
153 /* hooks to register handlers for getting GDK threads to cooperate
154 * with python threading */
155 void (*set_thread_block_funcs) (PyGThreadBlockFunc block_threads_func,
156 PyGThreadBlockFunc unblock_threads_func);
157 PyGThreadBlockFunc block_threads;
158 PyGThreadBlockFunc unblock_threads;
159
160 PyTypeObject *paramspec_type;
161 PyObject *(*paramspec_new) (GParamSpec *spec);
162 GParamSpec *(*paramspec_get) (PyObject *tuple);
163 int (*pyobj_to_unichar_conv) (PyObject *pyobj, void *ptr);
164 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
165 gboolean (*parse_constructor_args) (GType obj_type, char **arg_names,
166 char **prop_names, GParameter *params,
167 guint *nparams, PyObject **py_args);
168 G_GNUC_END_IGNORE_DEPRECATIONS
169 PyObject *(*param_gvalue_as_pyobject) (const GValue *gvalue,
170 gboolean copy_boxed,
171 const GParamSpec *pspec);
172 int (*gvalue_from_param_pyobject) (GValue *value, PyObject *py_obj,
173 const GParamSpec *pspec);
174 PyTypeObject *enum_type;
175 PyObject *(*enum_add) (PyObject *module, const char *type_name_,
176 const char *strip_prefix, GType gtype);
177 PyObject *(*enum_from_gtype) (GType gtype, int value);
178
179 PyTypeObject *flags_type;
180 PyObject *(*flags_add) (PyObject *module, const char *type_name_,
181 const char *strip_prefix, GType gtype);
182 PyObject *(*flags_from_gtype) (GType gtype, guint value);
183
184 gboolean threads_enabled;
185 int (*enable_threads) (void);
186
187 int (*gil_state_ensure) (void);
188 void (*gil_state_release) (int flag);
189
190 void (*register_class_init) (GType gtype, PyGClassInitFunc class_init);
191 void (*register_interface_info) (GType gtype, const GInterfaceInfo *info);
192 void (*closure_set_exception_handler) (GClosure *closure,
193 PyClosureExceptionHandler handler);
194
195 void (*add_warning_redirection) (const char *domain, PyObject *warning);
196 void (*disable_warning_redirections) (void);
197
198 /* type_register_custom API is removed, but left a pointer to not break ABI. */
199 void *_type_register_custom;
200
201 gboolean (*gerror_exception_check) (GError **error);
202
203 /* option_group_new API is removed, but left a pointer to not break ABI. */
204 void *_option_group_new;
205
206 GType (*type_from_object_strict) (PyObject *obj, gboolean strict);
207
208 PyObject *(*newgobj_full) (GObject *obj, gboolean steal, gpointer g_class);
209 PyTypeObject *object_type;
210 int (*value_from_pyobject_with_error) (GValue *value, PyObject *obj);
211 };
212
213 G_END_DECLS
214
215 #endif /* __PYGOBJECT_TYPES_H__ */