binding: Add a default marshaller for the closure API
[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: 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:
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:
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:
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:
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: 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:
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:
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: an array of #GValue<!-- -->s holding the arguments on
730  *                which to invoke the callback of @closure
731  * @invocation_hint: a context-dependent invocation hint
732  *
733  * Invokes the closure, i.e. executes the callback represented by the @closure.
734  */
735 void
736 g_closure_invoke (GClosure       *closure,
737                   GValue /*out*/ *return_value,
738                   guint           n_param_values,
739                   const GValue   *param_values,
740                   gpointer        invocation_hint)
741 {
742   g_return_if_fail (closure != NULL);
743
744   g_closure_ref (closure);      /* preserve floating flag */
745   if (!closure->is_invalid)
746     {
747       GClosureMarshal marshal;
748       gpointer marshal_data;
749       gboolean in_marshal = closure->in_marshal;
750
751       g_return_if_fail (closure->marshal || closure->meta_marshal);
752
753       SET (closure, in_marshal, TRUE);
754       if (closure->meta_marshal)
755         {
756           marshal_data = closure->notifiers[0].data;
757           marshal = (GClosureMarshal) closure->notifiers[0].notify;
758         }
759       else
760         {
761           marshal_data = NULL;
762           marshal = closure->marshal;
763         }
764       if (!in_marshal)
765         closure_invoke_notifiers (closure, PRE_NOTIFY);
766       marshal (closure,
767                return_value,
768                n_param_values, param_values,
769                invocation_hint,
770                marshal_data);
771       if (!in_marshal)
772         closure_invoke_notifiers (closure, POST_NOTIFY);
773       SET (closure, in_marshal, in_marshal);
774     }
775   g_closure_unref (closure);
776 }
777
778 /**
779  * g_closure_set_marshal:
780  * @closure: a #GClosure
781  * @marshal: a #GClosureMarshal function
782  *
783  * Sets the marshaller of @closure. The <literal>marshal_data</literal>
784  * of @marshal provides a way for a meta marshaller to provide additional
785  * information to the marshaller. (See g_closure_set_meta_marshal().) For
786  * GObject's C predefined marshallers (the g_cclosure_marshal_*()
787  * functions), what it provides is a callback function to use instead of
788  * @closure->callback.
789  */
790 void
791 g_closure_set_marshal (GClosure       *closure,
792                        GClosureMarshal marshal)
793 {
794   g_return_if_fail (closure != NULL);
795   g_return_if_fail (marshal != NULL);
796
797   if (closure->marshal && closure->marshal != marshal)
798     g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)",
799                closure->marshal, marshal);
800   else
801     closure->marshal = marshal;
802 }
803
804 /**
805  * g_cclosure_new:
806  * @callback_func: the function to invoke
807  * @user_data: user data to pass to @callback_func
808  * @destroy_data: destroy notify to be called when @user_data is no longer used
809  *
810  * Creates a new closure which invokes @callback_func with @user_data as
811  * the last parameter.
812  *
813  * Returns: a new #GCClosure
814  */
815 GClosure*
816 g_cclosure_new (GCallback      callback_func,
817                 gpointer       user_data,
818                 GClosureNotify destroy_data)
819 {
820   GClosure *closure;
821   
822   g_return_val_if_fail (callback_func != NULL, NULL);
823   
824   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
825   if (destroy_data)
826     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
827   ((GCClosure*) closure)->callback = (gpointer) callback_func;
828   
829   return closure;
830 }
831
832 /**
833  * g_cclosure_new_swap:
834  * @callback_func: the function to invoke
835  * @user_data: user data to pass to @callback_func
836  * @destroy_data: destroy notify to be called when @user_data is no longer used
837  *
838  * Creates a new closure which invokes @callback_func with @user_data as
839  * the first parameter.
840  *
841  * Returns: a new #GCClosure
842  */
843 GClosure*
844 g_cclosure_new_swap (GCallback      callback_func,
845                      gpointer       user_data,
846                      GClosureNotify destroy_data)
847 {
848   GClosure *closure;
849   
850   g_return_val_if_fail (callback_func != NULL, NULL);
851   
852   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
853   if (destroy_data)
854     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
855   ((GCClosure*) closure)->callback = (gpointer) callback_func;
856   SET (closure, derivative_flag, TRUE);
857   
858   return closure;
859 }
860
861 static void
862 g_type_class_meta_marshal (GClosure       *closure,
863                            GValue /*out*/ *return_value,
864                            guint           n_param_values,
865                            const GValue   *param_values,
866                            gpointer        invocation_hint,
867                            gpointer        marshal_data)
868 {
869   GTypeClass *class;
870   gpointer callback;
871   /* GType itype = (GType) closure->data; */
872   guint offset = GPOINTER_TO_UINT (marshal_data);
873   
874   class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
875   callback = G_STRUCT_MEMBER (gpointer, class, offset);
876   if (callback)
877     closure->marshal (closure,
878                       return_value,
879                       n_param_values, param_values,
880                       invocation_hint,
881                       callback);
882 }
883
884 static void
885 g_type_iface_meta_marshal (GClosure       *closure,
886                            GValue /*out*/ *return_value,
887                            guint           n_param_values,
888                            const GValue   *param_values,
889                            gpointer        invocation_hint,
890                            gpointer        marshal_data)
891 {
892   GTypeClass *class;
893   gpointer callback;
894   GType itype = (GType) closure->data;
895   guint offset = GPOINTER_TO_UINT (marshal_data);
896   
897   class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
898   callback = G_STRUCT_MEMBER (gpointer, class, offset);
899   if (callback)
900     closure->marshal (closure,
901                       return_value,
902                       n_param_values, param_values,
903                       invocation_hint,
904                       callback);
905 }
906
907 /**
908  * g_signal_type_cclosure_new:
909  * @itype: the #GType identifier of an interface or classed type
910  * @struct_offset: the offset of the member function of @itype's class
911  *  structure which is to be invoked by the new closure
912  *
913  * Creates a new closure which invokes the function found at the offset
914  * @struct_offset in the class structure of the interface or classed type
915  * identified by @itype.
916  *
917  * Returns: a new #GCClosure
918  */
919 GClosure*
920 g_signal_type_cclosure_new (GType    itype,
921                             guint    struct_offset)
922 {
923   GClosure *closure;
924   
925   g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
926   g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL);
927   
928   closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype);
929   if (G_TYPE_IS_INTERFACE (itype))
930     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal);
931   else
932     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal);
933   
934   return closure;
935 }
936
937
938 /**
939  * g_cclosure_marshal_VOID__VOID:
940  * @closure: the #GClosure to which the marshaller belongs
941  * @return_value: ignored
942  * @n_param_values: 1
943  * @param_values: a #GValue array holding only the instance
944  * @invocation_hint: the invocation hint given as the last argument
945  *  to g_closure_invoke()
946  * @marshal_data: additional data specified when registering the marshaller
947  *
948  * A marshaller for a #GCClosure with a callback of type
949  * <literal>void (*callback) (gpointer instance, gpointer user_data)</literal>.
950  */
951
952 /**
953  * g_cclosure_marshal_VOID__BOOLEAN:
954  * @closure: the #GClosure to which the marshaller belongs
955  * @return_value: ignored
956  * @n_param_values: 2
957  * @param_values: a #GValue array holding the instance and the #gboolean parameter
958  * @invocation_hint: the invocation hint given as the last argument
959  *  to g_closure_invoke()
960  * @marshal_data: additional data specified when registering the marshaller
961  *
962  * A marshaller for a #GCClosure with a callback of type
963  * <literal>void (*callback) (gpointer instance, gboolean arg1, gpointer user_data)</literal>.
964  */
965
966 /**
967  * g_cclosure_marshal_VOID__CHAR:
968  * @closure: the #GClosure to which the marshaller belongs
969  * @return_value: ignored
970  * @n_param_values: 2
971  * @param_values: a #GValue array holding the instance and the #gchar parameter
972  * @invocation_hint: the invocation hint given as the last argument
973  *  to g_closure_invoke()
974  * @marshal_data: additional data specified when registering the marshaller
975  *
976  * A marshaller for a #GCClosure with a callback of type
977  * <literal>void (*callback) (gpointer instance, gchar arg1, gpointer user_data)</literal>.
978  */
979
980 /**
981  * g_cclosure_marshal_VOID__UCHAR:
982  * @closure: the #GClosure to which the marshaller belongs
983  * @return_value: ignored
984  * @n_param_values: 2
985  * @param_values: a #GValue array holding the instance and the #guchar parameter
986  * @invocation_hint: the invocation hint given as the last argument
987  *  to g_closure_invoke()
988  * @marshal_data: additional data specified when registering the marshaller
989  *
990  * A marshaller for a #GCClosure with a callback of type
991  * <literal>void (*callback) (gpointer instance, guchar arg1, gpointer user_data)</literal>.
992  */
993
994 /**
995  * g_cclosure_marshal_VOID__INT:
996  * @closure: the #GClosure to which the marshaller belongs
997  * @return_value: ignored
998  * @n_param_values: 2
999  * @param_values: a #GValue array holding the instance and the #gint parameter
1000  * @invocation_hint: the invocation hint given as the last argument
1001  *  to g_closure_invoke()
1002  * @marshal_data: additional data specified when registering the marshaller
1003  *
1004  * A marshaller for a #GCClosure with a callback of type
1005  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal>.
1006  */
1007
1008 /**
1009  * g_cclosure_marshal_VOID__UINT:
1010  * @closure: the #GClosure to which the marshaller belongs
1011  * @return_value: ignored
1012  * @n_param_values: 2
1013  * @param_values: a #GValue array holding the instance and the #guint parameter
1014  * @invocation_hint: the invocation hint given as the last argument
1015  *  to g_closure_invoke()
1016  * @marshal_data: additional data specified when registering the marshaller
1017  *
1018  * A marshaller for a #GCClosure with a callback of type
1019  * <literal>void (*callback) (gpointer instance, guint arg1, gpointer user_data)</literal>.
1020  */
1021
1022 /**
1023  * g_cclosure_marshal_VOID__LONG:
1024  * @closure: the #GClosure to which the marshaller belongs
1025  * @return_value: ignored
1026  * @n_param_values: 2
1027  * @param_values: a #GValue array holding the instance and the #glong parameter
1028  * @invocation_hint: the invocation hint given as the last argument
1029  *  to g_closure_invoke()
1030  * @marshal_data: additional data specified when registering the marshaller
1031  *
1032  * A marshaller for a #GCClosure with a callback of type
1033  * <literal>void (*callback) (gpointer instance, glong arg1, gpointer user_data)</literal>.
1034  */
1035
1036 /**
1037  * g_cclosure_marshal_VOID__ULONG:
1038  * @closure: the #GClosure to which the marshaller belongs
1039  * @return_value: ignored
1040  * @n_param_values: 2
1041  * @param_values: a #GValue array holding the instance and the #gulong parameter
1042  * @invocation_hint: the invocation hint given as the last argument
1043  *  to g_closure_invoke()
1044  * @marshal_data: additional data specified when registering the marshaller
1045  *
1046  * A marshaller for a #GCClosure with a callback of type
1047  * <literal>void (*callback) (gpointer instance, gulong arg1, gpointer user_data)</literal>.
1048  */
1049
1050 /**
1051  * g_cclosure_marshal_VOID__ENUM:
1052  * @closure: the #GClosure to which the marshaller belongs
1053  * @return_value: ignored
1054  * @n_param_values: 2
1055  * @param_values: a #GValue array holding the instance and the enumeration parameter
1056  * @invocation_hint: the invocation hint given as the last argument
1057  *  to g_closure_invoke()
1058  * @marshal_data: additional data specified when registering the marshaller
1059  *
1060  * A marshaller for a #GCClosure with a callback of type
1061  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes an enumeration type..
1062  */
1063
1064 /**
1065  * g_cclosure_marshal_VOID__FLAGS:
1066  * @closure: the #GClosure to which the marshaller belongs
1067  * @return_value: ignored
1068  * @n_param_values: 2
1069  * @param_values: a #GValue array holding the instance and the flags parameter
1070  * @invocation_hint: the invocation hint given as the last argument
1071  *  to g_closure_invoke()
1072  * @marshal_data: additional data specified when registering the marshaller
1073  *
1074  * A marshaller for a #GCClosure with a callback of type
1075  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes a flags type.
1076  */
1077
1078 /**
1079  * g_cclosure_marshal_VOID__FLOAT:
1080  * @closure: the #GClosure to which the marshaller belongs
1081  * @return_value: ignored
1082  * @n_param_values: 2
1083  * @param_values: a #GValue array holding the instance and the #gfloat parameter
1084  * @invocation_hint: the invocation hint given as the last argument
1085  *  to g_closure_invoke()
1086  * @marshal_data: additional data specified when registering the marshaller
1087  *
1088  * A marshaller for a #GCClosure with a callback of type
1089  * <literal>void (*callback) (gpointer instance, gfloat arg1, gpointer user_data)</literal>.
1090  */
1091
1092 /**
1093  * g_cclosure_marshal_VOID__DOUBLE:
1094  * @closure: the #GClosure to which the marshaller belongs
1095  * @return_value: ignored
1096  * @n_param_values: 2
1097  * @param_values: a #GValue array holding the instance and the #gdouble parameter
1098  * @invocation_hint: the invocation hint given as the last argument
1099  *  to g_closure_invoke()
1100  * @marshal_data: additional data specified when registering the marshaller
1101  *
1102  * A marshaller for a #GCClosure with a callback of type
1103  * <literal>void (*callback) (gpointer instance, gdouble arg1, gpointer user_data)</literal>.
1104  */
1105
1106 /**
1107  * g_cclosure_marshal_VOID__STRING:
1108  * @closure: the #GClosure to which the marshaller belongs
1109  * @return_value: ignored
1110  * @n_param_values: 2
1111  * @param_values: a #GValue array holding the instance and the #gchar* parameter
1112  * @invocation_hint: the invocation hint given as the last argument
1113  *  to g_closure_invoke()
1114  * @marshal_data: additional data specified when registering the marshaller
1115  *
1116  * A marshaller for a #GCClosure with a callback of type
1117  * <literal>void (*callback) (gpointer instance, const gchar *arg1, gpointer user_data)</literal>.
1118  */
1119
1120 /**
1121  * g_cclosure_marshal_VOID__PARAM:
1122  * @closure: the #GClosure to which the marshaller belongs
1123  * @return_value: ignored
1124  * @n_param_values: 2
1125  * @param_values: a #GValue array holding the instance and the #GParamSpec* parameter
1126  * @invocation_hint: the invocation hint given as the last argument
1127  *  to g_closure_invoke()
1128  * @marshal_data: additional data specified when registering the marshaller
1129  *
1130  * A marshaller for a #GCClosure with a callback of type
1131  * <literal>void (*callback) (gpointer instance, GParamSpec *arg1, gpointer user_data)</literal>.
1132  */
1133
1134 /**
1135  * g_cclosure_marshal_VOID__BOXED:
1136  * @closure: the #GClosure to which the marshaller belongs
1137  * @return_value: ignored
1138  * @n_param_values: 2
1139  * @param_values: a #GValue array holding the instance and the #GBoxed* parameter
1140  * @invocation_hint: the invocation hint given as the last argument
1141  *  to g_closure_invoke()
1142  * @marshal_data: additional data specified when registering the marshaller
1143  *
1144  * A marshaller for a #GCClosure with a callback of type
1145  * <literal>void (*callback) (gpointer instance, GBoxed *arg1, gpointer user_data)</literal>.
1146  */
1147
1148 /**
1149  * g_cclosure_marshal_VOID__POINTER:
1150  * @closure: the #GClosure to which the marshaller belongs
1151  * @return_value: ignored
1152  * @n_param_values: 2
1153  * @param_values: a #GValue array holding the instance and the #gpointer parameter
1154  * @invocation_hint: the invocation hint given as the last argument
1155  *  to g_closure_invoke()
1156  * @marshal_data: additional data specified when registering the marshaller
1157  *
1158  * A marshaller for a #GCClosure with a callback of type
1159  * <literal>void (*callback) (gpointer instance, gpointer arg1, gpointer user_data)</literal>.
1160  */
1161
1162 /**
1163  * g_cclosure_marshal_VOID__OBJECT:
1164  * @closure: the #GClosure to which the marshaller belongs
1165  * @return_value: ignored
1166  * @n_param_values: 2
1167  * @param_values: a #GValue array holding the instance and the #GObject* parameter
1168  * @invocation_hint: the invocation hint given as the last argument
1169  *  to g_closure_invoke()
1170  * @marshal_data: additional data specified when registering the marshaller
1171  *
1172  * A marshaller for a #GCClosure with a callback of type
1173  * <literal>void (*callback) (gpointer instance, GObject *arg1, gpointer user_data)</literal>.
1174  */
1175
1176 /**
1177  * g_cclosure_marshal_VOID__VARIANT:
1178  * @closure: the #GClosure to which the marshaller belongs
1179  * @return_value: ignored
1180  * @n_param_values: 2
1181  * @param_values: a #GValue array holding the instance and the #GVariant* parameter
1182  * @invocation_hint: the invocation hint given as the last argument
1183  *  to g_closure_invoke()
1184  * @marshal_data: additional data specified when registering the marshaller
1185  *
1186  * A marshaller for a #GCClosure with a callback of type
1187  * <literal>void (*callback) (gpointer instance, GVariant *arg1, gpointer user_data)</literal>.
1188  *
1189  * Since: 2.26
1190  */
1191
1192 /**
1193  * g_cclosure_marshal_VOID__UINT_POINTER:
1194  * @closure: the #GClosure to which the marshaller belongs
1195  * @return_value: ignored
1196  * @n_param_values: 3
1197  * @param_values: a #GValue array holding instance, arg1 and arg2
1198  * @invocation_hint: the invocation hint given as the last argument
1199  *  to g_closure_invoke()
1200  * @marshal_data: additional data specified when registering the marshaller
1201  *
1202  * A marshaller for a #GCClosure with a callback of type
1203  * <literal>void (*callback) (gpointer instance, guint arg1, gpointer arg2, gpointer user_data)</literal>.
1204  */
1205
1206 /**
1207  * g_cclosure_marshal_BOOLEAN__FLAGS:
1208  * @closure: the #GClosure to which the marshaller belongs
1209  * @return_value: a #GValue which can store the returned #gboolean
1210  * @n_param_values: 2
1211  * @param_values: a #GValue array holding instance and arg1
1212  * @invocation_hint: the invocation hint given as the last argument
1213  *  to g_closure_invoke()
1214  * @marshal_data: additional data specified when registering the marshaller
1215  *
1216  * A marshaller for a #GCClosure with a callback of type
1217  * <literal>gboolean (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter
1218  * denotes a flags type.
1219  */
1220
1221 /**
1222  * g_cclosure_marshal_BOOL__FLAGS:
1223  *
1224  * Another name for g_cclosure_marshal_BOOLEAN__FLAGS().
1225  */
1226 /**
1227  * g_cclosure_marshal_STRING__OBJECT_POINTER:
1228  * @closure: the #GClosure to which the marshaller belongs
1229  * @return_value: a #GValue, which can store the returned string
1230  * @n_param_values: 3
1231  * @param_values: a #GValue array holding instance, arg1 and arg2
1232  * @invocation_hint: the invocation hint given as the last argument
1233  *  to g_closure_invoke()
1234  * @marshal_data: additional data specified when registering the marshaller
1235  *
1236  * A marshaller for a #GCClosure with a callback of type
1237  * <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>.
1238  */
1239 /**
1240  * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED:
1241  * @closure: the #GClosure to which the marshaller belongs
1242  * @return_value: a #GValue, which can store the returned string
1243  * @n_param_values: 3
1244  * @param_values: a #GValue array holding instance, arg1 and arg2
1245  * @invocation_hint: the invocation hint given as the last argument
1246  *  to g_closure_invoke()
1247  * @marshal_data: additional data specified when registering the marshaller
1248  *
1249  * A marshaller for a #GCClosure with a callback of type
1250  * <literal>gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)</literal>.
1251  *
1252  * Since: 2.26
1253  */