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