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