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