gclosure: add missing fundamental types to generic marshaler
[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 "genums.h"
34 #include "gvalue.h"
35 #include "gvaluetypes.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
93 #define CLOSURE_MAX_REF_COUNT           ((1 << 15) - 1)
94 #define CLOSURE_MAX_N_GUARDS            ((1 << 1) - 1)
95 #define CLOSURE_MAX_N_FNOTIFIERS        ((1 << 2) - 1)
96 #define CLOSURE_MAX_N_INOTIFIERS        ((1 << 8) - 1)
97 #define CLOSURE_N_MFUNCS(cl)            ((cl)->meta_marshal + \
98                                          ((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   GClosure *closure;
201
202   g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL);
203
204   closure = g_malloc0 (sizeof_closure);
205   SET (closure, ref_count, 1);
206   SET (closure, meta_marshal, 0);
207   SET (closure, n_guards, 0);
208   SET (closure, n_fnotifiers, 0);
209   SET (closure, n_inotifiers, 0);
210   SET (closure, in_inotify, FALSE);
211   SET (closure, floating, TRUE);
212   SET (closure, derivative_flag, 0);
213   SET (closure, in_marshal, FALSE);
214   SET (closure, is_invalid, FALSE);
215   closure->marshal = NULL;
216   closure->data = data;
217   closure->notifiers = NULL;
218   memset (G_STRUCT_MEMBER_P (closure, sizeof (*closure)), 0, sizeof_closure - sizeof (*closure));
219
220   return closure;
221 }
222
223 static inline void
224 closure_invoke_notifiers (GClosure *closure,
225                           guint     notify_type)
226 {
227   /* notifier layout:
228    *     meta_marshal  n_guards    n_guards     n_fnotif.  n_inotifiers
229    * ->[[meta_marshal][pre_guards][post_guards][fnotifiers][inotifiers]]
230    *
231    * CLOSURE_N_MFUNCS(cl)    = meta_marshal + n_guards + n_guards;
232    * CLOSURE_N_NOTIFIERS(cl) = CLOSURE_N_MFUNCS(cl) + n_fnotifiers + n_inotifiers
233    *
234    * constrains/catches:
235    * - closure->notifiers may be reloacted during callback
236    * - closure->n_fnotifiers and closure->n_inotifiers may change during callback
237    * - i.e. callbacks can be removed/added during invocation
238    * - must prepare for callback removal during FNOTIFY and INOTIFY (done via ->marshal= & ->data=)
239    * - must distinguish (->marshal= & ->data=) for INOTIFY vs. FNOTIFY (via ->in_inotify)
240    * + closure->n_guards is const during PRE_NOTIFY & POST_NOTIFY
241    * + closure->meta_marshal is const for all cases
242    * + none of the callbacks can cause recursion
243    * + closure->n_inotifiers is const 0 during FNOTIFY
244    */
245   switch (notify_type)
246     {
247       GClosureNotifyData *ndata;
248       guint i, offs;
249     case FNOTIFY:
250       while (closure->n_fnotifiers)
251         {
252           guint n;
253           DEC_ASSIGN (closure, n_fnotifiers, &n);
254
255           ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + n;
256           closure->marshal = (GClosureMarshal) ndata->notify;
257           closure->data = ndata->data;
258           ndata->notify (ndata->data, closure);
259         }
260       closure->marshal = NULL;
261       closure->data = NULL;
262       break;
263     case INOTIFY:
264       SET (closure, in_inotify, TRUE);
265       while (closure->n_inotifiers)
266         {
267           guint n;
268           DEC_ASSIGN (closure, n_inotifiers, &n);
269
270           ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n;
271           closure->marshal = (GClosureMarshal) ndata->notify;
272           closure->data = ndata->data;
273           ndata->notify (ndata->data, closure);
274         }
275       closure->marshal = NULL;
276       closure->data = NULL;
277       SET (closure, in_inotify, FALSE);
278       break;
279     case PRE_NOTIFY:
280       i = closure->n_guards;
281       offs = closure->meta_marshal;
282       while (i--)
283         {
284           ndata = closure->notifiers + offs + i;
285           ndata->notify (ndata->data, closure);
286         }
287       break;
288     case POST_NOTIFY:
289       i = closure->n_guards;
290       offs = closure->meta_marshal + i;
291       while (i--)
292         {
293           ndata = closure->notifiers + offs + i;
294           ndata->notify (ndata->data, closure);
295         }
296       break;
297     }
298 }
299
300 /**
301  * g_closure_set_meta_marshal: (skip)
302  * @closure: a #GClosure
303  * @marshal_data: context-dependent data to pass to @meta_marshal
304  * @meta_marshal: a #GClosureMarshal function
305  *
306  * Sets the meta marshaller of @closure.  A meta marshaller wraps
307  * @closure->marshal and modifies the way it is called in some
308  * fashion. The most common use of this facility is for C callbacks.
309  * The same marshallers (generated by <link
310  * linkend="glib-genmarshal">glib-genmarshal</link>) are used
311  * everywhere, but the way that we get the callback function
312  * differs. In most cases we want to use @closure->callback, but in
313  * other cases we want to use some different technique to retrieve the
314  * callback function.
315  *
316  * For example, class closures for signals (see
317  * g_signal_type_cclosure_new()) retrieve the callback function from a
318  * fixed offset in the class structure.  The meta marshaller retrieves
319  * the right callback and passes it to the marshaller as the
320  * @marshal_data argument.
321  */
322 void
323 g_closure_set_meta_marshal (GClosure       *closure,
324                             gpointer        marshal_data,
325                             GClosureMarshal meta_marshal)
326 {
327   GClosureNotifyData *notifiers;
328
329   g_return_if_fail (closure != NULL);
330   g_return_if_fail (meta_marshal != NULL);
331   g_return_if_fail (closure->is_invalid == FALSE);
332   g_return_if_fail (closure->in_marshal == FALSE);
333   g_return_if_fail (closure->meta_marshal == 0);
334
335   notifiers = closure->notifiers;
336   closure->notifiers = g_renew (GClosureNotifyData, NULL, CLOSURE_N_NOTIFIERS (closure) + 1);
337   if (notifiers)
338     {
339       /* usually the meta marshal will be setup right after creation, so the
340        * g_memmove() should be rare-case scenario
341        */
342       g_memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
343       g_free (notifiers);
344     }
345   closure->notifiers[0].data = marshal_data;
346   closure->notifiers[0].notify = (GClosureNotify) meta_marshal;
347   SET (closure, meta_marshal, 1);
348 }
349
350 /**
351  * g_closure_add_marshal_guards: (skip)
352  * @closure: a #GClosure
353  * @pre_marshal_data: data to pass to @pre_marshal_notify
354  * @pre_marshal_notify: a function to call before the closure callback
355  * @post_marshal_data: data to pass to @post_marshal_notify
356  * @post_marshal_notify: a function to call after the closure callback
357  *
358  * Adds a pair of notifiers which get invoked before and after the
359  * closure callback, respectively. This is typically used to protect
360  * the extra arguments for the duration of the callback. See
361  * g_object_watch_closure() for an example of marshal guards.
362  */
363 void
364 g_closure_add_marshal_guards (GClosure      *closure,
365                               gpointer       pre_marshal_data,
366                               GClosureNotify pre_marshal_notify,
367                               gpointer       post_marshal_data,
368                               GClosureNotify post_marshal_notify)
369 {
370   guint i;
371
372   g_return_if_fail (closure != NULL);
373   g_return_if_fail (pre_marshal_notify != NULL);
374   g_return_if_fail (post_marshal_notify != NULL);
375   g_return_if_fail (closure->is_invalid == FALSE);
376   g_return_if_fail (closure->in_marshal == FALSE);
377   g_return_if_fail (closure->n_guards < CLOSURE_MAX_N_GUARDS);
378
379   closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2);
380   if (closure->n_inotifiers)
381     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
382                         closure->n_fnotifiers +
383                         closure->n_inotifiers + 1)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
384                                                                           closure->n_fnotifiers + 0)];
385   if (closure->n_inotifiers > 1)
386     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
387                         closure->n_fnotifiers +
388                         closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
389                                                                       closure->n_fnotifiers + 1)];
390   if (closure->n_fnotifiers)
391     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
392                         closure->n_fnotifiers + 1)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 0];
393   if (closure->n_fnotifiers > 1)
394     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
395                         closure->n_fnotifiers)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 1];
396   if (closure->n_guards)
397     closure->notifiers[(closure->meta_marshal +
398                         closure->n_guards +
399                         closure->n_guards + 1)] = closure->notifiers[closure->meta_marshal + closure->n_guards];
400   i = closure->n_guards;
401   closure->notifiers[closure->meta_marshal + i].data = pre_marshal_data;
402   closure->notifiers[closure->meta_marshal + i].notify = pre_marshal_notify;
403   closure->notifiers[closure->meta_marshal + i + 1].data = post_marshal_data;
404   closure->notifiers[closure->meta_marshal + 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 (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 existance 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 intial 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: a #GValue to store the return value. May be %NULL if the
732  *                callback of @closure doesn't return a value.
733  * @n_param_values: the length of the @param_values array
734  * @param_values: (array length=n_param_values): an array of
735  *                #GValue<!-- -->s holding the arguments on which to
736  *                invoke the callback of @closure
737  * @invocation_hint: a context-dependent invocation hint
738  *
739  * Invokes the closure, i.e. executes the callback represented by the @closure.
740  */
741 void
742 g_closure_invoke (GClosure       *closure,
743                   GValue /*out*/ *return_value,
744                   guint           n_param_values,
745                   const GValue   *param_values,
746                   gpointer        invocation_hint)
747 {
748   g_return_if_fail (closure != NULL);
749
750   g_closure_ref (closure);      /* preserve floating flag */
751   if (!closure->is_invalid)
752     {
753       GClosureMarshal marshal;
754       gpointer marshal_data;
755       gboolean in_marshal = closure->in_marshal;
756
757       g_return_if_fail (closure->marshal || closure->meta_marshal);
758
759       SET (closure, in_marshal, TRUE);
760       if (closure->meta_marshal)
761         {
762           marshal_data = closure->notifiers[0].data;
763           marshal = (GClosureMarshal) closure->notifiers[0].notify;
764         }
765       else
766         {
767           marshal_data = NULL;
768           marshal = closure->marshal;
769         }
770       if (!in_marshal)
771         closure_invoke_notifiers (closure, PRE_NOTIFY);
772       marshal (closure,
773                return_value,
774                n_param_values, param_values,
775                invocation_hint,
776                marshal_data);
777       if (!in_marshal)
778         closure_invoke_notifiers (closure, POST_NOTIFY);
779       SET (closure, in_marshal, in_marshal);
780     }
781   g_closure_unref (closure);
782 }
783
784 /**
785  * g_closure_set_marshal: (skip)
786  * @closure: a #GClosure
787  * @marshal: a #GClosureMarshal function
788  *
789  * Sets the marshaller of @closure. The <literal>marshal_data</literal>
790  * of @marshal provides a way for a meta marshaller to provide additional
791  * information to the marshaller. (See g_closure_set_meta_marshal().) For
792  * GObject's C predefined marshallers (the g_cclosure_marshal_*()
793  * functions), what it provides is a callback function to use instead of
794  * @closure->callback.
795  */
796 void
797 g_closure_set_marshal (GClosure       *closure,
798                        GClosureMarshal marshal)
799 {
800   g_return_if_fail (closure != NULL);
801   g_return_if_fail (marshal != NULL);
802
803   if (closure->marshal && closure->marshal != marshal)
804     g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)",
805                closure->marshal, marshal);
806   else
807     closure->marshal = marshal;
808 }
809
810 /**
811  * g_cclosure_new: (skip)
812  * @callback_func: the function to invoke
813  * @user_data: user data to pass to @callback_func
814  * @destroy_data: destroy notify to be called when @user_data is no longer used
815  *
816  * Creates a new closure which invokes @callback_func with @user_data as
817  * the last parameter.
818  *
819  * Returns: a new #GCClosure
820  */
821 GClosure*
822 g_cclosure_new (GCallback      callback_func,
823                 gpointer       user_data,
824                 GClosureNotify destroy_data)
825 {
826   GClosure *closure;
827   
828   g_return_val_if_fail (callback_func != NULL, NULL);
829   
830   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
831   if (destroy_data)
832     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
833   ((GCClosure*) closure)->callback = (gpointer) callback_func;
834   
835   return closure;
836 }
837
838 /**
839  * g_cclosure_new_swap: (skip)
840  * @callback_func: the function to invoke
841  * @user_data: user data to pass to @callback_func
842  * @destroy_data: destroy notify to be called when @user_data is no longer used
843  *
844  * Creates a new closure which invokes @callback_func with @user_data as
845  * the first parameter.
846  *
847  * Returns: (transfer full): a new #GCClosure
848  */
849 GClosure*
850 g_cclosure_new_swap (GCallback      callback_func,
851                      gpointer       user_data,
852                      GClosureNotify destroy_data)
853 {
854   GClosure *closure;
855   
856   g_return_val_if_fail (callback_func != NULL, NULL);
857   
858   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
859   if (destroy_data)
860     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
861   ((GCClosure*) closure)->callback = (gpointer) callback_func;
862   SET (closure, derivative_flag, TRUE);
863   
864   return closure;
865 }
866
867 static void
868 g_type_class_meta_marshal (GClosure       *closure,
869                            GValue /*out*/ *return_value,
870                            guint           n_param_values,
871                            const GValue   *param_values,
872                            gpointer        invocation_hint,
873                            gpointer        marshal_data)
874 {
875   GTypeClass *class;
876   gpointer callback;
877   /* GType itype = (GType) closure->data; */
878   guint offset = GPOINTER_TO_UINT (marshal_data);
879   
880   class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
881   callback = G_STRUCT_MEMBER (gpointer, class, offset);
882   if (callback)
883     closure->marshal (closure,
884                       return_value,
885                       n_param_values, param_values,
886                       invocation_hint,
887                       callback);
888 }
889
890 static void
891 g_type_iface_meta_marshal (GClosure       *closure,
892                            GValue /*out*/ *return_value,
893                            guint           n_param_values,
894                            const GValue   *param_values,
895                            gpointer        invocation_hint,
896                            gpointer        marshal_data)
897 {
898   GTypeClass *class;
899   gpointer callback;
900   GType itype = (GType) closure->data;
901   guint offset = GPOINTER_TO_UINT (marshal_data);
902   
903   class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
904   callback = G_STRUCT_MEMBER (gpointer, class, offset);
905   if (callback)
906     closure->marshal (closure,
907                       return_value,
908                       n_param_values, param_values,
909                       invocation_hint,
910                       callback);
911 }
912
913 /**
914  * g_signal_type_cclosure_new:
915  * @itype: the #GType identifier of an interface or classed type
916  * @struct_offset: the offset of the member function of @itype's class
917  *  structure which is to be invoked by the new closure
918  *
919  * Creates a new closure which invokes the function found at the offset
920  * @struct_offset in the class structure of the interface or classed type
921  * identified by @itype.
922  *
923  * Returns: a new #GCClosure
924  */
925 GClosure*
926 g_signal_type_cclosure_new (GType    itype,
927                             guint    struct_offset)
928 {
929   GClosure *closure;
930   
931   g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
932   g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL);
933   
934   closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype);
935   if (G_TYPE_IS_INTERFACE (itype))
936     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal);
937   else
938     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal);
939   
940   return closure;
941 }
942
943 #include <ffi.h>
944 static ffi_type *
945 value_to_ffi_type (const GValue *gvalue, gpointer *value)
946 {
947   ffi_type *rettype = NULL;
948   GType type = g_type_fundamental (G_VALUE_TYPE (gvalue));
949   g_assert (type != G_TYPE_INVALID);
950
951   switch (type)
952     {
953     case G_TYPE_BOOLEAN:
954     case G_TYPE_CHAR:
955     case G_TYPE_INT:
956       rettype = &ffi_type_sint;
957       *value = (gpointer)&(gvalue->data[0].v_int);
958       break;
959     case G_TYPE_UCHAR:
960     case G_TYPE_UINT:
961     case G_TYPE_FLAGS:
962       rettype = &ffi_type_uint;
963       *value = (gpointer)&(gvalue->data[0].v_uint);
964       break;
965     case G_TYPE_STRING:
966     case G_TYPE_OBJECT:
967     case G_TYPE_BOXED:
968     case G_TYPE_POINTER:
969     case G_TYPE_INTERFACE:
970     case G_TYPE_VARIANT:
971       rettype = &ffi_type_pointer;
972       *value = (gpointer)&(gvalue->data[0].v_pointer);
973       break;
974     case G_TYPE_FLOAT:
975       rettype = &ffi_type_float;
976       *value = (gpointer)&(gvalue->data[0].v_float);
977       break;
978     case G_TYPE_DOUBLE:
979       rettype = &ffi_type_double;
980       *value = (gpointer)&(gvalue->data[0].v_double);
981       break;
982     case G_TYPE_LONG:
983       rettype = &ffi_type_slong;
984       *value = (gpointer)&(gvalue->data[0].v_long);
985       break;
986     case G_TYPE_ULONG:
987       rettype = &ffi_type_ulong;
988       *value = (gpointer)&(gvalue->data[0].v_ulong);
989       break;
990     case G_TYPE_INT64:
991       rettype = &ffi_type_sint64;
992       *value = (gpointer)&(gvalue->data[0].v_int64);
993       break;
994     case G_TYPE_UINT64:
995       rettype = &ffi_type_uint64;
996       *value = (gpointer)&(gvalue->data[0].v_uint64);
997       break;
998     default:
999       rettype = &ffi_type_pointer;
1000       *value = NULL;
1001       g_warning ("value_to_ffi_type: Unsupported fundamental type: %s", g_type_name (type));
1002       break;
1003     }
1004   return rettype;
1005 }
1006
1007 static void
1008 value_from_ffi_type (GValue *gvalue, gpointer *value)
1009 {
1010   switch (g_type_fundamental (G_VALUE_TYPE (gvalue)))
1011     {
1012     case G_TYPE_INT:
1013       g_value_set_int (gvalue, *(gint*)value);
1014       break;
1015     case G_TYPE_FLOAT:
1016       g_value_set_float (gvalue, *(gfloat*)value);
1017       break;
1018     case G_TYPE_DOUBLE:
1019       g_value_set_double (gvalue, *(gdouble*)value);
1020       break;
1021     case G_TYPE_BOOLEAN:
1022       g_value_set_boolean (gvalue, *(gboolean*)value);
1023       break;
1024     case G_TYPE_STRING:
1025       g_value_set_string (gvalue, *(gchar**)value);
1026       break;
1027     case G_TYPE_CHAR:
1028       g_value_set_char (gvalue, *(gchar*)value);
1029       break;
1030     case G_TYPE_UCHAR:
1031       g_value_set_uchar (gvalue, *(guchar*)value);
1032       break;
1033     case G_TYPE_UINT:
1034       g_value_set_uint (gvalue, *(guint*)value);
1035       break;
1036     case G_TYPE_POINTER:
1037       g_value_set_pointer (gvalue, *(gpointer*)value);
1038       break;
1039     case G_TYPE_LONG:
1040       g_value_set_long (gvalue, *(glong*)value);
1041       break;
1042     case G_TYPE_ULONG:
1043       g_value_set_ulong (gvalue, *(gulong*)value);
1044       break;
1045     case G_TYPE_INT64:
1046       g_value_set_int64 (gvalue, *(gint64*)value);
1047       break;
1048     case G_TYPE_UINT64:
1049       g_value_set_uint64 (gvalue, *(guint64*)value);
1050       break;
1051     case G_TYPE_BOXED:
1052       g_value_set_boxed (gvalue, *(gpointer*)value);
1053       break;
1054     case G_TYPE_FLAGS:
1055       g_value_set_flags (gvalue, *(guint*)value);
1056       break;
1057     case G_TYPE_OBJECT:
1058       g_value_set_object (gvalue, *(gpointer*)value);
1059       break;
1060     default:
1061       g_warning ("value_from_ffi_type: Unsupported fundamental type: %s",
1062                 g_type_name (g_type_fundamental (G_VALUE_TYPE (gvalue))));
1063     }
1064 }
1065
1066 /**
1067  * g_cclosure_marshal_generic:
1068  * @closure: A #GClosure.
1069  * @return_gvalue: A #GValue to store the return value. May be %NULL
1070  *   if the callback of closure doesn't return a value.
1071  * @n_param_values: The length of the @param_values array.
1072  * @param_values: An array of #GValue<!-- -->s holding the arguments
1073  *   on which to invoke the callback of closure.
1074  * @invocation_hint: The invocation hint given as the last argument to
1075  *   g_closure_invoke().
1076  * @marshal_data: Additional data specified when registering the
1077  *   marshaller, see g_closure_set_marshal() and
1078  *   g_closure_set_meta_marshal()
1079  *
1080  * A generic marshaller function implemented via <ulink
1081  * url="http://sourceware.org/libffi/">libffi</ulink>.
1082  *
1083  * Since: 2.30
1084  */
1085 void
1086 g_cclosure_marshal_generic (GClosure     *closure,
1087                             GValue       *return_gvalue,
1088                             guint         n_param_values,
1089                             const GValue *param_values,
1090                             gpointer      invocation_hint,
1091                             gpointer      marshal_data)
1092 {
1093   ffi_type *rtype;
1094   void *rvalue;
1095   int n_args;
1096   ffi_type **atypes;
1097   void **args;
1098   int i;
1099   ffi_cif cif;
1100   GCClosure *cc = (GCClosure*) closure;
1101
1102   if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1103     {
1104       rtype = value_to_ffi_type (return_gvalue, &rvalue);
1105     }
1106   else
1107     {
1108       rtype = &ffi_type_void;
1109     }
1110
1111   rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg)));
1112
1113   n_args = n_param_values + 1;
1114   atypes = g_alloca (sizeof (ffi_type *) * n_args);
1115   args =  g_alloca (sizeof (gpointer) * n_args);
1116
1117   if (G_CCLOSURE_SWAP_DATA (closure))
1118     {
1119       atypes[n_args-1] = value_to_ffi_type (param_values + 0,
1120                                             &args[n_args-1]);
1121       atypes[0] = &ffi_type_pointer;
1122       args[0] = &closure->data;
1123     }
1124   else
1125     {
1126       atypes[0] = value_to_ffi_type (param_values + 0, &args[0]);
1127       atypes[n_args-1] = &ffi_type_pointer;
1128       args[n_args-1] = &closure->data;
1129     }
1130
1131   for (i = 1; i < n_args - 1; i++)
1132     atypes[i] = value_to_ffi_type (param_values + i, &args[i]);
1133
1134   if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, n_args, rtype, atypes) != FFI_OK)
1135     return;
1136
1137   ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args);
1138
1139   if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1140     value_from_ffi_type (return_gvalue, rvalue);
1141 }
1142
1143 /**
1144  * g_cclosure_marshal_VOID__VOID:
1145  * @closure: the #GClosure to which the marshaller belongs
1146  * @return_value: ignored
1147  * @n_param_values: 1
1148  * @param_values: a #GValue array holding only the instance
1149  * @invocation_hint: the invocation hint given as the last argument
1150  *  to g_closure_invoke()
1151  * @marshal_data: additional data specified when registering the marshaller
1152  *
1153  * A marshaller for a #GCClosure with a callback of type
1154  * <literal>void (*callback) (gpointer instance, gpointer user_data)</literal>.
1155  */
1156
1157 /**
1158  * g_cclosure_marshal_VOID__BOOLEAN:
1159  * @closure: the #GClosure to which the marshaller belongs
1160  * @return_value: ignored
1161  * @n_param_values: 2
1162  * @param_values: a #GValue array holding the instance and the #gboolean parameter
1163  * @invocation_hint: the invocation hint given as the last argument
1164  *  to g_closure_invoke()
1165  * @marshal_data: additional data specified when registering the marshaller
1166  *
1167  * A marshaller for a #GCClosure with a callback of type
1168  * <literal>void (*callback) (gpointer instance, gboolean arg1, gpointer user_data)</literal>.
1169  */
1170
1171 /**
1172  * g_cclosure_marshal_VOID__CHAR:
1173  * @closure: the #GClosure to which the marshaller belongs
1174  * @return_value: ignored
1175  * @n_param_values: 2
1176  * @param_values: a #GValue array holding the instance and the #gchar parameter
1177  * @invocation_hint: the invocation hint given as the last argument
1178  *  to g_closure_invoke()
1179  * @marshal_data: additional data specified when registering the marshaller
1180  *
1181  * A marshaller for a #GCClosure with a callback of type
1182  * <literal>void (*callback) (gpointer instance, gchar arg1, gpointer user_data)</literal>.
1183  */
1184
1185 /**
1186  * g_cclosure_marshal_VOID__UCHAR:
1187  * @closure: the #GClosure to which the marshaller belongs
1188  * @return_value: ignored
1189  * @n_param_values: 2
1190  * @param_values: a #GValue array holding the instance and the #guchar parameter
1191  * @invocation_hint: the invocation hint given as the last argument
1192  *  to g_closure_invoke()
1193  * @marshal_data: additional data specified when registering the marshaller
1194  *
1195  * A marshaller for a #GCClosure with a callback of type
1196  * <literal>void (*callback) (gpointer instance, guchar arg1, gpointer user_data)</literal>.
1197  */
1198
1199 /**
1200  * g_cclosure_marshal_VOID__INT:
1201  * @closure: the #GClosure to which the marshaller belongs
1202  * @return_value: ignored
1203  * @n_param_values: 2
1204  * @param_values: a #GValue array holding the instance and the #gint parameter
1205  * @invocation_hint: the invocation hint given as the last argument
1206  *  to g_closure_invoke()
1207  * @marshal_data: additional data specified when registering the marshaller
1208  *
1209  * A marshaller for a #GCClosure with a callback of type
1210  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal>.
1211  */
1212
1213 /**
1214  * g_cclosure_marshal_VOID__UINT:
1215  * @closure: the #GClosure to which the marshaller belongs
1216  * @return_value: ignored
1217  * @n_param_values: 2
1218  * @param_values: a #GValue array holding the instance and the #guint parameter
1219  * @invocation_hint: the invocation hint given as the last argument
1220  *  to g_closure_invoke()
1221  * @marshal_data: additional data specified when registering the marshaller
1222  *
1223  * A marshaller for a #GCClosure with a callback of type
1224  * <literal>void (*callback) (gpointer instance, guint arg1, gpointer user_data)</literal>.
1225  */
1226
1227 /**
1228  * g_cclosure_marshal_VOID__LONG:
1229  * @closure: the #GClosure to which the marshaller belongs
1230  * @return_value: ignored
1231  * @n_param_values: 2
1232  * @param_values: a #GValue array holding the instance and the #glong parameter
1233  * @invocation_hint: the invocation hint given as the last argument
1234  *  to g_closure_invoke()
1235  * @marshal_data: additional data specified when registering the marshaller
1236  *
1237  * A marshaller for a #GCClosure with a callback of type
1238  * <literal>void (*callback) (gpointer instance, glong arg1, gpointer user_data)</literal>.
1239  */
1240
1241 /**
1242  * g_cclosure_marshal_VOID__ULONG:
1243  * @closure: the #GClosure to which the marshaller belongs
1244  * @return_value: ignored
1245  * @n_param_values: 2
1246  * @param_values: a #GValue array holding the instance and the #gulong parameter
1247  * @invocation_hint: the invocation hint given as the last argument
1248  *  to g_closure_invoke()
1249  * @marshal_data: additional data specified when registering the marshaller
1250  *
1251  * A marshaller for a #GCClosure with a callback of type
1252  * <literal>void (*callback) (gpointer instance, gulong arg1, gpointer user_data)</literal>.
1253  */
1254
1255 /**
1256  * g_cclosure_marshal_VOID__ENUM:
1257  * @closure: the #GClosure to which the marshaller belongs
1258  * @return_value: ignored
1259  * @n_param_values: 2
1260  * @param_values: a #GValue array holding the instance and the enumeration parameter
1261  * @invocation_hint: the invocation hint given as the last argument
1262  *  to g_closure_invoke()
1263  * @marshal_data: additional data specified when registering the marshaller
1264  *
1265  * A marshaller for a #GCClosure with a callback of type
1266  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes an enumeration type..
1267  */
1268
1269 /**
1270  * g_cclosure_marshal_VOID__FLAGS:
1271  * @closure: the #GClosure to which the marshaller belongs
1272  * @return_value: ignored
1273  * @n_param_values: 2
1274  * @param_values: a #GValue array holding the instance and the flags parameter
1275  * @invocation_hint: the invocation hint given as the last argument
1276  *  to g_closure_invoke()
1277  * @marshal_data: additional data specified when registering the marshaller
1278  *
1279  * A marshaller for a #GCClosure with a callback of type
1280  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes a flags type.
1281  */
1282
1283 /**
1284  * g_cclosure_marshal_VOID__FLOAT:
1285  * @closure: the #GClosure to which the marshaller belongs
1286  * @return_value: ignored
1287  * @n_param_values: 2
1288  * @param_values: a #GValue array holding the instance and the #gfloat parameter
1289  * @invocation_hint: the invocation hint given as the last argument
1290  *  to g_closure_invoke()
1291  * @marshal_data: additional data specified when registering the marshaller
1292  *
1293  * A marshaller for a #GCClosure with a callback of type
1294  * <literal>void (*callback) (gpointer instance, gfloat arg1, gpointer user_data)</literal>.
1295  */
1296
1297 /**
1298  * g_cclosure_marshal_VOID__DOUBLE:
1299  * @closure: the #GClosure to which the marshaller belongs
1300  * @return_value: ignored
1301  * @n_param_values: 2
1302  * @param_values: a #GValue array holding the instance and the #gdouble parameter
1303  * @invocation_hint: the invocation hint given as the last argument
1304  *  to g_closure_invoke()
1305  * @marshal_data: additional data specified when registering the marshaller
1306  *
1307  * A marshaller for a #GCClosure with a callback of type
1308  * <literal>void (*callback) (gpointer instance, gdouble arg1, gpointer user_data)</literal>.
1309  */
1310
1311 /**
1312  * g_cclosure_marshal_VOID__STRING:
1313  * @closure: the #GClosure to which the marshaller belongs
1314  * @return_value: ignored
1315  * @n_param_values: 2
1316  * @param_values: a #GValue array holding the instance and the #gchar* parameter
1317  * @invocation_hint: the invocation hint given as the last argument
1318  *  to g_closure_invoke()
1319  * @marshal_data: additional data specified when registering the marshaller
1320  *
1321  * A marshaller for a #GCClosure with a callback of type
1322  * <literal>void (*callback) (gpointer instance, const gchar *arg1, gpointer user_data)</literal>.
1323  */
1324
1325 /**
1326  * g_cclosure_marshal_VOID__PARAM:
1327  * @closure: the #GClosure to which the marshaller belongs
1328  * @return_value: ignored
1329  * @n_param_values: 2
1330  * @param_values: a #GValue array holding the instance and the #GParamSpec* parameter
1331  * @invocation_hint: the invocation hint given as the last argument
1332  *  to g_closure_invoke()
1333  * @marshal_data: additional data specified when registering the marshaller
1334  *
1335  * A marshaller for a #GCClosure with a callback of type
1336  * <literal>void (*callback) (gpointer instance, GParamSpec *arg1, gpointer user_data)</literal>.
1337  */
1338
1339 /**
1340  * g_cclosure_marshal_VOID__BOXED:
1341  * @closure: the #GClosure to which the marshaller belongs
1342  * @return_value: ignored
1343  * @n_param_values: 2
1344  * @param_values: a #GValue array holding the instance and the #GBoxed* parameter
1345  * @invocation_hint: the invocation hint given as the last argument
1346  *  to g_closure_invoke()
1347  * @marshal_data: additional data specified when registering the marshaller
1348  *
1349  * A marshaller for a #GCClosure with a callback of type
1350  * <literal>void (*callback) (gpointer instance, GBoxed *arg1, gpointer user_data)</literal>.
1351  */
1352
1353 /**
1354  * g_cclosure_marshal_VOID__POINTER:
1355  * @closure: the #GClosure to which the marshaller belongs
1356  * @return_value: ignored
1357  * @n_param_values: 2
1358  * @param_values: a #GValue array holding the instance and the #gpointer parameter
1359  * @invocation_hint: the invocation hint given as the last argument
1360  *  to g_closure_invoke()
1361  * @marshal_data: additional data specified when registering the marshaller
1362  *
1363  * A marshaller for a #GCClosure with a callback of type
1364  * <literal>void (*callback) (gpointer instance, gpointer arg1, gpointer user_data)</literal>.
1365  */
1366
1367 /**
1368  * g_cclosure_marshal_VOID__OBJECT:
1369  * @closure: the #GClosure to which the marshaller belongs
1370  * @return_value: ignored
1371  * @n_param_values: 2
1372  * @param_values: a #GValue array holding the instance and the #GObject* parameter
1373  * @invocation_hint: the invocation hint given as the last argument
1374  *  to g_closure_invoke()
1375  * @marshal_data: additional data specified when registering the marshaller
1376  *
1377  * A marshaller for a #GCClosure with a callback of type
1378  * <literal>void (*callback) (gpointer instance, GObject *arg1, gpointer user_data)</literal>.
1379  */
1380
1381 /**
1382  * g_cclosure_marshal_VOID__VARIANT:
1383  * @closure: the #GClosure to which the marshaller belongs
1384  * @return_value: ignored
1385  * @n_param_values: 2
1386  * @param_values: a #GValue array holding the instance and the #GVariant* parameter
1387  * @invocation_hint: the invocation hint given as the last argument
1388  *  to g_closure_invoke()
1389  * @marshal_data: additional data specified when registering the marshaller
1390  *
1391  * A marshaller for a #GCClosure with a callback of type
1392  * <literal>void (*callback) (gpointer instance, GVariant *arg1, gpointer user_data)</literal>.
1393  *
1394  * Since: 2.26
1395  */
1396
1397 /**
1398  * g_cclosure_marshal_VOID__UINT_POINTER:
1399  * @closure: the #GClosure to which the marshaller belongs
1400  * @return_value: ignored
1401  * @n_param_values: 3
1402  * @param_values: a #GValue array holding instance, arg1 and arg2
1403  * @invocation_hint: the invocation hint given as the last argument
1404  *  to g_closure_invoke()
1405  * @marshal_data: additional data specified when registering the marshaller
1406  *
1407  * A marshaller for a #GCClosure with a callback of type
1408  * <literal>void (*callback) (gpointer instance, guint arg1, gpointer arg2, gpointer user_data)</literal>.
1409  */
1410
1411 /**
1412  * g_cclosure_marshal_BOOLEAN__FLAGS:
1413  * @closure: the #GClosure to which the marshaller belongs
1414  * @return_value: a #GValue which can store the returned #gboolean
1415  * @n_param_values: 2
1416  * @param_values: a #GValue array holding instance and arg1
1417  * @invocation_hint: the invocation hint given as the last argument
1418  *  to g_closure_invoke()
1419  * @marshal_data: additional data specified when registering the marshaller
1420  *
1421  * A marshaller for a #GCClosure with a callback of type
1422  * <literal>gboolean (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter
1423  * denotes a flags type.
1424  */
1425
1426 /**
1427  * g_cclosure_marshal_BOOL__FLAGS:
1428  *
1429  * Another name for g_cclosure_marshal_BOOLEAN__FLAGS().
1430  */
1431 /**
1432  * g_cclosure_marshal_STRING__OBJECT_POINTER:
1433  * @closure: the #GClosure to which the marshaller belongs
1434  * @return_value: a #GValue, which can store the returned string
1435  * @n_param_values: 3
1436  * @param_values: a #GValue array holding instance, arg1 and arg2
1437  * @invocation_hint: the invocation hint given as the last argument
1438  *  to g_closure_invoke()
1439  * @marshal_data: additional data specified when registering the marshaller
1440  *
1441  * A marshaller for a #GCClosure with a callback of type
1442  * <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>.
1443  */
1444 /**
1445  * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED:
1446  * @closure: the #GClosure to which the marshaller belongs
1447  * @return_value: a #GValue, which can store the returned string
1448  * @n_param_values: 3
1449  * @param_values: a #GValue array holding instance, arg1 and arg2
1450  * @invocation_hint: the invocation hint given as the last argument
1451  *  to g_closure_invoke()
1452  * @marshal_data: additional data specified when registering the marshaller
1453  *
1454  * A marshaller for a #GCClosure with a callback of type
1455  * <literal>gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)</literal>.
1456  *
1457  * Since: 2.26
1458  */