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