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