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