/src/glib/gobject/gclosure.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* GObject - GLib Type, Object, Parameter and Signal Library |
2 | | * Copyright (C) 2000-2001 Red Hat, Inc. |
3 | | * Copyright (C) 2005 Imendio AB |
4 | | * |
5 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
6 | | * |
7 | | * This library is free software; you can redistribute it and/or |
8 | | * modify it under the terms of the GNU Lesser General Public |
9 | | * License as published by the Free Software Foundation; either |
10 | | * version 2.1 of the License, or (at your option) any later version. |
11 | | * |
12 | | * This library is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | | * Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General |
18 | | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
19 | | */ |
20 | | |
21 | | /* |
22 | | * MT safe with regards to reference counting. |
23 | | */ |
24 | | |
25 | | #include "config.h" |
26 | | |
27 | | #include "../glib/gvalgrind.h" |
28 | | #include <string.h> |
29 | | |
30 | | #include <ffi.h> |
31 | | |
32 | | #include "gclosure.h" |
33 | | #include "gboxed.h" |
34 | | #include "gobject.h" |
35 | | #include "genums.h" |
36 | | #include "gvalue.h" |
37 | | #include "gvaluetypes.h" |
38 | | #include "gtype-private.h" |
39 | | |
40 | | |
41 | | /** |
42 | | * SECTION:gclosure |
43 | | * @short_description: Functions as first-class objects |
44 | | * @title: Closures |
45 | | * |
46 | | * A #GClosure represents a callback supplied by the programmer. |
47 | | * |
48 | | * It will generally comprise a function of some kind and a marshaller |
49 | | * used to call it. It is the responsibility of the marshaller to |
50 | | * convert the arguments for the invocation from #GValues into |
51 | | * a suitable form, perform the callback on the converted arguments, |
52 | | * and transform the return value back into a #GValue. |
53 | | * |
54 | | * In the case of C programs, a closure usually just holds a pointer |
55 | | * to a function and maybe a data argument, and the marshaller |
56 | | * converts between #GValue and native C types. The GObject |
57 | | * library provides the #GCClosure type for this purpose. Bindings for |
58 | | * other languages need marshallers which convert between #GValues |
59 | | * and suitable representations in the runtime of the language in |
60 | | * order to use functions written in that language as callbacks. Use |
61 | | * g_closure_set_marshal() to set the marshaller on such a custom |
62 | | * closure implementation. |
63 | | * |
64 | | * Within GObject, closures play an important role in the |
65 | | * implementation of signals. When a signal is registered, the |
66 | | * @c_marshaller argument to g_signal_new() specifies the default C |
67 | | * marshaller for any closure which is connected to this |
68 | | * signal. GObject provides a number of C marshallers for this |
69 | | * purpose, see the g_cclosure_marshal_*() functions. Additional C |
70 | | * marshallers can be generated with the [glib-genmarshal][glib-genmarshal] |
71 | | * utility. Closures can be explicitly connected to signals with |
72 | | * g_signal_connect_closure(), but it usually more convenient to let |
73 | | * GObject create a closure automatically by using one of the |
74 | | * g_signal_connect_*() functions which take a callback function/user |
75 | | * data pair. |
76 | | * |
77 | | * Using closures has a number of important advantages over a simple |
78 | | * callback function/data pointer combination: |
79 | | * |
80 | | * - Closures allow the callee to get the types of the callback parameters, |
81 | | * which means that language bindings don't have to write individual glue |
82 | | * for each callback type. |
83 | | * |
84 | | * - The reference counting of #GClosure makes it easy to handle reentrancy |
85 | | * right; if a callback is removed while it is being invoked, the closure |
86 | | * and its parameters won't be freed until the invocation finishes. |
87 | | * |
88 | | * - g_closure_invalidate() and invalidation notifiers allow callbacks to be |
89 | | * automatically removed when the objects they point to go away. |
90 | | */ |
91 | | |
92 | | #define CLOSURE_MAX_REF_COUNT ((1 << 15) - 1) |
93 | | #define CLOSURE_MAX_N_GUARDS ((1 << 1) - 1) |
94 | | #define CLOSURE_MAX_N_FNOTIFIERS ((1 << 2) - 1) |
95 | | #define CLOSURE_MAX_N_INOTIFIERS ((1 << 8) - 1) |
96 | 0 | #define CLOSURE_N_MFUNCS(cl) (((cl)->n_guards << 1L)) |
97 | | /* same as G_CLOSURE_N_NOTIFIERS() (keep in sync) */ |
98 | 0 | #define CLOSURE_N_NOTIFIERS(cl) (CLOSURE_N_MFUNCS (cl) + \ |
99 | 0 | (cl)->n_fnotifiers + \ |
100 | 0 | (cl)->n_inotifiers) |
101 | | |
102 | | typedef union { |
103 | | GClosure closure; |
104 | | gint vint; |
105 | | } ClosureInt; |
106 | | |
107 | 15 | #define CHANGE_FIELD(_closure, _field, _OP, _value, _must_set, _SET_OLD, _SET_NEW) \ |
108 | 15 | G_STMT_START { \ |
109 | 15 | ClosureInt *cunion = (ClosureInt*) _closure; \ |
110 | 15 | gint new_int, old_int, success; \ |
111 | 15 | do \ |
112 | 15 | { \ |
113 | 15 | ClosureInt tmp; \ |
114 | 15 | tmp.vint = old_int = cunion->vint; \ |
115 | 15 | _SET_OLD tmp.closure._field; \ |
116 | 15 | tmp.closure._field _OP _value; \ |
117 | 15 | _SET_NEW tmp.closure._field; \ |
118 | 15 | new_int = tmp.vint; \ |
119 | 15 | success = g_atomic_int_compare_and_exchange (&cunion->vint, old_int, new_int); \ |
120 | 15 | } \ |
121 | 15 | while (!success && _must_set); \ |
122 | 15 | } G_STMT_END |
123 | | |
124 | 3 | #define SWAP(_closure, _field, _value, _oldv) CHANGE_FIELD (_closure, _field, =, _value, TRUE, *(_oldv) =, (void) ) |
125 | 6 | #define SET(_closure, _field, _value) CHANGE_FIELD (_closure, _field, =, _value, TRUE, (void), (void) ) |
126 | 0 | #define INC(_closure, _field) CHANGE_FIELD (_closure, _field, +=, 1, TRUE, (void), (void) ) |
127 | 3 | #define INC_ASSIGN(_closure, _field, _newv) CHANGE_FIELD (_closure, _field, +=, 1, TRUE, (void), *(_newv) = ) |
128 | 0 | #define DEC(_closure, _field) CHANGE_FIELD (_closure, _field, -=, 1, TRUE, (void), (void) ) |
129 | 3 | #define DEC_ASSIGN(_closure, _field, _newv) CHANGE_FIELD (_closure, _field, -=, 1, TRUE, (void), *(_newv) = ) |
130 | | |
131 | | #if 0 /* for non-thread-safe closures */ |
132 | | #define SWAP(cl,f,v,o) (void) (*(o) = cl->f, cl->f = v) |
133 | | #define SET(cl,f,v) (void) (cl->f = v) |
134 | | #define INC(cl,f) (void) (cl->f += 1) |
135 | | #define INC_ASSIGN(cl,f,n) (void) (cl->f += 1, *(n) = cl->f) |
136 | | #define DEC(cl,f) (void) (cl->f -= 1) |
137 | | #define DEC_ASSIGN(cl,f,n) (void) (cl->f -= 1, *(n) = cl->f) |
138 | | #endif |
139 | | |
140 | | enum { |
141 | | FNOTIFY, |
142 | | INOTIFY, |
143 | | PRE_NOTIFY, |
144 | | POST_NOTIFY |
145 | | }; |
146 | | |
147 | | |
148 | | /* --- functions --- */ |
149 | | /** |
150 | | * g_closure_new_simple: |
151 | | * @sizeof_closure: the size of the structure to allocate, must be at least |
152 | | * `sizeof (GClosure)` |
153 | | * @data: data to store in the @data field of the newly allocated #GClosure |
154 | | * |
155 | | * Allocates a struct of the given size and initializes the initial |
156 | | * part as a #GClosure. |
157 | | * |
158 | | * This function is mainly useful when implementing new types of closures: |
159 | | * |
160 | | * |[<!-- language="C" --> |
161 | | * typedef struct _MyClosure MyClosure; |
162 | | * struct _MyClosure |
163 | | * { |
164 | | * GClosure closure; |
165 | | * // extra data goes here |
166 | | * }; |
167 | | * |
168 | | * static void |
169 | | * my_closure_finalize (gpointer notify_data, |
170 | | * GClosure *closure) |
171 | | * { |
172 | | * MyClosure *my_closure = (MyClosure *)closure; |
173 | | * |
174 | | * // free extra data here |
175 | | * } |
176 | | * |
177 | | * MyClosure *my_closure_new (gpointer data) |
178 | | * { |
179 | | * GClosure *closure; |
180 | | * MyClosure *my_closure; |
181 | | * |
182 | | * closure = g_closure_new_simple (sizeof (MyClosure), data); |
183 | | * my_closure = (MyClosure *) closure; |
184 | | * |
185 | | * // initialize extra data here |
186 | | * |
187 | | * g_closure_add_finalize_notifier (closure, notify_data, |
188 | | * my_closure_finalize); |
189 | | * return my_closure; |
190 | | * } |
191 | | * ]| |
192 | | * |
193 | | * Returns: (transfer floating): a floating reference to a new #GClosure |
194 | | */ |
195 | | GClosure* |
196 | | g_closure_new_simple (guint sizeof_closure, |
197 | | gpointer data) |
198 | 3 | { |
199 | 3 | GClosure *closure; |
200 | 3 | gint private_size; |
201 | 3 | gchar *allocated; |
202 | | |
203 | 3 | g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL); |
204 | | |
205 | 3 | private_size = sizeof (GRealClosure) - sizeof (GClosure); |
206 | | |
207 | 3 | #ifdef ENABLE_VALGRIND |
208 | | /* See comments in gtype.c about what's going on here... */ |
209 | 3 | if (RUNNING_ON_VALGRIND) |
210 | 0 | { |
211 | 0 | private_size += sizeof (gpointer); |
212 | |
|
213 | 0 | allocated = g_malloc0 (private_size + sizeof_closure + sizeof (gpointer)); |
214 | |
|
215 | 0 | *(gpointer *) (allocated + private_size + sizeof_closure) = allocated + sizeof (gpointer); |
216 | |
|
217 | 0 | VALGRIND_MALLOCLIKE_BLOCK (allocated + private_size, sizeof_closure + sizeof (gpointer), 0, TRUE); |
218 | 0 | VALGRIND_MALLOCLIKE_BLOCK (allocated + sizeof (gpointer), private_size - sizeof (gpointer), 0, TRUE); |
219 | 0 | } |
220 | 3 | else |
221 | 3 | #endif |
222 | 3 | allocated = g_malloc0 (private_size + sizeof_closure); |
223 | | |
224 | 3 | closure = (GClosure *) (allocated + private_size); |
225 | | |
226 | 3 | SET (closure, ref_count, 1); |
227 | 3 | SET (closure, floating, TRUE); |
228 | 3 | closure->data = data; |
229 | | |
230 | 3 | return closure; |
231 | 3 | } |
232 | | |
233 | | static inline void |
234 | | closure_invoke_notifiers (GClosure *closure, |
235 | | guint notify_type) |
236 | 0 | { |
237 | | /* notifier layout: |
238 | | * n_guards n_guards n_fnotif. n_inotifiers |
239 | | * ->[[pre_guards][post_guards][fnotifiers][inotifiers]] |
240 | | * |
241 | | * CLOSURE_N_MFUNCS(cl) = n_guards + n_guards; |
242 | | * CLOSURE_N_NOTIFIERS(cl) = CLOSURE_N_MFUNCS(cl) + n_fnotifiers + n_inotifiers |
243 | | * |
244 | | * constrains/catches: |
245 | | * - closure->notifiers may be reloacted during callback |
246 | | * - closure->n_fnotifiers and closure->n_inotifiers may change during callback |
247 | | * - i.e. callbacks can be removed/added during invocation |
248 | | * - must prepare for callback removal during FNOTIFY and INOTIFY (done via ->marshal= & ->data=) |
249 | | * - must distinguish (->marshal= & ->data=) for INOTIFY vs. FNOTIFY (via ->in_inotify) |
250 | | * + closure->n_guards is const during PRE_NOTIFY & POST_NOTIFY |
251 | | * + none of the callbacks can cause recursion |
252 | | * + closure->n_inotifiers is const 0 during FNOTIFY |
253 | | */ |
254 | 0 | switch (notify_type) |
255 | 0 | { |
256 | 0 | GClosureNotifyData *ndata; |
257 | 0 | guint i, offs; |
258 | 0 | case FNOTIFY: |
259 | 0 | while (closure->n_fnotifiers) |
260 | 0 | { |
261 | 0 | guint n; |
262 | 0 | DEC_ASSIGN (closure, n_fnotifiers, &n); |
263 | |
|
264 | 0 | ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + n; |
265 | 0 | closure->marshal = (GClosureMarshal) ndata->notify; |
266 | 0 | closure->data = ndata->data; |
267 | 0 | ndata->notify (ndata->data, closure); |
268 | 0 | } |
269 | 0 | closure->marshal = NULL; |
270 | 0 | closure->data = NULL; |
271 | 0 | break; |
272 | 0 | case INOTIFY: |
273 | 0 | SET (closure, in_inotify, TRUE); |
274 | 0 | while (closure->n_inotifiers) |
275 | 0 | { |
276 | 0 | guint n; |
277 | 0 | DEC_ASSIGN (closure, n_inotifiers, &n); |
278 | |
|
279 | 0 | ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n; |
280 | 0 | closure->marshal = (GClosureMarshal) ndata->notify; |
281 | 0 | closure->data = ndata->data; |
282 | 0 | ndata->notify (ndata->data, closure); |
283 | 0 | } |
284 | 0 | closure->marshal = NULL; |
285 | 0 | closure->data = NULL; |
286 | 0 | SET (closure, in_inotify, FALSE); |
287 | 0 | break; |
288 | 0 | case PRE_NOTIFY: |
289 | 0 | i = closure->n_guards; |
290 | 0 | offs = 0; |
291 | 0 | while (i--) |
292 | 0 | { |
293 | 0 | ndata = closure->notifiers + offs + i; |
294 | 0 | ndata->notify (ndata->data, closure); |
295 | 0 | } |
296 | 0 | break; |
297 | 0 | case POST_NOTIFY: |
298 | 0 | i = closure->n_guards; |
299 | 0 | offs = i; |
300 | 0 | while (i--) |
301 | 0 | { |
302 | 0 | ndata = closure->notifiers + offs + i; |
303 | 0 | ndata->notify (ndata->data, closure); |
304 | 0 | } |
305 | 0 | break; |
306 | 0 | } |
307 | 0 | } |
308 | | |
309 | | static void |
310 | | g_closure_set_meta_va_marshal (GClosure *closure, |
311 | | GVaClosureMarshal va_meta_marshal) |
312 | 3 | { |
313 | 3 | GRealClosure *real_closure; |
314 | | |
315 | 3 | g_return_if_fail (closure != NULL); |
316 | 3 | g_return_if_fail (va_meta_marshal != NULL); |
317 | 3 | g_return_if_fail (closure->is_invalid == FALSE); |
318 | 3 | g_return_if_fail (closure->in_marshal == FALSE); |
319 | | |
320 | 3 | real_closure = G_REAL_CLOSURE (closure); |
321 | | |
322 | 3 | g_return_if_fail (real_closure->meta_marshal != NULL); |
323 | | |
324 | 3 | real_closure->va_meta_marshal = va_meta_marshal; |
325 | 3 | } |
326 | | |
327 | | /** |
328 | | * g_closure_set_meta_marshal: (skip) |
329 | | * @closure: a #GClosure |
330 | | * @marshal_data: (closure meta_marshal): context-dependent data to pass |
331 | | * to @meta_marshal |
332 | | * @meta_marshal: a #GClosureMarshal function |
333 | | * |
334 | | * Sets the meta marshaller of @closure. |
335 | | * |
336 | | * A meta marshaller wraps the @closure's marshal and modifies the way |
337 | | * it is called in some fashion. The most common use of this facility |
338 | | * is for C callbacks. |
339 | | * |
340 | | * The same marshallers (generated by [glib-genmarshal][glib-genmarshal]), |
341 | | * are used everywhere, but the way that we get the callback function |
342 | | * differs. In most cases we want to use the @closure's callback, but in |
343 | | * other cases we want to use some different technique to retrieve the |
344 | | * callback function. |
345 | | * |
346 | | * For example, class closures for signals (see |
347 | | * g_signal_type_cclosure_new()) retrieve the callback function from a |
348 | | * fixed offset in the class structure. The meta marshaller retrieves |
349 | | * the right callback and passes it to the marshaller as the |
350 | | * @marshal_data argument. |
351 | | */ |
352 | | void |
353 | | g_closure_set_meta_marshal (GClosure *closure, |
354 | | gpointer marshal_data, |
355 | | GClosureMarshal meta_marshal) |
356 | 3 | { |
357 | 3 | GRealClosure *real_closure; |
358 | | |
359 | 3 | g_return_if_fail (closure != NULL); |
360 | 3 | g_return_if_fail (meta_marshal != NULL); |
361 | 3 | g_return_if_fail (closure->is_invalid == FALSE); |
362 | 3 | g_return_if_fail (closure->in_marshal == FALSE); |
363 | | |
364 | 3 | real_closure = G_REAL_CLOSURE (closure); |
365 | | |
366 | 3 | g_return_if_fail (real_closure->meta_marshal == NULL); |
367 | | |
368 | 3 | real_closure->meta_marshal = meta_marshal; |
369 | 3 | real_closure->meta_marshal_data = marshal_data; |
370 | 3 | } |
371 | | |
372 | | /** |
373 | | * g_closure_add_marshal_guards: (skip) |
374 | | * @closure: a #GClosure |
375 | | * @pre_marshal_data: (closure pre_marshal_notify): data to pass |
376 | | * to @pre_marshal_notify |
377 | | * @pre_marshal_notify: a function to call before the closure callback |
378 | | * @post_marshal_data: (closure post_marshal_notify): data to pass |
379 | | * to @post_marshal_notify |
380 | | * @post_marshal_notify: a function to call after the closure callback |
381 | | * |
382 | | * Adds a pair of notifiers which get invoked before and after the |
383 | | * closure callback, respectively. |
384 | | * |
385 | | * This is typically used to protect the extra arguments for the |
386 | | * duration of the callback. See g_object_watch_closure() for an |
387 | | * example of marshal guards. |
388 | | */ |
389 | | void |
390 | | g_closure_add_marshal_guards (GClosure *closure, |
391 | | gpointer pre_marshal_data, |
392 | | GClosureNotify pre_marshal_notify, |
393 | | gpointer post_marshal_data, |
394 | | GClosureNotify post_marshal_notify) |
395 | 0 | { |
396 | 0 | guint i; |
397 | |
|
398 | 0 | g_return_if_fail (closure != NULL); |
399 | 0 | g_return_if_fail (pre_marshal_notify != NULL); |
400 | 0 | g_return_if_fail (post_marshal_notify != NULL); |
401 | 0 | g_return_if_fail (closure->is_invalid == FALSE); |
402 | 0 | g_return_if_fail (closure->in_marshal == FALSE); |
403 | 0 | g_return_if_fail (closure->n_guards < CLOSURE_MAX_N_GUARDS); |
404 | | |
405 | 0 | closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2); |
406 | 0 | if (closure->n_inotifiers) |
407 | 0 | closure->notifiers[(CLOSURE_N_MFUNCS (closure) + |
408 | 0 | closure->n_fnotifiers + |
409 | 0 | closure->n_inotifiers + 1)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) + |
410 | 0 | closure->n_fnotifiers + 0)]; |
411 | 0 | if (closure->n_inotifiers > 1) |
412 | 0 | closure->notifiers[(CLOSURE_N_MFUNCS (closure) + |
413 | 0 | closure->n_fnotifiers + |
414 | 0 | closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) + |
415 | 0 | closure->n_fnotifiers + 1)]; |
416 | 0 | if (closure->n_fnotifiers) |
417 | 0 | closure->notifiers[(CLOSURE_N_MFUNCS (closure) + |
418 | 0 | closure->n_fnotifiers + 1)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 0]; |
419 | 0 | if (closure->n_fnotifiers > 1) |
420 | 0 | closure->notifiers[(CLOSURE_N_MFUNCS (closure) + |
421 | 0 | closure->n_fnotifiers)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 1]; |
422 | 0 | if (closure->n_guards) |
423 | 0 | closure->notifiers[(closure->n_guards + |
424 | 0 | closure->n_guards + 1)] = closure->notifiers[closure->n_guards]; |
425 | 0 | i = closure->n_guards; |
426 | 0 | closure->notifiers[i].data = pre_marshal_data; |
427 | 0 | closure->notifiers[i].notify = pre_marshal_notify; |
428 | 0 | closure->notifiers[i + 1].data = post_marshal_data; |
429 | 0 | closure->notifiers[i + 1].notify = post_marshal_notify; |
430 | 0 | INC (closure, n_guards); |
431 | 0 | } |
432 | | |
433 | | /** |
434 | | * g_closure_add_finalize_notifier: (skip) |
435 | | * @closure: a #GClosure |
436 | | * @notify_data: (closure notify_func): data to pass to @notify_func |
437 | | * @notify_func: the callback function to register |
438 | | * |
439 | | * Registers a finalization notifier which will be called when the |
440 | | * reference count of @closure goes down to 0. |
441 | | * |
442 | | * Multiple finalization notifiers on a single closure are invoked in |
443 | | * unspecified order. If a single call to g_closure_unref() results in |
444 | | * the closure being both invalidated and finalized, then the invalidate |
445 | | * notifiers will be run before the finalize notifiers. |
446 | | */ |
447 | | void |
448 | | g_closure_add_finalize_notifier (GClosure *closure, |
449 | | gpointer notify_data, |
450 | | GClosureNotify notify_func) |
451 | 0 | { |
452 | 0 | guint i; |
453 | |
|
454 | 0 | g_return_if_fail (closure != NULL); |
455 | 0 | g_return_if_fail (notify_func != NULL); |
456 | 0 | g_return_if_fail (closure->n_fnotifiers < CLOSURE_MAX_N_FNOTIFIERS); |
457 | | |
458 | 0 | closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1); |
459 | 0 | if (closure->n_inotifiers) |
460 | 0 | closure->notifiers[(CLOSURE_N_MFUNCS (closure) + |
461 | 0 | closure->n_fnotifiers + |
462 | 0 | closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) + |
463 | 0 | closure->n_fnotifiers + 0)]; |
464 | 0 | i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers; |
465 | 0 | closure->notifiers[i].data = notify_data; |
466 | 0 | closure->notifiers[i].notify = notify_func; |
467 | 0 | INC (closure, n_fnotifiers); |
468 | 0 | } |
469 | | |
470 | | /** |
471 | | * g_closure_add_invalidate_notifier: (skip) |
472 | | * @closure: a #GClosure |
473 | | * @notify_data: (closure notify_func): data to pass to @notify_func |
474 | | * @notify_func: the callback function to register |
475 | | * |
476 | | * Registers an invalidation notifier which will be called when the |
477 | | * @closure is invalidated with g_closure_invalidate(). |
478 | | * |
479 | | * Invalidation notifiers are invoked before finalization notifiers, |
480 | | * in an unspecified order. |
481 | | */ |
482 | | void |
483 | | g_closure_add_invalidate_notifier (GClosure *closure, |
484 | | gpointer notify_data, |
485 | | GClosureNotify notify_func) |
486 | 0 | { |
487 | 0 | guint i; |
488 | |
|
489 | 0 | g_return_if_fail (closure != NULL); |
490 | 0 | g_return_if_fail (notify_func != NULL); |
491 | 0 | g_return_if_fail (closure->is_invalid == FALSE); |
492 | 0 | g_return_if_fail (closure->n_inotifiers < CLOSURE_MAX_N_INOTIFIERS); |
493 | | |
494 | 0 | closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1); |
495 | 0 | i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + closure->n_inotifiers; |
496 | 0 | closure->notifiers[i].data = notify_data; |
497 | 0 | closure->notifiers[i].notify = notify_func; |
498 | 0 | INC (closure, n_inotifiers); |
499 | 0 | } |
500 | | |
501 | | static inline gboolean |
502 | | closure_try_remove_inotify (GClosure *closure, |
503 | | gpointer notify_data, |
504 | | GClosureNotify notify_func) |
505 | 0 | { |
506 | 0 | GClosureNotifyData *ndata, *nlast; |
507 | |
|
508 | 0 | nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - 1; |
509 | 0 | for (ndata = nlast + 1 - closure->n_inotifiers; ndata <= nlast; ndata++) |
510 | 0 | if (ndata->notify == notify_func && ndata->data == notify_data) |
511 | 0 | { |
512 | 0 | DEC (closure, n_inotifiers); |
513 | 0 | if (ndata < nlast) |
514 | 0 | *ndata = *nlast; |
515 | |
|
516 | 0 | return TRUE; |
517 | 0 | } |
518 | 0 | return FALSE; |
519 | 0 | } |
520 | | |
521 | | static inline gboolean |
522 | | closure_try_remove_fnotify (GClosure *closure, |
523 | | gpointer notify_data, |
524 | | GClosureNotify notify_func) |
525 | 0 | { |
526 | 0 | GClosureNotifyData *ndata, *nlast; |
527 | |
|
528 | 0 | nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1; |
529 | 0 | for (ndata = nlast + 1 - closure->n_fnotifiers; ndata <= nlast; ndata++) |
530 | 0 | if (ndata->notify == notify_func && ndata->data == notify_data) |
531 | 0 | { |
532 | 0 | DEC (closure, n_fnotifiers); |
533 | 0 | if (ndata < nlast) |
534 | 0 | *ndata = *nlast; |
535 | 0 | if (closure->n_inotifiers) |
536 | 0 | closure->notifiers[(CLOSURE_N_MFUNCS (closure) + |
537 | 0 | closure->n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) + |
538 | 0 | closure->n_fnotifiers + |
539 | 0 | closure->n_inotifiers)]; |
540 | 0 | return TRUE; |
541 | 0 | } |
542 | 0 | return FALSE; |
543 | 0 | } |
544 | | |
545 | | /** |
546 | | * g_closure_ref: |
547 | | * @closure: #GClosure to increment the reference count on |
548 | | * |
549 | | * Increments the reference count on a closure to force it staying |
550 | | * alive while the caller holds a pointer to it. |
551 | | * |
552 | | * Returns: (transfer none): The @closure passed in, for convenience |
553 | | */ |
554 | | GClosure* |
555 | | g_closure_ref (GClosure *closure) |
556 | 3 | { |
557 | 3 | guint new_ref_count; |
558 | 3 | g_return_val_if_fail (closure != NULL, NULL); |
559 | 3 | g_return_val_if_fail (closure->ref_count > 0, NULL); |
560 | 3 | g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL); |
561 | | |
562 | 3 | INC_ASSIGN (closure, ref_count, &new_ref_count); |
563 | 3 | g_return_val_if_fail (new_ref_count > 1, NULL); |
564 | | |
565 | 3 | return closure; |
566 | 3 | } |
567 | | |
568 | | /** |
569 | | * g_closure_invalidate: |
570 | | * @closure: #GClosure to invalidate |
571 | | * |
572 | | * Sets a flag on the closure to indicate that its calling |
573 | | * environment has become invalid, and thus causes any future |
574 | | * invocations of g_closure_invoke() on this @closure to be |
575 | | * ignored. |
576 | | * |
577 | | * Also, invalidation notifiers installed on the closure will |
578 | | * be called at this point. Note that unless you are holding a |
579 | | * reference to the closure yourself, the invalidation notifiers may |
580 | | * unref the closure and cause it to be destroyed, so if you need to |
581 | | * access the closure after calling g_closure_invalidate(), make sure |
582 | | * that you've previously called g_closure_ref(). |
583 | | * |
584 | | * Note that g_closure_invalidate() will also be called when the |
585 | | * reference count of a closure drops to zero (unless it has already |
586 | | * been invalidated before). |
587 | | */ |
588 | | void |
589 | | g_closure_invalidate (GClosure *closure) |
590 | 0 | { |
591 | 0 | g_return_if_fail (closure != NULL); |
592 | | |
593 | 0 | if (!closure->is_invalid) |
594 | 0 | { |
595 | 0 | gboolean was_invalid; |
596 | 0 | g_closure_ref (closure); /* preserve floating flag */ |
597 | 0 | SWAP (closure, is_invalid, TRUE, &was_invalid); |
598 | | /* invalidate only once */ |
599 | 0 | if (!was_invalid) |
600 | 0 | closure_invoke_notifiers (closure, INOTIFY); |
601 | 0 | g_closure_unref (closure); |
602 | 0 | } |
603 | 0 | } |
604 | | |
605 | | /** |
606 | | * g_closure_unref: |
607 | | * @closure: #GClosure to decrement the reference count on |
608 | | * |
609 | | * Decrements the reference count of a closure after it was previously |
610 | | * incremented by the same caller. |
611 | | * |
612 | | * If no other callers are using the closure, then the closure will be |
613 | | * destroyed and freed. |
614 | | */ |
615 | | void |
616 | | g_closure_unref (GClosure *closure) |
617 | 3 | { |
618 | 3 | guint new_ref_count; |
619 | | |
620 | 3 | g_return_if_fail (closure != NULL); |
621 | 3 | g_return_if_fail (closure->ref_count > 0); |
622 | | |
623 | 3 | if (closure->ref_count == 1) /* last unref, invalidate first */ |
624 | 0 | g_closure_invalidate (closure); |
625 | | |
626 | 3 | DEC_ASSIGN (closure, ref_count, &new_ref_count); |
627 | | |
628 | 3 | if (new_ref_count == 0) |
629 | 0 | { |
630 | 0 | closure_invoke_notifiers (closure, FNOTIFY); |
631 | 0 | g_free (closure->notifiers); |
632 | |
|
633 | 0 | #ifdef ENABLE_VALGRIND |
634 | | /* See comments in gtype.c about what's going on here... */ |
635 | 0 | if (RUNNING_ON_VALGRIND) |
636 | 0 | { |
637 | 0 | gchar *allocated; |
638 | |
|
639 | 0 | allocated = (gchar *) G_REAL_CLOSURE (closure); |
640 | 0 | allocated -= sizeof (gpointer); |
641 | |
|
642 | 0 | g_free (allocated); |
643 | |
|
644 | 0 | VALGRIND_FREELIKE_BLOCK (allocated + sizeof (gpointer), 0); |
645 | 0 | VALGRIND_FREELIKE_BLOCK (closure, 0); |
646 | 0 | } |
647 | 0 | else |
648 | 0 | #endif |
649 | 0 | g_free (G_REAL_CLOSURE (closure)); |
650 | 0 | } |
651 | 3 | } |
652 | | |
653 | | /** |
654 | | * g_closure_sink: |
655 | | * @closure: #GClosure to decrement the initial reference count on, if it's |
656 | | * still being held |
657 | | * |
658 | | * Takes over the initial ownership of a closure. |
659 | | * |
660 | | * Each closure is initially created in a "floating" state, which means |
661 | | * that the initial reference count is not owned by any caller. |
662 | | * |
663 | | * This function checks to see if the object is still floating, and if so, |
664 | | * unsets the floating state and decreases the reference count. If the |
665 | | * closure is not floating, g_closure_sink() does nothing. |
666 | | * |
667 | | * The reason for the existence of the floating state is to prevent |
668 | | * cumbersome code sequences like: |
669 | | * |
670 | | * |[<!-- language="C" --> |
671 | | * closure = g_cclosure_new (cb_func, cb_data); |
672 | | * g_source_set_closure (source, closure); |
673 | | * g_closure_unref (closure); // GObject doesn't really need this |
674 | | * ]| |
675 | | * |
676 | | * Because g_source_set_closure() (and similar functions) take ownership of the |
677 | | * initial reference count, if it is unowned, we instead can write: |
678 | | * |
679 | | * |[<!-- language="C" --> |
680 | | * g_source_set_closure (source, g_cclosure_new (cb_func, cb_data)); |
681 | | * ]| |
682 | | * |
683 | | * Generally, this function is used together with g_closure_ref(). An example |
684 | | * of storing a closure for later notification looks like: |
685 | | * |
686 | | * |[<!-- language="C" --> |
687 | | * static GClosure *notify_closure = NULL; |
688 | | * void |
689 | | * foo_notify_set_closure (GClosure *closure) |
690 | | * { |
691 | | * if (notify_closure) |
692 | | * g_closure_unref (notify_closure); |
693 | | * notify_closure = closure; |
694 | | * if (notify_closure) |
695 | | * { |
696 | | * g_closure_ref (notify_closure); |
697 | | * g_closure_sink (notify_closure); |
698 | | * } |
699 | | * } |
700 | | * ]| |
701 | | * |
702 | | * Because g_closure_sink() may decrement the reference count of a closure |
703 | | * (if it hasn't been called on @closure yet) just like g_closure_unref(), |
704 | | * g_closure_ref() should be called prior to this function. |
705 | | */ |
706 | | void |
707 | | g_closure_sink (GClosure *closure) |
708 | 3 | { |
709 | 3 | g_return_if_fail (closure != NULL); |
710 | 3 | g_return_if_fail (closure->ref_count > 0); |
711 | | |
712 | | /* floating is basically a kludge to avoid creating closures |
713 | | * with a ref_count of 0. so the initial ref_count a closure has |
714 | | * is unowned. with invoking g_closure_sink() code may |
715 | | * indicate that it takes over that initial ref_count. |
716 | | */ |
717 | 3 | if (closure->floating) |
718 | 3 | { |
719 | 3 | gboolean was_floating; |
720 | 3 | SWAP (closure, floating, FALSE, &was_floating); |
721 | | /* unref floating flag only once */ |
722 | 3 | if (was_floating) |
723 | 3 | g_closure_unref (closure); |
724 | 3 | } |
725 | 3 | } |
726 | | |
727 | | /** |
728 | | * g_closure_remove_invalidate_notifier: (skip) |
729 | | * @closure: a #GClosure |
730 | | * @notify_data: data which was passed to g_closure_add_invalidate_notifier() |
731 | | * when registering @notify_func |
732 | | * @notify_func: the callback function to remove |
733 | | * |
734 | | * Removes an invalidation notifier. |
735 | | * |
736 | | * Notice that notifiers are automatically removed after they are run. |
737 | | */ |
738 | | void |
739 | | g_closure_remove_invalidate_notifier (GClosure *closure, |
740 | | gpointer notify_data, |
741 | | GClosureNotify notify_func) |
742 | 0 | { |
743 | 0 | g_return_if_fail (closure != NULL); |
744 | 0 | g_return_if_fail (notify_func != NULL); |
745 | | |
746 | 0 | if (closure->is_invalid && closure->in_inotify && /* account removal of notify_func() while it's called */ |
747 | 0 | ((gpointer) closure->marshal) == ((gpointer) notify_func) && |
748 | 0 | closure->data == notify_data) |
749 | 0 | closure->marshal = NULL; |
750 | 0 | else if (!closure_try_remove_inotify (closure, notify_data, notify_func)) |
751 | 0 | g_critical (G_STRLOC ": unable to remove uninstalled invalidation notifier: %p (%p)", |
752 | 0 | notify_func, notify_data); |
753 | 0 | } |
754 | | |
755 | | /** |
756 | | * g_closure_remove_finalize_notifier: (skip) |
757 | | * @closure: a #GClosure |
758 | | * @notify_data: data which was passed to g_closure_add_finalize_notifier() |
759 | | * when registering @notify_func |
760 | | * @notify_func: the callback function to remove |
761 | | * |
762 | | * Removes a finalization notifier. |
763 | | * |
764 | | * Notice that notifiers are automatically removed after they are run. |
765 | | */ |
766 | | void |
767 | | g_closure_remove_finalize_notifier (GClosure *closure, |
768 | | gpointer notify_data, |
769 | | GClosureNotify notify_func) |
770 | 0 | { |
771 | 0 | g_return_if_fail (closure != NULL); |
772 | 0 | g_return_if_fail (notify_func != NULL); |
773 | | |
774 | 0 | if (closure->is_invalid && !closure->in_inotify && /* account removal of notify_func() while it's called */ |
775 | 0 | ((gpointer) closure->marshal) == ((gpointer) notify_func) && |
776 | 0 | closure->data == notify_data) |
777 | 0 | closure->marshal = NULL; |
778 | 0 | else if (!closure_try_remove_fnotify (closure, notify_data, notify_func)) |
779 | 0 | g_critical (G_STRLOC ": unable to remove uninstalled finalization notifier: %p (%p)", |
780 | 0 | notify_func, notify_data); |
781 | 0 | } |
782 | | |
783 | | /** |
784 | | * g_closure_invoke: |
785 | | * @closure: a #GClosure |
786 | | * @return_value: (optional) (out): a #GValue to store the return |
787 | | * value. May be %NULL if the callback of @closure |
788 | | * doesn't return a value. |
789 | | * @n_param_values: the length of the @param_values array |
790 | | * @param_values: (array length=n_param_values): an array of |
791 | | * #GValues holding the arguments on which to |
792 | | * invoke the callback of @closure |
793 | | * @invocation_hint: (nullable): a context-dependent invocation hint |
794 | | * |
795 | | * Invokes the closure, i.e. executes the callback represented by the @closure. |
796 | | */ |
797 | | void |
798 | | g_closure_invoke (GClosure *closure, |
799 | | GValue /*out*/ *return_value, |
800 | | guint n_param_values, |
801 | | const GValue *param_values, |
802 | | gpointer invocation_hint) |
803 | 0 | { |
804 | 0 | GRealClosure *real_closure; |
805 | |
|
806 | 0 | g_return_if_fail (closure != NULL); |
807 | | |
808 | 0 | real_closure = G_REAL_CLOSURE (closure); |
809 | |
|
810 | 0 | g_closure_ref (closure); /* preserve floating flag */ |
811 | 0 | if (!closure->is_invalid) |
812 | 0 | { |
813 | 0 | GClosureMarshal marshal; |
814 | 0 | gpointer marshal_data; |
815 | 0 | gboolean in_marshal = closure->in_marshal; |
816 | |
|
817 | 0 | g_return_if_fail (closure->marshal || real_closure->meta_marshal); |
818 | | |
819 | 0 | SET (closure, in_marshal, TRUE); |
820 | 0 | if (real_closure->meta_marshal) |
821 | 0 | { |
822 | 0 | marshal_data = real_closure->meta_marshal_data; |
823 | 0 | marshal = real_closure->meta_marshal; |
824 | 0 | } |
825 | 0 | else |
826 | 0 | { |
827 | 0 | marshal_data = NULL; |
828 | 0 | marshal = closure->marshal; |
829 | 0 | } |
830 | 0 | if (!in_marshal) |
831 | 0 | closure_invoke_notifiers (closure, PRE_NOTIFY); |
832 | 0 | marshal (closure, |
833 | 0 | return_value, |
834 | 0 | n_param_values, param_values, |
835 | 0 | invocation_hint, |
836 | 0 | marshal_data); |
837 | 0 | if (!in_marshal) |
838 | 0 | closure_invoke_notifiers (closure, POST_NOTIFY); |
839 | 0 | SET (closure, in_marshal, in_marshal); |
840 | 0 | } |
841 | 0 | g_closure_unref (closure); |
842 | 0 | } |
843 | | |
844 | | gboolean |
845 | | _g_closure_supports_invoke_va (GClosure *closure) |
846 | 0 | { |
847 | 0 | GRealClosure *real_closure; |
848 | |
|
849 | 0 | g_return_val_if_fail (closure != NULL, FALSE); |
850 | | |
851 | 0 | real_closure = G_REAL_CLOSURE (closure); |
852 | |
|
853 | 0 | return |
854 | 0 | real_closure->va_marshal != NULL && |
855 | 0 | (real_closure->meta_marshal == NULL || |
856 | 0 | real_closure->va_meta_marshal != NULL); |
857 | 0 | } |
858 | | |
859 | | void |
860 | | _g_closure_invoke_va (GClosure *closure, |
861 | | GValue /*out*/ *return_value, |
862 | | gpointer instance, |
863 | | va_list args, |
864 | | int n_params, |
865 | | GType *param_types) |
866 | 0 | { |
867 | 0 | GRealClosure *real_closure; |
868 | |
|
869 | 0 | g_return_if_fail (closure != NULL); |
870 | | |
871 | 0 | real_closure = G_REAL_CLOSURE (closure); |
872 | |
|
873 | 0 | g_closure_ref (closure); /* preserve floating flag */ |
874 | 0 | if (!closure->is_invalid) |
875 | 0 | { |
876 | 0 | GVaClosureMarshal marshal; |
877 | 0 | gpointer marshal_data; |
878 | 0 | gboolean in_marshal = closure->in_marshal; |
879 | |
|
880 | 0 | g_return_if_fail (closure->marshal || real_closure->meta_marshal); |
881 | | |
882 | 0 | SET (closure, in_marshal, TRUE); |
883 | 0 | if (real_closure->va_meta_marshal) |
884 | 0 | { |
885 | 0 | marshal_data = real_closure->meta_marshal_data; |
886 | 0 | marshal = real_closure->va_meta_marshal; |
887 | 0 | } |
888 | 0 | else |
889 | 0 | { |
890 | 0 | marshal_data = NULL; |
891 | 0 | marshal = real_closure->va_marshal; |
892 | 0 | } |
893 | 0 | if (!in_marshal) |
894 | 0 | closure_invoke_notifiers (closure, PRE_NOTIFY); |
895 | 0 | marshal (closure, |
896 | 0 | return_value, |
897 | 0 | instance, args, |
898 | 0 | marshal_data, |
899 | 0 | n_params, param_types); |
900 | 0 | if (!in_marshal) |
901 | 0 | closure_invoke_notifiers (closure, POST_NOTIFY); |
902 | 0 | SET (closure, in_marshal, in_marshal); |
903 | 0 | } |
904 | 0 | g_closure_unref (closure); |
905 | 0 | } |
906 | | |
907 | | |
908 | | /** |
909 | | * g_closure_set_marshal: (skip) |
910 | | * @closure: a #GClosure |
911 | | * @marshal: a #GClosureMarshal function |
912 | | * |
913 | | * Sets the marshaller of @closure. |
914 | | * |
915 | | * The `marshal_data` of @marshal provides a way for a meta marshaller to |
916 | | * provide additional information to the marshaller. |
917 | | * |
918 | | * For GObject's C predefined marshallers (the `g_cclosure_marshal_*()` |
919 | | * functions), what it provides is a callback function to use instead of |
920 | | * @closure->callback. |
921 | | * |
922 | | * See also: g_closure_set_meta_marshal() |
923 | | */ |
924 | | void |
925 | | g_closure_set_marshal (GClosure *closure, |
926 | | GClosureMarshal marshal) |
927 | 3 | { |
928 | 3 | g_return_if_fail (closure != NULL); |
929 | 3 | g_return_if_fail (marshal != NULL); |
930 | | |
931 | 3 | if (closure->marshal && closure->marshal != marshal) |
932 | 0 | g_critical ("attempt to override closure->marshal (%p) with new marshal (%p)", |
933 | 3 | closure->marshal, marshal); |
934 | 3 | else |
935 | 3 | closure->marshal = marshal; |
936 | 3 | } |
937 | | |
938 | | void |
939 | | _g_closure_set_va_marshal (GClosure *closure, |
940 | | GVaClosureMarshal marshal) |
941 | 3 | { |
942 | 3 | GRealClosure *real_closure; |
943 | | |
944 | 3 | g_return_if_fail (closure != NULL); |
945 | 3 | g_return_if_fail (marshal != NULL); |
946 | | |
947 | 3 | real_closure = G_REAL_CLOSURE (closure); |
948 | | |
949 | 3 | if (real_closure->va_marshal && real_closure->va_marshal != marshal) |
950 | 0 | g_critical ("attempt to override closure->va_marshal (%p) with new marshal (%p)", |
951 | 3 | real_closure->va_marshal, marshal); |
952 | 3 | else |
953 | 3 | real_closure->va_marshal = marshal; |
954 | 3 | } |
955 | | |
956 | | /** |
957 | | * g_cclosure_new: (skip) |
958 | | * @callback_func: the function to invoke |
959 | | * @user_data: (closure callback_func): user data to pass to @callback_func |
960 | | * @destroy_data: destroy notify to be called when @user_data is no longer used |
961 | | * |
962 | | * Creates a new closure which invokes @callback_func with @user_data as |
963 | | * the last parameter. |
964 | | * |
965 | | * @destroy_data will be called as a finalize notifier on the #GClosure. |
966 | | * |
967 | | * Returns: (transfer floating): a floating reference to a new #GCClosure |
968 | | */ |
969 | | GClosure* |
970 | | g_cclosure_new (GCallback callback_func, |
971 | | gpointer user_data, |
972 | | GClosureNotify destroy_data) |
973 | 0 | { |
974 | 0 | GClosure *closure; |
975 | | |
976 | 0 | g_return_val_if_fail (callback_func != NULL, NULL); |
977 | | |
978 | 0 | closure = g_closure_new_simple (sizeof (GCClosure), user_data); |
979 | 0 | if (destroy_data) |
980 | 0 | g_closure_add_finalize_notifier (closure, user_data, destroy_data); |
981 | 0 | ((GCClosure*) closure)->callback = (gpointer) callback_func; |
982 | | |
983 | 0 | return closure; |
984 | 0 | } |
985 | | |
986 | | /** |
987 | | * g_cclosure_new_swap: (skip) |
988 | | * @callback_func: the function to invoke |
989 | | * @user_data: (closure callback_func): user data to pass to @callback_func |
990 | | * @destroy_data: destroy notify to be called when @user_data is no longer used |
991 | | * |
992 | | * Creates a new closure which invokes @callback_func with @user_data as |
993 | | * the first parameter. |
994 | | * |
995 | | * @destroy_data will be called as a finalize notifier on the #GClosure. |
996 | | * |
997 | | * Returns: (transfer floating): a floating reference to a new #GCClosure |
998 | | */ |
999 | | GClosure* |
1000 | | g_cclosure_new_swap (GCallback callback_func, |
1001 | | gpointer user_data, |
1002 | | GClosureNotify destroy_data) |
1003 | 0 | { |
1004 | 0 | GClosure *closure; |
1005 | | |
1006 | 0 | g_return_val_if_fail (callback_func != NULL, NULL); |
1007 | | |
1008 | 0 | closure = g_closure_new_simple (sizeof (GCClosure), user_data); |
1009 | 0 | if (destroy_data) |
1010 | 0 | g_closure_add_finalize_notifier (closure, user_data, destroy_data); |
1011 | 0 | ((GCClosure*) closure)->callback = (gpointer) callback_func; |
1012 | 0 | SET (closure, derivative_flag, TRUE); |
1013 | | |
1014 | 0 | return closure; |
1015 | 0 | } |
1016 | | |
1017 | | static void |
1018 | | g_type_class_meta_marshal (GClosure *closure, |
1019 | | GValue /*out*/ *return_value, |
1020 | | guint n_param_values, |
1021 | | const GValue *param_values, |
1022 | | gpointer invocation_hint, |
1023 | | gpointer marshal_data) |
1024 | 0 | { |
1025 | 0 | GTypeClass *class; |
1026 | 0 | gpointer callback; |
1027 | | /* GType itype = (GType) closure->data; */ |
1028 | 0 | guint offset = GPOINTER_TO_UINT (marshal_data); |
1029 | | |
1030 | 0 | class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass); |
1031 | 0 | callback = G_STRUCT_MEMBER (gpointer, class, offset); |
1032 | 0 | if (callback) |
1033 | 0 | closure->marshal (closure, |
1034 | 0 | return_value, |
1035 | 0 | n_param_values, param_values, |
1036 | 0 | invocation_hint, |
1037 | 0 | callback); |
1038 | 0 | } |
1039 | | |
1040 | | static void |
1041 | | g_type_class_meta_marshalv (GClosure *closure, |
1042 | | GValue *return_value, |
1043 | | gpointer instance, |
1044 | | va_list args, |
1045 | | gpointer marshal_data, |
1046 | | int n_params, |
1047 | | GType *param_types) |
1048 | 0 | { |
1049 | 0 | GRealClosure *real_closure; |
1050 | 0 | GTypeClass *class; |
1051 | 0 | gpointer callback; |
1052 | | /* GType itype = (GType) closure->data; */ |
1053 | 0 | guint offset = GPOINTER_TO_UINT (marshal_data); |
1054 | |
|
1055 | 0 | real_closure = G_REAL_CLOSURE (closure); |
1056 | |
|
1057 | 0 | class = G_TYPE_INSTANCE_GET_CLASS (instance, itype, GTypeClass); |
1058 | 0 | callback = G_STRUCT_MEMBER (gpointer, class, offset); |
1059 | 0 | if (callback) |
1060 | 0 | real_closure->va_marshal (closure, |
1061 | 0 | return_value, |
1062 | 0 | instance, args, |
1063 | 0 | callback, |
1064 | 0 | n_params, |
1065 | 0 | param_types); |
1066 | 0 | } |
1067 | | |
1068 | | static void |
1069 | | g_type_iface_meta_marshal (GClosure *closure, |
1070 | | GValue /*out*/ *return_value, |
1071 | | guint n_param_values, |
1072 | | const GValue *param_values, |
1073 | | gpointer invocation_hint, |
1074 | | gpointer marshal_data) |
1075 | 0 | { |
1076 | 0 | GTypeClass *class; |
1077 | 0 | gpointer callback; |
1078 | 0 | GType itype = (GType) closure->data; |
1079 | 0 | guint offset = GPOINTER_TO_UINT (marshal_data); |
1080 | | |
1081 | 0 | class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass); |
1082 | 0 | callback = G_STRUCT_MEMBER (gpointer, class, offset); |
1083 | 0 | if (callback) |
1084 | 0 | closure->marshal (closure, |
1085 | 0 | return_value, |
1086 | 0 | n_param_values, param_values, |
1087 | 0 | invocation_hint, |
1088 | 0 | callback); |
1089 | 0 | } |
1090 | | |
1091 | | gboolean |
1092 | | _g_closure_is_void (GClosure *closure, |
1093 | | gpointer instance) |
1094 | 0 | { |
1095 | 0 | GRealClosure *real_closure; |
1096 | 0 | GTypeClass *class; |
1097 | 0 | gpointer callback; |
1098 | 0 | GType itype; |
1099 | 0 | guint offset; |
1100 | |
|
1101 | 0 | if (closure->is_invalid) |
1102 | 0 | return TRUE; |
1103 | | |
1104 | 0 | real_closure = G_REAL_CLOSURE (closure); |
1105 | |
|
1106 | 0 | if (real_closure->meta_marshal == g_type_iface_meta_marshal) |
1107 | 0 | { |
1108 | 0 | itype = (GType) closure->data; |
1109 | 0 | offset = GPOINTER_TO_UINT (real_closure->meta_marshal_data); |
1110 | |
|
1111 | 0 | class = G_TYPE_INSTANCE_GET_INTERFACE (instance, itype, GTypeClass); |
1112 | 0 | callback = G_STRUCT_MEMBER (gpointer, class, offset); |
1113 | 0 | return callback == NULL; |
1114 | 0 | } |
1115 | 0 | else if (real_closure->meta_marshal == g_type_class_meta_marshal) |
1116 | 0 | { |
1117 | 0 | offset = GPOINTER_TO_UINT (real_closure->meta_marshal_data); |
1118 | |
|
1119 | 0 | class = G_TYPE_INSTANCE_GET_CLASS (instance, itype, GTypeClass); |
1120 | 0 | callback = G_STRUCT_MEMBER (gpointer, class, offset); |
1121 | 0 | return callback == NULL; |
1122 | 0 | } |
1123 | | |
1124 | 0 | return FALSE; |
1125 | 0 | } |
1126 | | |
1127 | | static void |
1128 | | g_type_iface_meta_marshalv (GClosure *closure, |
1129 | | GValue *return_value, |
1130 | | gpointer instance, |
1131 | | va_list args, |
1132 | | gpointer marshal_data, |
1133 | | int n_params, |
1134 | | GType *param_types) |
1135 | 0 | { |
1136 | 0 | GRealClosure *real_closure; |
1137 | 0 | GTypeClass *class; |
1138 | 0 | gpointer callback; |
1139 | 0 | GType itype = (GType) closure->data; |
1140 | 0 | guint offset = GPOINTER_TO_UINT (marshal_data); |
1141 | |
|
1142 | 0 | real_closure = G_REAL_CLOSURE (closure); |
1143 | |
|
1144 | 0 | class = G_TYPE_INSTANCE_GET_INTERFACE (instance, itype, GTypeClass); |
1145 | 0 | callback = G_STRUCT_MEMBER (gpointer, class, offset); |
1146 | 0 | if (callback) |
1147 | 0 | real_closure->va_marshal (closure, |
1148 | 0 | return_value, |
1149 | 0 | instance, args, |
1150 | 0 | callback, |
1151 | 0 | n_params, |
1152 | 0 | param_types); |
1153 | 0 | } |
1154 | | |
1155 | | /** |
1156 | | * g_signal_type_cclosure_new: |
1157 | | * @itype: the #GType identifier of an interface or classed type |
1158 | | * @struct_offset: the offset of the member function of @itype's class |
1159 | | * structure which is to be invoked by the new closure |
1160 | | * |
1161 | | * Creates a new closure which invokes the function found at the offset |
1162 | | * @struct_offset in the class structure of the interface or classed type |
1163 | | * identified by @itype. |
1164 | | * |
1165 | | * Returns: (transfer floating): a floating reference to a new #GCClosure |
1166 | | */ |
1167 | | GClosure* |
1168 | | g_signal_type_cclosure_new (GType itype, |
1169 | | guint struct_offset) |
1170 | 3 | { |
1171 | 3 | GClosure *closure; |
1172 | | |
1173 | 3 | g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL); |
1174 | 3 | g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL); |
1175 | | |
1176 | 3 | closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype); |
1177 | 3 | if (G_TYPE_IS_INTERFACE (itype)) |
1178 | 0 | { |
1179 | 0 | g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal); |
1180 | 0 | g_closure_set_meta_va_marshal (closure, g_type_iface_meta_marshalv); |
1181 | 0 | } |
1182 | 3 | else |
1183 | 3 | { |
1184 | 3 | g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal); |
1185 | 3 | g_closure_set_meta_va_marshal (closure, g_type_class_meta_marshalv); |
1186 | 3 | } |
1187 | 3 | return closure; |
1188 | 3 | } |
1189 | | |
1190 | | #include <ffi.h> |
1191 | | static ffi_type * |
1192 | | value_to_ffi_type (const GValue *gvalue, |
1193 | | gpointer *value, |
1194 | | gint *enum_tmpval, |
1195 | | gboolean *tmpval_used) |
1196 | 0 | { |
1197 | 0 | ffi_type *rettype = NULL; |
1198 | 0 | GType type = g_type_fundamental (G_VALUE_TYPE (gvalue)); |
1199 | 0 | g_assert (type != G_TYPE_INVALID); |
1200 | | |
1201 | 0 | if (enum_tmpval) |
1202 | 0 | { |
1203 | 0 | g_assert (tmpval_used != NULL); |
1204 | 0 | *tmpval_used = FALSE; |
1205 | 0 | } |
1206 | | |
1207 | 0 | switch (type) |
1208 | 0 | { |
1209 | 0 | case G_TYPE_BOOLEAN: |
1210 | 0 | case G_TYPE_CHAR: |
1211 | 0 | case G_TYPE_INT: |
1212 | 0 | rettype = &ffi_type_sint; |
1213 | 0 | *value = (gpointer)&(gvalue->data[0].v_int); |
1214 | 0 | break; |
1215 | 0 | case G_TYPE_ENUM: |
1216 | | /* enums are stored in v_long even though they are integers, which makes |
1217 | | * marshalling through libffi somewhat complicated. They need to be |
1218 | | * marshalled as signed ints, but we need to use a temporary int sized |
1219 | | * value to pass to libffi otherwise it'll pull the wrong value on |
1220 | | * BE machines with 32-bit integers when treating v_long as 32-bit int. |
1221 | | */ |
1222 | 0 | g_assert (enum_tmpval != NULL); |
1223 | 0 | rettype = &ffi_type_sint; |
1224 | 0 | *enum_tmpval = g_value_get_enum (gvalue); |
1225 | 0 | *value = enum_tmpval; |
1226 | 0 | *tmpval_used = TRUE; |
1227 | 0 | break; |
1228 | 0 | case G_TYPE_FLAGS: |
1229 | 0 | g_assert (enum_tmpval != NULL); |
1230 | 0 | rettype = &ffi_type_uint; |
1231 | 0 | *enum_tmpval = g_value_get_flags (gvalue); |
1232 | 0 | *value = enum_tmpval; |
1233 | 0 | *tmpval_used = TRUE; |
1234 | 0 | break; |
1235 | 0 | case G_TYPE_UCHAR: |
1236 | 0 | case G_TYPE_UINT: |
1237 | 0 | rettype = &ffi_type_uint; |
1238 | 0 | *value = (gpointer)&(gvalue->data[0].v_uint); |
1239 | 0 | break; |
1240 | 0 | case G_TYPE_STRING: |
1241 | 0 | case G_TYPE_OBJECT: |
1242 | 0 | case G_TYPE_BOXED: |
1243 | 0 | case G_TYPE_PARAM: |
1244 | 0 | case G_TYPE_POINTER: |
1245 | 0 | case G_TYPE_INTERFACE: |
1246 | 0 | case G_TYPE_VARIANT: |
1247 | 0 | rettype = &ffi_type_pointer; |
1248 | 0 | *value = (gpointer)&(gvalue->data[0].v_pointer); |
1249 | 0 | break; |
1250 | 0 | case G_TYPE_FLOAT: |
1251 | 0 | rettype = &ffi_type_float; |
1252 | 0 | *value = (gpointer)&(gvalue->data[0].v_float); |
1253 | 0 | break; |
1254 | 0 | case G_TYPE_DOUBLE: |
1255 | 0 | rettype = &ffi_type_double; |
1256 | 0 | *value = (gpointer)&(gvalue->data[0].v_double); |
1257 | 0 | break; |
1258 | 0 | case G_TYPE_LONG: |
1259 | 0 | rettype = &ffi_type_slong; |
1260 | 0 | *value = (gpointer)&(gvalue->data[0].v_long); |
1261 | 0 | break; |
1262 | 0 | case G_TYPE_ULONG: |
1263 | 0 | rettype = &ffi_type_ulong; |
1264 | 0 | *value = (gpointer)&(gvalue->data[0].v_ulong); |
1265 | 0 | break; |
1266 | 0 | case G_TYPE_INT64: |
1267 | 0 | rettype = &ffi_type_sint64; |
1268 | 0 | *value = (gpointer)&(gvalue->data[0].v_int64); |
1269 | 0 | break; |
1270 | 0 | case G_TYPE_UINT64: |
1271 | 0 | rettype = &ffi_type_uint64; |
1272 | 0 | *value = (gpointer)&(gvalue->data[0].v_uint64); |
1273 | 0 | break; |
1274 | 0 | default: |
1275 | 0 | rettype = &ffi_type_pointer; |
1276 | 0 | *value = NULL; |
1277 | 0 | g_critical ("value_to_ffi_type: Unsupported fundamental type: %s", g_type_name (type)); |
1278 | 0 | break; |
1279 | 0 | } |
1280 | 0 | return rettype; |
1281 | 0 | } |
1282 | | |
1283 | | static void |
1284 | | value_from_ffi_type (GValue *gvalue, gpointer *value) |
1285 | 0 | { |
1286 | 0 | ffi_arg *int_val = (ffi_arg*) value; |
1287 | 0 | GType type; |
1288 | |
|
1289 | 0 | type = G_VALUE_TYPE (gvalue); |
1290 | |
|
1291 | 0 | restart: |
1292 | 0 | switch (g_type_fundamental (type)) |
1293 | 0 | { |
1294 | 0 | case G_TYPE_INT: |
1295 | 0 | g_value_set_int (gvalue, (gint) *int_val); |
1296 | 0 | break; |
1297 | 0 | case G_TYPE_FLOAT: |
1298 | 0 | g_value_set_float (gvalue, *(gfloat*)value); |
1299 | 0 | break; |
1300 | 0 | case G_TYPE_DOUBLE: |
1301 | 0 | g_value_set_double (gvalue, *(gdouble*)value); |
1302 | 0 | break; |
1303 | 0 | case G_TYPE_BOOLEAN: |
1304 | 0 | g_value_set_boolean (gvalue, (gboolean) *int_val); |
1305 | 0 | break; |
1306 | 0 | case G_TYPE_STRING: |
1307 | 0 | g_value_take_string (gvalue, *(gchar**)value); |
1308 | 0 | break; |
1309 | 0 | case G_TYPE_CHAR: |
1310 | 0 | g_value_set_schar (gvalue, (gint8) *int_val); |
1311 | 0 | break; |
1312 | 0 | case G_TYPE_UCHAR: |
1313 | 0 | g_value_set_uchar (gvalue, (guchar) *int_val); |
1314 | 0 | break; |
1315 | 0 | case G_TYPE_UINT: |
1316 | 0 | g_value_set_uint (gvalue, (guint) *int_val); |
1317 | 0 | break; |
1318 | 0 | case G_TYPE_POINTER: |
1319 | 0 | g_value_set_pointer (gvalue, *(gpointer*)value); |
1320 | 0 | break; |
1321 | 0 | case G_TYPE_LONG: |
1322 | 0 | g_value_set_long (gvalue, (glong) *int_val); |
1323 | 0 | break; |
1324 | 0 | case G_TYPE_ULONG: |
1325 | 0 | g_value_set_ulong (gvalue, (gulong) *int_val); |
1326 | 0 | break; |
1327 | 0 | case G_TYPE_INT64: |
1328 | 0 | g_value_set_int64 (gvalue, (gint64) *int_val); |
1329 | 0 | break; |
1330 | 0 | case G_TYPE_UINT64: |
1331 | 0 | g_value_set_uint64 (gvalue, (guint64) *int_val); |
1332 | 0 | break; |
1333 | 0 | case G_TYPE_BOXED: |
1334 | 0 | g_value_take_boxed (gvalue, *(gpointer*)value); |
1335 | 0 | break; |
1336 | 0 | case G_TYPE_ENUM: |
1337 | 0 | g_value_set_enum (gvalue, (gint) *int_val); |
1338 | 0 | break; |
1339 | 0 | case G_TYPE_FLAGS: |
1340 | 0 | g_value_set_flags (gvalue, (guint) *int_val); |
1341 | 0 | break; |
1342 | 0 | case G_TYPE_PARAM: |
1343 | 0 | g_value_take_param (gvalue, *(gpointer*)value); |
1344 | 0 | break; |
1345 | 0 | case G_TYPE_OBJECT: |
1346 | 0 | g_value_take_object (gvalue, *(gpointer*)value); |
1347 | 0 | break; |
1348 | 0 | case G_TYPE_VARIANT: |
1349 | 0 | g_value_take_variant (gvalue, *(gpointer*)value); |
1350 | 0 | break; |
1351 | 0 | case G_TYPE_INTERFACE: |
1352 | 0 | type = g_type_interface_instantiatable_prerequisite (type); |
1353 | 0 | if (type) |
1354 | 0 | goto restart; |
1355 | 0 | G_GNUC_FALLTHROUGH; |
1356 | 0 | default: |
1357 | 0 | g_critical ("value_from_ffi_type: Unsupported fundamental type %s for type %s", |
1358 | 0 | g_type_name (g_type_fundamental (G_VALUE_TYPE (gvalue))), |
1359 | 0 | g_type_name (G_VALUE_TYPE (gvalue))); |
1360 | 0 | } |
1361 | 0 | } |
1362 | | |
1363 | | typedef union { |
1364 | | gpointer _gpointer; |
1365 | | float _float; |
1366 | | double _double; |
1367 | | gint _gint; |
1368 | | guint _guint; |
1369 | | glong _glong; |
1370 | | gulong _gulong; |
1371 | | gint64 _gint64; |
1372 | | guint64 _guint64; |
1373 | | } va_arg_storage; |
1374 | | |
1375 | | static ffi_type * |
1376 | | va_to_ffi_type (GType gtype, |
1377 | | va_list *va, |
1378 | | va_arg_storage *storage) |
1379 | 0 | { |
1380 | 0 | ffi_type *rettype = NULL; |
1381 | 0 | GType type = g_type_fundamental (gtype); |
1382 | 0 | g_assert (type != G_TYPE_INVALID); |
1383 | | |
1384 | 0 | switch (type) |
1385 | 0 | { |
1386 | 0 | case G_TYPE_BOOLEAN: |
1387 | 0 | case G_TYPE_CHAR: |
1388 | 0 | case G_TYPE_INT: |
1389 | 0 | case G_TYPE_ENUM: |
1390 | 0 | rettype = &ffi_type_sint; |
1391 | 0 | storage->_gint = va_arg (*va, gint); |
1392 | 0 | break; |
1393 | 0 | case G_TYPE_UCHAR: |
1394 | 0 | case G_TYPE_UINT: |
1395 | 0 | case G_TYPE_FLAGS: |
1396 | 0 | rettype = &ffi_type_uint; |
1397 | 0 | storage->_guint = va_arg (*va, guint); |
1398 | 0 | break; |
1399 | 0 | case G_TYPE_STRING: |
1400 | 0 | case G_TYPE_OBJECT: |
1401 | 0 | case G_TYPE_BOXED: |
1402 | 0 | case G_TYPE_PARAM: |
1403 | 0 | case G_TYPE_POINTER: |
1404 | 0 | case G_TYPE_INTERFACE: |
1405 | 0 | case G_TYPE_VARIANT: |
1406 | 0 | rettype = &ffi_type_pointer; |
1407 | 0 | storage->_gpointer = va_arg (*va, gpointer); |
1408 | 0 | break; |
1409 | 0 | case G_TYPE_FLOAT: |
1410 | | /* Float args are passed as doubles in varargs */ |
1411 | 0 | rettype = &ffi_type_float; |
1412 | 0 | storage->_float = (float)va_arg (*va, double); |
1413 | 0 | break; |
1414 | 0 | case G_TYPE_DOUBLE: |
1415 | 0 | rettype = &ffi_type_double; |
1416 | 0 | storage->_double = va_arg (*va, double); |
1417 | 0 | break; |
1418 | 0 | case G_TYPE_LONG: |
1419 | 0 | rettype = &ffi_type_slong; |
1420 | 0 | storage->_glong = va_arg (*va, glong); |
1421 | 0 | break; |
1422 | 0 | case G_TYPE_ULONG: |
1423 | 0 | rettype = &ffi_type_ulong; |
1424 | 0 | storage->_gulong = va_arg (*va, gulong); |
1425 | 0 | break; |
1426 | 0 | case G_TYPE_INT64: |
1427 | 0 | rettype = &ffi_type_sint64; |
1428 | 0 | storage->_gint64 = va_arg (*va, gint64); |
1429 | 0 | break; |
1430 | 0 | case G_TYPE_UINT64: |
1431 | 0 | rettype = &ffi_type_uint64; |
1432 | 0 | storage->_guint64 = va_arg (*va, guint64); |
1433 | 0 | break; |
1434 | 0 | default: |
1435 | 0 | rettype = &ffi_type_pointer; |
1436 | 0 | storage->_guint64 = 0; |
1437 | 0 | g_critical ("va_to_ffi_type: Unsupported fundamental type: %s", g_type_name (type)); |
1438 | 0 | break; |
1439 | 0 | } |
1440 | 0 | return rettype; |
1441 | 0 | } |
1442 | | |
1443 | | /** |
1444 | | * g_cclosure_marshal_generic: |
1445 | | * @closure: A #GClosure. |
1446 | | * @return_gvalue: A #GValue to store the return value. May be %NULL |
1447 | | * if the callback of closure doesn't return a value. |
1448 | | * @n_param_values: The length of the @param_values array. |
1449 | | * @param_values: An array of #GValues holding the arguments |
1450 | | * on which to invoke the callback of closure. |
1451 | | * @invocation_hint: The invocation hint given as the last argument to |
1452 | | * g_closure_invoke(). |
1453 | | * @marshal_data: Additional data specified when registering the |
1454 | | * marshaller, see g_closure_set_marshal() and |
1455 | | * g_closure_set_meta_marshal() |
1456 | | * |
1457 | | * A generic marshaller function implemented via |
1458 | | * [libffi](http://sourceware.org/libffi/). |
1459 | | * |
1460 | | * Normally this function is not passed explicitly to g_signal_new(), |
1461 | | * but used automatically by GLib when specifying a %NULL marshaller. |
1462 | | * |
1463 | | * Since: 2.30 |
1464 | | */ |
1465 | | void |
1466 | | g_cclosure_marshal_generic (GClosure *closure, |
1467 | | GValue *return_gvalue, |
1468 | | guint n_param_values, |
1469 | | const GValue *param_values, |
1470 | | gpointer invocation_hint, |
1471 | | gpointer marshal_data) |
1472 | 0 | { |
1473 | 0 | ffi_type *rtype; |
1474 | 0 | void *rvalue; |
1475 | 0 | int n_args; |
1476 | 0 | ffi_type **atypes; |
1477 | 0 | void **args; |
1478 | 0 | int i; |
1479 | 0 | ffi_cif cif; |
1480 | 0 | GCClosure *cc = (GCClosure*) closure; |
1481 | 0 | gint *enum_tmpval; |
1482 | 0 | gboolean tmpval_used = FALSE; |
1483 | |
|
1484 | 0 | enum_tmpval = g_alloca (sizeof (gint)); |
1485 | 0 | if (return_gvalue && G_VALUE_TYPE (return_gvalue)) |
1486 | 0 | { |
1487 | 0 | rtype = value_to_ffi_type (return_gvalue, &rvalue, enum_tmpval, &tmpval_used); |
1488 | 0 | } |
1489 | 0 | else |
1490 | 0 | { |
1491 | 0 | rtype = &ffi_type_void; |
1492 | 0 | } |
1493 | |
|
1494 | 0 | rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg))); |
1495 | |
|
1496 | 0 | n_args = n_param_values + 1; |
1497 | 0 | atypes = g_alloca (sizeof (ffi_type *) * n_args); |
1498 | 0 | args = g_alloca (sizeof (gpointer) * n_args); |
1499 | |
|
1500 | 0 | if (tmpval_used) |
1501 | 0 | enum_tmpval = g_alloca (sizeof (gint)); |
1502 | |
|
1503 | 0 | if (G_CCLOSURE_SWAP_DATA (closure)) |
1504 | 0 | { |
1505 | 0 | atypes[n_args-1] = value_to_ffi_type (param_values + 0, |
1506 | 0 | &args[n_args-1], |
1507 | 0 | enum_tmpval, |
1508 | 0 | &tmpval_used); |
1509 | 0 | atypes[0] = &ffi_type_pointer; |
1510 | 0 | args[0] = &closure->data; |
1511 | 0 | } |
1512 | 0 | else |
1513 | 0 | { |
1514 | 0 | atypes[0] = value_to_ffi_type (param_values + 0, |
1515 | 0 | &args[0], |
1516 | 0 | enum_tmpval, |
1517 | 0 | &tmpval_used); |
1518 | 0 | atypes[n_args-1] = &ffi_type_pointer; |
1519 | 0 | args[n_args-1] = &closure->data; |
1520 | 0 | } |
1521 | |
|
1522 | 0 | for (i = 1; i < n_args - 1; i++) |
1523 | 0 | { |
1524 | 0 | if (tmpval_used) |
1525 | 0 | enum_tmpval = g_alloca (sizeof (gint)); |
1526 | |
|
1527 | 0 | atypes[i] = value_to_ffi_type (param_values + i, |
1528 | 0 | &args[i], |
1529 | 0 | enum_tmpval, |
1530 | 0 | &tmpval_used); |
1531 | 0 | } |
1532 | |
|
1533 | 0 | if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, n_args, rtype, atypes) != FFI_OK) |
1534 | 0 | return; |
1535 | | |
1536 | 0 | ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args); |
1537 | |
|
1538 | 0 | if (return_gvalue && G_VALUE_TYPE (return_gvalue)) |
1539 | 0 | value_from_ffi_type (return_gvalue, rvalue); |
1540 | 0 | } |
1541 | | |
1542 | | /** |
1543 | | * g_cclosure_marshal_generic_va: |
1544 | | * @closure: the #GClosure to which the marshaller belongs |
1545 | | * @return_value: (nullable): a #GValue to store the return |
1546 | | * value. May be %NULL if the callback of @closure doesn't return a |
1547 | | * value. |
1548 | | * @instance: (type GObject.TypeInstance): the instance on which the closure is |
1549 | | * invoked. |
1550 | | * @args_list: va_list of arguments to be passed to the closure. |
1551 | | * @marshal_data: (nullable): additional data specified when |
1552 | | * registering the marshaller, see g_closure_set_marshal() and |
1553 | | * g_closure_set_meta_marshal() |
1554 | | * @n_params: the length of the @param_types array |
1555 | | * @param_types: (array length=n_params): the #GType of each argument from |
1556 | | * @args_list. |
1557 | | * |
1558 | | * A generic #GVaClosureMarshal function implemented via |
1559 | | * [libffi](http://sourceware.org/libffi/). |
1560 | | * |
1561 | | * Since: 2.30 |
1562 | | */ |
1563 | | void |
1564 | | g_cclosure_marshal_generic_va (GClosure *closure, |
1565 | | GValue *return_value, |
1566 | | gpointer instance, |
1567 | | va_list args_list, |
1568 | | gpointer marshal_data, |
1569 | | int n_params, |
1570 | | GType *param_types) |
1571 | 0 | { |
1572 | 0 | ffi_type *rtype; |
1573 | 0 | void *rvalue; |
1574 | 0 | int n_args; |
1575 | 0 | ffi_type **atypes; |
1576 | 0 | void **args; |
1577 | 0 | va_arg_storage *storage; |
1578 | 0 | int i; |
1579 | 0 | ffi_cif cif; |
1580 | 0 | GCClosure *cc = (GCClosure*) closure; |
1581 | 0 | gint *enum_tmpval; |
1582 | 0 | gboolean tmpval_used = FALSE; |
1583 | 0 | va_list args_copy; |
1584 | |
|
1585 | 0 | enum_tmpval = g_alloca (sizeof (gint)); |
1586 | 0 | if (return_value && G_VALUE_TYPE (return_value)) |
1587 | 0 | { |
1588 | 0 | rtype = value_to_ffi_type (return_value, &rvalue, enum_tmpval, &tmpval_used); |
1589 | 0 | } |
1590 | 0 | else |
1591 | 0 | { |
1592 | 0 | rtype = &ffi_type_void; |
1593 | 0 | } |
1594 | |
|
1595 | 0 | rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg))); |
1596 | |
|
1597 | 0 | n_args = n_params + 2; |
1598 | 0 | atypes = g_alloca (sizeof (ffi_type *) * n_args); |
1599 | 0 | args = g_alloca (sizeof (gpointer) * n_args); |
1600 | 0 | storage = g_alloca (sizeof (va_arg_storage) * n_params); |
1601 | |
|
1602 | 0 | if (G_CCLOSURE_SWAP_DATA (closure)) |
1603 | 0 | { |
1604 | 0 | atypes[n_args-1] = &ffi_type_pointer; |
1605 | 0 | args[n_args-1] = &instance; |
1606 | 0 | atypes[0] = &ffi_type_pointer; |
1607 | 0 | args[0] = &closure->data; |
1608 | 0 | } |
1609 | 0 | else |
1610 | 0 | { |
1611 | 0 | atypes[0] = &ffi_type_pointer; |
1612 | 0 | args[0] = &instance; |
1613 | 0 | atypes[n_args-1] = &ffi_type_pointer; |
1614 | 0 | args[n_args-1] = &closure->data; |
1615 | 0 | } |
1616 | |
|
1617 | 0 | va_copy (args_copy, args_list); |
1618 | | |
1619 | | /* Box non-primitive arguments */ |
1620 | 0 | for (i = 0; i < n_params; i++) |
1621 | 0 | { |
1622 | 0 | GType type = param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE; |
1623 | 0 | GType fundamental = G_TYPE_FUNDAMENTAL (type); |
1624 | |
|
1625 | 0 | atypes[i+1] = va_to_ffi_type (type, |
1626 | 0 | &args_copy, |
1627 | 0 | &storage[i]); |
1628 | 0 | args[i+1] = &storage[i]; |
1629 | |
|
1630 | 0 | if ((param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0) |
1631 | 0 | { |
1632 | 0 | if (fundamental == G_TYPE_STRING && storage[i]._gpointer != NULL) |
1633 | 0 | storage[i]._gpointer = g_strdup (storage[i]._gpointer); |
1634 | 0 | else if (fundamental == G_TYPE_PARAM && storage[i]._gpointer != NULL) |
1635 | 0 | storage[i]._gpointer = g_param_spec_ref (storage[i]._gpointer); |
1636 | 0 | else if (fundamental == G_TYPE_BOXED && storage[i]._gpointer != NULL) |
1637 | 0 | storage[i]._gpointer = g_boxed_copy (type, storage[i]._gpointer); |
1638 | 0 | else if (fundamental == G_TYPE_VARIANT && storage[i]._gpointer != NULL) |
1639 | 0 | storage[i]._gpointer = g_variant_ref_sink (storage[i]._gpointer); |
1640 | 0 | } |
1641 | 0 | if (fundamental == G_TYPE_OBJECT && storage[i]._gpointer != NULL) |
1642 | 0 | storage[i]._gpointer = g_object_ref (storage[i]._gpointer); |
1643 | 0 | } |
1644 | |
|
1645 | 0 | va_end (args_copy); |
1646 | | |
1647 | 0 | if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, n_args, rtype, atypes) != FFI_OK) |
1648 | 0 | return; |
1649 | | |
1650 | 0 | ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args); |
1651 | | |
1652 | | /* Unbox non-primitive arguments */ |
1653 | 0 | for (i = 0; i < n_params; i++) |
1654 | 0 | { |
1655 | 0 | GType type = param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE; |
1656 | 0 | GType fundamental = G_TYPE_FUNDAMENTAL (type); |
1657 | |
|
1658 | 0 | if ((param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0) |
1659 | 0 | { |
1660 | 0 | if (fundamental == G_TYPE_STRING && storage[i]._gpointer != NULL) |
1661 | 0 | g_free (storage[i]._gpointer); |
1662 | 0 | else if (fundamental == G_TYPE_PARAM && storage[i]._gpointer != NULL) |
1663 | 0 | g_param_spec_unref (storage[i]._gpointer); |
1664 | 0 | else if (fundamental == G_TYPE_BOXED && storage[i]._gpointer != NULL) |
1665 | 0 | g_boxed_free (type, storage[i]._gpointer); |
1666 | 0 | else if (fundamental == G_TYPE_VARIANT && storage[i]._gpointer != NULL) |
1667 | 0 | g_variant_unref (storage[i]._gpointer); |
1668 | 0 | } |
1669 | 0 | if (fundamental == G_TYPE_OBJECT && storage[i]._gpointer != NULL) |
1670 | 0 | g_object_unref (storage[i]._gpointer); |
1671 | 0 | } |
1672 | | |
1673 | 0 | if (return_value && G_VALUE_TYPE (return_value)) |
1674 | 0 | value_from_ffi_type (return_value, rvalue); |
1675 | 0 | } |
1676 | | |
1677 | | /** |
1678 | | * g_cclosure_marshal_VOID__VOID: |
1679 | | * @closure: the #GClosure to which the marshaller belongs |
1680 | | * @return_value: ignored |
1681 | | * @n_param_values: 1 |
1682 | | * @param_values: a #GValue array holding only the instance |
1683 | | * @invocation_hint: the invocation hint given as the last argument |
1684 | | * to g_closure_invoke() |
1685 | | * @marshal_data: additional data specified when registering the marshaller |
1686 | | * |
1687 | | * A marshaller for a #GCClosure with a callback of type |
1688 | | * `void (*callback) (gpointer instance, gpointer user_data)`. |
1689 | | */ |
1690 | | |
1691 | | /** |
1692 | | * g_cclosure_marshal_VOID__BOOLEAN: |
1693 | | * @closure: the #GClosure to which the marshaller belongs |
1694 | | * @return_value: ignored |
1695 | | * @n_param_values: 2 |
1696 | | * @param_values: a #GValue array holding the instance and the #gboolean parameter |
1697 | | * @invocation_hint: the invocation hint given as the last argument |
1698 | | * to g_closure_invoke() |
1699 | | * @marshal_data: additional data specified when registering the marshaller |
1700 | | * |
1701 | | * A marshaller for a #GCClosure with a callback of type |
1702 | | * `void (*callback) (gpointer instance, gboolean arg1, gpointer user_data)`. |
1703 | | */ |
1704 | | |
1705 | | /** |
1706 | | * g_cclosure_marshal_VOID__CHAR: |
1707 | | * @closure: the #GClosure to which the marshaller belongs |
1708 | | * @return_value: ignored |
1709 | | * @n_param_values: 2 |
1710 | | * @param_values: a #GValue array holding the instance and the #gchar parameter |
1711 | | * @invocation_hint: the invocation hint given as the last argument |
1712 | | * to g_closure_invoke() |
1713 | | * @marshal_data: additional data specified when registering the marshaller |
1714 | | * |
1715 | | * A marshaller for a #GCClosure with a callback of type |
1716 | | * `void (*callback) (gpointer instance, gchar arg1, gpointer user_data)`. |
1717 | | */ |
1718 | | |
1719 | | /** |
1720 | | * g_cclosure_marshal_VOID__UCHAR: |
1721 | | * @closure: the #GClosure to which the marshaller belongs |
1722 | | * @return_value: ignored |
1723 | | * @n_param_values: 2 |
1724 | | * @param_values: a #GValue array holding the instance and the #guchar parameter |
1725 | | * @invocation_hint: the invocation hint given as the last argument |
1726 | | * to g_closure_invoke() |
1727 | | * @marshal_data: additional data specified when registering the marshaller |
1728 | | * |
1729 | | * A marshaller for a #GCClosure with a callback of type |
1730 | | * `void (*callback) (gpointer instance, guchar arg1, gpointer user_data)`. |
1731 | | */ |
1732 | | |
1733 | | /** |
1734 | | * g_cclosure_marshal_VOID__INT: |
1735 | | * @closure: the #GClosure to which the marshaller belongs |
1736 | | * @return_value: ignored |
1737 | | * @n_param_values: 2 |
1738 | | * @param_values: a #GValue array holding the instance and the #gint parameter |
1739 | | * @invocation_hint: the invocation hint given as the last argument |
1740 | | * to g_closure_invoke() |
1741 | | * @marshal_data: additional data specified when registering the marshaller |
1742 | | * |
1743 | | * A marshaller for a #GCClosure with a callback of type |
1744 | | * `void (*callback) (gpointer instance, gint arg1, gpointer user_data)`. |
1745 | | */ |
1746 | | |
1747 | | /** |
1748 | | * g_cclosure_marshal_VOID__UINT: |
1749 | | * @closure: the #GClosure to which the marshaller belongs |
1750 | | * @return_value: ignored |
1751 | | * @n_param_values: 2 |
1752 | | * @param_values: a #GValue array holding the instance and the #guint parameter |
1753 | | * @invocation_hint: the invocation hint given as the last argument |
1754 | | * to g_closure_invoke() |
1755 | | * @marshal_data: additional data specified when registering the marshaller |
1756 | | * |
1757 | | * A marshaller for a #GCClosure with a callback of type |
1758 | | * `void (*callback) (gpointer instance, guint arg1, gpointer user_data)`. |
1759 | | */ |
1760 | | |
1761 | | /** |
1762 | | * g_cclosure_marshal_VOID__LONG: |
1763 | | * @closure: the #GClosure to which the marshaller belongs |
1764 | | * @return_value: ignored |
1765 | | * @n_param_values: 2 |
1766 | | * @param_values: a #GValue array holding the instance and the #glong parameter |
1767 | | * @invocation_hint: the invocation hint given as the last argument |
1768 | | * to g_closure_invoke() |
1769 | | * @marshal_data: additional data specified when registering the marshaller |
1770 | | * |
1771 | | * A marshaller for a #GCClosure with a callback of type |
1772 | | * `void (*callback) (gpointer instance, glong arg1, gpointer user_data)`. |
1773 | | */ |
1774 | | |
1775 | | /** |
1776 | | * g_cclosure_marshal_VOID__ULONG: |
1777 | | * @closure: the #GClosure to which the marshaller belongs |
1778 | | * @return_value: ignored |
1779 | | * @n_param_values: 2 |
1780 | | * @param_values: a #GValue array holding the instance and the #gulong parameter |
1781 | | * @invocation_hint: the invocation hint given as the last argument |
1782 | | * to g_closure_invoke() |
1783 | | * @marshal_data: additional data specified when registering the marshaller |
1784 | | * |
1785 | | * A marshaller for a #GCClosure with a callback of type |
1786 | | * `void (*callback) (gpointer instance, gulong arg1, gpointer user_data)`. |
1787 | | */ |
1788 | | |
1789 | | /** |
1790 | | * g_cclosure_marshal_VOID__ENUM: |
1791 | | * @closure: the #GClosure to which the marshaller belongs |
1792 | | * @return_value: ignored |
1793 | | * @n_param_values: 2 |
1794 | | * @param_values: a #GValue array holding the instance and the enumeration parameter |
1795 | | * @invocation_hint: the invocation hint given as the last argument |
1796 | | * to g_closure_invoke() |
1797 | | * @marshal_data: additional data specified when registering the marshaller |
1798 | | * |
1799 | | * A marshaller for a #GCClosure with a callback of type |
1800 | | * `void (*callback) (gpointer instance, gint arg1, gpointer user_data)` where the #gint parameter denotes an enumeration type.. |
1801 | | */ |
1802 | | |
1803 | | /** |
1804 | | * g_cclosure_marshal_VOID__FLAGS: |
1805 | | * @closure: the #GClosure to which the marshaller belongs |
1806 | | * @return_value: ignored |
1807 | | * @n_param_values: 2 |
1808 | | * @param_values: a #GValue array holding the instance and the flags parameter |
1809 | | * @invocation_hint: the invocation hint given as the last argument |
1810 | | * to g_closure_invoke() |
1811 | | * @marshal_data: additional data specified when registering the marshaller |
1812 | | * |
1813 | | * A marshaller for a #GCClosure with a callback of type |
1814 | | * `void (*callback) (gpointer instance, gint arg1, gpointer user_data)` where the #gint parameter denotes a flags type. |
1815 | | */ |
1816 | | |
1817 | | /** |
1818 | | * g_cclosure_marshal_VOID__FLOAT: |
1819 | | * @closure: the #GClosure to which the marshaller belongs |
1820 | | * @return_value: ignored |
1821 | | * @n_param_values: 2 |
1822 | | * @param_values: a #GValue array holding the instance and the #gfloat parameter |
1823 | | * @invocation_hint: the invocation hint given as the last argument |
1824 | | * to g_closure_invoke() |
1825 | | * @marshal_data: additional data specified when registering the marshaller |
1826 | | * |
1827 | | * A marshaller for a #GCClosure with a callback of type |
1828 | | * `void (*callback) (gpointer instance, gfloat arg1, gpointer user_data)`. |
1829 | | */ |
1830 | | |
1831 | | /** |
1832 | | * g_cclosure_marshal_VOID__DOUBLE: |
1833 | | * @closure: the #GClosure to which the marshaller belongs |
1834 | | * @return_value: ignored |
1835 | | * @n_param_values: 2 |
1836 | | * @param_values: a #GValue array holding the instance and the #gdouble parameter |
1837 | | * @invocation_hint: the invocation hint given as the last argument |
1838 | | * to g_closure_invoke() |
1839 | | * @marshal_data: additional data specified when registering the marshaller |
1840 | | * |
1841 | | * A marshaller for a #GCClosure with a callback of type |
1842 | | * `void (*callback) (gpointer instance, gdouble arg1, gpointer user_data)`. |
1843 | | */ |
1844 | | |
1845 | | /** |
1846 | | * g_cclosure_marshal_VOID__STRING: |
1847 | | * @closure: the #GClosure to which the marshaller belongs |
1848 | | * @return_value: ignored |
1849 | | * @n_param_values: 2 |
1850 | | * @param_values: a #GValue array holding the instance and the #gchar* parameter |
1851 | | * @invocation_hint: the invocation hint given as the last argument |
1852 | | * to g_closure_invoke() |
1853 | | * @marshal_data: additional data specified when registering the marshaller |
1854 | | * |
1855 | | * A marshaller for a #GCClosure with a callback of type |
1856 | | * `void (*callback) (gpointer instance, const gchar *arg1, gpointer user_data)`. |
1857 | | */ |
1858 | | |
1859 | | /** |
1860 | | * g_cclosure_marshal_VOID__PARAM: |
1861 | | * @closure: the #GClosure to which the marshaller belongs |
1862 | | * @return_value: ignored |
1863 | | * @n_param_values: 2 |
1864 | | * @param_values: a #GValue array holding the instance and the #GParamSpec* parameter |
1865 | | * @invocation_hint: the invocation hint given as the last argument |
1866 | | * to g_closure_invoke() |
1867 | | * @marshal_data: additional data specified when registering the marshaller |
1868 | | * |
1869 | | * A marshaller for a #GCClosure with a callback of type |
1870 | | * `void (*callback) (gpointer instance, GParamSpec *arg1, gpointer user_data)`. |
1871 | | */ |
1872 | | |
1873 | | /** |
1874 | | * g_cclosure_marshal_VOID__BOXED: |
1875 | | * @closure: the #GClosure to which the marshaller belongs |
1876 | | * @return_value: ignored |
1877 | | * @n_param_values: 2 |
1878 | | * @param_values: a #GValue array holding the instance and the #GBoxed* parameter |
1879 | | * @invocation_hint: the invocation hint given as the last argument |
1880 | | * to g_closure_invoke() |
1881 | | * @marshal_data: additional data specified when registering the marshaller |
1882 | | * |
1883 | | * A marshaller for a #GCClosure with a callback of type |
1884 | | * `void (*callback) (gpointer instance, GBoxed *arg1, gpointer user_data)`. |
1885 | | */ |
1886 | | |
1887 | | /** |
1888 | | * g_cclosure_marshal_VOID__POINTER: |
1889 | | * @closure: the #GClosure to which the marshaller belongs |
1890 | | * @return_value: ignored |
1891 | | * @n_param_values: 2 |
1892 | | * @param_values: a #GValue array holding the instance and the #gpointer parameter |
1893 | | * @invocation_hint: the invocation hint given as the last argument |
1894 | | * to g_closure_invoke() |
1895 | | * @marshal_data: additional data specified when registering the marshaller |
1896 | | * |
1897 | | * A marshaller for a #GCClosure with a callback of type |
1898 | | * `void (*callback) (gpointer instance, gpointer arg1, gpointer user_data)`. |
1899 | | */ |
1900 | | |
1901 | | /** |
1902 | | * g_cclosure_marshal_VOID__OBJECT: |
1903 | | * @closure: the #GClosure to which the marshaller belongs |
1904 | | * @return_value: ignored |
1905 | | * @n_param_values: 2 |
1906 | | * @param_values: a #GValue array holding the instance and the #GObject* parameter |
1907 | | * @invocation_hint: the invocation hint given as the last argument |
1908 | | * to g_closure_invoke() |
1909 | | * @marshal_data: additional data specified when registering the marshaller |
1910 | | * |
1911 | | * A marshaller for a #GCClosure with a callback of type |
1912 | | * `void (*callback) (gpointer instance, GObject *arg1, gpointer user_data)`. |
1913 | | */ |
1914 | | |
1915 | | /** |
1916 | | * g_cclosure_marshal_VOID__VARIANT: |
1917 | | * @closure: the #GClosure to which the marshaller belongs |
1918 | | * @return_value: ignored |
1919 | | * @n_param_values: 2 |
1920 | | * @param_values: a #GValue array holding the instance and the #GVariant* parameter |
1921 | | * @invocation_hint: the invocation hint given as the last argument |
1922 | | * to g_closure_invoke() |
1923 | | * @marshal_data: additional data specified when registering the marshaller |
1924 | | * |
1925 | | * A marshaller for a #GCClosure with a callback of type |
1926 | | * `void (*callback) (gpointer instance, GVariant *arg1, gpointer user_data)`. |
1927 | | * |
1928 | | * Since: 2.26 |
1929 | | */ |
1930 | | |
1931 | | /** |
1932 | | * g_cclosure_marshal_VOID__UINT_POINTER: |
1933 | | * @closure: the #GClosure to which the marshaller belongs |
1934 | | * @return_value: ignored |
1935 | | * @n_param_values: 3 |
1936 | | * @param_values: a #GValue array holding instance, arg1 and arg2 |
1937 | | * @invocation_hint: the invocation hint given as the last argument |
1938 | | * to g_closure_invoke() |
1939 | | * @marshal_data: additional data specified when registering the marshaller |
1940 | | * |
1941 | | * A marshaller for a #GCClosure with a callback of type |
1942 | | * `void (*callback) (gpointer instance, guint arg1, gpointer arg2, gpointer user_data)`. |
1943 | | */ |
1944 | | |
1945 | | /** |
1946 | | * g_cclosure_marshal_BOOLEAN__FLAGS: |
1947 | | * @closure: the #GClosure to which the marshaller belongs |
1948 | | * @return_value: a #GValue which can store the returned #gboolean |
1949 | | * @n_param_values: 2 |
1950 | | * @param_values: a #GValue array holding instance and arg1 |
1951 | | * @invocation_hint: the invocation hint given as the last argument |
1952 | | * to g_closure_invoke() |
1953 | | * @marshal_data: additional data specified when registering the marshaller |
1954 | | * |
1955 | | * A marshaller for a #GCClosure with a callback of type |
1956 | | * `gboolean (*callback) (gpointer instance, gint arg1, gpointer user_data)` where the #gint parameter |
1957 | | * denotes a flags type. |
1958 | | */ |
1959 | | |
1960 | | /** |
1961 | | * g_cclosure_marshal_BOOL__FLAGS: |
1962 | | * |
1963 | | * Another name for g_cclosure_marshal_BOOLEAN__FLAGS(). |
1964 | | */ |
1965 | | /** |
1966 | | * g_cclosure_marshal_STRING__OBJECT_POINTER: |
1967 | | * @closure: the #GClosure to which the marshaller belongs |
1968 | | * @return_value: a #GValue, which can store the returned string |
1969 | | * @n_param_values: 3 |
1970 | | * @param_values: a #GValue array holding instance, arg1 and arg2 |
1971 | | * @invocation_hint: the invocation hint given as the last argument |
1972 | | * to g_closure_invoke() |
1973 | | * @marshal_data: additional data specified when registering the marshaller |
1974 | | * |
1975 | | * A marshaller for a #GCClosure with a callback of type |
1976 | | * `gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)`. |
1977 | | */ |
1978 | | /** |
1979 | | * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED: |
1980 | | * @closure: the #GClosure to which the marshaller belongs |
1981 | | * @return_value: a #GValue, which can store the returned string |
1982 | | * @n_param_values: 3 |
1983 | | * @param_values: a #GValue array holding instance, arg1 and arg2 |
1984 | | * @invocation_hint: the invocation hint given as the last argument |
1985 | | * to g_closure_invoke() |
1986 | | * @marshal_data: additional data specified when registering the marshaller |
1987 | | * |
1988 | | * A marshaller for a #GCClosure with a callback of type |
1989 | | * `gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)`. |
1990 | | * |
1991 | | * Since: 2.26 |
1992 | | */ |