Add GMenuModel testcases
[glib.git] / gobject / gclosure.c
blob17b7690b26ae9f6e2aaaad0341475c9bc998d98b
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2000-2001 Red Hat, Inc.
3 * Copyright (C) 2005 Imendio AB
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 of the License, or (at your option) any later version.
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.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * MT safe with regards to reference counting.
25 #include "config.h"
27 #include <string.h>
29 #include <ffi.h>
31 #include "gclosure.h"
32 #include "gboxed.h"
33 #include "gobject.h"
34 #include "genums.h"
35 #include "gvalue.h"
36 #include "gvaluetypes.h"
39 /**
40 * SECTION:gclosure
41 * @short_description: Functions as first-class objects
42 * @title: Closures
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 reponsibility of the marshaller to
47 * convert the arguments for the invocation from #GValue<!-- -->s into
48 * a suitable form, perform the callback on the converted arguments,
49 * and transform the return value back into a #GValue.
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 #GValue<!--
56 * -->s and suitable representations in the runtime of the language in
57 * order to use functions written in that languages as callbacks.
59 * Within GObject, closures play an important role in the
60 * implementation of signals. When a signal is registered, the
61 * @c_marshaller argument to g_signal_new() specifies the default C
62 * marshaller for any closure which is connected to this
63 * signal. GObject provides a number of C marshallers for this
64 * purpose, see the g_cclosure_marshal_*() functions. Additional C
65 * marshallers can be generated with the <link
66 * linkend="glib-genmarshal">glib-genmarshal</link> utility. Closures
67 * can be explicitly connected to signals with
68 * g_signal_connect_closure(), but it usually more convenient to let
69 * GObject create a closure automatically by using one of the
70 * g_signal_connect_*() functions which take a callback function/user
71 * data pair.
73 * Using closures has a number of important advantages over a simple
74 * callback function/data pointer combination:
75 * <itemizedlist>
76 * <listitem><para>
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 * </para></listitem>
81 * <listitem><para>
82 * The reference counting of #GClosure makes it easy to handle reentrancy
83 * right; if a callback is removed while it is being invoked, the closure
84 * and its parameters won't be freed until the invocation finishes.
85 * </para></listitem>
86 * <listitem><para>
87 * g_closure_invalidate() and invalidation notifiers allow callbacks to be
88 * automatically removed when the objects they point to go away.
89 * </para></listitem>
90 * </itemizedlist>
94 #define CLOSURE_MAX_REF_COUNT ((1 << 15) - 1)
95 #define CLOSURE_MAX_N_GUARDS ((1 << 1) - 1)
96 #define CLOSURE_MAX_N_FNOTIFIERS ((1 << 2) - 1)
97 #define CLOSURE_MAX_N_INOTIFIERS ((1 << 8) - 1)
98 #define CLOSURE_N_MFUNCS(cl) ((cl)->meta_marshal + \
99 ((cl)->n_guards << 1L))
100 /* same as G_CLOSURE_N_NOTIFIERS() (keep in sync) */
101 #define CLOSURE_N_NOTIFIERS(cl) (CLOSURE_N_MFUNCS (cl) + \
102 (cl)->n_fnotifiers + \
103 (cl)->n_inotifiers)
105 typedef union {
106 GClosure closure;
107 volatile gint vint;
108 } ClosureInt;
110 #define CHANGE_FIELD(_closure, _field, _OP, _value, _must_set, _SET_OLD, _SET_NEW) \
111 G_STMT_START { \
112 ClosureInt *cunion = (ClosureInt*) _closure; \
113 gint new_int, old_int, success; \
114 do \
116 ClosureInt tmp; \
117 tmp.vint = old_int = cunion->vint; \
118 _SET_OLD tmp.closure._field; \
119 tmp.closure._field _OP _value; \
120 _SET_NEW tmp.closure._field; \
121 new_int = tmp.vint; \
122 success = g_atomic_int_compare_and_exchange (&cunion->vint, old_int, new_int); \
124 while (!success && _must_set); \
125 } G_STMT_END
127 #define SWAP(_closure, _field, _value, _oldv) CHANGE_FIELD (_closure, _field, =, _value, TRUE, *(_oldv) =, (void) )
128 #define SET(_closure, _field, _value) CHANGE_FIELD (_closure, _field, =, _value, TRUE, (void), (void) )
129 #define INC(_closure, _field) CHANGE_FIELD (_closure, _field, +=, 1, TRUE, (void), (void) )
130 #define INC_ASSIGN(_closure, _field, _newv) CHANGE_FIELD (_closure, _field, +=, 1, TRUE, (void), *(_newv) = )
131 #define DEC(_closure, _field) CHANGE_FIELD (_closure, _field, -=, 1, TRUE, (void), (void) )
132 #define DEC_ASSIGN(_closure, _field, _newv) CHANGE_FIELD (_closure, _field, -=, 1, TRUE, (void), *(_newv) = )
134 #if 0 /* for non-thread-safe closures */
135 #define SWAP(cl,f,v,o) (void) (*(o) = cl->f, cl->f = v)
136 #define SET(cl,f,v) (void) (cl->f = v)
137 #define INC(cl,f) (void) (cl->f += 1)
138 #define INC_ASSIGN(cl,f,n) (void) (cl->f += 1, *(n) = cl->f)
139 #define DEC(cl,f) (void) (cl->f -= 1)
140 #define DEC_ASSIGN(cl,f,n) (void) (cl->f -= 1, *(n) = cl->f)
141 #endif
143 enum {
144 FNOTIFY,
145 INOTIFY,
146 PRE_NOTIFY,
147 POST_NOTIFY
151 /* --- functions --- */
153 * g_closure_new_simple:
154 * @sizeof_closure: the size of the structure to allocate, must be at least
155 * <literal>sizeof (GClosure)</literal>
156 * @data: data to store in the @data field of the newly allocated #GClosure
158 * Allocates a struct of the given size and initializes the initial
159 * part as a #GClosure. This function is mainly useful when
160 * implementing new types of closures.
162 * |[
163 * typedef struct _MyClosure MyClosure;
164 * struct _MyClosure
166 * GClosure closure;
167 * // extra data goes here
168 * };
170 * static void
171 * my_closure_finalize (gpointer notify_data,
172 * GClosure *closure)
174 * MyClosure *my_closure = (MyClosure *)closure;
176 * // free extra data here
179 * MyClosure *my_closure_new (gpointer data)
181 * GClosure *closure;
182 * MyClosure *my_closure;
184 * closure = g_closure_new_simple (sizeof (MyClosure), data);
185 * my_closure = (MyClosure *) closure;
187 * // initialize extra data here
189 * g_closure_add_finalize_notifier (closure, notify_data,
190 * my_closure_finalize);
191 * return my_closure;
193 * ]|
195 * Returns: (transfer full): a newly allocated #GClosure
197 GClosure*
198 g_closure_new_simple (guint sizeof_closure,
199 gpointer data)
201 GClosure *closure;
203 g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL);
205 closure = g_malloc0 (sizeof_closure);
206 SET (closure, ref_count, 1);
207 SET (closure, meta_marshal, 0);
208 SET (closure, n_guards, 0);
209 SET (closure, n_fnotifiers, 0);
210 SET (closure, n_inotifiers, 0);
211 SET (closure, in_inotify, FALSE);
212 SET (closure, floating, TRUE);
213 SET (closure, derivative_flag, 0);
214 SET (closure, in_marshal, FALSE);
215 SET (closure, is_invalid, FALSE);
216 closure->marshal = NULL;
217 closure->data = data;
218 closure->notifiers = NULL;
219 memset (G_STRUCT_MEMBER_P (closure, sizeof (*closure)), 0, sizeof_closure - sizeof (*closure));
221 return closure;
224 static inline void
225 closure_invoke_notifiers (GClosure *closure,
226 guint notify_type)
228 /* notifier layout:
229 * meta_marshal n_guards n_guards n_fnotif. n_inotifiers
230 * ->[[meta_marshal][pre_guards][post_guards][fnotifiers][inotifiers]]
232 * CLOSURE_N_MFUNCS(cl) = meta_marshal + n_guards + n_guards;
233 * CLOSURE_N_NOTIFIERS(cl) = CLOSURE_N_MFUNCS(cl) + n_fnotifiers + n_inotifiers
235 * constrains/catches:
236 * - closure->notifiers may be reloacted during callback
237 * - closure->n_fnotifiers and closure->n_inotifiers may change during callback
238 * - i.e. callbacks can be removed/added during invocation
239 * - must prepare for callback removal during FNOTIFY and INOTIFY (done via ->marshal= & ->data=)
240 * - must distinguish (->marshal= & ->data=) for INOTIFY vs. FNOTIFY (via ->in_inotify)
241 * + closure->n_guards is const during PRE_NOTIFY & POST_NOTIFY
242 * + closure->meta_marshal is const for all cases
243 * + none of the callbacks can cause recursion
244 * + closure->n_inotifiers is const 0 during FNOTIFY
246 switch (notify_type)
248 GClosureNotifyData *ndata;
249 guint i, offs;
250 case FNOTIFY:
251 while (closure->n_fnotifiers)
253 guint n;
254 DEC_ASSIGN (closure, n_fnotifiers, &n);
256 ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + n;
257 closure->marshal = (GClosureMarshal) ndata->notify;
258 closure->data = ndata->data;
259 ndata->notify (ndata->data, closure);
261 closure->marshal = NULL;
262 closure->data = NULL;
263 break;
264 case INOTIFY:
265 SET (closure, in_inotify, TRUE);
266 while (closure->n_inotifiers)
268 guint n;
269 DEC_ASSIGN (closure, n_inotifiers, &n);
271 ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n;
272 closure->marshal = (GClosureMarshal) ndata->notify;
273 closure->data = ndata->data;
274 ndata->notify (ndata->data, closure);
276 closure->marshal = NULL;
277 closure->data = NULL;
278 SET (closure, in_inotify, FALSE);
279 break;
280 case PRE_NOTIFY:
281 i = closure->n_guards;
282 offs = closure->meta_marshal;
283 while (i--)
285 ndata = closure->notifiers + offs + i;
286 ndata->notify (ndata->data, closure);
288 break;
289 case POST_NOTIFY:
290 i = closure->n_guards;
291 offs = closure->meta_marshal + i;
292 while (i--)
294 ndata = closure->notifiers + offs + i;
295 ndata->notify (ndata->data, closure);
297 break;
302 * g_closure_set_meta_marshal: (skip)
303 * @closure: a #GClosure
304 * @marshal_data: context-dependent data to pass to @meta_marshal
305 * @meta_marshal: a #GClosureMarshal function
307 * Sets the meta marshaller of @closure. A meta marshaller wraps
308 * @closure->marshal and modifies the way it is called in some
309 * fashion. The most common use of this facility is for C callbacks.
310 * The same marshallers (generated by <link
311 * linkend="glib-genmarshal">glib-genmarshal</link>) are used
312 * everywhere, but the way that we get the callback function
313 * differs. In most cases we want to use @closure->callback, but in
314 * other cases we want to use some different technique to retrieve the
315 * callback function.
317 * For example, class closures for signals (see
318 * g_signal_type_cclosure_new()) retrieve the callback function from a
319 * fixed offset in the class structure. The meta marshaller retrieves
320 * the right callback and passes it to the marshaller as the
321 * @marshal_data argument.
323 void
324 g_closure_set_meta_marshal (GClosure *closure,
325 gpointer marshal_data,
326 GClosureMarshal meta_marshal)
328 GClosureNotifyData *notifiers;
330 g_return_if_fail (closure != NULL);
331 g_return_if_fail (meta_marshal != NULL);
332 g_return_if_fail (closure->is_invalid == FALSE);
333 g_return_if_fail (closure->in_marshal == FALSE);
334 g_return_if_fail (closure->meta_marshal == 0);
336 notifiers = closure->notifiers;
337 closure->notifiers = g_renew (GClosureNotifyData, NULL, CLOSURE_N_NOTIFIERS (closure) + 1);
338 if (notifiers)
340 /* usually the meta marshal will be setup right after creation, so the
341 * g_memmove() should be rare-case scenario
343 g_memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
344 g_free (notifiers);
346 closure->notifiers[0].data = marshal_data;
347 closure->notifiers[0].notify = (GClosureNotify) meta_marshal;
348 SET (closure, meta_marshal, 1);
352 * g_closure_add_marshal_guards: (skip)
353 * @closure: a #GClosure
354 * @pre_marshal_data: data to pass to @pre_marshal_notify
355 * @pre_marshal_notify: a function to call before the closure callback
356 * @post_marshal_data: data to pass to @post_marshal_notify
357 * @post_marshal_notify: a function to call after the closure callback
359 * Adds a pair of notifiers which get invoked before and after the
360 * closure callback, respectively. This is typically used to protect
361 * the extra arguments for the duration of the callback. See
362 * g_object_watch_closure() for an example of marshal guards.
364 void
365 g_closure_add_marshal_guards (GClosure *closure,
366 gpointer pre_marshal_data,
367 GClosureNotify pre_marshal_notify,
368 gpointer post_marshal_data,
369 GClosureNotify post_marshal_notify)
371 guint i;
373 g_return_if_fail (closure != NULL);
374 g_return_if_fail (pre_marshal_notify != NULL);
375 g_return_if_fail (post_marshal_notify != NULL);
376 g_return_if_fail (closure->is_invalid == FALSE);
377 g_return_if_fail (closure->in_marshal == FALSE);
378 g_return_if_fail (closure->n_guards < CLOSURE_MAX_N_GUARDS);
380 closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2);
381 if (closure->n_inotifiers)
382 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
383 closure->n_fnotifiers +
384 closure->n_inotifiers + 1)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
385 closure->n_fnotifiers + 0)];
386 if (closure->n_inotifiers > 1)
387 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
388 closure->n_fnotifiers +
389 closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
390 closure->n_fnotifiers + 1)];
391 if (closure->n_fnotifiers)
392 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
393 closure->n_fnotifiers + 1)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 0];
394 if (closure->n_fnotifiers > 1)
395 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
396 closure->n_fnotifiers)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 1];
397 if (closure->n_guards)
398 closure->notifiers[(closure->meta_marshal +
399 closure->n_guards +
400 closure->n_guards + 1)] = closure->notifiers[closure->meta_marshal + closure->n_guards];
401 i = closure->n_guards;
402 closure->notifiers[closure->meta_marshal + i].data = pre_marshal_data;
403 closure->notifiers[closure->meta_marshal + i].notify = pre_marshal_notify;
404 closure->notifiers[closure->meta_marshal + i + 1].data = post_marshal_data;
405 closure->notifiers[closure->meta_marshal + i + 1].notify = post_marshal_notify;
406 INC (closure, n_guards);
410 * g_closure_add_finalize_notifier: (skip)
411 * @closure: a #GClosure
412 * @notify_data: data to pass to @notify_func
413 * @notify_func: the callback function to register
415 * Registers a finalization notifier which will be called when the
416 * reference count of @closure goes down to 0. Multiple finalization
417 * notifiers on a single closure are invoked in unspecified order. If
418 * a single call to g_closure_unref() results in the closure being
419 * both invalidated and finalized, then the invalidate notifiers will
420 * be run before the finalize notifiers.
422 void
423 g_closure_add_finalize_notifier (GClosure *closure,
424 gpointer notify_data,
425 GClosureNotify notify_func)
427 guint i;
429 g_return_if_fail (closure != NULL);
430 g_return_if_fail (notify_func != NULL);
431 g_return_if_fail (closure->n_fnotifiers < CLOSURE_MAX_N_FNOTIFIERS);
433 closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
434 if (closure->n_inotifiers)
435 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
436 closure->n_fnotifiers +
437 closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
438 closure->n_fnotifiers + 0)];
439 i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers;
440 closure->notifiers[i].data = notify_data;
441 closure->notifiers[i].notify = notify_func;
442 INC (closure, n_fnotifiers);
446 * g_closure_add_invalidate_notifier: (skip)
447 * @closure: a #GClosure
448 * @notify_data: data to pass to @notify_func
449 * @notify_func: the callback function to register
451 * Registers an invalidation notifier which will be called when the
452 * @closure is invalidated with g_closure_invalidate(). Invalidation
453 * notifiers are invoked before finalization notifiers, in an
454 * unspecified order.
456 void
457 g_closure_add_invalidate_notifier (GClosure *closure,
458 gpointer notify_data,
459 GClosureNotify notify_func)
461 guint i;
463 g_return_if_fail (closure != NULL);
464 g_return_if_fail (notify_func != NULL);
465 g_return_if_fail (closure->is_invalid == FALSE);
466 g_return_if_fail (closure->n_inotifiers < CLOSURE_MAX_N_INOTIFIERS);
468 closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
469 i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + closure->n_inotifiers;
470 closure->notifiers[i].data = notify_data;
471 closure->notifiers[i].notify = notify_func;
472 INC (closure, n_inotifiers);
475 static inline gboolean
476 closure_try_remove_inotify (GClosure *closure,
477 gpointer notify_data,
478 GClosureNotify notify_func)
480 GClosureNotifyData *ndata, *nlast;
482 nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - 1;
483 for (ndata = nlast + 1 - closure->n_inotifiers; ndata <= nlast; ndata++)
484 if (ndata->notify == notify_func && ndata->data == notify_data)
486 DEC (closure, n_inotifiers);
487 if (ndata < nlast)
488 *ndata = *nlast;
490 return TRUE;
492 return FALSE;
495 static inline gboolean
496 closure_try_remove_fnotify (GClosure *closure,
497 gpointer notify_data,
498 GClosureNotify notify_func)
500 GClosureNotifyData *ndata, *nlast;
502 nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1;
503 for (ndata = nlast + 1 - closure->n_fnotifiers; ndata <= nlast; ndata++)
504 if (ndata->notify == notify_func && ndata->data == notify_data)
506 DEC (closure, n_fnotifiers);
507 if (ndata < nlast)
508 *ndata = *nlast;
509 if (closure->n_inotifiers)
510 closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
511 closure->n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
512 closure->n_fnotifiers +
513 closure->n_inotifiers)];
514 return TRUE;
516 return FALSE;
520 * g_closure_ref:
521 * @closure: #GClosure to increment the reference count on
523 * Increments the reference count on a closure to force it staying
524 * alive while the caller holds a pointer to it.
526 * Returns: (transfer none): The @closure passed in, for convenience
528 GClosure*
529 g_closure_ref (GClosure *closure)
531 guint new_ref_count;
532 g_return_val_if_fail (closure != NULL, NULL);
533 g_return_val_if_fail (closure->ref_count > 0, NULL);
534 g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL);
536 INC_ASSIGN (closure, ref_count, &new_ref_count);
537 g_return_val_if_fail (new_ref_count > 1, NULL);
539 return closure;
543 * g_closure_invalidate:
544 * @closure: GClosure to invalidate
546 * Sets a flag on the closure to indicate that its calling
547 * environment has become invalid, and thus causes any future
548 * invocations of g_closure_invoke() on this @closure to be
549 * ignored. Also, invalidation notifiers installed on the closure will
550 * be called at this point. Note that unless you are holding a
551 * reference to the closure yourself, the invalidation notifiers may
552 * unref the closure and cause it to be destroyed, so if you need to
553 * access the closure after calling g_closure_invalidate(), make sure
554 * that you've previously called g_closure_ref().
556 * Note that g_closure_invalidate() will also be called when the
557 * reference count of a closure drops to zero (unless it has already
558 * been invalidated before).
560 void
561 g_closure_invalidate (GClosure *closure)
563 g_return_if_fail (closure != NULL);
565 if (!closure->is_invalid)
567 gboolean was_invalid;
568 g_closure_ref (closure); /* preserve floating flag */
569 SWAP (closure, is_invalid, TRUE, &was_invalid);
570 /* invalidate only once */
571 if (!was_invalid)
572 closure_invoke_notifiers (closure, INOTIFY);
573 g_closure_unref (closure);
578 * g_closure_unref:
579 * @closure: #GClosure to decrement the reference count on
581 * Decrements the reference count of a closure after it was previously
582 * incremented by the same caller. If no other callers are using the
583 * closure, then the closure will be destroyed and freed.
585 void
586 g_closure_unref (GClosure *closure)
588 guint new_ref_count;
590 g_return_if_fail (closure != NULL);
591 g_return_if_fail (closure->ref_count > 0);
593 if (closure->ref_count == 1) /* last unref, invalidate first */
594 g_closure_invalidate (closure);
596 DEC_ASSIGN (closure, ref_count, &new_ref_count);
598 if (new_ref_count == 0)
600 closure_invoke_notifiers (closure, FNOTIFY);
601 g_free (closure->notifiers);
602 g_free (closure);
607 * g_closure_sink:
608 * @closure: #GClosure to decrement the initial reference count on, if it's
609 * still being held
611 * Takes over the initial ownership of a closure. Each closure is
612 * initially created in a <firstterm>floating</firstterm> state, which
613 * means that the initial reference count is not owned by any caller.
614 * g_closure_sink() checks to see if the object is still floating, and
615 * if so, unsets the floating state and decreases the reference
616 * count. If the closure is not floating, g_closure_sink() does
617 * nothing. The reason for the existence of the floating state is to
618 * prevent cumbersome code sequences like:
619 * |[
620 * closure = g_cclosure_new (cb_func, cb_data);
621 * g_source_set_closure (source, closure);
622 * g_closure_unref (closure); // XXX GObject doesn't really need this
623 * ]|
624 * Because g_source_set_closure() (and similar functions) take ownership of the
625 * initial reference count, if it is unowned, we instead can write:
626 * |[
627 * g_source_set_closure (source, g_cclosure_new (cb_func, cb_data));
628 * ]|
630 * Generally, this function is used together with g_closure_ref(). Ane example
631 * of storing a closure for later notification looks like:
632 * |[
633 * static GClosure *notify_closure = NULL;
634 * void
635 * foo_notify_set_closure (GClosure *closure)
637 * if (notify_closure)
638 * g_closure_unref (notify_closure);
639 * notify_closure = closure;
640 * if (notify_closure)
642 * g_closure_ref (notify_closure);
643 * g_closure_sink (notify_closure);
646 * ]|
648 * Because g_closure_sink() may decrement the reference count of a closure
649 * (if it hasn't been called on @closure yet) just like g_closure_unref(),
650 * g_closure_ref() should be called prior to this function.
652 void
653 g_closure_sink (GClosure *closure)
655 g_return_if_fail (closure != NULL);
656 g_return_if_fail (closure->ref_count > 0);
658 /* floating is basically a kludge to avoid creating closures
659 * with a ref_count of 0. so the initial ref_count a closure has
660 * is unowned. with invoking g_closure_sink() code may
661 * indicate that it takes over that intiial ref_count.
663 if (closure->floating)
665 gboolean was_floating;
666 SWAP (closure, floating, FALSE, &was_floating);
667 /* unref floating flag only once */
668 if (was_floating)
669 g_closure_unref (closure);
674 * g_closure_remove_invalidate_notifier: (skip)
675 * @closure: a #GClosure
676 * @notify_data: data which was passed to g_closure_add_invalidate_notifier()
677 * when registering @notify_func
678 * @notify_func: the callback function to remove
680 * Removes an invalidation notifier.
682 * Notice that notifiers are automatically removed after they are run.
684 void
685 g_closure_remove_invalidate_notifier (GClosure *closure,
686 gpointer notify_data,
687 GClosureNotify notify_func)
689 g_return_if_fail (closure != NULL);
690 g_return_if_fail (notify_func != NULL);
692 if (closure->is_invalid && closure->in_inotify && /* account removal of notify_func() while it's called */
693 ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
694 closure->data == notify_data)
695 closure->marshal = NULL;
696 else if (!closure_try_remove_inotify (closure, notify_data, notify_func))
697 g_warning (G_STRLOC ": unable to remove uninstalled invalidation notifier: %p (%p)",
698 notify_func, notify_data);
702 * g_closure_remove_finalize_notifier: (skip)
703 * @closure: a #GClosure
704 * @notify_data: data which was passed to g_closure_add_finalize_notifier()
705 * when registering @notify_func
706 * @notify_func: the callback function to remove
708 * Removes a finalization notifier.
710 * Notice that notifiers are automatically removed after they are run.
712 void
713 g_closure_remove_finalize_notifier (GClosure *closure,
714 gpointer notify_data,
715 GClosureNotify notify_func)
717 g_return_if_fail (closure != NULL);
718 g_return_if_fail (notify_func != NULL);
720 if (closure->is_invalid && !closure->in_inotify && /* account removal of notify_func() while it's called */
721 ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
722 closure->data == notify_data)
723 closure->marshal = NULL;
724 else if (!closure_try_remove_fnotify (closure, notify_data, notify_func))
725 g_warning (G_STRLOC ": unable to remove uninstalled finalization notifier: %p (%p)",
726 notify_func, notify_data);
730 * g_closure_invoke:
731 * @closure: a #GClosure
732 * @return_value: (allow-none): a #GValue to store the return
733 * value. May be %NULL if the callback of @closure
734 * doesn't return a value.
735 * @n_param_values: the length of the @param_values array
736 * @param_values: (array length=n_param_values): an array of
737 * #GValue<!-- -->s holding the arguments on which to
738 * invoke the callback of @closure
739 * @invocation_hint: (allow-none): a context-dependent invocation hint
741 * Invokes the closure, i.e. executes the callback represented by the @closure.
743 void
744 g_closure_invoke (GClosure *closure,
745 GValue /*out*/ *return_value,
746 guint n_param_values,
747 const GValue *param_values,
748 gpointer invocation_hint)
750 g_return_if_fail (closure != NULL);
752 g_closure_ref (closure); /* preserve floating flag */
753 if (!closure->is_invalid)
755 GClosureMarshal marshal;
756 gpointer marshal_data;
757 gboolean in_marshal = closure->in_marshal;
759 g_return_if_fail (closure->marshal || closure->meta_marshal);
761 SET (closure, in_marshal, TRUE);
762 if (closure->meta_marshal)
764 marshal_data = closure->notifiers[0].data;
765 marshal = (GClosureMarshal) closure->notifiers[0].notify;
767 else
769 marshal_data = NULL;
770 marshal = closure->marshal;
772 if (!in_marshal)
773 closure_invoke_notifiers (closure, PRE_NOTIFY);
774 marshal (closure,
775 return_value,
776 n_param_values, param_values,
777 invocation_hint,
778 marshal_data);
779 if (!in_marshal)
780 closure_invoke_notifiers (closure, POST_NOTIFY);
781 SET (closure, in_marshal, in_marshal);
783 g_closure_unref (closure);
787 * g_closure_set_marshal: (skip)
788 * @closure: a #GClosure
789 * @marshal: a #GClosureMarshal function
791 * Sets the marshaller of @closure. The <literal>marshal_data</literal>
792 * of @marshal provides a way for a meta marshaller to provide additional
793 * information to the marshaller. (See g_closure_set_meta_marshal().) For
794 * GObject's C predefined marshallers (the g_cclosure_marshal_*()
795 * functions), what it provides is a callback function to use instead of
796 * @closure->callback.
798 void
799 g_closure_set_marshal (GClosure *closure,
800 GClosureMarshal marshal)
802 g_return_if_fail (closure != NULL);
803 g_return_if_fail (marshal != NULL);
805 if (closure->marshal && closure->marshal != marshal)
806 g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)",
807 closure->marshal, marshal);
808 else
809 closure->marshal = marshal;
813 * g_cclosure_new: (skip)
814 * @callback_func: the function to invoke
815 * @user_data: user data to pass to @callback_func
816 * @destroy_data: destroy notify to be called when @user_data is no longer used
818 * Creates a new closure which invokes @callback_func with @user_data as
819 * the last parameter.
821 * Returns: a new #GCClosure
823 GClosure*
824 g_cclosure_new (GCallback callback_func,
825 gpointer user_data,
826 GClosureNotify destroy_data)
828 GClosure *closure;
830 g_return_val_if_fail (callback_func != NULL, NULL);
832 closure = g_closure_new_simple (sizeof (GCClosure), user_data);
833 if (destroy_data)
834 g_closure_add_finalize_notifier (closure, user_data, destroy_data);
835 ((GCClosure*) closure)->callback = (gpointer) callback_func;
837 return closure;
841 * g_cclosure_new_swap: (skip)
842 * @callback_func: the function to invoke
843 * @user_data: user data to pass to @callback_func
844 * @destroy_data: destroy notify to be called when @user_data is no longer used
846 * Creates a new closure which invokes @callback_func with @user_data as
847 * the first parameter.
849 * Returns: (transfer full): a new #GCClosure
851 GClosure*
852 g_cclosure_new_swap (GCallback callback_func,
853 gpointer user_data,
854 GClosureNotify destroy_data)
856 GClosure *closure;
858 g_return_val_if_fail (callback_func != NULL, NULL);
860 closure = g_closure_new_simple (sizeof (GCClosure), user_data);
861 if (destroy_data)
862 g_closure_add_finalize_notifier (closure, user_data, destroy_data);
863 ((GCClosure*) closure)->callback = (gpointer) callback_func;
864 SET (closure, derivative_flag, TRUE);
866 return closure;
869 static void
870 g_type_class_meta_marshal (GClosure *closure,
871 GValue /*out*/ *return_value,
872 guint n_param_values,
873 const GValue *param_values,
874 gpointer invocation_hint,
875 gpointer marshal_data)
877 GTypeClass *class;
878 gpointer callback;
879 /* GType itype = (GType) closure->data; */
880 guint offset = GPOINTER_TO_UINT (marshal_data);
882 class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
883 callback = G_STRUCT_MEMBER (gpointer, class, offset);
884 if (callback)
885 closure->marshal (closure,
886 return_value,
887 n_param_values, param_values,
888 invocation_hint,
889 callback);
892 static void
893 g_type_iface_meta_marshal (GClosure *closure,
894 GValue /*out*/ *return_value,
895 guint n_param_values,
896 const GValue *param_values,
897 gpointer invocation_hint,
898 gpointer marshal_data)
900 GTypeClass *class;
901 gpointer callback;
902 GType itype = (GType) closure->data;
903 guint offset = GPOINTER_TO_UINT (marshal_data);
905 class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
906 callback = G_STRUCT_MEMBER (gpointer, class, offset);
907 if (callback)
908 closure->marshal (closure,
909 return_value,
910 n_param_values, param_values,
911 invocation_hint,
912 callback);
916 * g_signal_type_cclosure_new:
917 * @itype: the #GType identifier of an interface or classed type
918 * @struct_offset: the offset of the member function of @itype's class
919 * structure which is to be invoked by the new closure
921 * Creates a new closure which invokes the function found at the offset
922 * @struct_offset in the class structure of the interface or classed type
923 * identified by @itype.
925 * Returns: a new #GCClosure
927 GClosure*
928 g_signal_type_cclosure_new (GType itype,
929 guint struct_offset)
931 GClosure *closure;
933 g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
934 g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL);
936 closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype);
937 if (G_TYPE_IS_INTERFACE (itype))
938 g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal);
939 else
940 g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal);
942 return closure;
945 #include <ffi.h>
946 static ffi_type *
947 value_to_ffi_type (const GValue *gvalue,
948 gpointer *value,
949 gint *enum_tmpval,
950 gboolean *tmpval_used)
952 ffi_type *rettype = NULL;
953 GType type = g_type_fundamental (G_VALUE_TYPE (gvalue));
954 g_assert (type != G_TYPE_INVALID);
956 if (enum_tmpval)
958 g_assert (tmpval_used != NULL);
959 *tmpval_used = FALSE;
962 switch (type)
964 case G_TYPE_BOOLEAN:
965 case G_TYPE_CHAR:
966 case G_TYPE_INT:
967 rettype = &ffi_type_sint;
968 *value = (gpointer)&(gvalue->data[0].v_int);
969 break;
970 case G_TYPE_ENUM:
971 /* enums are stored in v_long even though they are integers, which makes
972 * marshalling through libffi somewhat complicated. They need to be
973 * marshalled as signed ints, but we need to use a temporary int sized
974 * value to pass to libffi otherwise it'll pull the wrong value on
975 * BE machines with 32-bit integers when treating v_long as 32-bit int.
977 g_assert (enum_tmpval != NULL);
978 rettype = &ffi_type_sint;
979 *enum_tmpval = g_value_get_enum (gvalue);
980 *value = enum_tmpval;
981 *tmpval_used = TRUE;
982 break;
983 case G_TYPE_UCHAR:
984 case G_TYPE_UINT:
985 case G_TYPE_FLAGS:
986 rettype = &ffi_type_uint;
987 *value = (gpointer)&(gvalue->data[0].v_uint);
988 break;
989 case G_TYPE_STRING:
990 case G_TYPE_OBJECT:
991 case G_TYPE_BOXED:
992 case G_TYPE_PARAM:
993 case G_TYPE_POINTER:
994 case G_TYPE_INTERFACE:
995 case G_TYPE_VARIANT:
996 rettype = &ffi_type_pointer;
997 *value = (gpointer)&(gvalue->data[0].v_pointer);
998 break;
999 case G_TYPE_FLOAT:
1000 rettype = &ffi_type_float;
1001 *value = (gpointer)&(gvalue->data[0].v_float);
1002 break;
1003 case G_TYPE_DOUBLE:
1004 rettype = &ffi_type_double;
1005 *value = (gpointer)&(gvalue->data[0].v_double);
1006 break;
1007 case G_TYPE_LONG:
1008 rettype = &ffi_type_slong;
1009 *value = (gpointer)&(gvalue->data[0].v_long);
1010 break;
1011 case G_TYPE_ULONG:
1012 rettype = &ffi_type_ulong;
1013 *value = (gpointer)&(gvalue->data[0].v_ulong);
1014 break;
1015 case G_TYPE_INT64:
1016 rettype = &ffi_type_sint64;
1017 *value = (gpointer)&(gvalue->data[0].v_int64);
1018 break;
1019 case G_TYPE_UINT64:
1020 rettype = &ffi_type_uint64;
1021 *value = (gpointer)&(gvalue->data[0].v_uint64);
1022 break;
1023 default:
1024 rettype = &ffi_type_pointer;
1025 *value = NULL;
1026 g_warning ("value_to_ffi_type: Unsupported fundamental type: %s", g_type_name (type));
1027 break;
1029 return rettype;
1032 static void
1033 value_from_ffi_type (GValue *gvalue, gpointer *value)
1035 ffi_arg *int_val = (ffi_arg*) value;
1037 switch (g_type_fundamental (G_VALUE_TYPE (gvalue)))
1039 case G_TYPE_INT:
1040 g_value_set_int (gvalue, (gint) *int_val);
1041 break;
1042 case G_TYPE_FLOAT:
1043 g_value_set_float (gvalue, *(gfloat*)value);
1044 break;
1045 case G_TYPE_DOUBLE:
1046 g_value_set_double (gvalue, *(gdouble*)value);
1047 break;
1048 case G_TYPE_BOOLEAN:
1049 g_value_set_boolean (gvalue, (gboolean) *int_val);
1050 break;
1051 case G_TYPE_STRING:
1052 g_value_set_string (gvalue, *(gchar**)value);
1053 break;
1054 case G_TYPE_CHAR:
1055 g_value_set_schar (gvalue, (gint8) *int_val);
1056 break;
1057 case G_TYPE_UCHAR:
1058 g_value_set_uchar (gvalue, (guchar) *int_val);
1059 break;
1060 case G_TYPE_UINT:
1061 g_value_set_uint (gvalue, (guint) *int_val);
1062 break;
1063 case G_TYPE_POINTER:
1064 g_value_set_pointer (gvalue, *(gpointer*)value);
1065 break;
1066 case G_TYPE_LONG:
1067 g_value_set_long (gvalue, (glong) *int_val);
1068 break;
1069 case G_TYPE_ULONG:
1070 g_value_set_ulong (gvalue, (gulong) *int_val);
1071 break;
1072 case G_TYPE_INT64:
1073 g_value_set_int64 (gvalue, (gint64) *int_val);
1074 break;
1075 case G_TYPE_UINT64:
1076 g_value_set_uint64 (gvalue, (guint64) *int_val);
1077 break;
1078 case G_TYPE_BOXED:
1079 g_value_set_boxed (gvalue, *(gpointer*)value);
1080 break;
1081 case G_TYPE_ENUM:
1082 g_value_set_enum (gvalue, (gint) *int_val);
1083 break;
1084 case G_TYPE_FLAGS:
1085 g_value_set_flags (gvalue, (guint) *int_val);
1086 break;
1087 case G_TYPE_PARAM:
1088 g_value_set_param (gvalue, *(gpointer*)value);
1089 break;
1090 case G_TYPE_OBJECT:
1091 g_value_set_object (gvalue, *(gpointer*)value);
1092 break;
1093 default:
1094 g_warning ("value_from_ffi_type: Unsupported fundamental type: %s",
1095 g_type_name (g_type_fundamental (G_VALUE_TYPE (gvalue))));
1100 * g_cclosure_marshal_generic:
1101 * @closure: A #GClosure.
1102 * @return_gvalue: A #GValue to store the return value. May be %NULL
1103 * if the callback of closure doesn't return a value.
1104 * @n_param_values: The length of the @param_values array.
1105 * @param_values: An array of #GValue<!-- -->s holding the arguments
1106 * on which to invoke the callback of closure.
1107 * @invocation_hint: The invocation hint given as the last argument to
1108 * g_closure_invoke().
1109 * @marshal_data: Additional data specified when registering the
1110 * marshaller, see g_closure_set_marshal() and
1111 * g_closure_set_meta_marshal()
1113 * A generic marshaller function implemented via <ulink
1114 * url="http://sourceware.org/libffi/">libffi</ulink>.
1116 * Since: 2.30
1118 void
1119 g_cclosure_marshal_generic (GClosure *closure,
1120 GValue *return_gvalue,
1121 guint n_param_values,
1122 const GValue *param_values,
1123 gpointer invocation_hint,
1124 gpointer marshal_data)
1126 ffi_type *rtype;
1127 void *rvalue;
1128 int n_args;
1129 ffi_type **atypes;
1130 void **args;
1131 int i;
1132 ffi_cif cif;
1133 GCClosure *cc = (GCClosure*) closure;
1134 gint *enum_tmpval;
1135 gboolean tmpval_used = FALSE;
1137 enum_tmpval = g_alloca (sizeof (gint));
1138 if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1140 rtype = value_to_ffi_type (return_gvalue, &rvalue, enum_tmpval, &tmpval_used);
1142 else
1144 rtype = &ffi_type_void;
1147 rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg)));
1149 n_args = n_param_values + 1;
1150 atypes = g_alloca (sizeof (ffi_type *) * n_args);
1151 args = g_alloca (sizeof (gpointer) * n_args);
1153 if (tmpval_used)
1154 enum_tmpval = g_alloca (sizeof (gint));
1156 if (G_CCLOSURE_SWAP_DATA (closure))
1158 atypes[n_args-1] = value_to_ffi_type (param_values + 0,
1159 &args[n_args-1],
1160 enum_tmpval,
1161 &tmpval_used);
1162 atypes[0] = &ffi_type_pointer;
1163 args[0] = &closure->data;
1165 else
1167 atypes[0] = value_to_ffi_type (param_values + 0,
1168 &args[0],
1169 enum_tmpval,
1170 &tmpval_used);
1171 atypes[n_args-1] = &ffi_type_pointer;
1172 args[n_args-1] = &closure->data;
1175 for (i = 1; i < n_args - 1; i++)
1177 if (tmpval_used)
1178 enum_tmpval = g_alloca (sizeof (gint));
1180 atypes[i] = value_to_ffi_type (param_values + i,
1181 &args[i],
1182 enum_tmpval,
1183 &tmpval_used);
1186 if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, n_args, rtype, atypes) != FFI_OK)
1187 return;
1189 ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args);
1191 if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1192 value_from_ffi_type (return_gvalue, rvalue);
1196 * g_cclosure_marshal_VOID__VOID:
1197 * @closure: the #GClosure to which the marshaller belongs
1198 * @return_value: ignored
1199 * @n_param_values: 1
1200 * @param_values: a #GValue array holding only the instance
1201 * @invocation_hint: the invocation hint given as the last argument
1202 * to g_closure_invoke()
1203 * @marshal_data: additional data specified when registering the marshaller
1205 * A marshaller for a #GCClosure with a callback of type
1206 * <literal>void (*callback) (gpointer instance, gpointer user_data)</literal>.
1210 * g_cclosure_marshal_VOID__BOOLEAN:
1211 * @closure: the #GClosure to which the marshaller belongs
1212 * @return_value: ignored
1213 * @n_param_values: 2
1214 * @param_values: a #GValue array holding the instance and the #gboolean parameter
1215 * @invocation_hint: the invocation hint given as the last argument
1216 * to g_closure_invoke()
1217 * @marshal_data: additional data specified when registering the marshaller
1219 * A marshaller for a #GCClosure with a callback of type
1220 * <literal>void (*callback) (gpointer instance, gboolean arg1, gpointer user_data)</literal>.
1224 * g_cclosure_marshal_VOID__CHAR:
1225 * @closure: the #GClosure to which the marshaller belongs
1226 * @return_value: ignored
1227 * @n_param_values: 2
1228 * @param_values: a #GValue array holding the instance and the #gchar parameter
1229 * @invocation_hint: the invocation hint given as the last argument
1230 * to g_closure_invoke()
1231 * @marshal_data: additional data specified when registering the marshaller
1233 * A marshaller for a #GCClosure with a callback of type
1234 * <literal>void (*callback) (gpointer instance, gchar arg1, gpointer user_data)</literal>.
1238 * g_cclosure_marshal_VOID__UCHAR:
1239 * @closure: the #GClosure to which the marshaller belongs
1240 * @return_value: ignored
1241 * @n_param_values: 2
1242 * @param_values: a #GValue array holding the instance and the #guchar parameter
1243 * @invocation_hint: the invocation hint given as the last argument
1244 * to g_closure_invoke()
1245 * @marshal_data: additional data specified when registering the marshaller
1247 * A marshaller for a #GCClosure with a callback of type
1248 * <literal>void (*callback) (gpointer instance, guchar arg1, gpointer user_data)</literal>.
1252 * g_cclosure_marshal_VOID__INT:
1253 * @closure: the #GClosure to which the marshaller belongs
1254 * @return_value: ignored
1255 * @n_param_values: 2
1256 * @param_values: a #GValue array holding the instance and the #gint parameter
1257 * @invocation_hint: the invocation hint given as the last argument
1258 * to g_closure_invoke()
1259 * @marshal_data: additional data specified when registering the marshaller
1261 * A marshaller for a #GCClosure with a callback of type
1262 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal>.
1266 * g_cclosure_marshal_VOID__UINT:
1267 * @closure: the #GClosure to which the marshaller belongs
1268 * @return_value: ignored
1269 * @n_param_values: 2
1270 * @param_values: a #GValue array holding the instance and the #guint parameter
1271 * @invocation_hint: the invocation hint given as the last argument
1272 * to g_closure_invoke()
1273 * @marshal_data: additional data specified when registering the marshaller
1275 * A marshaller for a #GCClosure with a callback of type
1276 * <literal>void (*callback) (gpointer instance, guint arg1, gpointer user_data)</literal>.
1280 * g_cclosure_marshal_VOID__LONG:
1281 * @closure: the #GClosure to which the marshaller belongs
1282 * @return_value: ignored
1283 * @n_param_values: 2
1284 * @param_values: a #GValue array holding the instance and the #glong parameter
1285 * @invocation_hint: the invocation hint given as the last argument
1286 * to g_closure_invoke()
1287 * @marshal_data: additional data specified when registering the marshaller
1289 * A marshaller for a #GCClosure with a callback of type
1290 * <literal>void (*callback) (gpointer instance, glong arg1, gpointer user_data)</literal>.
1294 * g_cclosure_marshal_VOID__ULONG:
1295 * @closure: the #GClosure to which the marshaller belongs
1296 * @return_value: ignored
1297 * @n_param_values: 2
1298 * @param_values: a #GValue array holding the instance and the #gulong parameter
1299 * @invocation_hint: the invocation hint given as the last argument
1300 * to g_closure_invoke()
1301 * @marshal_data: additional data specified when registering the marshaller
1303 * A marshaller for a #GCClosure with a callback of type
1304 * <literal>void (*callback) (gpointer instance, gulong arg1, gpointer user_data)</literal>.
1308 * g_cclosure_marshal_VOID__ENUM:
1309 * @closure: the #GClosure to which the marshaller belongs
1310 * @return_value: ignored
1311 * @n_param_values: 2
1312 * @param_values: a #GValue array holding the instance and the enumeration parameter
1313 * @invocation_hint: the invocation hint given as the last argument
1314 * to g_closure_invoke()
1315 * @marshal_data: additional data specified when registering the marshaller
1317 * A marshaller for a #GCClosure with a callback of type
1318 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes an enumeration type..
1322 * g_cclosure_marshal_VOID__FLAGS:
1323 * @closure: the #GClosure to which the marshaller belongs
1324 * @return_value: ignored
1325 * @n_param_values: 2
1326 * @param_values: a #GValue array holding the instance and the flags parameter
1327 * @invocation_hint: the invocation hint given as the last argument
1328 * to g_closure_invoke()
1329 * @marshal_data: additional data specified when registering the marshaller
1331 * A marshaller for a #GCClosure with a callback of type
1332 * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes a flags type.
1336 * g_cclosure_marshal_VOID__FLOAT:
1337 * @closure: the #GClosure to which the marshaller belongs
1338 * @return_value: ignored
1339 * @n_param_values: 2
1340 * @param_values: a #GValue array holding the instance and the #gfloat parameter
1341 * @invocation_hint: the invocation hint given as the last argument
1342 * to g_closure_invoke()
1343 * @marshal_data: additional data specified when registering the marshaller
1345 * A marshaller for a #GCClosure with a callback of type
1346 * <literal>void (*callback) (gpointer instance, gfloat arg1, gpointer user_data)</literal>.
1350 * g_cclosure_marshal_VOID__DOUBLE:
1351 * @closure: the #GClosure to which the marshaller belongs
1352 * @return_value: ignored
1353 * @n_param_values: 2
1354 * @param_values: a #GValue array holding the instance and the #gdouble parameter
1355 * @invocation_hint: the invocation hint given as the last argument
1356 * to g_closure_invoke()
1357 * @marshal_data: additional data specified when registering the marshaller
1359 * A marshaller for a #GCClosure with a callback of type
1360 * <literal>void (*callback) (gpointer instance, gdouble arg1, gpointer user_data)</literal>.
1364 * g_cclosure_marshal_VOID__STRING:
1365 * @closure: the #GClosure to which the marshaller belongs
1366 * @return_value: ignored
1367 * @n_param_values: 2
1368 * @param_values: a #GValue array holding the instance and the #gchar* parameter
1369 * @invocation_hint: the invocation hint given as the last argument
1370 * to g_closure_invoke()
1371 * @marshal_data: additional data specified when registering the marshaller
1373 * A marshaller for a #GCClosure with a callback of type
1374 * <literal>void (*callback) (gpointer instance, const gchar *arg1, gpointer user_data)</literal>.
1378 * g_cclosure_marshal_VOID__PARAM:
1379 * @closure: the #GClosure to which the marshaller belongs
1380 * @return_value: ignored
1381 * @n_param_values: 2
1382 * @param_values: a #GValue array holding the instance and the #GParamSpec* parameter
1383 * @invocation_hint: the invocation hint given as the last argument
1384 * to g_closure_invoke()
1385 * @marshal_data: additional data specified when registering the marshaller
1387 * A marshaller for a #GCClosure with a callback of type
1388 * <literal>void (*callback) (gpointer instance, GParamSpec *arg1, gpointer user_data)</literal>.
1392 * g_cclosure_marshal_VOID__BOXED:
1393 * @closure: the #GClosure to which the marshaller belongs
1394 * @return_value: ignored
1395 * @n_param_values: 2
1396 * @param_values: a #GValue array holding the instance and the #GBoxed* parameter
1397 * @invocation_hint: the invocation hint given as the last argument
1398 * to g_closure_invoke()
1399 * @marshal_data: additional data specified when registering the marshaller
1401 * A marshaller for a #GCClosure with a callback of type
1402 * <literal>void (*callback) (gpointer instance, GBoxed *arg1, gpointer user_data)</literal>.
1406 * g_cclosure_marshal_VOID__POINTER:
1407 * @closure: the #GClosure to which the marshaller belongs
1408 * @return_value: ignored
1409 * @n_param_values: 2
1410 * @param_values: a #GValue array holding the instance and the #gpointer parameter
1411 * @invocation_hint: the invocation hint given as the last argument
1412 * to g_closure_invoke()
1413 * @marshal_data: additional data specified when registering the marshaller
1415 * A marshaller for a #GCClosure with a callback of type
1416 * <literal>void (*callback) (gpointer instance, gpointer arg1, gpointer user_data)</literal>.
1420 * g_cclosure_marshal_VOID__OBJECT:
1421 * @closure: the #GClosure to which the marshaller belongs
1422 * @return_value: ignored
1423 * @n_param_values: 2
1424 * @param_values: a #GValue array holding the instance and the #GObject* parameter
1425 * @invocation_hint: the invocation hint given as the last argument
1426 * to g_closure_invoke()
1427 * @marshal_data: additional data specified when registering the marshaller
1429 * A marshaller for a #GCClosure with a callback of type
1430 * <literal>void (*callback) (gpointer instance, GObject *arg1, gpointer user_data)</literal>.
1434 * g_cclosure_marshal_VOID__VARIANT:
1435 * @closure: the #GClosure to which the marshaller belongs
1436 * @return_value: ignored
1437 * @n_param_values: 2
1438 * @param_values: a #GValue array holding the instance and the #GVariant* parameter
1439 * @invocation_hint: the invocation hint given as the last argument
1440 * to g_closure_invoke()
1441 * @marshal_data: additional data specified when registering the marshaller
1443 * A marshaller for a #GCClosure with a callback of type
1444 * <literal>void (*callback) (gpointer instance, GVariant *arg1, gpointer user_data)</literal>.
1446 * Since: 2.26
1450 * g_cclosure_marshal_VOID__UINT_POINTER:
1451 * @closure: the #GClosure to which the marshaller belongs
1452 * @return_value: ignored
1453 * @n_param_values: 3
1454 * @param_values: a #GValue array holding instance, arg1 and arg2
1455 * @invocation_hint: the invocation hint given as the last argument
1456 * to g_closure_invoke()
1457 * @marshal_data: additional data specified when registering the marshaller
1459 * A marshaller for a #GCClosure with a callback of type
1460 * <literal>void (*callback) (gpointer instance, guint arg1, gpointer arg2, gpointer user_data)</literal>.
1464 * g_cclosure_marshal_BOOLEAN__FLAGS:
1465 * @closure: the #GClosure to which the marshaller belongs
1466 * @return_value: a #GValue which can store the returned #gboolean
1467 * @n_param_values: 2
1468 * @param_values: a #GValue array holding instance and arg1
1469 * @invocation_hint: the invocation hint given as the last argument
1470 * to g_closure_invoke()
1471 * @marshal_data: additional data specified when registering the marshaller
1473 * A marshaller for a #GCClosure with a callback of type
1474 * <literal>gboolean (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter
1475 * denotes a flags type.
1479 * g_cclosure_marshal_BOOL__FLAGS:
1481 * Another name for g_cclosure_marshal_BOOLEAN__FLAGS().
1484 * g_cclosure_marshal_STRING__OBJECT_POINTER:
1485 * @closure: the #GClosure to which the marshaller belongs
1486 * @return_value: a #GValue, which can store the returned string
1487 * @n_param_values: 3
1488 * @param_values: a #GValue array holding instance, arg1 and arg2
1489 * @invocation_hint: the invocation hint given as the last argument
1490 * to g_closure_invoke()
1491 * @marshal_data: additional data specified when registering the marshaller
1493 * A marshaller for a #GCClosure with a callback of type
1494 * <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>.
1497 * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED:
1498 * @closure: the #GClosure to which the marshaller belongs
1499 * @return_value: a #GValue, which can store the returned string
1500 * @n_param_values: 3
1501 * @param_values: a #GValue array holding instance, arg1 and arg2
1502 * @invocation_hint: the invocation hint given as the last argument
1503 * to g_closure_invoke()
1504 * @marshal_data: additional data specified when registering the marshaller
1506 * A marshaller for a #GCClosure with a callback of type
1507 * <literal>gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)</literal>.
1509 * Since: 2.26