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