Merge remote-tracking branch 'gvdb/master'
[platform/upstream/glib.git] / gobject / gclosure.c
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 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, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * MT safe with regards to reference counting.
23  */
24
25 #include "config.h"
26
27 #include <string.h>
28
29 #include "gclosure.h"
30 #include "gvalue.h"
31
32
33 /**
34  * SECTION:gclosure
35  * @short_description: Functions as first-class objects
36  * @title: Closures
37  *
38  * A #GClosure represents a callback supplied by the programmer. It
39  * will generally comprise a function of some kind and a marshaller
40  * used to call it. It is the reponsibility of the marshaller to
41  * convert the arguments for the invocation from #GValue<!-- -->s into
42  * a suitable form, perform the callback on the converted arguments,
43  * and transform the return value back into a #GValue.
44  *
45  * In the case of C programs, a closure usually just holds a pointer
46  * to a function and maybe a data argument, and the marshaller
47  * converts between #GValue<!-- --> and native C types. The GObject
48  * library provides the #GCClosure type for this purpose. Bindings for
49  * other languages need marshallers which convert between #GValue<!--
50  * -->s and suitable representations in the runtime of the language in
51  * order to use functions written in that languages as callbacks.
52  *
53  * Within GObject, closures play an important role in the
54  * implementation of signals. When a signal is registered, the
55  * @c_marshaller argument to g_signal_new() specifies the default C
56  * marshaller for any closure which is connected to this
57  * signal. GObject provides a number of C marshallers for this
58  * purpose, see the g_cclosure_marshal_*() functions. Additional C
59  * marshallers can be generated with the <link
60  * linkend="glib-genmarshal">glib-genmarshal</link> utility.  Closures
61  * can be explicitly connected to signals with
62  * g_signal_connect_closure(), but it usually more convenient to let
63  * GObject create a closure automatically by using one of the
64  * g_signal_connect_*() functions which take a callback function/user
65  * data pair.
66  *
67  * Using closures has a number of important advantages over a simple
68  * callback function/data pointer combination:
69  * <itemizedlist>
70  * <listitem><para>
71  * Closures allow the callee to get the types of the callback parameters,
72  * which means that language bindings don't have to write individual glue
73  * for each callback type.
74  * </para></listitem>
75  * <listitem><para>
76  * The reference counting of #GClosure makes it easy to handle reentrancy
77  * right; if a callback is removed while it is being invoked, the closure
78  * and its parameters won't be freed until the invocation finishes.
79  * </para></listitem>
80  * <listitem><para>
81  * g_closure_invalidate() and invalidation notifiers allow callbacks to be
82  * automatically removed when the objects they point to go away.
83  * </para></listitem>
84  * </itemizedlist>
85  */
86
87
88 #define CLOSURE_MAX_REF_COUNT           ((1 << 15) - 1)
89 #define CLOSURE_MAX_N_GUARDS            ((1 << 1) - 1)
90 #define CLOSURE_MAX_N_FNOTIFIERS        ((1 << 2) - 1)
91 #define CLOSURE_MAX_N_INOTIFIERS        ((1 << 8) - 1)
92 #define CLOSURE_N_MFUNCS(cl)            ((cl)->meta_marshal + \
93                                          ((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   volatile 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  *                  <literal>sizeof (GClosure)</literal>
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  * |[
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 full): a newly allocated #GClosure
190  */
191 GClosure*
192 g_closure_new_simple (guint           sizeof_closure,
193                       gpointer        data)
194 {
195   GClosure *closure;
196
197   g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL);
198
199   closure = g_malloc0 (sizeof_closure);
200   SET (closure, ref_count, 1);
201   SET (closure, meta_marshal, 0);
202   SET (closure, n_guards, 0);
203   SET (closure, n_fnotifiers, 0);
204   SET (closure, n_inotifiers, 0);
205   SET (closure, in_inotify, FALSE);
206   SET (closure, floating, TRUE);
207   SET (closure, derivative_flag, 0);
208   SET (closure, in_marshal, FALSE);
209   SET (closure, is_invalid, FALSE);
210   closure->marshal = NULL;
211   closure->data = data;
212   closure->notifiers = NULL;
213   memset (G_STRUCT_MEMBER_P (closure, sizeof (*closure)), 0, sizeof_closure - sizeof (*closure));
214
215   return closure;
216 }
217
218 static inline void
219 closure_invoke_notifiers (GClosure *closure,
220                           guint     notify_type)
221 {
222   /* notifier layout:
223    *     meta_marshal  n_guards    n_guards     n_fnotif.  n_inotifiers
224    * ->[[meta_marshal][pre_guards][post_guards][fnotifiers][inotifiers]]
225    *
226    * CLOSURE_N_MFUNCS(cl)    = meta_marshal + n_guards + n_guards;
227    * CLOSURE_N_NOTIFIERS(cl) = CLOSURE_N_MFUNCS(cl) + n_fnotifiers + n_inotifiers
228    *
229    * constrains/catches:
230    * - closure->notifiers may be reloacted during callback
231    * - closure->n_fnotifiers and closure->n_inotifiers may change during callback
232    * - i.e. callbacks can be removed/added during invocation
233    * - must prepare for callback removal during FNOTIFY and INOTIFY (done via ->marshal= & ->data=)
234    * - must distinguish (->marshal= & ->data=) for INOTIFY vs. FNOTIFY (via ->in_inotify)
235    * + closure->n_guards is const during PRE_NOTIFY & POST_NOTIFY
236    * + closure->meta_marshal is const for all cases
237    * + none of the callbacks can cause recursion
238    * + closure->n_inotifiers is const 0 during FNOTIFY
239    */
240   switch (notify_type)
241     {
242       GClosureNotifyData *ndata;
243       guint i, offs;
244     case FNOTIFY:
245       while (closure->n_fnotifiers)
246         {
247           guint n;
248           DEC_ASSIGN (closure, n_fnotifiers, &n);
249
250           ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + n;
251           closure->marshal = (GClosureMarshal) ndata->notify;
252           closure->data = ndata->data;
253           ndata->notify (ndata->data, closure);
254         }
255       closure->marshal = NULL;
256       closure->data = NULL;
257       break;
258     case INOTIFY:
259       SET (closure, in_inotify, TRUE);
260       while (closure->n_inotifiers)
261         {
262           guint n;
263           DEC_ASSIGN (closure, n_inotifiers, &n);
264
265           ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n;
266           closure->marshal = (GClosureMarshal) ndata->notify;
267           closure->data = ndata->data;
268           ndata->notify (ndata->data, closure);
269         }
270       closure->marshal = NULL;
271       closure->data = NULL;
272       SET (closure, in_inotify, FALSE);
273       break;
274     case PRE_NOTIFY:
275       i = closure->n_guards;
276       offs = closure->meta_marshal;
277       while (i--)
278         {
279           ndata = closure->notifiers + offs + i;
280           ndata->notify (ndata->data, closure);
281         }
282       break;
283     case POST_NOTIFY:
284       i = closure->n_guards;
285       offs = closure->meta_marshal + i;
286       while (i--)
287         {
288           ndata = closure->notifiers + offs + i;
289           ndata->notify (ndata->data, closure);
290         }
291       break;
292     }
293 }
294
295 /**
296  * g_closure_set_meta_marshal: (skip)
297  * @closure: a #GClosure
298  * @marshal_data: context-dependent data to pass to @meta_marshal
299  * @meta_marshal: a #GClosureMarshal function
300  *
301  * Sets the meta marshaller of @closure.  A meta marshaller wraps
302  * @closure->marshal and modifies the way it is called in some
303  * fashion. The most common use of this facility is for C callbacks.
304  * The same marshallers (generated by <link
305  * linkend="glib-genmarshal">glib-genmarshal</link>) are used
306  * everywhere, but the way that we get the callback function
307  * differs. In most cases we want to use @closure->callback, but in
308  * other cases we want to use some different technique to retrieve the
309  * callback function.
310  *
311  * For example, class closures for signals (see
312  * g_signal_type_cclosure_new()) retrieve the callback function from a
313  * fixed offset in the class structure.  The meta marshaller retrieves
314  * the right callback and passes it to the marshaller as the
315  * @marshal_data argument.
316  */
317 void
318 g_closure_set_meta_marshal (GClosure       *closure,
319                             gpointer        marshal_data,
320                             GClosureMarshal meta_marshal)
321 {
322   GClosureNotifyData *notifiers;
323
324   g_return_if_fail (closure != NULL);
325   g_return_if_fail (meta_marshal != NULL);
326   g_return_if_fail (closure->is_invalid == FALSE);
327   g_return_if_fail (closure->in_marshal == FALSE);
328   g_return_if_fail (closure->meta_marshal == 0);
329
330   notifiers = closure->notifiers;
331   closure->notifiers = g_renew (GClosureNotifyData, NULL, CLOSURE_N_NOTIFIERS (closure) + 1);
332   if (notifiers)
333     {
334       /* usually the meta marshal will be setup right after creation, so the
335        * g_memmove() should be rare-case scenario
336        */
337       g_memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
338       g_free (notifiers);
339     }
340   closure->notifiers[0].data = marshal_data;
341   closure->notifiers[0].notify = (GClosureNotify) meta_marshal;
342   SET (closure, meta_marshal, 1);
343 }
344
345 /**
346  * g_closure_add_marshal_guards: (skip)
347  * @closure: a #GClosure
348  * @pre_marshal_data: data to pass to @pre_marshal_notify
349  * @pre_marshal_notify: a function to call before the closure callback
350  * @post_marshal_data: data to pass to @post_marshal_notify
351  * @post_marshal_notify: a function to call after the closure callback
352  *
353  * Adds a pair of notifiers which get invoked before and after the
354  * closure callback, respectively. This is typically used to protect
355  * the extra arguments for the duration of the callback. See
356  * g_object_watch_closure() for an example of marshal guards.
357  */
358 void
359 g_closure_add_marshal_guards (GClosure      *closure,
360                               gpointer       pre_marshal_data,
361                               GClosureNotify pre_marshal_notify,
362                               gpointer       post_marshal_data,
363                               GClosureNotify post_marshal_notify)
364 {
365   guint i;
366
367   g_return_if_fail (closure != NULL);
368   g_return_if_fail (pre_marshal_notify != NULL);
369   g_return_if_fail (post_marshal_notify != NULL);
370   g_return_if_fail (closure->is_invalid == FALSE);
371   g_return_if_fail (closure->in_marshal == FALSE);
372   g_return_if_fail (closure->n_guards < CLOSURE_MAX_N_GUARDS);
373
374   closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2);
375   if (closure->n_inotifiers)
376     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
377                         closure->n_fnotifiers +
378                         closure->n_inotifiers + 1)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
379                                                                           closure->n_fnotifiers + 0)];
380   if (closure->n_inotifiers > 1)
381     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
382                         closure->n_fnotifiers +
383                         closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
384                                                                       closure->n_fnotifiers + 1)];
385   if (closure->n_fnotifiers)
386     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
387                         closure->n_fnotifiers + 1)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 0];
388   if (closure->n_fnotifiers > 1)
389     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
390                         closure->n_fnotifiers)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 1];
391   if (closure->n_guards)
392     closure->notifiers[(closure->meta_marshal +
393                         closure->n_guards +
394                         closure->n_guards + 1)] = closure->notifiers[closure->meta_marshal + closure->n_guards];
395   i = closure->n_guards;
396   closure->notifiers[closure->meta_marshal + i].data = pre_marshal_data;
397   closure->notifiers[closure->meta_marshal + i].notify = pre_marshal_notify;
398   closure->notifiers[closure->meta_marshal + i + 1].data = post_marshal_data;
399   closure->notifiers[closure->meta_marshal + i + 1].notify = post_marshal_notify;
400   INC (closure, n_guards);
401 }
402
403 /**
404  * g_closure_add_finalize_notifier: (skip)
405  * @closure: a #GClosure
406  * @notify_data: data to pass to @notify_func
407  * @notify_func: the callback function to register
408  *
409  * Registers a finalization notifier which will be called when the
410  * reference count of @closure goes down to 0. Multiple finalization
411  * notifiers on a single closure are invoked in unspecified order. If
412  * a single call to g_closure_unref() results in the closure being
413  * both invalidated and finalized, then the invalidate notifiers will
414  * be run before the finalize notifiers.
415  */
416 void
417 g_closure_add_finalize_notifier (GClosure      *closure,
418                                  gpointer       notify_data,
419                                  GClosureNotify notify_func)
420 {
421   guint i;
422
423   g_return_if_fail (closure != NULL);
424   g_return_if_fail (notify_func != NULL);
425   g_return_if_fail (closure->n_fnotifiers < CLOSURE_MAX_N_FNOTIFIERS);
426
427   closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
428   if (closure->n_inotifiers)
429     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
430                         closure->n_fnotifiers +
431                         closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
432                                                                       closure->n_fnotifiers + 0)];
433   i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers;
434   closure->notifiers[i].data = notify_data;
435   closure->notifiers[i].notify = notify_func;
436   INC (closure, n_fnotifiers);
437 }
438
439 /**
440  * g_closure_add_invalidate_notifier: (skip)
441  * @closure: a #GClosure
442  * @notify_data: data to pass to @notify_func
443  * @notify_func: the callback function to register
444  *
445  * Registers an invalidation notifier which will be called when the
446  * @closure is invalidated with g_closure_invalidate(). Invalidation
447  * notifiers are invoked before finalization notifiers, in an
448  * unspecified order.
449  */
450 void
451 g_closure_add_invalidate_notifier (GClosure      *closure,
452                                    gpointer       notify_data,
453                                    GClosureNotify notify_func)
454 {
455   guint i;
456
457   g_return_if_fail (closure != NULL);
458   g_return_if_fail (notify_func != NULL);
459   g_return_if_fail (closure->is_invalid == FALSE);
460   g_return_if_fail (closure->n_inotifiers < CLOSURE_MAX_N_INOTIFIERS);
461
462   closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
463   i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + closure->n_inotifiers;
464   closure->notifiers[i].data = notify_data;
465   closure->notifiers[i].notify = notify_func;
466   INC (closure, n_inotifiers);
467 }
468
469 static inline gboolean
470 closure_try_remove_inotify (GClosure       *closure,
471                             gpointer       notify_data,
472                             GClosureNotify notify_func)
473 {
474   GClosureNotifyData *ndata, *nlast;
475
476   nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - 1;
477   for (ndata = nlast + 1 - closure->n_inotifiers; ndata <= nlast; ndata++)
478     if (ndata->notify == notify_func && ndata->data == notify_data)
479       {
480         DEC (closure, n_inotifiers);
481         if (ndata < nlast)
482           *ndata = *nlast;
483
484         return TRUE;
485       }
486   return FALSE;
487 }
488
489 static inline gboolean
490 closure_try_remove_fnotify (GClosure       *closure,
491                             gpointer       notify_data,
492                             GClosureNotify notify_func)
493 {
494   GClosureNotifyData *ndata, *nlast;
495
496   nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1;
497   for (ndata = nlast + 1 - closure->n_fnotifiers; ndata <= nlast; ndata++)
498     if (ndata->notify == notify_func && ndata->data == notify_data)
499       {
500         DEC (closure, n_fnotifiers);
501         if (ndata < nlast)
502           *ndata = *nlast;
503         if (closure->n_inotifiers)
504           closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
505                               closure->n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
506                                                                             closure->n_fnotifiers +
507                                                                             closure->n_inotifiers)];
508         return TRUE;
509       }
510   return FALSE;
511 }
512
513 /**
514  * g_closure_ref:
515  * @closure: #GClosure to increment the reference count on
516  *
517  * Increments the reference count on a closure to force it staying
518  * alive while the caller holds a pointer to it.
519  *
520  * Returns: (transfer none): The @closure passed in, for convenience
521  */
522 GClosure*
523 g_closure_ref (GClosure *closure)
524 {
525   guint new_ref_count;
526   g_return_val_if_fail (closure != NULL, NULL);
527   g_return_val_if_fail (closure->ref_count > 0, NULL);
528   g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL);
529
530   INC_ASSIGN (closure, ref_count, &new_ref_count);
531   g_return_val_if_fail (new_ref_count > 1, NULL);
532
533   return closure;
534 }
535
536 /**
537  * g_closure_invalidate:
538  * @closure: GClosure to invalidate
539  *
540  * Sets a flag on the closure to indicate that its calling
541  * environment has become invalid, and thus causes any future
542  * invocations of g_closure_invoke() on this @closure to be
543  * ignored. Also, invalidation notifiers installed on the closure will
544  * be called at this point. Note that unless you are holding a
545  * reference to the closure yourself, the invalidation notifiers may
546  * unref the closure and cause it to be destroyed, so if you need to
547  * access the closure after calling g_closure_invalidate(), make sure
548  * that you've previously called g_closure_ref().
549  *
550  * Note that g_closure_invalidate() will also be called when the
551  * reference count of a closure drops to zero (unless it has already
552  * been invalidated before).
553  */
554 void
555 g_closure_invalidate (GClosure *closure)
556 {
557   g_return_if_fail (closure != NULL);
558
559   if (!closure->is_invalid)
560     {
561       gboolean was_invalid;
562       g_closure_ref (closure);           /* preserve floating flag */
563       SWAP (closure, is_invalid, TRUE, &was_invalid);
564       /* invalidate only once */
565       if (!was_invalid)
566         closure_invoke_notifiers (closure, INOTIFY);
567       g_closure_unref (closure);
568     }
569 }
570
571 /**
572  * g_closure_unref:
573  * @closure: #GClosure to decrement the reference count on
574  *
575  * Decrements the reference count of a closure after it was previously
576  * incremented by the same caller. If no other callers are using the
577  * closure, then the closure will be destroyed and freed.
578  */
579 void
580 g_closure_unref (GClosure *closure)
581 {
582   guint new_ref_count;
583
584   g_return_if_fail (closure != NULL);
585   g_return_if_fail (closure->ref_count > 0);
586
587   if (closure->ref_count == 1)  /* last unref, invalidate first */
588     g_closure_invalidate (closure);
589
590   DEC_ASSIGN (closure, ref_count, &new_ref_count);
591
592   if (new_ref_count == 0)
593     {
594       closure_invoke_notifiers (closure, FNOTIFY);
595       g_free (closure->notifiers);
596       g_free (closure);
597     }
598 }
599
600 /**
601  * g_closure_sink:
602  * @closure: #GClosure to decrement the initial reference count on, if it's
603  *           still being held
604  *
605  * Takes over the initial ownership of a closure.  Each closure is
606  * initially created in a <firstterm>floating</firstterm> state, which
607  * means that the initial reference count is not owned by any caller.
608  * g_closure_sink() checks to see if the object is still floating, and
609  * if so, unsets the floating state and decreases the reference
610  * count. If the closure is not floating, g_closure_sink() does
611  * nothing. The reason for the existance of the floating state is to
612  * prevent cumbersome code sequences like:
613  * |[
614  * closure = g_cclosure_new (cb_func, cb_data);
615  * g_source_set_closure (source, closure);
616  * g_closure_unref (closure); // XXX GObject doesn't really need this
617  * ]|
618  * Because g_source_set_closure() (and similar functions) take ownership of the
619  * initial reference count, if it is unowned, we instead can write:
620  * |[
621  * g_source_set_closure (source, g_cclosure_new (cb_func, cb_data));
622  * ]|
623  *
624  * Generally, this function is used together with g_closure_ref(). Ane example
625  * of storing a closure for later notification looks like:
626  * |[
627  * static GClosure *notify_closure = NULL;
628  * void
629  * foo_notify_set_closure (GClosure *closure)
630  * {
631  *   if (notify_closure)
632  *     g_closure_unref (notify_closure);
633  *   notify_closure = closure;
634  *   if (notify_closure)
635  *     {
636  *       g_closure_ref (notify_closure);
637  *       g_closure_sink (notify_closure);
638  *     }
639  * }
640  * ]|
641  *
642  * Because g_closure_sink() may decrement the reference count of a closure
643  * (if it hasn't been called on @closure yet) just like g_closure_unref(),
644  * g_closure_ref() should be called prior to this function.
645  */
646 void
647 g_closure_sink (GClosure *closure)
648 {
649   g_return_if_fail (closure != NULL);
650   g_return_if_fail (closure->ref_count > 0);
651
652   /* floating is basically a kludge to avoid creating closures
653    * with a ref_count of 0. so the intial ref_count a closure has
654    * is unowned. with invoking g_closure_sink() code may
655    * indicate that it takes over that intiial ref_count.
656    */
657   if (closure->floating)
658     {
659       gboolean was_floating;
660       SWAP (closure, floating, FALSE, &was_floating);
661       /* unref floating flag only once */
662       if (was_floating)
663         g_closure_unref (closure);
664     }
665 }
666
667 /**
668  * g_closure_remove_invalidate_notifier: (skip)
669  * @closure: a #GClosure
670  * @notify_data: data which was passed to g_closure_add_invalidate_notifier()
671  *               when registering @notify_func
672  * @notify_func: the callback function to remove
673  *
674  * Removes an invalidation notifier.
675  *
676  * Notice that notifiers are automatically removed after they are run.
677  */
678 void
679 g_closure_remove_invalidate_notifier (GClosure      *closure,
680                                       gpointer       notify_data,
681                                       GClosureNotify notify_func)
682 {
683   g_return_if_fail (closure != NULL);
684   g_return_if_fail (notify_func != NULL);
685
686   if (closure->is_invalid && closure->in_inotify && /* account removal of notify_func() while it's called */
687       ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
688       closure->data == notify_data)
689     closure->marshal = NULL;
690   else if (!closure_try_remove_inotify (closure, notify_data, notify_func))
691     g_warning (G_STRLOC ": unable to remove uninstalled invalidation notifier: %p (%p)",
692                notify_func, notify_data);
693 }
694
695 /**
696  * g_closure_remove_finalize_notifier: (skip)
697  * @closure: a #GClosure
698  * @notify_data: data which was passed to g_closure_add_finalize_notifier()
699  *  when registering @notify_func
700  * @notify_func: the callback function to remove
701  *
702  * Removes a finalization notifier.
703  *
704  * Notice that notifiers are automatically removed after they are run.
705  */
706 void
707 g_closure_remove_finalize_notifier (GClosure      *closure,
708                                     gpointer       notify_data,
709                                     GClosureNotify notify_func)
710 {
711   g_return_if_fail (closure != NULL);
712   g_return_if_fail (notify_func != NULL);
713
714   if (closure->is_invalid && !closure->in_inotify && /* account removal of notify_func() while it's called */
715       ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
716       closure->data == notify_data)
717     closure->marshal = NULL;
718   else if (!closure_try_remove_fnotify (closure, notify_data, notify_func))
719     g_warning (G_STRLOC ": unable to remove uninstalled finalization notifier: %p (%p)",
720                notify_func, notify_data);
721 }
722
723 /**
724  * g_closure_invoke:
725  * @closure: a #GClosure
726  * @return_value: a #GValue to store the return value. May be %NULL if the
727  *                callback of @closure doesn't return a value.
728  * @n_param_values: the length of the @param_values array
729  * @param_values: (array length=n_param_values): an array of
730  *                #GValue<!-- -->s holding the arguments on which to
731  *                invoke the callback of @closure
732  * @invocation_hint: a context-dependent invocation hint
733  *
734  * Invokes the closure, i.e. executes the callback represented by the @closure.
735  */
736 void
737 g_closure_invoke (GClosure       *closure,
738                   GValue /*out*/ *return_value,
739                   guint           n_param_values,
740                   const GValue   *param_values,
741                   gpointer        invocation_hint)
742 {
743   g_return_if_fail (closure != NULL);
744
745   g_closure_ref (closure);      /* preserve floating flag */
746   if (!closure->is_invalid)
747     {
748       GClosureMarshal marshal;
749       gpointer marshal_data;
750       gboolean in_marshal = closure->in_marshal;
751
752       g_return_if_fail (closure->marshal || closure->meta_marshal);
753
754       SET (closure, in_marshal, TRUE);
755       if (closure->meta_marshal)
756         {
757           marshal_data = closure->notifiers[0].data;
758           marshal = (GClosureMarshal) closure->notifiers[0].notify;
759         }
760       else
761         {
762           marshal_data = NULL;
763           marshal = closure->marshal;
764         }
765       if (!in_marshal)
766         closure_invoke_notifiers (closure, PRE_NOTIFY);
767       marshal (closure,
768                return_value,
769                n_param_values, param_values,
770                invocation_hint,
771                marshal_data);
772       if (!in_marshal)
773         closure_invoke_notifiers (closure, POST_NOTIFY);
774       SET (closure, in_marshal, in_marshal);
775     }
776   g_closure_unref (closure);
777 }
778
779 /**
780  * g_closure_set_marshal: (skip)
781  * @closure: a #GClosure
782  * @marshal: a #GClosureMarshal function
783  *
784  * Sets the marshaller of @closure. The <literal>marshal_data</literal>
785  * of @marshal provides a way for a meta marshaller to provide additional
786  * information to the marshaller. (See g_closure_set_meta_marshal().) For
787  * GObject's C predefined marshallers (the g_cclosure_marshal_*()
788  * functions), what it provides is a callback function to use instead of
789  * @closure->callback.
790  */
791 void
792 g_closure_set_marshal (GClosure       *closure,
793                        GClosureMarshal marshal)
794 {
795   g_return_if_fail (closure != NULL);
796   g_return_if_fail (marshal != NULL);
797
798   if (closure->marshal && closure->marshal != marshal)
799     g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)",
800                closure->marshal, marshal);
801   else
802     closure->marshal = marshal;
803 }
804
805 /**
806  * g_cclosure_new: (skip)
807  * @callback_func: the function to invoke
808  * @user_data: user data to pass to @callback_func
809  * @destroy_data: destroy notify to be called when @user_data is no longer used
810  *
811  * Creates a new closure which invokes @callback_func with @user_data as
812  * the last parameter.
813  *
814  * Returns: a new #GCClosure
815  */
816 GClosure*
817 g_cclosure_new (GCallback      callback_func,
818                 gpointer       user_data,
819                 GClosureNotify destroy_data)
820 {
821   GClosure *closure;
822   
823   g_return_val_if_fail (callback_func != NULL, NULL);
824   
825   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
826   if (destroy_data)
827     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
828   ((GCClosure*) closure)->callback = (gpointer) callback_func;
829   
830   return closure;
831 }
832
833 /**
834  * g_cclosure_new_swap: (skip)
835  * @callback_func: the function to invoke
836  * @user_data: user data to pass to @callback_func
837  * @destroy_data: destroy notify to be called when @user_data is no longer used
838  *
839  * Creates a new closure which invokes @callback_func with @user_data as
840  * the first parameter.
841  *
842  * Returns: (transfer full): a new #GCClosure
843  */
844 GClosure*
845 g_cclosure_new_swap (GCallback      callback_func,
846                      gpointer       user_data,
847                      GClosureNotify destroy_data)
848 {
849   GClosure *closure;
850   
851   g_return_val_if_fail (callback_func != NULL, NULL);
852   
853   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
854   if (destroy_data)
855     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
856   ((GCClosure*) closure)->callback = (gpointer) callback_func;
857   SET (closure, derivative_flag, TRUE);
858   
859   return closure;
860 }
861
862 static void
863 g_type_class_meta_marshal (GClosure       *closure,
864                            GValue /*out*/ *return_value,
865                            guint           n_param_values,
866                            const GValue   *param_values,
867                            gpointer        invocation_hint,
868                            gpointer        marshal_data)
869 {
870   GTypeClass *class;
871   gpointer callback;
872   /* GType itype = (GType) closure->data; */
873   guint offset = GPOINTER_TO_UINT (marshal_data);
874   
875   class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
876   callback = G_STRUCT_MEMBER (gpointer, class, offset);
877   if (callback)
878     closure->marshal (closure,
879                       return_value,
880                       n_param_values, param_values,
881                       invocation_hint,
882                       callback);
883 }
884
885 static void
886 g_type_iface_meta_marshal (GClosure       *closure,
887                            GValue /*out*/ *return_value,
888                            guint           n_param_values,
889                            const GValue   *param_values,
890                            gpointer        invocation_hint,
891                            gpointer        marshal_data)
892 {
893   GTypeClass *class;
894   gpointer callback;
895   GType itype = (GType) closure->data;
896   guint offset = GPOINTER_TO_UINT (marshal_data);
897   
898   class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
899   callback = G_STRUCT_MEMBER (gpointer, class, offset);
900   if (callback)
901     closure->marshal (closure,
902                       return_value,
903                       n_param_values, param_values,
904                       invocation_hint,
905                       callback);
906 }
907
908 /**
909  * g_signal_type_cclosure_new:
910  * @itype: the #GType identifier of an interface or classed type
911  * @struct_offset: the offset of the member function of @itype's class
912  *  structure which is to be invoked by the new closure
913  *
914  * Creates a new closure which invokes the function found at the offset
915  * @struct_offset in the class structure of the interface or classed type
916  * identified by @itype.
917  *
918  * Returns: a new #GCClosure
919  */
920 GClosure*
921 g_signal_type_cclosure_new (GType    itype,
922                             guint    struct_offset)
923 {
924   GClosure *closure;
925   
926   g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
927   g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL);
928   
929   closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype);
930   if (G_TYPE_IS_INTERFACE (itype))
931     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal);
932   else
933     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal);
934   
935   return closure;
936 }
937
938
939 /**
940  * g_cclosure_marshal_VOID__VOID:
941  * @closure: the #GClosure to which the marshaller belongs
942  * @return_value: ignored
943  * @n_param_values: 1
944  * @param_values: a #GValue array holding only the instance
945  * @invocation_hint: the invocation hint given as the last argument
946  *  to g_closure_invoke()
947  * @marshal_data: additional data specified when registering the marshaller
948  *
949  * A marshaller for a #GCClosure with a callback of type
950  * <literal>void (*callback) (gpointer instance, gpointer user_data)</literal>.
951  */
952
953 /**
954  * g_cclosure_marshal_VOID__BOOLEAN:
955  * @closure: the #GClosure to which the marshaller belongs
956  * @return_value: ignored
957  * @n_param_values: 2
958  * @param_values: a #GValue array holding the instance and the #gboolean parameter
959  * @invocation_hint: the invocation hint given as the last argument
960  *  to g_closure_invoke()
961  * @marshal_data: additional data specified when registering the marshaller
962  *
963  * A marshaller for a #GCClosure with a callback of type
964  * <literal>void (*callback) (gpointer instance, gboolean arg1, gpointer user_data)</literal>.
965  */
966
967 /**
968  * g_cclosure_marshal_VOID__CHAR:
969  * @closure: the #GClosure to which the marshaller belongs
970  * @return_value: ignored
971  * @n_param_values: 2
972  * @param_values: a #GValue array holding the instance and the #gchar parameter
973  * @invocation_hint: the invocation hint given as the last argument
974  *  to g_closure_invoke()
975  * @marshal_data: additional data specified when registering the marshaller
976  *
977  * A marshaller for a #GCClosure with a callback of type
978  * <literal>void (*callback) (gpointer instance, gchar arg1, gpointer user_data)</literal>.
979  */
980
981 /**
982  * g_cclosure_marshal_VOID__UCHAR:
983  * @closure: the #GClosure to which the marshaller belongs
984  * @return_value: ignored
985  * @n_param_values: 2
986  * @param_values: a #GValue array holding the instance and the #guchar parameter
987  * @invocation_hint: the invocation hint given as the last argument
988  *  to g_closure_invoke()
989  * @marshal_data: additional data specified when registering the marshaller
990  *
991  * A marshaller for a #GCClosure with a callback of type
992  * <literal>void (*callback) (gpointer instance, guchar arg1, gpointer user_data)</literal>.
993  */
994
995 /**
996  * g_cclosure_marshal_VOID__INT:
997  * @closure: the #GClosure to which the marshaller belongs
998  * @return_value: ignored
999  * @n_param_values: 2
1000  * @param_values: a #GValue array holding the instance and the #gint parameter
1001  * @invocation_hint: the invocation hint given as the last argument
1002  *  to g_closure_invoke()
1003  * @marshal_data: additional data specified when registering the marshaller
1004  *
1005  * A marshaller for a #GCClosure with a callback of type
1006  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal>.
1007  */
1008
1009 /**
1010  * g_cclosure_marshal_VOID__UINT:
1011  * @closure: the #GClosure to which the marshaller belongs
1012  * @return_value: ignored
1013  * @n_param_values: 2
1014  * @param_values: a #GValue array holding the instance and the #guint parameter
1015  * @invocation_hint: the invocation hint given as the last argument
1016  *  to g_closure_invoke()
1017  * @marshal_data: additional data specified when registering the marshaller
1018  *
1019  * A marshaller for a #GCClosure with a callback of type
1020  * <literal>void (*callback) (gpointer instance, guint arg1, gpointer user_data)</literal>.
1021  */
1022
1023 /**
1024  * g_cclosure_marshal_VOID__LONG:
1025  * @closure: the #GClosure to which the marshaller belongs
1026  * @return_value: ignored
1027  * @n_param_values: 2
1028  * @param_values: a #GValue array holding the instance and the #glong parameter
1029  * @invocation_hint: the invocation hint given as the last argument
1030  *  to g_closure_invoke()
1031  * @marshal_data: additional data specified when registering the marshaller
1032  *
1033  * A marshaller for a #GCClosure with a callback of type
1034  * <literal>void (*callback) (gpointer instance, glong arg1, gpointer user_data)</literal>.
1035  */
1036
1037 /**
1038  * g_cclosure_marshal_VOID__ULONG:
1039  * @closure: the #GClosure to which the marshaller belongs
1040  * @return_value: ignored
1041  * @n_param_values: 2
1042  * @param_values: a #GValue array holding the instance and the #gulong parameter
1043  * @invocation_hint: the invocation hint given as the last argument
1044  *  to g_closure_invoke()
1045  * @marshal_data: additional data specified when registering the marshaller
1046  *
1047  * A marshaller for a #GCClosure with a callback of type
1048  * <literal>void (*callback) (gpointer instance, gulong arg1, gpointer user_data)</literal>.
1049  */
1050
1051 /**
1052  * g_cclosure_marshal_VOID__ENUM:
1053  * @closure: the #GClosure to which the marshaller belongs
1054  * @return_value: ignored
1055  * @n_param_values: 2
1056  * @param_values: a #GValue array holding the instance and the enumeration parameter
1057  * @invocation_hint: the invocation hint given as the last argument
1058  *  to g_closure_invoke()
1059  * @marshal_data: additional data specified when registering the marshaller
1060  *
1061  * A marshaller for a #GCClosure with a callback of type
1062  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes an enumeration type..
1063  */
1064
1065 /**
1066  * g_cclosure_marshal_VOID__FLAGS:
1067  * @closure: the #GClosure to which the marshaller belongs
1068  * @return_value: ignored
1069  * @n_param_values: 2
1070  * @param_values: a #GValue array holding the instance and the flags parameter
1071  * @invocation_hint: the invocation hint given as the last argument
1072  *  to g_closure_invoke()
1073  * @marshal_data: additional data specified when registering the marshaller
1074  *
1075  * A marshaller for a #GCClosure with a callback of type
1076  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes a flags type.
1077  */
1078
1079 /**
1080  * g_cclosure_marshal_VOID__FLOAT:
1081  * @closure: the #GClosure to which the marshaller belongs
1082  * @return_value: ignored
1083  * @n_param_values: 2
1084  * @param_values: a #GValue array holding the instance and the #gfloat parameter
1085  * @invocation_hint: the invocation hint given as the last argument
1086  *  to g_closure_invoke()
1087  * @marshal_data: additional data specified when registering the marshaller
1088  *
1089  * A marshaller for a #GCClosure with a callback of type
1090  * <literal>void (*callback) (gpointer instance, gfloat arg1, gpointer user_data)</literal>.
1091  */
1092
1093 /**
1094  * g_cclosure_marshal_VOID__DOUBLE:
1095  * @closure: the #GClosure to which the marshaller belongs
1096  * @return_value: ignored
1097  * @n_param_values: 2
1098  * @param_values: a #GValue array holding the instance and the #gdouble parameter
1099  * @invocation_hint: the invocation hint given as the last argument
1100  *  to g_closure_invoke()
1101  * @marshal_data: additional data specified when registering the marshaller
1102  *
1103  * A marshaller for a #GCClosure with a callback of type
1104  * <literal>void (*callback) (gpointer instance, gdouble arg1, gpointer user_data)</literal>.
1105  */
1106
1107 /**
1108  * g_cclosure_marshal_VOID__STRING:
1109  * @closure: the #GClosure to which the marshaller belongs
1110  * @return_value: ignored
1111  * @n_param_values: 2
1112  * @param_values: a #GValue array holding the instance and the #gchar* parameter
1113  * @invocation_hint: the invocation hint given as the last argument
1114  *  to g_closure_invoke()
1115  * @marshal_data: additional data specified when registering the marshaller
1116  *
1117  * A marshaller for a #GCClosure with a callback of type
1118  * <literal>void (*callback) (gpointer instance, const gchar *arg1, gpointer user_data)</literal>.
1119  */
1120
1121 /**
1122  * g_cclosure_marshal_VOID__PARAM:
1123  * @closure: the #GClosure to which the marshaller belongs
1124  * @return_value: ignored
1125  * @n_param_values: 2
1126  * @param_values: a #GValue array holding the instance and the #GParamSpec* parameter
1127  * @invocation_hint: the invocation hint given as the last argument
1128  *  to g_closure_invoke()
1129  * @marshal_data: additional data specified when registering the marshaller
1130  *
1131  * A marshaller for a #GCClosure with a callback of type
1132  * <literal>void (*callback) (gpointer instance, GParamSpec *arg1, gpointer user_data)</literal>.
1133  */
1134
1135 /**
1136  * g_cclosure_marshal_VOID__BOXED:
1137  * @closure: the #GClosure to which the marshaller belongs
1138  * @return_value: ignored
1139  * @n_param_values: 2
1140  * @param_values: a #GValue array holding the instance and the #GBoxed* parameter
1141  * @invocation_hint: the invocation hint given as the last argument
1142  *  to g_closure_invoke()
1143  * @marshal_data: additional data specified when registering the marshaller
1144  *
1145  * A marshaller for a #GCClosure with a callback of type
1146  * <literal>void (*callback) (gpointer instance, GBoxed *arg1, gpointer user_data)</literal>.
1147  */
1148
1149 /**
1150  * g_cclosure_marshal_VOID__POINTER:
1151  * @closure: the #GClosure to which the marshaller belongs
1152  * @return_value: ignored
1153  * @n_param_values: 2
1154  * @param_values: a #GValue array holding the instance and the #gpointer parameter
1155  * @invocation_hint: the invocation hint given as the last argument
1156  *  to g_closure_invoke()
1157  * @marshal_data: additional data specified when registering the marshaller
1158  *
1159  * A marshaller for a #GCClosure with a callback of type
1160  * <literal>void (*callback) (gpointer instance, gpointer arg1, gpointer user_data)</literal>.
1161  */
1162
1163 /**
1164  * g_cclosure_marshal_VOID__OBJECT:
1165  * @closure: the #GClosure to which the marshaller belongs
1166  * @return_value: ignored
1167  * @n_param_values: 2
1168  * @param_values: a #GValue array holding the instance and the #GObject* parameter
1169  * @invocation_hint: the invocation hint given as the last argument
1170  *  to g_closure_invoke()
1171  * @marshal_data: additional data specified when registering the marshaller
1172  *
1173  * A marshaller for a #GCClosure with a callback of type
1174  * <literal>void (*callback) (gpointer instance, GObject *arg1, gpointer user_data)</literal>.
1175  */
1176
1177 /**
1178  * g_cclosure_marshal_VOID__VARIANT:
1179  * @closure: the #GClosure to which the marshaller belongs
1180  * @return_value: ignored
1181  * @n_param_values: 2
1182  * @param_values: a #GValue array holding the instance and the #GVariant* parameter
1183  * @invocation_hint: the invocation hint given as the last argument
1184  *  to g_closure_invoke()
1185  * @marshal_data: additional data specified when registering the marshaller
1186  *
1187  * A marshaller for a #GCClosure with a callback of type
1188  * <literal>void (*callback) (gpointer instance, GVariant *arg1, gpointer user_data)</literal>.
1189  *
1190  * Since: 2.26
1191  */
1192
1193 /**
1194  * g_cclosure_marshal_VOID__UINT_POINTER:
1195  * @closure: the #GClosure to which the marshaller belongs
1196  * @return_value: ignored
1197  * @n_param_values: 3
1198  * @param_values: a #GValue array holding instance, arg1 and arg2
1199  * @invocation_hint: the invocation hint given as the last argument
1200  *  to g_closure_invoke()
1201  * @marshal_data: additional data specified when registering the marshaller
1202  *
1203  * A marshaller for a #GCClosure with a callback of type
1204  * <literal>void (*callback) (gpointer instance, guint arg1, gpointer arg2, gpointer user_data)</literal>.
1205  */
1206
1207 /**
1208  * g_cclosure_marshal_BOOLEAN__FLAGS:
1209  * @closure: the #GClosure to which the marshaller belongs
1210  * @return_value: a #GValue which can store the returned #gboolean
1211  * @n_param_values: 2
1212  * @param_values: a #GValue array holding instance and arg1
1213  * @invocation_hint: the invocation hint given as the last argument
1214  *  to g_closure_invoke()
1215  * @marshal_data: additional data specified when registering the marshaller
1216  *
1217  * A marshaller for a #GCClosure with a callback of type
1218  * <literal>gboolean (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter
1219  * denotes a flags type.
1220  */
1221
1222 /**
1223  * g_cclosure_marshal_BOOL__FLAGS:
1224  *
1225  * Another name for g_cclosure_marshal_BOOLEAN__FLAGS().
1226  */
1227 /**
1228  * g_cclosure_marshal_STRING__OBJECT_POINTER:
1229  * @closure: the #GClosure to which the marshaller belongs
1230  * @return_value: a #GValue, which can store the returned string
1231  * @n_param_values: 3
1232  * @param_values: a #GValue array holding instance, arg1 and arg2
1233  * @invocation_hint: the invocation hint given as the last argument
1234  *  to g_closure_invoke()
1235  * @marshal_data: additional data specified when registering the marshaller
1236  *
1237  * A marshaller for a #GCClosure with a callback of type
1238  * <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>.
1239  */
1240 /**
1241  * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED:
1242  * @closure: the #GClosure to which the marshaller belongs
1243  * @return_value: a #GValue, which can store the returned string
1244  * @n_param_values: 3
1245  * @param_values: a #GValue array holding instance, arg1 and arg2
1246  * @invocation_hint: the invocation hint given as the last argument
1247  *  to g_closure_invoke()
1248  * @marshal_data: additional data specified when registering the marshaller
1249  *
1250  * A marshaller for a #GCClosure with a callback of type
1251  * <literal>gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)</literal>.
1252  *
1253  * Since: 2.26
1254  */