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