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