gclosure: Add missing include
[platform/upstream/glib.git] / gobject / gclosure.c
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 2000-2001 Red Hat, Inc.
3  * Copyright (C) 2005 Imendio AB
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * MT safe with regards to reference counting.
23  */
24
25 #include "config.h"
26
27 #include <string.h>
28
29 #include <ffi.h>
30
31 #include "gclosure.h"
32 #include "gboxed.h"
33 #include "gobject.h"
34 #include "genums.h"
35 #include "gvalue.h"
36 #include "gvaluetypes.h"
37
38
39 /**
40  * SECTION:gclosure
41  * @short_description: Functions as first-class objects
42  * @title: Closures
43  *
44  * A #GClosure represents a callback supplied by the programmer. It
45  * will generally comprise a function of some kind and a marshaller
46  * used to call it. It is the reponsibility of the marshaller to
47  * convert the arguments for the invocation from #GValue<!-- -->s into
48  * a suitable form, perform the callback on the converted arguments,
49  * and transform the return value back into a #GValue.
50  *
51  * In the case of C programs, a closure usually just holds a pointer
52  * to a function and maybe a data argument, and the marshaller
53  * converts between #GValue<!-- --> and native C types. The GObject
54  * library provides the #GCClosure type for this purpose. Bindings for
55  * other languages need marshallers which convert between #GValue<!--
56  * -->s and suitable representations in the runtime of the language in
57  * order to use functions written in that languages as callbacks.
58  *
59  * Within GObject, closures play an important role in the
60  * implementation of signals. When a signal is registered, the
61  * @c_marshaller argument to g_signal_new() specifies the default C
62  * marshaller for any closure which is connected to this
63  * signal. GObject provides a number of C marshallers for this
64  * purpose, see the g_cclosure_marshal_*() functions. Additional C
65  * marshallers can be generated with the <link
66  * linkend="glib-genmarshal">glib-genmarshal</link> utility.  Closures
67  * can be explicitly connected to signals with
68  * g_signal_connect_closure(), but it usually more convenient to let
69  * GObject create a closure automatically by using one of the
70  * g_signal_connect_*() functions which take a callback function/user
71  * data pair.
72  *
73  * Using closures has a number of important advantages over a simple
74  * callback function/data pointer combination:
75  * <itemizedlist>
76  * <listitem><para>
77  * Closures allow the callee to get the types of the callback parameters,
78  * which means that language bindings don't have to write individual glue
79  * for each callback type.
80  * </para></listitem>
81  * <listitem><para>
82  * The reference counting of #GClosure makes it easy to handle reentrancy
83  * right; if a callback is removed while it is being invoked, the closure
84  * and its parameters won't be freed until the invocation finishes.
85  * </para></listitem>
86  * <listitem><para>
87  * g_closure_invalidate() and invalidation notifiers allow callbacks to be
88  * automatically removed when the objects they point to go away.
89  * </para></listitem>
90  * </itemizedlist>
91  */
92
93
94 #define CLOSURE_MAX_REF_COUNT           ((1 << 15) - 1)
95 #define CLOSURE_MAX_N_GUARDS            ((1 << 1) - 1)
96 #define CLOSURE_MAX_N_FNOTIFIERS        ((1 << 2) - 1)
97 #define CLOSURE_MAX_N_INOTIFIERS        ((1 << 8) - 1)
98 #define CLOSURE_N_MFUNCS(cl)            ((cl)->meta_marshal + \
99                                          ((cl)->n_guards << 1L))
100 /* same as G_CLOSURE_N_NOTIFIERS() (keep in sync) */
101 #define CLOSURE_N_NOTIFIERS(cl)         (CLOSURE_N_MFUNCS (cl) + \
102                                          (cl)->n_fnotifiers + \
103                                          (cl)->n_inotifiers)
104
105 typedef union {
106   GClosure closure;
107   volatile gint vint;
108 } ClosureInt;
109
110 #define CHANGE_FIELD(_closure, _field, _OP, _value, _must_set, _SET_OLD, _SET_NEW)      \
111 G_STMT_START {                                                                          \
112   ClosureInt *cunion = (ClosureInt*) _closure;                                          \
113   gint new_int, old_int, success;                                                       \
114   do                                                                                    \
115     {                                                                                   \
116       ClosureInt tmp;                                                                   \
117       tmp.vint = old_int = cunion->vint;                                                \
118       _SET_OLD tmp.closure._field;                                                      \
119       tmp.closure._field _OP _value;                                                    \
120       _SET_NEW tmp.closure._field;                                                      \
121       new_int = tmp.vint;                                                               \
122       success = g_atomic_int_compare_and_exchange (&cunion->vint, old_int, new_int);    \
123     }                                                                                   \
124   while (!success && _must_set);                                                        \
125 } G_STMT_END
126
127 #define SWAP(_closure, _field, _value, _oldv)   CHANGE_FIELD (_closure, _field, =, _value, TRUE, *(_oldv) =,     (void) )
128 #define SET(_closure, _field, _value)           CHANGE_FIELD (_closure, _field, =, _value, TRUE,     (void),     (void) )
129 #define INC(_closure, _field)                   CHANGE_FIELD (_closure, _field, +=,     1, TRUE,     (void),     (void) )
130 #define INC_ASSIGN(_closure, _field, _newv)     CHANGE_FIELD (_closure, _field, +=,     1, TRUE,     (void), *(_newv) = )
131 #define DEC(_closure, _field)                   CHANGE_FIELD (_closure, _field, -=,     1, TRUE,     (void),     (void) )
132 #define DEC_ASSIGN(_closure, _field, _newv)     CHANGE_FIELD (_closure, _field, -=,     1, TRUE,     (void), *(_newv) = )
133
134 #if 0   /* for non-thread-safe closures */
135 #define SWAP(cl,f,v,o)     (void) (*(o) = cl->f, cl->f = v)
136 #define SET(cl,f,v)        (void) (cl->f = v)
137 #define INC(cl,f)          (void) (cl->f += 1)
138 #define INC_ASSIGN(cl,f,n) (void) (cl->f += 1, *(n) = cl->f)
139 #define DEC(cl,f)          (void) (cl->f -= 1)
140 #define DEC_ASSIGN(cl,f,n) (void) (cl->f -= 1, *(n) = cl->f)
141 #endif
142
143 enum {
144   FNOTIFY,
145   INOTIFY,
146   PRE_NOTIFY,
147   POST_NOTIFY
148 };
149
150
151 /* --- functions --- */
152 /**
153  * g_closure_new_simple:
154  * @sizeof_closure: the size of the structure to allocate, must be at least
155  *                  <literal>sizeof (GClosure)</literal>
156  * @data: data to store in the @data field of the newly allocated #GClosure
157  *
158  * Allocates a struct of the given size and initializes the initial
159  * part as a #GClosure. This function is mainly useful when
160  * implementing new types of closures.
161  *
162  * |[
163  * typedef struct _MyClosure MyClosure;
164  * struct _MyClosure
165  * {
166  *   GClosure closure;
167  *   // extra data goes here
168  * };
169  *
170  * static void
171  * my_closure_finalize (gpointer  notify_data,
172  *                      GClosure *closure)
173  * {
174  *   MyClosure *my_closure = (MyClosure *)closure;
175  *
176  *   // free extra data here
177  * }
178  *
179  * MyClosure *my_closure_new (gpointer data)
180  * {
181  *   GClosure *closure;
182  *   MyClosure *my_closure;
183  *
184  *   closure = g_closure_new_simple (sizeof (MyClosure), data);
185  *   my_closure = (MyClosure *) closure;
186  *
187  *   // initialize extra data here
188  *
189  *   g_closure_add_finalize_notifier (closure, notify_data,
190  *                                    my_closure_finalize);
191  *   return my_closure;
192  * }
193  * ]|
194  *
195  * Returns: (transfer full): a newly allocated #GClosure
196  */
197 GClosure*
198 g_closure_new_simple (guint           sizeof_closure,
199                       gpointer        data)
200 {
201   GClosure *closure;
202
203   g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL);
204
205   closure = g_malloc0 (sizeof_closure);
206   SET (closure, ref_count, 1);
207   SET (closure, meta_marshal, 0);
208   SET (closure, n_guards, 0);
209   SET (closure, n_fnotifiers, 0);
210   SET (closure, n_inotifiers, 0);
211   SET (closure, in_inotify, FALSE);
212   SET (closure, floating, TRUE);
213   SET (closure, derivative_flag, 0);
214   SET (closure, in_marshal, FALSE);
215   SET (closure, is_invalid, FALSE);
216   closure->marshal = NULL;
217   closure->data = data;
218   closure->notifiers = NULL;
219   memset (G_STRUCT_MEMBER_P (closure, sizeof (*closure)), 0, sizeof_closure - sizeof (*closure));
220
221   return closure;
222 }
223
224 static inline void
225 closure_invoke_notifiers (GClosure *closure,
226                           guint     notify_type)
227 {
228   /* notifier layout:
229    *     meta_marshal  n_guards    n_guards     n_fnotif.  n_inotifiers
230    * ->[[meta_marshal][pre_guards][post_guards][fnotifiers][inotifiers]]
231    *
232    * CLOSURE_N_MFUNCS(cl)    = meta_marshal + n_guards + n_guards;
233    * CLOSURE_N_NOTIFIERS(cl) = CLOSURE_N_MFUNCS(cl) + n_fnotifiers + n_inotifiers
234    *
235    * constrains/catches:
236    * - closure->notifiers may be reloacted during callback
237    * - closure->n_fnotifiers and closure->n_inotifiers may change during callback
238    * - i.e. callbacks can be removed/added during invocation
239    * - must prepare for callback removal during FNOTIFY and INOTIFY (done via ->marshal= & ->data=)
240    * - must distinguish (->marshal= & ->data=) for INOTIFY vs. FNOTIFY (via ->in_inotify)
241    * + closure->n_guards is const during PRE_NOTIFY & POST_NOTIFY
242    * + closure->meta_marshal is const for all cases
243    * + none of the callbacks can cause recursion
244    * + closure->n_inotifiers is const 0 during FNOTIFY
245    */
246   switch (notify_type)
247     {
248       GClosureNotifyData *ndata;
249       guint i, offs;
250     case FNOTIFY:
251       while (closure->n_fnotifiers)
252         {
253           guint n;
254           DEC_ASSIGN (closure, n_fnotifiers, &n);
255
256           ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + n;
257           closure->marshal = (GClosureMarshal) ndata->notify;
258           closure->data = ndata->data;
259           ndata->notify (ndata->data, closure);
260         }
261       closure->marshal = NULL;
262       closure->data = NULL;
263       break;
264     case INOTIFY:
265       SET (closure, in_inotify, TRUE);
266       while (closure->n_inotifiers)
267         {
268           guint n;
269           DEC_ASSIGN (closure, n_inotifiers, &n);
270
271           ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n;
272           closure->marshal = (GClosureMarshal) ndata->notify;
273           closure->data = ndata->data;
274           ndata->notify (ndata->data, closure);
275         }
276       closure->marshal = NULL;
277       closure->data = NULL;
278       SET (closure, in_inotify, FALSE);
279       break;
280     case PRE_NOTIFY:
281       i = closure->n_guards;
282       offs = closure->meta_marshal;
283       while (i--)
284         {
285           ndata = closure->notifiers + offs + i;
286           ndata->notify (ndata->data, closure);
287         }
288       break;
289     case POST_NOTIFY:
290       i = closure->n_guards;
291       offs = closure->meta_marshal + i;
292       while (i--)
293         {
294           ndata = closure->notifiers + offs + i;
295           ndata->notify (ndata->data, closure);
296         }
297       break;
298     }
299 }
300
301 /**
302  * g_closure_set_meta_marshal: (skip)
303  * @closure: a #GClosure
304  * @marshal_data: context-dependent data to pass to @meta_marshal
305  * @meta_marshal: a #GClosureMarshal function
306  *
307  * Sets the meta marshaller of @closure.  A meta marshaller wraps
308  * @closure->marshal and modifies the way it is called in some
309  * fashion. The most common use of this facility is for C callbacks.
310  * The same marshallers (generated by <link
311  * linkend="glib-genmarshal">glib-genmarshal</link>) are used
312  * everywhere, but the way that we get the callback function
313  * differs. In most cases we want to use @closure->callback, but in
314  * other cases we want to use some different technique to retrieve the
315  * callback function.
316  *
317  * For example, class closures for signals (see
318  * g_signal_type_cclosure_new()) retrieve the callback function from a
319  * fixed offset in the class structure.  The meta marshaller retrieves
320  * the right callback and passes it to the marshaller as the
321  * @marshal_data argument.
322  */
323 void
324 g_closure_set_meta_marshal (GClosure       *closure,
325                             gpointer        marshal_data,
326                             GClosureMarshal meta_marshal)
327 {
328   GClosureNotifyData *notifiers;
329
330   g_return_if_fail (closure != NULL);
331   g_return_if_fail (meta_marshal != NULL);
332   g_return_if_fail (closure->is_invalid == FALSE);
333   g_return_if_fail (closure->in_marshal == FALSE);
334   g_return_if_fail (closure->meta_marshal == 0);
335
336   notifiers = closure->notifiers;
337   closure->notifiers = g_renew (GClosureNotifyData, NULL, CLOSURE_N_NOTIFIERS (closure) + 1);
338   if (notifiers)
339     {
340       /* usually the meta marshal will be setup right after creation, so the
341        * g_memmove() should be rare-case scenario
342        */
343       g_memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
344       g_free (notifiers);
345     }
346   closure->notifiers[0].data = marshal_data;
347   closure->notifiers[0].notify = (GClosureNotify) meta_marshal;
348   SET (closure, meta_marshal, 1);
349 }
350
351 /**
352  * g_closure_add_marshal_guards: (skip)
353  * @closure: a #GClosure
354  * @pre_marshal_data: data to pass to @pre_marshal_notify
355  * @pre_marshal_notify: a function to call before the closure callback
356  * @post_marshal_data: data to pass to @post_marshal_notify
357  * @post_marshal_notify: a function to call after the closure callback
358  *
359  * Adds a pair of notifiers which get invoked before and after the
360  * closure callback, respectively. This is typically used to protect
361  * the extra arguments for the duration of the callback. See
362  * g_object_watch_closure() for an example of marshal guards.
363  */
364 void
365 g_closure_add_marshal_guards (GClosure      *closure,
366                               gpointer       pre_marshal_data,
367                               GClosureNotify pre_marshal_notify,
368                               gpointer       post_marshal_data,
369                               GClosureNotify post_marshal_notify)
370 {
371   guint i;
372
373   g_return_if_fail (closure != NULL);
374   g_return_if_fail (pre_marshal_notify != NULL);
375   g_return_if_fail (post_marshal_notify != NULL);
376   g_return_if_fail (closure->is_invalid == FALSE);
377   g_return_if_fail (closure->in_marshal == FALSE);
378   g_return_if_fail (closure->n_guards < CLOSURE_MAX_N_GUARDS);
379
380   closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2);
381   if (closure->n_inotifiers)
382     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
383                         closure->n_fnotifiers +
384                         closure->n_inotifiers + 1)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
385                                                                           closure->n_fnotifiers + 0)];
386   if (closure->n_inotifiers > 1)
387     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
388                         closure->n_fnotifiers +
389                         closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
390                                                                       closure->n_fnotifiers + 1)];
391   if (closure->n_fnotifiers)
392     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
393                         closure->n_fnotifiers + 1)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 0];
394   if (closure->n_fnotifiers > 1)
395     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
396                         closure->n_fnotifiers)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 1];
397   if (closure->n_guards)
398     closure->notifiers[(closure->meta_marshal +
399                         closure->n_guards +
400                         closure->n_guards + 1)] = closure->notifiers[closure->meta_marshal + closure->n_guards];
401   i = closure->n_guards;
402   closure->notifiers[closure->meta_marshal + i].data = pre_marshal_data;
403   closure->notifiers[closure->meta_marshal + i].notify = pre_marshal_notify;
404   closure->notifiers[closure->meta_marshal + i + 1].data = post_marshal_data;
405   closure->notifiers[closure->meta_marshal + i + 1].notify = post_marshal_notify;
406   INC (closure, n_guards);
407 }
408
409 /**
410  * g_closure_add_finalize_notifier: (skip)
411  * @closure: a #GClosure
412  * @notify_data: data to pass to @notify_func
413  * @notify_func: the callback function to register
414  *
415  * Registers a finalization notifier which will be called when the
416  * reference count of @closure goes down to 0. Multiple finalization
417  * notifiers on a single closure are invoked in unspecified order. If
418  * a single call to g_closure_unref() results in the closure being
419  * both invalidated and finalized, then the invalidate notifiers will
420  * be run before the finalize notifiers.
421  */
422 void
423 g_closure_add_finalize_notifier (GClosure      *closure,
424                                  gpointer       notify_data,
425                                  GClosureNotify notify_func)
426 {
427   guint i;
428
429   g_return_if_fail (closure != NULL);
430   g_return_if_fail (notify_func != NULL);
431   g_return_if_fail (closure->n_fnotifiers < CLOSURE_MAX_N_FNOTIFIERS);
432
433   closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
434   if (closure->n_inotifiers)
435     closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
436                         closure->n_fnotifiers +
437                         closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
438                                                                       closure->n_fnotifiers + 0)];
439   i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers;
440   closure->notifiers[i].data = notify_data;
441   closure->notifiers[i].notify = notify_func;
442   INC (closure, n_fnotifiers);
443 }
444
445 /**
446  * g_closure_add_invalidate_notifier: (skip)
447  * @closure: a #GClosure
448  * @notify_data: data to pass to @notify_func
449  * @notify_func: the callback function to register
450  *
451  * Registers an invalidation notifier which will be called when the
452  * @closure is invalidated with g_closure_invalidate(). Invalidation
453  * notifiers are invoked before finalization notifiers, in an
454  * unspecified order.
455  */
456 void
457 g_closure_add_invalidate_notifier (GClosure      *closure,
458                                    gpointer       notify_data,
459                                    GClosureNotify notify_func)
460 {
461   guint i;
462
463   g_return_if_fail (closure != NULL);
464   g_return_if_fail (notify_func != NULL);
465   g_return_if_fail (closure->is_invalid == FALSE);
466   g_return_if_fail (closure->n_inotifiers < CLOSURE_MAX_N_INOTIFIERS);
467
468   closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
469   i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + closure->n_inotifiers;
470   closure->notifiers[i].data = notify_data;
471   closure->notifiers[i].notify = notify_func;
472   INC (closure, n_inotifiers);
473 }
474
475 static inline gboolean
476 closure_try_remove_inotify (GClosure       *closure,
477                             gpointer       notify_data,
478                             GClosureNotify notify_func)
479 {
480   GClosureNotifyData *ndata, *nlast;
481
482   nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - 1;
483   for (ndata = nlast + 1 - closure->n_inotifiers; ndata <= nlast; ndata++)
484     if (ndata->notify == notify_func && ndata->data == notify_data)
485       {
486         DEC (closure, n_inotifiers);
487         if (ndata < nlast)
488           *ndata = *nlast;
489
490         return TRUE;
491       }
492   return FALSE;
493 }
494
495 static inline gboolean
496 closure_try_remove_fnotify (GClosure       *closure,
497                             gpointer       notify_data,
498                             GClosureNotify notify_func)
499 {
500   GClosureNotifyData *ndata, *nlast;
501
502   nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1;
503   for (ndata = nlast + 1 - closure->n_fnotifiers; ndata <= nlast; ndata++)
504     if (ndata->notify == notify_func && ndata->data == notify_data)
505       {
506         DEC (closure, n_fnotifiers);
507         if (ndata < nlast)
508           *ndata = *nlast;
509         if (closure->n_inotifiers)
510           closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
511                               closure->n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
512                                                                             closure->n_fnotifiers +
513                                                                             closure->n_inotifiers)];
514         return TRUE;
515       }
516   return FALSE;
517 }
518
519 /**
520  * g_closure_ref:
521  * @closure: #GClosure to increment the reference count on
522  *
523  * Increments the reference count on a closure to force it staying
524  * alive while the caller holds a pointer to it.
525  *
526  * Returns: (transfer none): The @closure passed in, for convenience
527  */
528 GClosure*
529 g_closure_ref (GClosure *closure)
530 {
531   guint new_ref_count;
532   g_return_val_if_fail (closure != NULL, NULL);
533   g_return_val_if_fail (closure->ref_count > 0, NULL);
534   g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL);
535
536   INC_ASSIGN (closure, ref_count, &new_ref_count);
537   g_return_val_if_fail (new_ref_count > 1, NULL);
538
539   return closure;
540 }
541
542 /**
543  * g_closure_invalidate:
544  * @closure: GClosure to invalidate
545  *
546  * Sets a flag on the closure to indicate that its calling
547  * environment has become invalid, and thus causes any future
548  * invocations of g_closure_invoke() on this @closure to be
549  * ignored. Also, invalidation notifiers installed on the closure will
550  * be called at this point. Note that unless you are holding a
551  * reference to the closure yourself, the invalidation notifiers may
552  * unref the closure and cause it to be destroyed, so if you need to
553  * access the closure after calling g_closure_invalidate(), make sure
554  * that you've previously called g_closure_ref().
555  *
556  * Note that g_closure_invalidate() will also be called when the
557  * reference count of a closure drops to zero (unless it has already
558  * been invalidated before).
559  */
560 void
561 g_closure_invalidate (GClosure *closure)
562 {
563   g_return_if_fail (closure != NULL);
564
565   if (!closure->is_invalid)
566     {
567       gboolean was_invalid;
568       g_closure_ref (closure);           /* preserve floating flag */
569       SWAP (closure, is_invalid, TRUE, &was_invalid);
570       /* invalidate only once */
571       if (!was_invalid)
572         closure_invoke_notifiers (closure, INOTIFY);
573       g_closure_unref (closure);
574     }
575 }
576
577 /**
578  * g_closure_unref:
579  * @closure: #GClosure to decrement the reference count on
580  *
581  * Decrements the reference count of a closure after it was previously
582  * incremented by the same caller. If no other callers are using the
583  * closure, then the closure will be destroyed and freed.
584  */
585 void
586 g_closure_unref (GClosure *closure)
587 {
588   guint new_ref_count;
589
590   g_return_if_fail (closure != NULL);
591   g_return_if_fail (closure->ref_count > 0);
592
593   if (closure->ref_count == 1)  /* last unref, invalidate first */
594     g_closure_invalidate (closure);
595
596   DEC_ASSIGN (closure, ref_count, &new_ref_count);
597
598   if (new_ref_count == 0)
599     {
600       closure_invoke_notifiers (closure, FNOTIFY);
601       g_free (closure->notifiers);
602       g_free (closure);
603     }
604 }
605
606 /**
607  * g_closure_sink:
608  * @closure: #GClosure to decrement the initial reference count on, if it's
609  *           still being held
610  *
611  * Takes over the initial ownership of a closure.  Each closure is
612  * initially created in a <firstterm>floating</firstterm> state, which
613  * means that the initial reference count is not owned by any caller.
614  * g_closure_sink() checks to see if the object is still floating, and
615  * if so, unsets the floating state and decreases the reference
616  * count. If the closure is not floating, g_closure_sink() does
617  * nothing. The reason for the existance of the floating state is to
618  * prevent cumbersome code sequences like:
619  * |[
620  * closure = g_cclosure_new (cb_func, cb_data);
621  * g_source_set_closure (source, closure);
622  * g_closure_unref (closure); // XXX GObject doesn't really need this
623  * ]|
624  * Because g_source_set_closure() (and similar functions) take ownership of the
625  * initial reference count, if it is unowned, we instead can write:
626  * |[
627  * g_source_set_closure (source, g_cclosure_new (cb_func, cb_data));
628  * ]|
629  *
630  * Generally, this function is used together with g_closure_ref(). Ane example
631  * of storing a closure for later notification looks like:
632  * |[
633  * static GClosure *notify_closure = NULL;
634  * void
635  * foo_notify_set_closure (GClosure *closure)
636  * {
637  *   if (notify_closure)
638  *     g_closure_unref (notify_closure);
639  *   notify_closure = closure;
640  *   if (notify_closure)
641  *     {
642  *       g_closure_ref (notify_closure);
643  *       g_closure_sink (notify_closure);
644  *     }
645  * }
646  * ]|
647  *
648  * Because g_closure_sink() may decrement the reference count of a closure
649  * (if it hasn't been called on @closure yet) just like g_closure_unref(),
650  * g_closure_ref() should be called prior to this function.
651  */
652 void
653 g_closure_sink (GClosure *closure)
654 {
655   g_return_if_fail (closure != NULL);
656   g_return_if_fail (closure->ref_count > 0);
657
658   /* floating is basically a kludge to avoid creating closures
659    * with a ref_count of 0. so the intial ref_count a closure has
660    * is unowned. with invoking g_closure_sink() code may
661    * indicate that it takes over that intiial ref_count.
662    */
663   if (closure->floating)
664     {
665       gboolean was_floating;
666       SWAP (closure, floating, FALSE, &was_floating);
667       /* unref floating flag only once */
668       if (was_floating)
669         g_closure_unref (closure);
670     }
671 }
672
673 /**
674  * g_closure_remove_invalidate_notifier: (skip)
675  * @closure: a #GClosure
676  * @notify_data: data which was passed to g_closure_add_invalidate_notifier()
677  *               when registering @notify_func
678  * @notify_func: the callback function to remove
679  *
680  * Removes an invalidation notifier.
681  *
682  * Notice that notifiers are automatically removed after they are run.
683  */
684 void
685 g_closure_remove_invalidate_notifier (GClosure      *closure,
686                                       gpointer       notify_data,
687                                       GClosureNotify notify_func)
688 {
689   g_return_if_fail (closure != NULL);
690   g_return_if_fail (notify_func != NULL);
691
692   if (closure->is_invalid && closure->in_inotify && /* account removal of notify_func() while it's called */
693       ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
694       closure->data == notify_data)
695     closure->marshal = NULL;
696   else if (!closure_try_remove_inotify (closure, notify_data, notify_func))
697     g_warning (G_STRLOC ": unable to remove uninstalled invalidation notifier: %p (%p)",
698                notify_func, notify_data);
699 }
700
701 /**
702  * g_closure_remove_finalize_notifier: (skip)
703  * @closure: a #GClosure
704  * @notify_data: data which was passed to g_closure_add_finalize_notifier()
705  *  when registering @notify_func
706  * @notify_func: the callback function to remove
707  *
708  * Removes a finalization notifier.
709  *
710  * Notice that notifiers are automatically removed after they are run.
711  */
712 void
713 g_closure_remove_finalize_notifier (GClosure      *closure,
714                                     gpointer       notify_data,
715                                     GClosureNotify notify_func)
716 {
717   g_return_if_fail (closure != NULL);
718   g_return_if_fail (notify_func != NULL);
719
720   if (closure->is_invalid && !closure->in_inotify && /* account removal of notify_func() while it's called */
721       ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
722       closure->data == notify_data)
723     closure->marshal = NULL;
724   else if (!closure_try_remove_fnotify (closure, notify_data, notify_func))
725     g_warning (G_STRLOC ": unable to remove uninstalled finalization notifier: %p (%p)",
726                notify_func, notify_data);
727 }
728
729 /**
730  * g_closure_invoke:
731  * @closure: a #GClosure
732  * @return_value: a #GValue to store the return value. May be %NULL if the
733  *                callback of @closure doesn't return a value.
734  * @n_param_values: the length of the @param_values array
735  * @param_values: (array length=n_param_values): an array of
736  *                #GValue<!-- -->s holding the arguments on which to
737  *                invoke the callback of @closure
738  * @invocation_hint: a context-dependent invocation hint
739  *
740  * Invokes the closure, i.e. executes the callback represented by the @closure.
741  */
742 void
743 g_closure_invoke (GClosure       *closure,
744                   GValue /*out*/ *return_value,
745                   guint           n_param_values,
746                   const GValue   *param_values,
747                   gpointer        invocation_hint)
748 {
749   g_return_if_fail (closure != NULL);
750
751   g_closure_ref (closure);      /* preserve floating flag */
752   if (!closure->is_invalid)
753     {
754       GClosureMarshal marshal;
755       gpointer marshal_data;
756       gboolean in_marshal = closure->in_marshal;
757
758       g_return_if_fail (closure->marshal || closure->meta_marshal);
759
760       SET (closure, in_marshal, TRUE);
761       if (closure->meta_marshal)
762         {
763           marshal_data = closure->notifiers[0].data;
764           marshal = (GClosureMarshal) closure->notifiers[0].notify;
765         }
766       else
767         {
768           marshal_data = NULL;
769           marshal = closure->marshal;
770         }
771       if (!in_marshal)
772         closure_invoke_notifiers (closure, PRE_NOTIFY);
773       marshal (closure,
774                return_value,
775                n_param_values, param_values,
776                invocation_hint,
777                marshal_data);
778       if (!in_marshal)
779         closure_invoke_notifiers (closure, POST_NOTIFY);
780       SET (closure, in_marshal, in_marshal);
781     }
782   g_closure_unref (closure);
783 }
784
785 /**
786  * g_closure_set_marshal: (skip)
787  * @closure: a #GClosure
788  * @marshal: a #GClosureMarshal function
789  *
790  * Sets the marshaller of @closure. The <literal>marshal_data</literal>
791  * of @marshal provides a way for a meta marshaller to provide additional
792  * information to the marshaller. (See g_closure_set_meta_marshal().) For
793  * GObject's C predefined marshallers (the g_cclosure_marshal_*()
794  * functions), what it provides is a callback function to use instead of
795  * @closure->callback.
796  */
797 void
798 g_closure_set_marshal (GClosure       *closure,
799                        GClosureMarshal marshal)
800 {
801   g_return_if_fail (closure != NULL);
802   g_return_if_fail (marshal != NULL);
803
804   if (closure->marshal && closure->marshal != marshal)
805     g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)",
806                closure->marshal, marshal);
807   else
808     closure->marshal = marshal;
809 }
810
811 /**
812  * g_cclosure_new: (skip)
813  * @callback_func: the function to invoke
814  * @user_data: user data to pass to @callback_func
815  * @destroy_data: destroy notify to be called when @user_data is no longer used
816  *
817  * Creates a new closure which invokes @callback_func with @user_data as
818  * the last parameter.
819  *
820  * Returns: a new #GCClosure
821  */
822 GClosure*
823 g_cclosure_new (GCallback      callback_func,
824                 gpointer       user_data,
825                 GClosureNotify destroy_data)
826 {
827   GClosure *closure;
828   
829   g_return_val_if_fail (callback_func != NULL, NULL);
830   
831   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
832   if (destroy_data)
833     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
834   ((GCClosure*) closure)->callback = (gpointer) callback_func;
835   
836   return closure;
837 }
838
839 /**
840  * g_cclosure_new_swap: (skip)
841  * @callback_func: the function to invoke
842  * @user_data: user data to pass to @callback_func
843  * @destroy_data: destroy notify to be called when @user_data is no longer used
844  *
845  * Creates a new closure which invokes @callback_func with @user_data as
846  * the first parameter.
847  *
848  * Returns: (transfer full): a new #GCClosure
849  */
850 GClosure*
851 g_cclosure_new_swap (GCallback      callback_func,
852                      gpointer       user_data,
853                      GClosureNotify destroy_data)
854 {
855   GClosure *closure;
856   
857   g_return_val_if_fail (callback_func != NULL, NULL);
858   
859   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
860   if (destroy_data)
861     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
862   ((GCClosure*) closure)->callback = (gpointer) callback_func;
863   SET (closure, derivative_flag, TRUE);
864   
865   return closure;
866 }
867
868 static void
869 g_type_class_meta_marshal (GClosure       *closure,
870                            GValue /*out*/ *return_value,
871                            guint           n_param_values,
872                            const GValue   *param_values,
873                            gpointer        invocation_hint,
874                            gpointer        marshal_data)
875 {
876   GTypeClass *class;
877   gpointer callback;
878   /* GType itype = (GType) closure->data; */
879   guint offset = GPOINTER_TO_UINT (marshal_data);
880   
881   class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
882   callback = G_STRUCT_MEMBER (gpointer, class, offset);
883   if (callback)
884     closure->marshal (closure,
885                       return_value,
886                       n_param_values, param_values,
887                       invocation_hint,
888                       callback);
889 }
890
891 static void
892 g_type_iface_meta_marshal (GClosure       *closure,
893                            GValue /*out*/ *return_value,
894                            guint           n_param_values,
895                            const GValue   *param_values,
896                            gpointer        invocation_hint,
897                            gpointer        marshal_data)
898 {
899   GTypeClass *class;
900   gpointer callback;
901   GType itype = (GType) closure->data;
902   guint offset = GPOINTER_TO_UINT (marshal_data);
903   
904   class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
905   callback = G_STRUCT_MEMBER (gpointer, class, offset);
906   if (callback)
907     closure->marshal (closure,
908                       return_value,
909                       n_param_values, param_values,
910                       invocation_hint,
911                       callback);
912 }
913
914 /**
915  * g_signal_type_cclosure_new:
916  * @itype: the #GType identifier of an interface or classed type
917  * @struct_offset: the offset of the member function of @itype's class
918  *  structure which is to be invoked by the new closure
919  *
920  * Creates a new closure which invokes the function found at the offset
921  * @struct_offset in the class structure of the interface or classed type
922  * identified by @itype.
923  *
924  * Returns: a new #GCClosure
925  */
926 GClosure*
927 g_signal_type_cclosure_new (GType    itype,
928                             guint    struct_offset)
929 {
930   GClosure *closure;
931   
932   g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
933   g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL);
934   
935   closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype);
936   if (G_TYPE_IS_INTERFACE (itype))
937     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal);
938   else
939     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal);
940   
941   return closure;
942 }
943
944 #include <ffi.h>
945 static ffi_type *
946 value_to_ffi_type (const GValue *gvalue, gpointer *value)
947 {
948   ffi_type *rettype = NULL;
949   GType type = g_type_fundamental (G_VALUE_TYPE (gvalue));
950   g_assert (type != G_TYPE_INVALID);
951
952   switch (type)
953     {
954     case G_TYPE_BOOLEAN:
955     case G_TYPE_CHAR:
956     case G_TYPE_INT:
957       rettype = &ffi_type_sint;
958       *value = (gpointer)&(gvalue->data[0].v_int);
959       break;
960     case G_TYPE_UCHAR:
961     case G_TYPE_UINT:
962     case G_TYPE_FLAGS:
963       rettype = &ffi_type_uint;
964       *value = (gpointer)&(gvalue->data[0].v_uint);
965       break;
966     case G_TYPE_STRING:
967     case G_TYPE_OBJECT:
968     case G_TYPE_BOXED:
969     case G_TYPE_POINTER:
970     case G_TYPE_INTERFACE:
971     case G_TYPE_VARIANT:
972       rettype = &ffi_type_pointer;
973       *value = (gpointer)&(gvalue->data[0].v_pointer);
974       break;
975     case G_TYPE_FLOAT:
976       rettype = &ffi_type_float;
977       *value = (gpointer)&(gvalue->data[0].v_float);
978       break;
979     case G_TYPE_DOUBLE:
980       rettype = &ffi_type_double;
981       *value = (gpointer)&(gvalue->data[0].v_double);
982       break;
983     case G_TYPE_LONG:
984       rettype = &ffi_type_slong;
985       *value = (gpointer)&(gvalue->data[0].v_long);
986       break;
987     case G_TYPE_ULONG:
988       rettype = &ffi_type_ulong;
989       *value = (gpointer)&(gvalue->data[0].v_ulong);
990       break;
991     case G_TYPE_INT64:
992       rettype = &ffi_type_sint64;
993       *value = (gpointer)&(gvalue->data[0].v_int64);
994       break;
995     case G_TYPE_UINT64:
996       rettype = &ffi_type_uint64;
997       *value = (gpointer)&(gvalue->data[0].v_uint64);
998       break;
999     default:
1000       rettype = &ffi_type_pointer;
1001       *value = NULL;
1002       g_warning ("value_to_ffi_type: Unsupported fundamental type: %s", g_type_name (type));
1003       break;
1004     }
1005   return rettype;
1006 }
1007
1008 static void
1009 value_from_ffi_type (GValue *gvalue, gpointer *value)
1010 {
1011   switch (g_type_fundamental (G_VALUE_TYPE (gvalue)))
1012     {
1013     case G_TYPE_INT:
1014       g_value_set_int (gvalue, *(gint*)value);
1015       break;
1016     case G_TYPE_FLOAT:
1017       g_value_set_float (gvalue, *(gfloat*)value);
1018       break;
1019     case G_TYPE_DOUBLE:
1020       g_value_set_double (gvalue, *(gdouble*)value);
1021       break;
1022     case G_TYPE_BOOLEAN:
1023       g_value_set_boolean (gvalue, *(gboolean*)value);
1024       break;
1025     case G_TYPE_STRING:
1026       g_value_set_string (gvalue, *(gchar**)value);
1027       break;
1028     case G_TYPE_CHAR:
1029       g_value_set_char (gvalue, *(gchar*)value);
1030       break;
1031     case G_TYPE_UCHAR:
1032       g_value_set_uchar (gvalue, *(guchar*)value);
1033       break;
1034     case G_TYPE_UINT:
1035       g_value_set_uint (gvalue, *(guint*)value);
1036       break;
1037     case G_TYPE_POINTER:
1038       g_value_set_pointer (gvalue, *(gpointer*)value);
1039       break;
1040     case G_TYPE_LONG:
1041       g_value_set_long (gvalue, *(glong*)value);
1042       break;
1043     case G_TYPE_ULONG:
1044       g_value_set_ulong (gvalue, *(gulong*)value);
1045       break;
1046     case G_TYPE_INT64:
1047       g_value_set_int64 (gvalue, *(gint64*)value);
1048       break;
1049     case G_TYPE_UINT64:
1050       g_value_set_uint64 (gvalue, *(guint64*)value);
1051       break;
1052     case G_TYPE_BOXED:
1053       g_value_set_boxed (gvalue, *(gpointer*)value);
1054       break;
1055     case G_TYPE_FLAGS:
1056       g_value_set_flags (gvalue, *(guint*)value);
1057       break;
1058     case G_TYPE_OBJECT:
1059       g_value_set_object (gvalue, *(gpointer*)value);
1060       break;
1061     default:
1062       g_warning ("value_from_ffi_type: Unsupported fundamental type: %s",
1063                 g_type_name (g_type_fundamental (G_VALUE_TYPE (gvalue))));
1064     }
1065 }
1066
1067 /**
1068  * g_cclosure_marshal_generic:
1069  * @closure: A #GClosure.
1070  * @return_gvalue: A #GValue to store the return value. May be %NULL
1071  *   if the callback of closure doesn't return a value.
1072  * @n_param_values: The length of the @param_values array.
1073  * @param_values: An array of #GValue<!-- -->s holding the arguments
1074  *   on which to invoke the callback of closure.
1075  * @invocation_hint: The invocation hint given as the last argument to
1076  *   g_closure_invoke().
1077  * @marshal_data: Additional data specified when registering the
1078  *   marshaller, see g_closure_set_marshal() and
1079  *   g_closure_set_meta_marshal()
1080  *
1081  * A generic marshaller function implemented via <ulink
1082  * url="http://sourceware.org/libffi/">libffi</ulink>.
1083  *
1084  * Since: 2.30
1085  */
1086 void
1087 g_cclosure_marshal_generic (GClosure     *closure,
1088                             GValue       *return_gvalue,
1089                             guint         n_param_values,
1090                             const GValue *param_values,
1091                             gpointer      invocation_hint,
1092                             gpointer      marshal_data)
1093 {
1094   ffi_type *rtype;
1095   void *rvalue;
1096   int n_args;
1097   ffi_type **atypes;
1098   void **args;
1099   int i;
1100   ffi_cif cif;
1101   GCClosure *cc = (GCClosure*) closure;
1102
1103   if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1104     {
1105       rtype = value_to_ffi_type (return_gvalue, &rvalue);
1106     }
1107   else
1108     {
1109       rtype = &ffi_type_void;
1110     }
1111
1112   rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg)));
1113
1114   n_args = n_param_values + 1;
1115   atypes = g_alloca (sizeof (ffi_type *) * n_args);
1116   args =  g_alloca (sizeof (gpointer) * n_args);
1117
1118   if (G_CCLOSURE_SWAP_DATA (closure))
1119     {
1120       atypes[n_args-1] = value_to_ffi_type (param_values + 0,
1121                                             &args[n_args-1]);
1122       atypes[0] = &ffi_type_pointer;
1123       args[0] = &closure->data;
1124     }
1125   else
1126     {
1127       atypes[0] = value_to_ffi_type (param_values + 0, &args[0]);
1128       atypes[n_args-1] = &ffi_type_pointer;
1129       args[n_args-1] = &closure->data;
1130     }
1131
1132   for (i = 1; i < n_args - 1; i++)
1133     atypes[i] = value_to_ffi_type (param_values + i, &args[i]);
1134
1135   if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, n_args, rtype, atypes) != FFI_OK)
1136     return;
1137
1138   ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args);
1139
1140   if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1141     value_from_ffi_type (return_gvalue, rvalue);
1142 }
1143
1144 /**
1145  * g_cclosure_marshal_VOID__VOID:
1146  * @closure: the #GClosure to which the marshaller belongs
1147  * @return_value: ignored
1148  * @n_param_values: 1
1149  * @param_values: a #GValue array holding only the instance
1150  * @invocation_hint: the invocation hint given as the last argument
1151  *  to g_closure_invoke()
1152  * @marshal_data: additional data specified when registering the marshaller
1153  *
1154  * A marshaller for a #GCClosure with a callback of type
1155  * <literal>void (*callback) (gpointer instance, gpointer user_data)</literal>.
1156  */
1157
1158 /**
1159  * g_cclosure_marshal_VOID__BOOLEAN:
1160  * @closure: the #GClosure to which the marshaller belongs
1161  * @return_value: ignored
1162  * @n_param_values: 2
1163  * @param_values: a #GValue array holding the instance and the #gboolean parameter
1164  * @invocation_hint: the invocation hint given as the last argument
1165  *  to g_closure_invoke()
1166  * @marshal_data: additional data specified when registering the marshaller
1167  *
1168  * A marshaller for a #GCClosure with a callback of type
1169  * <literal>void (*callback) (gpointer instance, gboolean arg1, gpointer user_data)</literal>.
1170  */
1171
1172 /**
1173  * g_cclosure_marshal_VOID__CHAR:
1174  * @closure: the #GClosure to which the marshaller belongs
1175  * @return_value: ignored
1176  * @n_param_values: 2
1177  * @param_values: a #GValue array holding the instance and the #gchar parameter
1178  * @invocation_hint: the invocation hint given as the last argument
1179  *  to g_closure_invoke()
1180  * @marshal_data: additional data specified when registering the marshaller
1181  *
1182  * A marshaller for a #GCClosure with a callback of type
1183  * <literal>void (*callback) (gpointer instance, gchar arg1, gpointer user_data)</literal>.
1184  */
1185
1186 /**
1187  * g_cclosure_marshal_VOID__UCHAR:
1188  * @closure: the #GClosure to which the marshaller belongs
1189  * @return_value: ignored
1190  * @n_param_values: 2
1191  * @param_values: a #GValue array holding the instance and the #guchar parameter
1192  * @invocation_hint: the invocation hint given as the last argument
1193  *  to g_closure_invoke()
1194  * @marshal_data: additional data specified when registering the marshaller
1195  *
1196  * A marshaller for a #GCClosure with a callback of type
1197  * <literal>void (*callback) (gpointer instance, guchar arg1, gpointer user_data)</literal>.
1198  */
1199
1200 /**
1201  * g_cclosure_marshal_VOID__INT:
1202  * @closure: the #GClosure to which the marshaller belongs
1203  * @return_value: ignored
1204  * @n_param_values: 2
1205  * @param_values: a #GValue array holding the instance and the #gint parameter
1206  * @invocation_hint: the invocation hint given as the last argument
1207  *  to g_closure_invoke()
1208  * @marshal_data: additional data specified when registering the marshaller
1209  *
1210  * A marshaller for a #GCClosure with a callback of type
1211  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal>.
1212  */
1213
1214 /**
1215  * g_cclosure_marshal_VOID__UINT:
1216  * @closure: the #GClosure to which the marshaller belongs
1217  * @return_value: ignored
1218  * @n_param_values: 2
1219  * @param_values: a #GValue array holding the instance and the #guint parameter
1220  * @invocation_hint: the invocation hint given as the last argument
1221  *  to g_closure_invoke()
1222  * @marshal_data: additional data specified when registering the marshaller
1223  *
1224  * A marshaller for a #GCClosure with a callback of type
1225  * <literal>void (*callback) (gpointer instance, guint arg1, gpointer user_data)</literal>.
1226  */
1227
1228 /**
1229  * g_cclosure_marshal_VOID__LONG:
1230  * @closure: the #GClosure to which the marshaller belongs
1231  * @return_value: ignored
1232  * @n_param_values: 2
1233  * @param_values: a #GValue array holding the instance and the #glong parameter
1234  * @invocation_hint: the invocation hint given as the last argument
1235  *  to g_closure_invoke()
1236  * @marshal_data: additional data specified when registering the marshaller
1237  *
1238  * A marshaller for a #GCClosure with a callback of type
1239  * <literal>void (*callback) (gpointer instance, glong arg1, gpointer user_data)</literal>.
1240  */
1241
1242 /**
1243  * g_cclosure_marshal_VOID__ULONG:
1244  * @closure: the #GClosure to which the marshaller belongs
1245  * @return_value: ignored
1246  * @n_param_values: 2
1247  * @param_values: a #GValue array holding the instance and the #gulong parameter
1248  * @invocation_hint: the invocation hint given as the last argument
1249  *  to g_closure_invoke()
1250  * @marshal_data: additional data specified when registering the marshaller
1251  *
1252  * A marshaller for a #GCClosure with a callback of type
1253  * <literal>void (*callback) (gpointer instance, gulong arg1, gpointer user_data)</literal>.
1254  */
1255
1256 /**
1257  * g_cclosure_marshal_VOID__ENUM:
1258  * @closure: the #GClosure to which the marshaller belongs
1259  * @return_value: ignored
1260  * @n_param_values: 2
1261  * @param_values: a #GValue array holding the instance and the enumeration parameter
1262  * @invocation_hint: the invocation hint given as the last argument
1263  *  to g_closure_invoke()
1264  * @marshal_data: additional data specified when registering the marshaller
1265  *
1266  * A marshaller for a #GCClosure with a callback of type
1267  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes an enumeration type..
1268  */
1269
1270 /**
1271  * g_cclosure_marshal_VOID__FLAGS:
1272  * @closure: the #GClosure to which the marshaller belongs
1273  * @return_value: ignored
1274  * @n_param_values: 2
1275  * @param_values: a #GValue array holding the instance and the flags parameter
1276  * @invocation_hint: the invocation hint given as the last argument
1277  *  to g_closure_invoke()
1278  * @marshal_data: additional data specified when registering the marshaller
1279  *
1280  * A marshaller for a #GCClosure with a callback of type
1281  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes a flags type.
1282  */
1283
1284 /**
1285  * g_cclosure_marshal_VOID__FLOAT:
1286  * @closure: the #GClosure to which the marshaller belongs
1287  * @return_value: ignored
1288  * @n_param_values: 2
1289  * @param_values: a #GValue array holding the instance and the #gfloat parameter
1290  * @invocation_hint: the invocation hint given as the last argument
1291  *  to g_closure_invoke()
1292  * @marshal_data: additional data specified when registering the marshaller
1293  *
1294  * A marshaller for a #GCClosure with a callback of type
1295  * <literal>void (*callback) (gpointer instance, gfloat arg1, gpointer user_data)</literal>.
1296  */
1297
1298 /**
1299  * g_cclosure_marshal_VOID__DOUBLE:
1300  * @closure: the #GClosure to which the marshaller belongs
1301  * @return_value: ignored
1302  * @n_param_values: 2
1303  * @param_values: a #GValue array holding the instance and the #gdouble parameter
1304  * @invocation_hint: the invocation hint given as the last argument
1305  *  to g_closure_invoke()
1306  * @marshal_data: additional data specified when registering the marshaller
1307  *
1308  * A marshaller for a #GCClosure with a callback of type
1309  * <literal>void (*callback) (gpointer instance, gdouble arg1, gpointer user_data)</literal>.
1310  */
1311
1312 /**
1313  * g_cclosure_marshal_VOID__STRING:
1314  * @closure: the #GClosure to which the marshaller belongs
1315  * @return_value: ignored
1316  * @n_param_values: 2
1317  * @param_values: a #GValue array holding the instance and the #gchar* parameter
1318  * @invocation_hint: the invocation hint given as the last argument
1319  *  to g_closure_invoke()
1320  * @marshal_data: additional data specified when registering the marshaller
1321  *
1322  * A marshaller for a #GCClosure with a callback of type
1323  * <literal>void (*callback) (gpointer instance, const gchar *arg1, gpointer user_data)</literal>.
1324  */
1325
1326 /**
1327  * g_cclosure_marshal_VOID__PARAM:
1328  * @closure: the #GClosure to which the marshaller belongs
1329  * @return_value: ignored
1330  * @n_param_values: 2
1331  * @param_values: a #GValue array holding the instance and the #GParamSpec* parameter
1332  * @invocation_hint: the invocation hint given as the last argument
1333  *  to g_closure_invoke()
1334  * @marshal_data: additional data specified when registering the marshaller
1335  *
1336  * A marshaller for a #GCClosure with a callback of type
1337  * <literal>void (*callback) (gpointer instance, GParamSpec *arg1, gpointer user_data)</literal>.
1338  */
1339
1340 /**
1341  * g_cclosure_marshal_VOID__BOXED:
1342  * @closure: the #GClosure to which the marshaller belongs
1343  * @return_value: ignored
1344  * @n_param_values: 2
1345  * @param_values: a #GValue array holding the instance and the #GBoxed* parameter
1346  * @invocation_hint: the invocation hint given as the last argument
1347  *  to g_closure_invoke()
1348  * @marshal_data: additional data specified when registering the marshaller
1349  *
1350  * A marshaller for a #GCClosure with a callback of type
1351  * <literal>void (*callback) (gpointer instance, GBoxed *arg1, gpointer user_data)</literal>.
1352  */
1353
1354 /**
1355  * g_cclosure_marshal_VOID__POINTER:
1356  * @closure: the #GClosure to which the marshaller belongs
1357  * @return_value: ignored
1358  * @n_param_values: 2
1359  * @param_values: a #GValue array holding the instance and the #gpointer parameter
1360  * @invocation_hint: the invocation hint given as the last argument
1361  *  to g_closure_invoke()
1362  * @marshal_data: additional data specified when registering the marshaller
1363  *
1364  * A marshaller for a #GCClosure with a callback of type
1365  * <literal>void (*callback) (gpointer instance, gpointer arg1, gpointer user_data)</literal>.
1366  */
1367
1368 /**
1369  * g_cclosure_marshal_VOID__OBJECT:
1370  * @closure: the #GClosure to which the marshaller belongs
1371  * @return_value: ignored
1372  * @n_param_values: 2
1373  * @param_values: a #GValue array holding the instance and the #GObject* parameter
1374  * @invocation_hint: the invocation hint given as the last argument
1375  *  to g_closure_invoke()
1376  * @marshal_data: additional data specified when registering the marshaller
1377  *
1378  * A marshaller for a #GCClosure with a callback of type
1379  * <literal>void (*callback) (gpointer instance, GObject *arg1, gpointer user_data)</literal>.
1380  */
1381
1382 /**
1383  * g_cclosure_marshal_VOID__VARIANT:
1384  * @closure: the #GClosure to which the marshaller belongs
1385  * @return_value: ignored
1386  * @n_param_values: 2
1387  * @param_values: a #GValue array holding the instance and the #GVariant* parameter
1388  * @invocation_hint: the invocation hint given as the last argument
1389  *  to g_closure_invoke()
1390  * @marshal_data: additional data specified when registering the marshaller
1391  *
1392  * A marshaller for a #GCClosure with a callback of type
1393  * <literal>void (*callback) (gpointer instance, GVariant *arg1, gpointer user_data)</literal>.
1394  *
1395  * Since: 2.26
1396  */
1397
1398 /**
1399  * g_cclosure_marshal_VOID__UINT_POINTER:
1400  * @closure: the #GClosure to which the marshaller belongs
1401  * @return_value: ignored
1402  * @n_param_values: 3
1403  * @param_values: a #GValue array holding instance, arg1 and arg2
1404  * @invocation_hint: the invocation hint given as the last argument
1405  *  to g_closure_invoke()
1406  * @marshal_data: additional data specified when registering the marshaller
1407  *
1408  * A marshaller for a #GCClosure with a callback of type
1409  * <literal>void (*callback) (gpointer instance, guint arg1, gpointer arg2, gpointer user_data)</literal>.
1410  */
1411
1412 /**
1413  * g_cclosure_marshal_BOOLEAN__FLAGS:
1414  * @closure: the #GClosure to which the marshaller belongs
1415  * @return_value: a #GValue which can store the returned #gboolean
1416  * @n_param_values: 2
1417  * @param_values: a #GValue array holding instance and arg1
1418  * @invocation_hint: the invocation hint given as the last argument
1419  *  to g_closure_invoke()
1420  * @marshal_data: additional data specified when registering the marshaller
1421  *
1422  * A marshaller for a #GCClosure with a callback of type
1423  * <literal>gboolean (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter
1424  * denotes a flags type.
1425  */
1426
1427 /**
1428  * g_cclosure_marshal_BOOL__FLAGS:
1429  *
1430  * Another name for g_cclosure_marshal_BOOLEAN__FLAGS().
1431  */
1432 /**
1433  * g_cclosure_marshal_STRING__OBJECT_POINTER:
1434  * @closure: the #GClosure to which the marshaller belongs
1435  * @return_value: a #GValue, which can store the returned string
1436  * @n_param_values: 3
1437  * @param_values: a #GValue array holding instance, arg1 and arg2
1438  * @invocation_hint: the invocation hint given as the last argument
1439  *  to g_closure_invoke()
1440  * @marshal_data: additional data specified when registering the marshaller
1441  *
1442  * A marshaller for a #GCClosure with a callback of type
1443  * <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>.
1444  */
1445 /**
1446  * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED:
1447  * @closure: the #GClosure to which the marshaller belongs
1448  * @return_value: a #GValue, which can store the returned string
1449  * @n_param_values: 3
1450  * @param_values: a #GValue array holding instance, arg1 and arg2
1451  * @invocation_hint: the invocation hint given as the last argument
1452  *  to g_closure_invoke()
1453  * @marshal_data: additional data specified when registering the marshaller
1454  *
1455  * A marshaller for a #GCClosure with a callback of type
1456  * <literal>gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)</literal>.
1457  *
1458  * Since: 2.26
1459  */