Spelling fixes
[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 existence 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 initial 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: (allow-none): a #GValue to store the return
733  *                value. May be %NULL if the callback of @closure
734  *                doesn't return a value.
735  * @n_param_values: the length of the @param_values array
736  * @param_values: (array length=n_param_values): an array of
737  *                #GValue<!-- -->s holding the arguments on which to
738  *                invoke the callback of @closure
739  * @invocation_hint: (allow-none): a context-dependent invocation hint
740  *
741  * Invokes the closure, i.e. executes the callback represented by the @closure.
742  */
743 void
744 g_closure_invoke (GClosure       *closure,
745                   GValue /*out*/ *return_value,
746                   guint           n_param_values,
747                   const GValue   *param_values,
748                   gpointer        invocation_hint)
749 {
750   g_return_if_fail (closure != NULL);
751
752   g_closure_ref (closure);      /* preserve floating flag */
753   if (!closure->is_invalid)
754     {
755       GClosureMarshal marshal;
756       gpointer marshal_data;
757       gboolean in_marshal = closure->in_marshal;
758
759       g_return_if_fail (closure->marshal || closure->meta_marshal);
760
761       SET (closure, in_marshal, TRUE);
762       if (closure->meta_marshal)
763         {
764           marshal_data = closure->notifiers[0].data;
765           marshal = (GClosureMarshal) closure->notifiers[0].notify;
766         }
767       else
768         {
769           marshal_data = NULL;
770           marshal = closure->marshal;
771         }
772       if (!in_marshal)
773         closure_invoke_notifiers (closure, PRE_NOTIFY);
774       marshal (closure,
775                return_value,
776                n_param_values, param_values,
777                invocation_hint,
778                marshal_data);
779       if (!in_marshal)
780         closure_invoke_notifiers (closure, POST_NOTIFY);
781       SET (closure, in_marshal, in_marshal);
782     }
783   g_closure_unref (closure);
784 }
785
786 /**
787  * g_closure_set_marshal: (skip)
788  * @closure: a #GClosure
789  * @marshal: a #GClosureMarshal function
790  *
791  * Sets the marshaller of @closure. The <literal>marshal_data</literal>
792  * of @marshal provides a way for a meta marshaller to provide additional
793  * information to the marshaller. (See g_closure_set_meta_marshal().) For
794  * GObject's C predefined marshallers (the g_cclosure_marshal_*()
795  * functions), what it provides is a callback function to use instead of
796  * @closure->callback.
797  */
798 void
799 g_closure_set_marshal (GClosure       *closure,
800                        GClosureMarshal marshal)
801 {
802   g_return_if_fail (closure != NULL);
803   g_return_if_fail (marshal != NULL);
804
805   if (closure->marshal && closure->marshal != marshal)
806     g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)",
807                closure->marshal, marshal);
808   else
809     closure->marshal = marshal;
810 }
811
812 /**
813  * g_cclosure_new: (skip)
814  * @callback_func: the function to invoke
815  * @user_data: user data to pass to @callback_func
816  * @destroy_data: destroy notify to be called when @user_data is no longer used
817  *
818  * Creates a new closure which invokes @callback_func with @user_data as
819  * the last parameter.
820  *
821  * Returns: a new #GCClosure
822  */
823 GClosure*
824 g_cclosure_new (GCallback      callback_func,
825                 gpointer       user_data,
826                 GClosureNotify destroy_data)
827 {
828   GClosure *closure;
829   
830   g_return_val_if_fail (callback_func != NULL, NULL);
831   
832   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
833   if (destroy_data)
834     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
835   ((GCClosure*) closure)->callback = (gpointer) callback_func;
836   
837   return closure;
838 }
839
840 /**
841  * g_cclosure_new_swap: (skip)
842  * @callback_func: the function to invoke
843  * @user_data: user data to pass to @callback_func
844  * @destroy_data: destroy notify to be called when @user_data is no longer used
845  *
846  * Creates a new closure which invokes @callback_func with @user_data as
847  * the first parameter.
848  *
849  * Returns: (transfer full): a new #GCClosure
850  */
851 GClosure*
852 g_cclosure_new_swap (GCallback      callback_func,
853                      gpointer       user_data,
854                      GClosureNotify destroy_data)
855 {
856   GClosure *closure;
857   
858   g_return_val_if_fail (callback_func != NULL, NULL);
859   
860   closure = g_closure_new_simple (sizeof (GCClosure), user_data);
861   if (destroy_data)
862     g_closure_add_finalize_notifier (closure, user_data, destroy_data);
863   ((GCClosure*) closure)->callback = (gpointer) callback_func;
864   SET (closure, derivative_flag, TRUE);
865   
866   return closure;
867 }
868
869 static void
870 g_type_class_meta_marshal (GClosure       *closure,
871                            GValue /*out*/ *return_value,
872                            guint           n_param_values,
873                            const GValue   *param_values,
874                            gpointer        invocation_hint,
875                            gpointer        marshal_data)
876 {
877   GTypeClass *class;
878   gpointer callback;
879   /* GType itype = (GType) closure->data; */
880   guint offset = GPOINTER_TO_UINT (marshal_data);
881   
882   class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
883   callback = G_STRUCT_MEMBER (gpointer, class, offset);
884   if (callback)
885     closure->marshal (closure,
886                       return_value,
887                       n_param_values, param_values,
888                       invocation_hint,
889                       callback);
890 }
891
892 static void
893 g_type_iface_meta_marshal (GClosure       *closure,
894                            GValue /*out*/ *return_value,
895                            guint           n_param_values,
896                            const GValue   *param_values,
897                            gpointer        invocation_hint,
898                            gpointer        marshal_data)
899 {
900   GTypeClass *class;
901   gpointer callback;
902   GType itype = (GType) closure->data;
903   guint offset = GPOINTER_TO_UINT (marshal_data);
904   
905   class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
906   callback = G_STRUCT_MEMBER (gpointer, class, offset);
907   if (callback)
908     closure->marshal (closure,
909                       return_value,
910                       n_param_values, param_values,
911                       invocation_hint,
912                       callback);
913 }
914
915 /**
916  * g_signal_type_cclosure_new:
917  * @itype: the #GType identifier of an interface or classed type
918  * @struct_offset: the offset of the member function of @itype's class
919  *  structure which is to be invoked by the new closure
920  *
921  * Creates a new closure which invokes the function found at the offset
922  * @struct_offset in the class structure of the interface or classed type
923  * identified by @itype.
924  *
925  * Returns: a new #GCClosure
926  */
927 GClosure*
928 g_signal_type_cclosure_new (GType    itype,
929                             guint    struct_offset)
930 {
931   GClosure *closure;
932   
933   g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
934   g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL);
935   
936   closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype);
937   if (G_TYPE_IS_INTERFACE (itype))
938     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal);
939   else
940     g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal);
941   
942   return closure;
943 }
944
945 #include <ffi.h>
946 static ffi_type *
947 value_to_ffi_type (const GValue *gvalue, gpointer *value)
948 {
949   ffi_type *rettype = NULL;
950   GType type = g_type_fundamental (G_VALUE_TYPE (gvalue));
951   g_assert (type != G_TYPE_INVALID);
952
953   switch (type)
954     {
955     case G_TYPE_BOOLEAN:
956     case G_TYPE_CHAR:
957     case G_TYPE_INT:
958     case G_TYPE_ENUM:
959       rettype = &ffi_type_sint;
960       *value = (gpointer)&(gvalue->data[0].v_int);
961       break;
962     case G_TYPE_UCHAR:
963     case G_TYPE_UINT:
964     case G_TYPE_FLAGS:
965       rettype = &ffi_type_uint;
966       *value = (gpointer)&(gvalue->data[0].v_uint);
967       break;
968     case G_TYPE_STRING:
969     case G_TYPE_OBJECT:
970     case G_TYPE_BOXED:
971     case G_TYPE_PARAM:
972     case G_TYPE_POINTER:
973     case G_TYPE_INTERFACE:
974     case G_TYPE_VARIANT:
975       rettype = &ffi_type_pointer;
976       *value = (gpointer)&(gvalue->data[0].v_pointer);
977       break;
978     case G_TYPE_FLOAT:
979       rettype = &ffi_type_float;
980       *value = (gpointer)&(gvalue->data[0].v_float);
981       break;
982     case G_TYPE_DOUBLE:
983       rettype = &ffi_type_double;
984       *value = (gpointer)&(gvalue->data[0].v_double);
985       break;
986     case G_TYPE_LONG:
987       rettype = &ffi_type_slong;
988       *value = (gpointer)&(gvalue->data[0].v_long);
989       break;
990     case G_TYPE_ULONG:
991       rettype = &ffi_type_ulong;
992       *value = (gpointer)&(gvalue->data[0].v_ulong);
993       break;
994     case G_TYPE_INT64:
995       rettype = &ffi_type_sint64;
996       *value = (gpointer)&(gvalue->data[0].v_int64);
997       break;
998     case G_TYPE_UINT64:
999       rettype = &ffi_type_uint64;
1000       *value = (gpointer)&(gvalue->data[0].v_uint64);
1001       break;
1002     default:
1003       rettype = &ffi_type_pointer;
1004       *value = NULL;
1005       g_warning ("value_to_ffi_type: Unsupported fundamental type: %s", g_type_name (type));
1006       break;
1007     }
1008   return rettype;
1009 }
1010
1011 static void
1012 value_from_ffi_type (GValue *gvalue, gpointer *value)
1013 {
1014   switch (g_type_fundamental (G_VALUE_TYPE (gvalue)))
1015     {
1016     case G_TYPE_INT:
1017       g_value_set_int (gvalue, *(gint*)value);
1018       break;
1019     case G_TYPE_FLOAT:
1020       g_value_set_float (gvalue, *(gfloat*)value);
1021       break;
1022     case G_TYPE_DOUBLE:
1023       g_value_set_double (gvalue, *(gdouble*)value);
1024       break;
1025     case G_TYPE_BOOLEAN:
1026       g_value_set_boolean (gvalue, *(gboolean*)value);
1027       break;
1028     case G_TYPE_STRING:
1029       g_value_set_string (gvalue, *(gchar**)value);
1030       break;
1031     case G_TYPE_CHAR:
1032       g_value_set_char (gvalue, *(gchar*)value);
1033       break;
1034     case G_TYPE_UCHAR:
1035       g_value_set_uchar (gvalue, *(guchar*)value);
1036       break;
1037     case G_TYPE_UINT:
1038       g_value_set_uint (gvalue, *(guint*)value);
1039       break;
1040     case G_TYPE_POINTER:
1041       g_value_set_pointer (gvalue, *(gpointer*)value);
1042       break;
1043     case G_TYPE_LONG:
1044       g_value_set_long (gvalue, *(glong*)value);
1045       break;
1046     case G_TYPE_ULONG:
1047       g_value_set_ulong (gvalue, *(gulong*)value);
1048       break;
1049     case G_TYPE_INT64:
1050       g_value_set_int64 (gvalue, *(gint64*)value);
1051       break;
1052     case G_TYPE_UINT64:
1053       g_value_set_uint64 (gvalue, *(guint64*)value);
1054       break;
1055     case G_TYPE_BOXED:
1056       g_value_set_boxed (gvalue, *(gpointer*)value);
1057       break;
1058     case G_TYPE_ENUM:
1059       g_value_set_enum (gvalue, *(gint*)value);
1060       break;
1061     case G_TYPE_FLAGS:
1062       g_value_set_flags (gvalue, *(guint*)value);
1063       break;
1064     case G_TYPE_PARAM:
1065       g_value_set_param (gvalue, *(gpointer*)value);
1066       break;
1067     case G_TYPE_OBJECT:
1068       g_value_set_object (gvalue, *(gpointer*)value);
1069       break;
1070     default:
1071       g_warning ("value_from_ffi_type: Unsupported fundamental type: %s",
1072                 g_type_name (g_type_fundamental (G_VALUE_TYPE (gvalue))));
1073     }
1074 }
1075
1076 /**
1077  * g_cclosure_marshal_generic:
1078  * @closure: A #GClosure.
1079  * @return_gvalue: A #GValue to store the return value. May be %NULL
1080  *   if the callback of closure doesn't return a value.
1081  * @n_param_values: The length of the @param_values array.
1082  * @param_values: An array of #GValue<!-- -->s holding the arguments
1083  *   on which to invoke the callback of closure.
1084  * @invocation_hint: The invocation hint given as the last argument to
1085  *   g_closure_invoke().
1086  * @marshal_data: Additional data specified when registering the
1087  *   marshaller, see g_closure_set_marshal() and
1088  *   g_closure_set_meta_marshal()
1089  *
1090  * A generic marshaller function implemented via <ulink
1091  * url="http://sourceware.org/libffi/">libffi</ulink>.
1092  *
1093  * Since: 2.30
1094  */
1095 void
1096 g_cclosure_marshal_generic (GClosure     *closure,
1097                             GValue       *return_gvalue,
1098                             guint         n_param_values,
1099                             const GValue *param_values,
1100                             gpointer      invocation_hint,
1101                             gpointer      marshal_data)
1102 {
1103   ffi_type *rtype;
1104   void *rvalue;
1105   int n_args;
1106   ffi_type **atypes;
1107   void **args;
1108   int i;
1109   ffi_cif cif;
1110   GCClosure *cc = (GCClosure*) closure;
1111
1112   if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1113     {
1114       rtype = value_to_ffi_type (return_gvalue, &rvalue);
1115     }
1116   else
1117     {
1118       rtype = &ffi_type_void;
1119     }
1120
1121   rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg)));
1122
1123   n_args = n_param_values + 1;
1124   atypes = g_alloca (sizeof (ffi_type *) * n_args);
1125   args =  g_alloca (sizeof (gpointer) * n_args);
1126
1127   if (G_CCLOSURE_SWAP_DATA (closure))
1128     {
1129       atypes[n_args-1] = value_to_ffi_type (param_values + 0,
1130                                             &args[n_args-1]);
1131       atypes[0] = &ffi_type_pointer;
1132       args[0] = &closure->data;
1133     }
1134   else
1135     {
1136       atypes[0] = value_to_ffi_type (param_values + 0, &args[0]);
1137       atypes[n_args-1] = &ffi_type_pointer;
1138       args[n_args-1] = &closure->data;
1139     }
1140
1141   for (i = 1; i < n_args - 1; i++)
1142     atypes[i] = value_to_ffi_type (param_values + i, &args[i]);
1143
1144   if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, n_args, rtype, atypes) != FFI_OK)
1145     return;
1146
1147   ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args);
1148
1149   if (return_gvalue && G_VALUE_TYPE (return_gvalue))
1150     value_from_ffi_type (return_gvalue, rvalue);
1151 }
1152
1153 /**
1154  * g_cclosure_marshal_VOID__VOID:
1155  * @closure: the #GClosure to which the marshaller belongs
1156  * @return_value: ignored
1157  * @n_param_values: 1
1158  * @param_values: a #GValue array holding only the instance
1159  * @invocation_hint: the invocation hint given as the last argument
1160  *  to g_closure_invoke()
1161  * @marshal_data: additional data specified when registering the marshaller
1162  *
1163  * A marshaller for a #GCClosure with a callback of type
1164  * <literal>void (*callback) (gpointer instance, gpointer user_data)</literal>.
1165  */
1166
1167 /**
1168  * g_cclosure_marshal_VOID__BOOLEAN:
1169  * @closure: the #GClosure to which the marshaller belongs
1170  * @return_value: ignored
1171  * @n_param_values: 2
1172  * @param_values: a #GValue array holding the instance and the #gboolean parameter
1173  * @invocation_hint: the invocation hint given as the last argument
1174  *  to g_closure_invoke()
1175  * @marshal_data: additional data specified when registering the marshaller
1176  *
1177  * A marshaller for a #GCClosure with a callback of type
1178  * <literal>void (*callback) (gpointer instance, gboolean arg1, gpointer user_data)</literal>.
1179  */
1180
1181 /**
1182  * g_cclosure_marshal_VOID__CHAR:
1183  * @closure: the #GClosure to which the marshaller belongs
1184  * @return_value: ignored
1185  * @n_param_values: 2
1186  * @param_values: a #GValue array holding the instance and the #gchar parameter
1187  * @invocation_hint: the invocation hint given as the last argument
1188  *  to g_closure_invoke()
1189  * @marshal_data: additional data specified when registering the marshaller
1190  *
1191  * A marshaller for a #GCClosure with a callback of type
1192  * <literal>void (*callback) (gpointer instance, gchar arg1, gpointer user_data)</literal>.
1193  */
1194
1195 /**
1196  * g_cclosure_marshal_VOID__UCHAR:
1197  * @closure: the #GClosure to which the marshaller belongs
1198  * @return_value: ignored
1199  * @n_param_values: 2
1200  * @param_values: a #GValue array holding the instance and the #guchar parameter
1201  * @invocation_hint: the invocation hint given as the last argument
1202  *  to g_closure_invoke()
1203  * @marshal_data: additional data specified when registering the marshaller
1204  *
1205  * A marshaller for a #GCClosure with a callback of type
1206  * <literal>void (*callback) (gpointer instance, guchar arg1, gpointer user_data)</literal>.
1207  */
1208
1209 /**
1210  * g_cclosure_marshal_VOID__INT:
1211  * @closure: the #GClosure to which the marshaller belongs
1212  * @return_value: ignored
1213  * @n_param_values: 2
1214  * @param_values: a #GValue array holding the instance and the #gint parameter
1215  * @invocation_hint: the invocation hint given as the last argument
1216  *  to g_closure_invoke()
1217  * @marshal_data: additional data specified when registering the marshaller
1218  *
1219  * A marshaller for a #GCClosure with a callback of type
1220  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal>.
1221  */
1222
1223 /**
1224  * g_cclosure_marshal_VOID__UINT:
1225  * @closure: the #GClosure to which the marshaller belongs
1226  * @return_value: ignored
1227  * @n_param_values: 2
1228  * @param_values: a #GValue array holding the instance and the #guint parameter
1229  * @invocation_hint: the invocation hint given as the last argument
1230  *  to g_closure_invoke()
1231  * @marshal_data: additional data specified when registering the marshaller
1232  *
1233  * A marshaller for a #GCClosure with a callback of type
1234  * <literal>void (*callback) (gpointer instance, guint arg1, gpointer user_data)</literal>.
1235  */
1236
1237 /**
1238  * g_cclosure_marshal_VOID__LONG:
1239  * @closure: the #GClosure to which the marshaller belongs
1240  * @return_value: ignored
1241  * @n_param_values: 2
1242  * @param_values: a #GValue array holding the instance and the #glong parameter
1243  * @invocation_hint: the invocation hint given as the last argument
1244  *  to g_closure_invoke()
1245  * @marshal_data: additional data specified when registering the marshaller
1246  *
1247  * A marshaller for a #GCClosure with a callback of type
1248  * <literal>void (*callback) (gpointer instance, glong arg1, gpointer user_data)</literal>.
1249  */
1250
1251 /**
1252  * g_cclosure_marshal_VOID__ULONG:
1253  * @closure: the #GClosure to which the marshaller belongs
1254  * @return_value: ignored
1255  * @n_param_values: 2
1256  * @param_values: a #GValue array holding the instance and the #gulong parameter
1257  * @invocation_hint: the invocation hint given as the last argument
1258  *  to g_closure_invoke()
1259  * @marshal_data: additional data specified when registering the marshaller
1260  *
1261  * A marshaller for a #GCClosure with a callback of type
1262  * <literal>void (*callback) (gpointer instance, gulong arg1, gpointer user_data)</literal>.
1263  */
1264
1265 /**
1266  * g_cclosure_marshal_VOID__ENUM:
1267  * @closure: the #GClosure to which the marshaller belongs
1268  * @return_value: ignored
1269  * @n_param_values: 2
1270  * @param_values: a #GValue array holding the instance and the enumeration parameter
1271  * @invocation_hint: the invocation hint given as the last argument
1272  *  to g_closure_invoke()
1273  * @marshal_data: additional data specified when registering the marshaller
1274  *
1275  * A marshaller for a #GCClosure with a callback of type
1276  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes an enumeration type..
1277  */
1278
1279 /**
1280  * g_cclosure_marshal_VOID__FLAGS:
1281  * @closure: the #GClosure to which the marshaller belongs
1282  * @return_value: ignored
1283  * @n_param_values: 2
1284  * @param_values: a #GValue array holding the instance and the flags parameter
1285  * @invocation_hint: the invocation hint given as the last argument
1286  *  to g_closure_invoke()
1287  * @marshal_data: additional data specified when registering the marshaller
1288  *
1289  * A marshaller for a #GCClosure with a callback of type
1290  * <literal>void (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter denotes a flags type.
1291  */
1292
1293 /**
1294  * g_cclosure_marshal_VOID__FLOAT:
1295  * @closure: the #GClosure to which the marshaller belongs
1296  * @return_value: ignored
1297  * @n_param_values: 2
1298  * @param_values: a #GValue array holding the instance and the #gfloat parameter
1299  * @invocation_hint: the invocation hint given as the last argument
1300  *  to g_closure_invoke()
1301  * @marshal_data: additional data specified when registering the marshaller
1302  *
1303  * A marshaller for a #GCClosure with a callback of type
1304  * <literal>void (*callback) (gpointer instance, gfloat arg1, gpointer user_data)</literal>.
1305  */
1306
1307 /**
1308  * g_cclosure_marshal_VOID__DOUBLE:
1309  * @closure: the #GClosure to which the marshaller belongs
1310  * @return_value: ignored
1311  * @n_param_values: 2
1312  * @param_values: a #GValue array holding the instance and the #gdouble parameter
1313  * @invocation_hint: the invocation hint given as the last argument
1314  *  to g_closure_invoke()
1315  * @marshal_data: additional data specified when registering the marshaller
1316  *
1317  * A marshaller for a #GCClosure with a callback of type
1318  * <literal>void (*callback) (gpointer instance, gdouble arg1, gpointer user_data)</literal>.
1319  */
1320
1321 /**
1322  * g_cclosure_marshal_VOID__STRING:
1323  * @closure: the #GClosure to which the marshaller belongs
1324  * @return_value: ignored
1325  * @n_param_values: 2
1326  * @param_values: a #GValue array holding the instance and the #gchar* parameter
1327  * @invocation_hint: the invocation hint given as the last argument
1328  *  to g_closure_invoke()
1329  * @marshal_data: additional data specified when registering the marshaller
1330  *
1331  * A marshaller for a #GCClosure with a callback of type
1332  * <literal>void (*callback) (gpointer instance, const gchar *arg1, gpointer user_data)</literal>.
1333  */
1334
1335 /**
1336  * g_cclosure_marshal_VOID__PARAM:
1337  * @closure: the #GClosure to which the marshaller belongs
1338  * @return_value: ignored
1339  * @n_param_values: 2
1340  * @param_values: a #GValue array holding the instance and the #GParamSpec* parameter
1341  * @invocation_hint: the invocation hint given as the last argument
1342  *  to g_closure_invoke()
1343  * @marshal_data: additional data specified when registering the marshaller
1344  *
1345  * A marshaller for a #GCClosure with a callback of type
1346  * <literal>void (*callback) (gpointer instance, GParamSpec *arg1, gpointer user_data)</literal>.
1347  */
1348
1349 /**
1350  * g_cclosure_marshal_VOID__BOXED:
1351  * @closure: the #GClosure to which the marshaller belongs
1352  * @return_value: ignored
1353  * @n_param_values: 2
1354  * @param_values: a #GValue array holding the instance and the #GBoxed* parameter
1355  * @invocation_hint: the invocation hint given as the last argument
1356  *  to g_closure_invoke()
1357  * @marshal_data: additional data specified when registering the marshaller
1358  *
1359  * A marshaller for a #GCClosure with a callback of type
1360  * <literal>void (*callback) (gpointer instance, GBoxed *arg1, gpointer user_data)</literal>.
1361  */
1362
1363 /**
1364  * g_cclosure_marshal_VOID__POINTER:
1365  * @closure: the #GClosure to which the marshaller belongs
1366  * @return_value: ignored
1367  * @n_param_values: 2
1368  * @param_values: a #GValue array holding the instance and the #gpointer parameter
1369  * @invocation_hint: the invocation hint given as the last argument
1370  *  to g_closure_invoke()
1371  * @marshal_data: additional data specified when registering the marshaller
1372  *
1373  * A marshaller for a #GCClosure with a callback of type
1374  * <literal>void (*callback) (gpointer instance, gpointer arg1, gpointer user_data)</literal>.
1375  */
1376
1377 /**
1378  * g_cclosure_marshal_VOID__OBJECT:
1379  * @closure: the #GClosure to which the marshaller belongs
1380  * @return_value: ignored
1381  * @n_param_values: 2
1382  * @param_values: a #GValue array holding the instance and the #GObject* parameter
1383  * @invocation_hint: the invocation hint given as the last argument
1384  *  to g_closure_invoke()
1385  * @marshal_data: additional data specified when registering the marshaller
1386  *
1387  * A marshaller for a #GCClosure with a callback of type
1388  * <literal>void (*callback) (gpointer instance, GObject *arg1, gpointer user_data)</literal>.
1389  */
1390
1391 /**
1392  * g_cclosure_marshal_VOID__VARIANT:
1393  * @closure: the #GClosure to which the marshaller belongs
1394  * @return_value: ignored
1395  * @n_param_values: 2
1396  * @param_values: a #GValue array holding the instance and the #GVariant* parameter
1397  * @invocation_hint: the invocation hint given as the last argument
1398  *  to g_closure_invoke()
1399  * @marshal_data: additional data specified when registering the marshaller
1400  *
1401  * A marshaller for a #GCClosure with a callback of type
1402  * <literal>void (*callback) (gpointer instance, GVariant *arg1, gpointer user_data)</literal>.
1403  *
1404  * Since: 2.26
1405  */
1406
1407 /**
1408  * g_cclosure_marshal_VOID__UINT_POINTER:
1409  * @closure: the #GClosure to which the marshaller belongs
1410  * @return_value: ignored
1411  * @n_param_values: 3
1412  * @param_values: a #GValue array holding instance, arg1 and arg2
1413  * @invocation_hint: the invocation hint given as the last argument
1414  *  to g_closure_invoke()
1415  * @marshal_data: additional data specified when registering the marshaller
1416  *
1417  * A marshaller for a #GCClosure with a callback of type
1418  * <literal>void (*callback) (gpointer instance, guint arg1, gpointer arg2, gpointer user_data)</literal>.
1419  */
1420
1421 /**
1422  * g_cclosure_marshal_BOOLEAN__FLAGS:
1423  * @closure: the #GClosure to which the marshaller belongs
1424  * @return_value: a #GValue which can store the returned #gboolean
1425  * @n_param_values: 2
1426  * @param_values: a #GValue array holding instance and arg1
1427  * @invocation_hint: the invocation hint given as the last argument
1428  *  to g_closure_invoke()
1429  * @marshal_data: additional data specified when registering the marshaller
1430  *
1431  * A marshaller for a #GCClosure with a callback of type
1432  * <literal>gboolean (*callback) (gpointer instance, gint arg1, gpointer user_data)</literal> where the #gint parameter
1433  * denotes a flags type.
1434  */
1435
1436 /**
1437  * g_cclosure_marshal_BOOL__FLAGS:
1438  *
1439  * Another name for g_cclosure_marshal_BOOLEAN__FLAGS().
1440  */
1441 /**
1442  * g_cclosure_marshal_STRING__OBJECT_POINTER:
1443  * @closure: the #GClosure to which the marshaller belongs
1444  * @return_value: a #GValue, which can store the returned string
1445  * @n_param_values: 3
1446  * @param_values: a #GValue array holding instance, arg1 and arg2
1447  * @invocation_hint: the invocation hint given as the last argument
1448  *  to g_closure_invoke()
1449  * @marshal_data: additional data specified when registering the marshaller
1450  *
1451  * A marshaller for a #GCClosure with a callback of type
1452  * <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>.
1453  */
1454 /**
1455  * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED:
1456  * @closure: the #GClosure to which the marshaller belongs
1457  * @return_value: a #GValue, which can store the returned string
1458  * @n_param_values: 3
1459  * @param_values: a #GValue array holding instance, arg1 and arg2
1460  * @invocation_hint: the invocation hint given as the last argument
1461  *  to g_closure_invoke()
1462  * @marshal_data: additional data specified when registering the marshaller
1463  *
1464  * A marshaller for a #GCClosure with a callback of type
1465  * <literal>gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)</literal>.
1466  *
1467  * Since: 2.26
1468  */