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