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