Blame gobject/gclosure.c

Packit ae235b
/* GObject - GLib Type, Object, Parameter and Signal Library
Packit ae235b
 * Copyright (C) 2000-2001 Red Hat, Inc.
Packit ae235b
 * Copyright (C) 2005 Imendio AB
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/*
Packit ae235b
 * MT safe with regards to reference counting.
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include "../glib/valgrind.h"
Packit ae235b
#include <string.h>
Packit ae235b
Packit ae235b
#include <ffi.h>
Packit ae235b
Packit ae235b
#include "gclosure.h"
Packit ae235b
#include "gboxed.h"
Packit ae235b
#include "gobject.h"
Packit ae235b
#include "genums.h"
Packit ae235b
#include "gvalue.h"
Packit ae235b
#include "gvaluetypes.h"
Packit ae235b
#include "gtype-private.h"
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gclosure
Packit ae235b
 * @short_description: Functions as first-class objects
Packit ae235b
 * @title: Closures
Packit ae235b
 *
Packit ae235b
 * A #GClosure represents a callback supplied by the programmer. It
Packit ae235b
 * will generally comprise a function of some kind and a marshaller
Packit ae235b
 * used to call it. It is the responsibility of the marshaller to
Packit ae235b
 * convert the arguments for the invocation from #GValues into
Packit ae235b
 * a suitable form, perform the callback on the converted arguments,
Packit ae235b
 * and transform the return value back into a #GValue.
Packit ae235b
 *
Packit ae235b
 * In the case of C programs, a closure usually just holds a pointer
Packit ae235b
 * to a function and maybe a data argument, and the marshaller
Packit ae235b
 * converts between #GValue and native C types. The GObject
Packit ae235b
 * library provides the #GCClosure type for this purpose. Bindings for
Packit ae235b
 * other languages need marshallers which convert between #GValues
Packit ae235b
 * and suitable representations in the runtime of the language in
Packit ae235b
 * order to use functions written in that languages as callbacks.
Packit ae235b
 *
Packit ae235b
 * Within GObject, closures play an important role in the
Packit ae235b
 * implementation of signals. When a signal is registered, the
Packit ae235b
 * @c_marshaller argument to g_signal_new() specifies the default C
Packit ae235b
 * marshaller for any closure which is connected to this
Packit ae235b
 * signal. GObject provides a number of C marshallers for this
Packit ae235b
 * purpose, see the g_cclosure_marshal_*() functions. Additional C
Packit ae235b
 * marshallers can be generated with the [glib-genmarshal][glib-genmarshal]
Packit ae235b
 * utility.  Closures can be explicitly connected to signals with
Packit ae235b
 * g_signal_connect_closure(), but it usually more convenient to let
Packit ae235b
 * GObject create a closure automatically by using one of the
Packit ae235b
 * g_signal_connect_*() functions which take a callback function/user
Packit ae235b
 * data pair.
Packit ae235b
 *
Packit ae235b
 * Using closures has a number of important advantages over a simple
Packit ae235b
 * callback function/data pointer combination:
Packit ae235b
 * 
Packit ae235b
 * - Closures allow the callee to get the types of the callback parameters,
Packit ae235b
 *   which means that language bindings don't have to write individual glue
Packit ae235b
 *   for each callback type.
Packit ae235b
 *
Packit ae235b
 * - The reference counting of #GClosure makes it easy to handle reentrancy
Packit ae235b
 *   right; if a callback is removed while it is being invoked, the closure
Packit ae235b
 *   and its parameters won't be freed until the invocation finishes.
Packit ae235b
 *
Packit ae235b
 * - g_closure_invalidate() and invalidation notifiers allow callbacks to be
Packit ae235b
 *   automatically removed when the objects they point to go away.
Packit ae235b
 */
Packit ae235b
Packit ae235b
#define	CLOSURE_MAX_REF_COUNT		((1 << 15) - 1)
Packit ae235b
#define	CLOSURE_MAX_N_GUARDS		((1 << 1) - 1)
Packit ae235b
#define	CLOSURE_MAX_N_FNOTIFIERS	((1 << 2) - 1)
Packit ae235b
#define	CLOSURE_MAX_N_INOTIFIERS	((1 << 8) - 1)
Packit ae235b
#define	CLOSURE_N_MFUNCS(cl)		(((cl)->n_guards << 1L))
Packit ae235b
/* same as G_CLOSURE_N_NOTIFIERS() (keep in sync) */
Packit ae235b
#define	CLOSURE_N_NOTIFIERS(cl)		(CLOSURE_N_MFUNCS (cl) + \
Packit ae235b
                                         (cl)->n_fnotifiers + \
Packit ae235b
                                         (cl)->n_inotifiers)
Packit ae235b
Packit ae235b
typedef union {
Packit ae235b
  GClosure closure;
Packit ae235b
  volatile gint vint;
Packit ae235b
} ClosureInt;
Packit ae235b
Packit ae235b
#define CHANGE_FIELD(_closure, _field, _OP, _value, _must_set, _SET_OLD, _SET_NEW)      \
Packit ae235b
G_STMT_START {                                                                          \
Packit ae235b
  ClosureInt *cunion = (ClosureInt*) _closure;                 		                \
Packit ae235b
  gint new_int, old_int, success;                              		                \
Packit ae235b
  do                                                    		                \
Packit ae235b
    {                                                   		                \
Packit ae235b
      ClosureInt tmp;                                   		                \
Packit ae235b
      tmp.vint = old_int = cunion->vint;                		                \
Packit ae235b
      _SET_OLD tmp.closure._field;                                                      \
Packit ae235b
      tmp.closure._field _OP _value;                      		                \
Packit ae235b
      _SET_NEW tmp.closure._field;                                                      \
Packit ae235b
      new_int = tmp.vint;                               		                \
Packit ae235b
      success = g_atomic_int_compare_and_exchange (&cunion->vint, old_int, new_int);    \
Packit ae235b
    }                                                   		                \
Packit ae235b
  while (!success && _must_set);                                                        \
Packit ae235b
} G_STMT_END
Packit ae235b
Packit ae235b
#define SWAP(_closure, _field, _value, _oldv)   CHANGE_FIELD (_closure, _field, =, _value, TRUE, *(_oldv) =,     (void) )
Packit ae235b
#define SET(_closure, _field, _value)           CHANGE_FIELD (_closure, _field, =, _value, TRUE,     (void),     (void) )
Packit ae235b
#define INC(_closure, _field)                   CHANGE_FIELD (_closure, _field, +=,     1, TRUE,     (void),     (void) )
Packit ae235b
#define INC_ASSIGN(_closure, _field, _newv)     CHANGE_FIELD (_closure, _field, +=,     1, TRUE,     (void), *(_newv) = )
Packit ae235b
#define DEC(_closure, _field)                   CHANGE_FIELD (_closure, _field, -=,     1, TRUE,     (void),     (void) )
Packit ae235b
#define DEC_ASSIGN(_closure, _field, _newv)     CHANGE_FIELD (_closure, _field, -=,     1, TRUE,     (void), *(_newv) = )
Packit ae235b
Packit ae235b
#if 0   /* for non-thread-safe closures */
Packit ae235b
#define SWAP(cl,f,v,o)     (void) (*(o) = cl->f, cl->f = v)
Packit ae235b
#define SET(cl,f,v)        (void) (cl->f = v)
Packit ae235b
#define INC(cl,f)          (void) (cl->f += 1)
Packit ae235b
#define INC_ASSIGN(cl,f,n) (void) (cl->f += 1, *(n) = cl->f)
Packit ae235b
#define DEC(cl,f)          (void) (cl->f -= 1)
Packit ae235b
#define DEC_ASSIGN(cl,f,n) (void) (cl->f -= 1, *(n) = cl->f)
Packit ae235b
#endif
Packit ae235b
Packit ae235b
enum {
Packit ae235b
  FNOTIFY,
Packit ae235b
  INOTIFY,
Packit ae235b
  PRE_NOTIFY,
Packit ae235b
  POST_NOTIFY
Packit ae235b
};
Packit ae235b
Packit ae235b
Packit ae235b
/* --- functions --- */
Packit ae235b
/**
Packit ae235b
 * g_closure_new_simple:
Packit ae235b
 * @sizeof_closure: the size of the structure to allocate, must be at least
Packit ae235b
 *                  `sizeof (GClosure)`
Packit ae235b
 * @data: data to store in the @data field of the newly allocated #GClosure
Packit ae235b
 *
Packit ae235b
 * Allocates a struct of the given size and initializes the initial
Packit ae235b
 * part as a #GClosure. This function is mainly useful when
Packit ae235b
 * implementing new types of closures.
Packit ae235b
 *
Packit ae235b
 * |[ 
Packit ae235b
 * typedef struct _MyClosure MyClosure;
Packit ae235b
 * struct _MyClosure
Packit ae235b
 * {
Packit ae235b
 *   GClosure closure;
Packit ae235b
 *   // extra data goes here
Packit ae235b
 * };
Packit ae235b
 *
Packit ae235b
 * static void
Packit ae235b
 * my_closure_finalize (gpointer  notify_data,
Packit ae235b
 *                      GClosure *closure)
Packit ae235b
 * {
Packit ae235b
 *   MyClosure *my_closure = (MyClosure *)closure;
Packit ae235b
 *
Packit ae235b
 *   // free extra data here
Packit ae235b
 * }
Packit ae235b
 *
Packit ae235b
 * MyClosure *my_closure_new (gpointer data)
Packit ae235b
 * {
Packit ae235b
 *   GClosure *closure;
Packit ae235b
 *   MyClosure *my_closure;
Packit ae235b
 *
Packit ae235b
 *   closure = g_closure_new_simple (sizeof (MyClosure), data);
Packit ae235b
 *   my_closure = (MyClosure *) closure;
Packit ae235b
 *
Packit ae235b
 *   // initialize extra data here
Packit ae235b
 *
Packit ae235b
 *   g_closure_add_finalize_notifier (closure, notify_data,
Packit ae235b
 *                                    my_closure_finalize);
Packit ae235b
 *   return my_closure;
Packit ae235b
 * }
Packit ae235b
 * ]|
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): a floating reference to a new #GClosure
Packit ae235b
 */
Packit ae235b
GClosure*
Packit ae235b
g_closure_new_simple (guint           sizeof_closure,
Packit ae235b
		      gpointer        data)
Packit ae235b
{
Packit ae235b
  GClosure *closure;
Packit ae235b
  gint private_size;
Packit ae235b
  gchar *allocated;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL);
Packit ae235b
Packit ae235b
  private_size = sizeof (GRealClosure) - sizeof (GClosure);
Packit ae235b
Packit ae235b
  /* See comments in gtype.c about what's going on here... */
Packit ae235b
  if (RUNNING_ON_VALGRIND)
Packit ae235b
    {
Packit ae235b
      private_size += sizeof (gpointer);
Packit ae235b
Packit ae235b
      allocated = g_malloc0 (private_size + sizeof_closure + sizeof (gpointer));
Packit ae235b
Packit ae235b
      *(gpointer *) (allocated + private_size + sizeof_closure) = allocated + sizeof (gpointer);
Packit ae235b
Packit ae235b
      VALGRIND_MALLOCLIKE_BLOCK (allocated + private_size, sizeof_closure + sizeof (gpointer), 0, TRUE);
Packit ae235b
      VALGRIND_MALLOCLIKE_BLOCK (allocated + sizeof (gpointer), private_size - sizeof (gpointer), 0, TRUE);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    allocated = g_malloc0 (private_size + sizeof_closure);
Packit ae235b
Packit ae235b
  closure = (GClosure *) (allocated + private_size);
Packit ae235b
Packit ae235b
  SET (closure, ref_count, 1);
Packit ae235b
  SET (closure, floating, TRUE);
Packit ae235b
  closure->data = data;
Packit ae235b
Packit ae235b
  return closure;
Packit ae235b
}
Packit ae235b
Packit ae235b
static inline void
Packit ae235b
closure_invoke_notifiers (GClosure *closure,
Packit ae235b
			  guint     notify_type)
Packit ae235b
{
Packit ae235b
  /* notifier layout:
Packit ae235b
   *     n_guards    n_guards     n_fnotif.  n_inotifiers
Packit ae235b
   * ->[[pre_guards][post_guards][fnotifiers][inotifiers]]
Packit ae235b
   *
Packit ae235b
   * CLOSURE_N_MFUNCS(cl)    = n_guards + n_guards;
Packit ae235b
   * CLOSURE_N_NOTIFIERS(cl) = CLOSURE_N_MFUNCS(cl) + n_fnotifiers + n_inotifiers
Packit ae235b
   *
Packit ae235b
   * constrains/catches:
Packit ae235b
   * - closure->notifiers may be reloacted during callback
Packit ae235b
   * - closure->n_fnotifiers and closure->n_inotifiers may change during callback
Packit ae235b
   * - i.e. callbacks can be removed/added during invocation
Packit ae235b
   * - must prepare for callback removal during FNOTIFY and INOTIFY (done via ->marshal= & ->data=)
Packit ae235b
   * - must distinguish (->marshal= & ->data=) for INOTIFY vs. FNOTIFY (via ->in_inotify)
Packit ae235b
   * + closure->n_guards is const during PRE_NOTIFY & POST_NOTIFY
Packit ae235b
   * + none of the callbacks can cause recursion
Packit ae235b
   * + closure->n_inotifiers is const 0 during FNOTIFY
Packit ae235b
   */
Packit ae235b
  switch (notify_type)
Packit ae235b
    {
Packit ae235b
      GClosureNotifyData *ndata;
Packit ae235b
      guint i, offs;
Packit ae235b
    case FNOTIFY:
Packit ae235b
      while (closure->n_fnotifiers)
Packit ae235b
	{
Packit ae235b
          guint n;
Packit ae235b
	  DEC_ASSIGN (closure, n_fnotifiers, &n);
Packit ae235b
Packit ae235b
	  ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + n;
Packit ae235b
	  closure->marshal = (GClosureMarshal) ndata->notify;
Packit ae235b
	  closure->data = ndata->data;
Packit ae235b
	  ndata->notify (ndata->data, closure);
Packit ae235b
	}
Packit ae235b
      closure->marshal = NULL;
Packit ae235b
      closure->data = NULL;
Packit ae235b
      break;
Packit ae235b
    case INOTIFY:
Packit ae235b
      SET (closure, in_inotify, TRUE);
Packit ae235b
      while (closure->n_inotifiers)
Packit ae235b
	{
Packit ae235b
          guint n;
Packit ae235b
          DEC_ASSIGN (closure, n_inotifiers, &n);
Packit ae235b
Packit ae235b
	  ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n;
Packit ae235b
	  closure->marshal = (GClosureMarshal) ndata->notify;
Packit ae235b
	  closure->data = ndata->data;
Packit ae235b
	  ndata->notify (ndata->data, closure);
Packit ae235b
	}
Packit ae235b
      closure->marshal = NULL;
Packit ae235b
      closure->data = NULL;
Packit ae235b
      SET (closure, in_inotify, FALSE);
Packit ae235b
      break;
Packit ae235b
    case PRE_NOTIFY:
Packit ae235b
      i = closure->n_guards;
Packit ae235b
      offs = 0;
Packit ae235b
      while (i--)
Packit ae235b
	{
Packit ae235b
	  ndata = closure->notifiers + offs + i;
Packit ae235b
	  ndata->notify (ndata->data, closure);
Packit ae235b
	}
Packit ae235b
      break;
Packit ae235b
    case POST_NOTIFY:
Packit ae235b
      i = closure->n_guards;
Packit ae235b
      offs = i;
Packit ae235b
      while (i--)
Packit ae235b
	{
Packit ae235b
	  ndata = closure->notifiers + offs + i;
Packit ae235b
	  ndata->notify (ndata->data, closure);
Packit ae235b
	}
Packit ae235b
      break;
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_closure_set_meta_va_marshal (GClosure       *closure,
Packit ae235b
			       GVaClosureMarshal va_meta_marshal)
Packit ae235b
{
Packit ae235b
  GRealClosure *real_closure;
Packit ae235b
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
  g_return_if_fail (va_meta_marshal != NULL);
Packit ae235b
  g_return_if_fail (closure->is_invalid == FALSE);
Packit ae235b
  g_return_if_fail (closure->in_marshal == FALSE);
Packit ae235b
Packit ae235b
  real_closure = G_REAL_CLOSURE (closure);
Packit ae235b
Packit ae235b
  g_return_if_fail (real_closure->meta_marshal != NULL);
Packit ae235b
Packit ae235b
  real_closure->va_meta_marshal = va_meta_marshal;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_set_meta_marshal: (skip)
Packit ae235b
 * @closure: a #GClosure
Packit ae235b
 * @marshal_data: (closure meta_marshal): context-dependent data to pass
Packit ae235b
 *  to @meta_marshal
Packit ae235b
 * @meta_marshal: a #GClosureMarshal function
Packit ae235b
 *
Packit ae235b
 * Sets the meta marshaller of @closure.  A meta marshaller wraps
Packit ae235b
 * @closure->marshal and modifies the way it is called in some
Packit ae235b
 * fashion. The most common use of this facility is for C callbacks.
Packit ae235b
 * The same marshallers (generated by [glib-genmarshal][glib-genmarshal]),
Packit ae235b
 * are used everywhere, but the way that we get the callback function
Packit ae235b
 * differs. In most cases we want to use @closure->callback, but in
Packit ae235b
 * other cases we want to use some different technique to retrieve the
Packit ae235b
 * callback function.
Packit ae235b
 *
Packit ae235b
 * For example, class closures for signals (see
Packit ae235b
 * g_signal_type_cclosure_new()) retrieve the callback function from a
Packit ae235b
 * fixed offset in the class structure.  The meta marshaller retrieves
Packit ae235b
 * the right callback and passes it to the marshaller as the
Packit ae235b
 * @marshal_data argument.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_closure_set_meta_marshal (GClosure       *closure,
Packit ae235b
			    gpointer        marshal_data,
Packit ae235b
			    GClosureMarshal meta_marshal)
Packit ae235b
{
Packit ae235b
  GRealClosure *real_closure;
Packit ae235b
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
  g_return_if_fail (meta_marshal != NULL);
Packit ae235b
  g_return_if_fail (closure->is_invalid == FALSE);
Packit ae235b
  g_return_if_fail (closure->in_marshal == FALSE);
Packit ae235b
Packit ae235b
  real_closure = G_REAL_CLOSURE (closure);
Packit ae235b
Packit ae235b
  g_return_if_fail (real_closure->meta_marshal == NULL);
Packit ae235b
Packit ae235b
  real_closure->meta_marshal = meta_marshal;
Packit ae235b
  real_closure->meta_marshal_data = marshal_data;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_add_marshal_guards: (skip)
Packit ae235b
 * @closure: a #GClosure
Packit ae235b
 * @pre_marshal_data: (closure pre_marshal_notify): data to pass
Packit ae235b
 *  to @pre_marshal_notify
Packit ae235b
 * @pre_marshal_notify: a function to call before the closure callback
Packit ae235b
 * @post_marshal_data: (closure post_marshal_notify): data to pass
Packit ae235b
 *  to @post_marshal_notify
Packit ae235b
 * @post_marshal_notify: a function to call after the closure callback
Packit ae235b
 *
Packit ae235b
 * Adds a pair of notifiers which get invoked before and after the
Packit ae235b
 * closure callback, respectively. This is typically used to protect
Packit ae235b
 * the extra arguments for the duration of the callback. See
Packit ae235b
 * g_object_watch_closure() for an example of marshal guards.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_closure_add_marshal_guards (GClosure      *closure,
Packit ae235b
			      gpointer       pre_marshal_data,
Packit ae235b
			      GClosureNotify pre_marshal_notify,
Packit ae235b
			      gpointer       post_marshal_data,
Packit ae235b
			      GClosureNotify post_marshal_notify)
Packit ae235b
{
Packit ae235b
  guint i;
Packit ae235b
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
  g_return_if_fail (pre_marshal_notify != NULL);
Packit ae235b
  g_return_if_fail (post_marshal_notify != NULL);
Packit ae235b
  g_return_if_fail (closure->is_invalid == FALSE);
Packit ae235b
  g_return_if_fail (closure->in_marshal == FALSE);
Packit ae235b
  g_return_if_fail (closure->n_guards < CLOSURE_MAX_N_GUARDS);
Packit ae235b
Packit ae235b
  closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2);
Packit ae235b
  if (closure->n_inotifiers)
Packit ae235b
    closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
Packit ae235b
			closure->n_fnotifiers +
Packit ae235b
			closure->n_inotifiers + 1)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
Packit ae235b
									  closure->n_fnotifiers + 0)];
Packit ae235b
  if (closure->n_inotifiers > 1)
Packit ae235b
    closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
Packit ae235b
			closure->n_fnotifiers +
Packit ae235b
			closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
Packit ae235b
								      closure->n_fnotifiers + 1)];
Packit ae235b
  if (closure->n_fnotifiers)
Packit ae235b
    closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
Packit ae235b
			closure->n_fnotifiers + 1)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 0];
Packit ae235b
  if (closure->n_fnotifiers > 1)
Packit ae235b
    closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
Packit ae235b
			closure->n_fnotifiers)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 1];
Packit ae235b
  if (closure->n_guards)
Packit ae235b
    closure->notifiers[(closure->n_guards +
Packit ae235b
			closure->n_guards + 1)] = closure->notifiers[closure->n_guards];
Packit ae235b
  i = closure->n_guards;
Packit ae235b
  closure->notifiers[i].data = pre_marshal_data;
Packit ae235b
  closure->notifiers[i].notify = pre_marshal_notify;
Packit ae235b
  closure->notifiers[i + 1].data = post_marshal_data;
Packit ae235b
  closure->notifiers[i + 1].notify = post_marshal_notify;
Packit ae235b
  INC (closure, n_guards);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_add_finalize_notifier: (skip)
Packit ae235b
 * @closure: a #GClosure
Packit ae235b
 * @notify_data: (closure notify_func): data to pass to @notify_func
Packit ae235b
 * @notify_func: the callback function to register
Packit ae235b
 *
Packit ae235b
 * Registers a finalization notifier which will be called when the
Packit ae235b
 * reference count of @closure goes down to 0. Multiple finalization
Packit ae235b
 * notifiers on a single closure are invoked in unspecified order. If
Packit ae235b
 * a single call to g_closure_unref() results in the closure being
Packit ae235b
 * both invalidated and finalized, then the invalidate notifiers will
Packit ae235b
 * be run before the finalize notifiers.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_closure_add_finalize_notifier (GClosure      *closure,
Packit ae235b
				 gpointer       notify_data,
Packit ae235b
				 GClosureNotify notify_func)
Packit ae235b
{
Packit ae235b
  guint i;
Packit ae235b
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
  g_return_if_fail (notify_func != NULL);
Packit ae235b
  g_return_if_fail (closure->n_fnotifiers < CLOSURE_MAX_N_FNOTIFIERS);
Packit ae235b
Packit ae235b
  closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
Packit ae235b
  if (closure->n_inotifiers)
Packit ae235b
    closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
Packit ae235b
			closure->n_fnotifiers +
Packit ae235b
			closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
Packit ae235b
								      closure->n_fnotifiers + 0)];
Packit ae235b
  i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers;
Packit ae235b
  closure->notifiers[i].data = notify_data;
Packit ae235b
  closure->notifiers[i].notify = notify_func;
Packit ae235b
  INC (closure, n_fnotifiers);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_add_invalidate_notifier: (skip)
Packit ae235b
 * @closure: a #GClosure
Packit ae235b
 * @notify_data: (closure notify_func): data to pass to @notify_func
Packit ae235b
 * @notify_func: the callback function to register
Packit ae235b
 *
Packit ae235b
 * Registers an invalidation notifier which will be called when the
Packit ae235b
 * @closure is invalidated with g_closure_invalidate(). Invalidation
Packit ae235b
 * notifiers are invoked before finalization notifiers, in an
Packit ae235b
 * unspecified order.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_closure_add_invalidate_notifier (GClosure      *closure,
Packit ae235b
				   gpointer       notify_data,
Packit ae235b
				   GClosureNotify notify_func)
Packit ae235b
{
Packit ae235b
  guint i;
Packit ae235b
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
  g_return_if_fail (notify_func != NULL);
Packit ae235b
  g_return_if_fail (closure->is_invalid == FALSE);
Packit ae235b
  g_return_if_fail (closure->n_inotifiers < CLOSURE_MAX_N_INOTIFIERS);
Packit ae235b
Packit ae235b
  closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
Packit ae235b
  i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + closure->n_inotifiers;
Packit ae235b
  closure->notifiers[i].data = notify_data;
Packit ae235b
  closure->notifiers[i].notify = notify_func;
Packit ae235b
  INC (closure, n_inotifiers);
Packit ae235b
}
Packit ae235b
Packit ae235b
static inline gboolean
Packit ae235b
closure_try_remove_inotify (GClosure       *closure,
Packit ae235b
			    gpointer       notify_data,
Packit ae235b
			    GClosureNotify notify_func)
Packit ae235b
{
Packit ae235b
  GClosureNotifyData *ndata, *nlast;
Packit ae235b
Packit ae235b
  nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - 1;
Packit ae235b
  for (ndata = nlast + 1 - closure->n_inotifiers; ndata <= nlast; ndata++)
Packit ae235b
    if (ndata->notify == notify_func && ndata->data == notify_data)
Packit ae235b
      {
Packit ae235b
	DEC (closure, n_inotifiers);
Packit ae235b
	if (ndata < nlast)
Packit ae235b
	  *ndata = *nlast;
Packit ae235b
Packit ae235b
	return TRUE;
Packit ae235b
      }
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
static inline gboolean
Packit ae235b
closure_try_remove_fnotify (GClosure       *closure,
Packit ae235b
			    gpointer       notify_data,
Packit ae235b
			    GClosureNotify notify_func)
Packit ae235b
{
Packit ae235b
  GClosureNotifyData *ndata, *nlast;
Packit ae235b
Packit ae235b
  nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1;
Packit ae235b
  for (ndata = nlast + 1 - closure->n_fnotifiers; ndata <= nlast; ndata++)
Packit ae235b
    if (ndata->notify == notify_func && ndata->data == notify_data)
Packit ae235b
      {
Packit ae235b
	DEC (closure, n_fnotifiers);
Packit ae235b
	if (ndata < nlast)
Packit ae235b
	  *ndata = *nlast;
Packit ae235b
	if (closure->n_inotifiers)
Packit ae235b
	  closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
Packit ae235b
			      closure->n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
Packit ae235b
									    closure->n_fnotifiers +
Packit ae235b
									    closure->n_inotifiers)];
Packit ae235b
	return TRUE;
Packit ae235b
      }
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_ref:
Packit ae235b
 * @closure: #GClosure to increment the reference count on
Packit ae235b
 *
Packit ae235b
 * Increments the reference count on a closure to force it staying
Packit ae235b
 * alive while the caller holds a pointer to it.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): The @closure passed in, for convenience
Packit ae235b
 */
Packit ae235b
GClosure*
Packit ae235b
g_closure_ref (GClosure *closure)
Packit ae235b
{
Packit ae235b
  guint new_ref_count;
Packit ae235b
  g_return_val_if_fail (closure != NULL, NULL);
Packit ae235b
  g_return_val_if_fail (closure->ref_count > 0, NULL);
Packit ae235b
  g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL);
Packit ae235b
Packit ae235b
  INC_ASSIGN (closure, ref_count, &new_ref_count);
Packit ae235b
  g_return_val_if_fail (new_ref_count > 1, NULL);
Packit ae235b
Packit ae235b
  return closure;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_invalidate:
Packit ae235b
 * @closure: GClosure to invalidate
Packit ae235b
 *
Packit ae235b
 * Sets a flag on the closure to indicate that its calling
Packit ae235b
 * environment has become invalid, and thus causes any future
Packit ae235b
 * invocations of g_closure_invoke() on this @closure to be
Packit ae235b
 * ignored. Also, invalidation notifiers installed on the closure will
Packit ae235b
 * be called at this point. Note that unless you are holding a
Packit ae235b
 * reference to the closure yourself, the invalidation notifiers may
Packit ae235b
 * unref the closure and cause it to be destroyed, so if you need to
Packit ae235b
 * access the closure after calling g_closure_invalidate(), make sure
Packit ae235b
 * that you've previously called g_closure_ref().
Packit ae235b
 *
Packit ae235b
 * Note that g_closure_invalidate() will also be called when the
Packit ae235b
 * reference count of a closure drops to zero (unless it has already
Packit ae235b
 * been invalidated before).
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_closure_invalidate (GClosure *closure)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
Packit ae235b
  if (!closure->is_invalid)
Packit ae235b
    {
Packit ae235b
      gboolean was_invalid;
Packit ae235b
      g_closure_ref (closure);           /* preserve floating flag */
Packit ae235b
      SWAP (closure, is_invalid, TRUE, &was_invalid);
Packit ae235b
      /* invalidate only once */
Packit ae235b
      if (!was_invalid)
Packit ae235b
        closure_invoke_notifiers (closure, INOTIFY);
Packit ae235b
      g_closure_unref (closure);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_unref:
Packit ae235b
 * @closure: #GClosure to decrement the reference count on
Packit ae235b
 *
Packit ae235b
 * Decrements the reference count of a closure after it was previously
Packit ae235b
 * incremented by the same caller. If no other callers are using the
Packit ae235b
 * closure, then the closure will be destroyed and freed.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_closure_unref (GClosure *closure)
Packit ae235b
{
Packit ae235b
  guint new_ref_count;
Packit ae235b
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
  g_return_if_fail (closure->ref_count > 0);
Packit ae235b
Packit ae235b
  if (closure->ref_count == 1)	/* last unref, invalidate first */
Packit ae235b
    g_closure_invalidate (closure);
Packit ae235b
Packit ae235b
  DEC_ASSIGN (closure, ref_count, &new_ref_count);
Packit ae235b
Packit ae235b
  if (new_ref_count == 0)
Packit ae235b
    {
Packit ae235b
      closure_invoke_notifiers (closure, FNOTIFY);
Packit ae235b
      g_free (closure->notifiers);
Packit ae235b
Packit ae235b
      /* See comments in gtype.c about what's going on here... */
Packit ae235b
      if (RUNNING_ON_VALGRIND)
Packit ae235b
        {
Packit ae235b
          gchar *allocated;
Packit ae235b
Packit ae235b
          allocated = (gchar *) G_REAL_CLOSURE (closure);
Packit ae235b
          allocated -= sizeof (gpointer);
Packit ae235b
Packit ae235b
          g_free (allocated);
Packit ae235b
Packit ae235b
          VALGRIND_FREELIKE_BLOCK (allocated + sizeof (gpointer), 0);
Packit ae235b
          VALGRIND_FREELIKE_BLOCK (closure, 0);
Packit ae235b
        }
Packit ae235b
      else
Packit ae235b
        g_free (G_REAL_CLOSURE (closure));
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_sink:
Packit ae235b
 * @closure: #GClosure to decrement the initial reference count on, if it's
Packit ae235b
 *           still being held
Packit ae235b
 *
Packit ae235b
 * Takes over the initial ownership of a closure.  Each closure is
Packit ae235b
 * initially created in a "floating" state, which means that the initial
Packit ae235b
 * reference count is not owned by any caller. g_closure_sink() checks
Packit ae235b
 * to see if the object is still floating, and if so, unsets the
Packit ae235b
 * floating state and decreases the reference count. If the closure
Packit ae235b
 * is not floating, g_closure_sink() does nothing. The reason for the
Packit ae235b
 * existence of the floating state is to prevent cumbersome code
Packit ae235b
 * sequences like:
Packit ae235b
 * |[ 
Packit ae235b
 * closure = g_cclosure_new (cb_func, cb_data);
Packit ae235b
 * g_source_set_closure (source, closure);
Packit ae235b
 * g_closure_unref (closure); // GObject doesn't really need this
Packit ae235b
 * ]|
Packit ae235b
 * Because g_source_set_closure() (and similar functions) take ownership of the
Packit ae235b
 * initial reference count, if it is unowned, we instead can write:
Packit ae235b
 * |[ 
Packit ae235b
 * g_source_set_closure (source, g_cclosure_new (cb_func, cb_data));
Packit ae235b
 * ]|
Packit ae235b
 *
Packit ae235b
 * Generally, this function is used together with g_closure_ref(). Ane example
Packit ae235b
 * of storing a closure for later notification looks like:
Packit ae235b
 * |[ 
Packit ae235b
 * static GClosure *notify_closure = NULL;
Packit ae235b
 * void
Packit ae235b
 * foo_notify_set_closure (GClosure *closure)
Packit ae235b
 * {
Packit ae235b
 *   if (notify_closure)
Packit ae235b
 *     g_closure_unref (notify_closure);
Packit ae235b
 *   notify_closure = closure;
Packit ae235b
 *   if (notify_closure)
Packit ae235b
 *     {
Packit ae235b
 *       g_closure_ref (notify_closure);
Packit ae235b
 *       g_closure_sink (notify_closure);
Packit ae235b
 *     }
Packit ae235b
 * }
Packit ae235b
 * ]|
Packit ae235b
 *
Packit ae235b
 * Because g_closure_sink() may decrement the reference count of a closure
Packit ae235b
 * (if it hasn't been called on @closure yet) just like g_closure_unref(),
Packit ae235b
 * g_closure_ref() should be called prior to this function.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_closure_sink (GClosure *closure)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
  g_return_if_fail (closure->ref_count > 0);
Packit ae235b
Packit ae235b
  /* floating is basically a kludge to avoid creating closures
Packit ae235b
   * with a ref_count of 0. so the initial ref_count a closure has
Packit ae235b
   * is unowned. with invoking g_closure_sink() code may
Packit ae235b
   * indicate that it takes over that intiial ref_count.
Packit ae235b
   */
Packit ae235b
  if (closure->floating)
Packit ae235b
    {
Packit ae235b
      gboolean was_floating;
Packit ae235b
      SWAP (closure, floating, FALSE, &was_floating);
Packit ae235b
      /* unref floating flag only once */
Packit ae235b
      if (was_floating)
Packit ae235b
        g_closure_unref (closure);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_remove_invalidate_notifier: (skip)
Packit ae235b
 * @closure: a #GClosure
Packit ae235b
 * @notify_data: data which was passed to g_closure_add_invalidate_notifier()
Packit ae235b
 *               when registering @notify_func
Packit ae235b
 * @notify_func: the callback function to remove
Packit ae235b
 *
Packit ae235b
 * Removes an invalidation notifier.
Packit ae235b
 *
Packit ae235b
 * Notice that notifiers are automatically removed after they are run.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_closure_remove_invalidate_notifier (GClosure      *closure,
Packit ae235b
				      gpointer       notify_data,
Packit ae235b
				      GClosureNotify notify_func)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
  g_return_if_fail (notify_func != NULL);
Packit ae235b
Packit ae235b
  if (closure->is_invalid && closure->in_inotify && /* account removal of notify_func() while it's called */
Packit ae235b
      ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
Packit ae235b
      closure->data == notify_data)
Packit ae235b
    closure->marshal = NULL;
Packit ae235b
  else if (!closure_try_remove_inotify (closure, notify_data, notify_func))
Packit ae235b
    g_warning (G_STRLOC ": unable to remove uninstalled invalidation notifier: %p (%p)",
Packit ae235b
	       notify_func, notify_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_remove_finalize_notifier: (skip)
Packit ae235b
 * @closure: a #GClosure
Packit ae235b
 * @notify_data: data which was passed to g_closure_add_finalize_notifier()
Packit ae235b
 *  when registering @notify_func
Packit ae235b
 * @notify_func: the callback function to remove
Packit ae235b
 *
Packit ae235b
 * Removes a finalization notifier.
Packit ae235b
 *
Packit ae235b
 * Notice that notifiers are automatically removed after they are run.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_closure_remove_finalize_notifier (GClosure      *closure,
Packit ae235b
				    gpointer       notify_data,
Packit ae235b
				    GClosureNotify notify_func)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
  g_return_if_fail (notify_func != NULL);
Packit ae235b
Packit ae235b
  if (closure->is_invalid && !closure->in_inotify && /* account removal of notify_func() while it's called */
Packit ae235b
      ((gpointer) closure->marshal) == ((gpointer) notify_func) &&
Packit ae235b
      closure->data == notify_data)
Packit ae235b
    closure->marshal = NULL;
Packit ae235b
  else if (!closure_try_remove_fnotify (closure, notify_data, notify_func))
Packit ae235b
    g_warning (G_STRLOC ": unable to remove uninstalled finalization notifier: %p (%p)",
Packit ae235b
               notify_func, notify_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_invoke:
Packit ae235b
 * @closure: a #GClosure
Packit ae235b
 * @return_value: (optional) (out): a #GValue to store the return
Packit ae235b
 *                value. May be %NULL if the callback of @closure
Packit ae235b
 *                doesn't return a value.
Packit ae235b
 * @n_param_values: the length of the @param_values array
Packit ae235b
 * @param_values: (array length=n_param_values): an array of
Packit ae235b
 *                #GValues holding the arguments on which to
Packit ae235b
 *                invoke the callback of @closure
Packit ae235b
 * @invocation_hint: (nullable): a context-dependent invocation hint
Packit ae235b
 *
Packit ae235b
 * Invokes the closure, i.e. executes the callback represented by the @closure.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_closure_invoke (GClosure       *closure,
Packit ae235b
		  GValue /*out*/ *return_value,
Packit ae235b
		  guint           n_param_values,
Packit ae235b
		  const GValue   *param_values,
Packit ae235b
		  gpointer        invocation_hint)
Packit ae235b
{
Packit ae235b
  GRealClosure *real_closure;
Packit ae235b
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
Packit ae235b
  real_closure = G_REAL_CLOSURE (closure);
Packit ae235b
Packit ae235b
  g_closure_ref (closure);      /* preserve floating flag */
Packit ae235b
  if (!closure->is_invalid)
Packit ae235b
    {
Packit ae235b
      GClosureMarshal marshal;
Packit ae235b
      gpointer marshal_data;
Packit ae235b
      gboolean in_marshal = closure->in_marshal;
Packit ae235b
Packit ae235b
      g_return_if_fail (closure->marshal || real_closure->meta_marshal);
Packit ae235b
Packit ae235b
      SET (closure, in_marshal, TRUE);
Packit ae235b
      if (real_closure->meta_marshal)
Packit ae235b
	{
Packit ae235b
	  marshal_data = real_closure->meta_marshal_data;
Packit ae235b
	  marshal = real_closure->meta_marshal;
Packit ae235b
	}
Packit ae235b
      else
Packit ae235b
	{
Packit ae235b
	  marshal_data = NULL;
Packit ae235b
	  marshal = closure->marshal;
Packit ae235b
	}
Packit ae235b
      if (!in_marshal)
Packit ae235b
	closure_invoke_notifiers (closure, PRE_NOTIFY);
Packit ae235b
      marshal (closure,
Packit ae235b
	       return_value,
Packit ae235b
	       n_param_values, param_values,
Packit ae235b
	       invocation_hint,
Packit ae235b
	       marshal_data);
Packit ae235b
      if (!in_marshal)
Packit ae235b
	closure_invoke_notifiers (closure, POST_NOTIFY);
Packit ae235b
      SET (closure, in_marshal, in_marshal);
Packit ae235b
    }
Packit ae235b
  g_closure_unref (closure);
Packit ae235b
}
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
_g_closure_supports_invoke_va (GClosure       *closure)
Packit ae235b
{
Packit ae235b
  GRealClosure *real_closure;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (closure != NULL, FALSE);
Packit ae235b
Packit ae235b
  real_closure = G_REAL_CLOSURE (closure);
Packit ae235b
Packit ae235b
  return
Packit ae235b
    real_closure->va_marshal != NULL &&
Packit ae235b
    (real_closure->meta_marshal == NULL ||
Packit ae235b
     real_closure->va_meta_marshal != NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
void
Packit ae235b
_g_closure_invoke_va (GClosure       *closure,
Packit ae235b
		      GValue /*out*/ *return_value,
Packit ae235b
		      gpointer        instance,
Packit ae235b
		      va_list         args,
Packit ae235b
		      int             n_params,
Packit ae235b
		      GType          *param_types)
Packit ae235b
{
Packit ae235b
  GRealClosure *real_closure;
Packit ae235b
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
Packit ae235b
  real_closure = G_REAL_CLOSURE (closure);
Packit ae235b
Packit ae235b
  g_closure_ref (closure);      /* preserve floating flag */
Packit ae235b
  if (!closure->is_invalid)
Packit ae235b
    {
Packit ae235b
      GVaClosureMarshal marshal;
Packit ae235b
      gpointer marshal_data;
Packit ae235b
      gboolean in_marshal = closure->in_marshal;
Packit ae235b
Packit ae235b
      g_return_if_fail (closure->marshal || real_closure->meta_marshal);
Packit ae235b
Packit ae235b
      SET (closure, in_marshal, TRUE);
Packit ae235b
      if (real_closure->va_meta_marshal)
Packit ae235b
	{
Packit ae235b
	  marshal_data = real_closure->meta_marshal_data;
Packit ae235b
	  marshal = real_closure->va_meta_marshal;
Packit ae235b
	}
Packit ae235b
      else
Packit ae235b
	{
Packit ae235b
	  marshal_data = NULL;
Packit ae235b
	  marshal = real_closure->va_marshal;
Packit ae235b
	}
Packit ae235b
      if (!in_marshal)
Packit ae235b
	closure_invoke_notifiers (closure, PRE_NOTIFY);
Packit ae235b
      marshal (closure,
Packit ae235b
	       return_value,
Packit ae235b
	       instance, args,
Packit ae235b
	       marshal_data,
Packit ae235b
	       n_params, param_types);
Packit ae235b
      if (!in_marshal)
Packit ae235b
	closure_invoke_notifiers (closure, POST_NOTIFY);
Packit ae235b
      SET (closure, in_marshal, in_marshal);
Packit ae235b
    }
Packit ae235b
  g_closure_unref (closure);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_closure_set_marshal: (skip)
Packit ae235b
 * @closure: a #GClosure
Packit ae235b
 * @marshal: a #GClosureMarshal function
Packit ae235b
 *
Packit ae235b
 * Sets the marshaller of @closure. The `marshal_data`
Packit ae235b
 * of @marshal provides a way for a meta marshaller to provide additional
Packit ae235b
 * information to the marshaller. (See g_closure_set_meta_marshal().) For
Packit ae235b
 * GObject's C predefined marshallers (the g_cclosure_marshal_*()
Packit ae235b
 * functions), what it provides is a callback function to use instead of
Packit ae235b
 * @closure->callback.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_closure_set_marshal (GClosure       *closure,
Packit ae235b
		       GClosureMarshal marshal)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
  g_return_if_fail (marshal != NULL);
Packit ae235b
Packit ae235b
  if (closure->marshal && closure->marshal != marshal)
Packit ae235b
    g_warning ("attempt to override closure->marshal (%p) with new marshal (%p)",
Packit ae235b
	       closure->marshal, marshal);
Packit ae235b
  else
Packit ae235b
    closure->marshal = marshal;
Packit ae235b
}
Packit ae235b
Packit ae235b
void
Packit ae235b
_g_closure_set_va_marshal (GClosure       *closure,
Packit ae235b
			   GVaClosureMarshal marshal)
Packit ae235b
{
Packit ae235b
  GRealClosure *real_closure;
Packit ae235b
Packit ae235b
  g_return_if_fail (closure != NULL);
Packit ae235b
  g_return_if_fail (marshal != NULL);
Packit ae235b
Packit ae235b
  real_closure = G_REAL_CLOSURE (closure);
Packit ae235b
Packit ae235b
  if (real_closure->va_marshal && real_closure->va_marshal != marshal)
Packit ae235b
    g_warning ("attempt to override closure->va_marshal (%p) with new marshal (%p)",
Packit ae235b
	       real_closure->va_marshal, marshal);
Packit ae235b
  else
Packit ae235b
    real_closure->va_marshal = marshal;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_new: (skip)
Packit ae235b
 * @callback_func: the function to invoke
Packit ae235b
 * @user_data: (closure callback_func): user data to pass to @callback_func
Packit ae235b
 * @destroy_data: destroy notify to be called when @user_data is no longer used
Packit ae235b
 *
Packit ae235b
 * Creates a new closure which invokes @callback_func with @user_data as
Packit ae235b
 * the last parameter.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): a floating reference to a new #GCClosure
Packit ae235b
 */
Packit ae235b
GClosure*
Packit ae235b
g_cclosure_new (GCallback      callback_func,
Packit ae235b
		gpointer       user_data,
Packit ae235b
		GClosureNotify destroy_data)
Packit ae235b
{
Packit ae235b
  GClosure *closure;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (callback_func != NULL, NULL);
Packit ae235b
  
Packit ae235b
  closure = g_closure_new_simple (sizeof (GCClosure), user_data);
Packit ae235b
  if (destroy_data)
Packit ae235b
    g_closure_add_finalize_notifier (closure, user_data, destroy_data);
Packit ae235b
  ((GCClosure*) closure)->callback = (gpointer) callback_func;
Packit ae235b
  
Packit ae235b
  return closure;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_new_swap: (skip)
Packit ae235b
 * @callback_func: the function to invoke
Packit ae235b
 * @user_data: (closure callback_func): user data to pass to @callback_func
Packit ae235b
 * @destroy_data: destroy notify to be called when @user_data is no longer used
Packit ae235b
 *
Packit ae235b
 * Creates a new closure which invokes @callback_func with @user_data as
Packit ae235b
 * the first parameter.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): a floating reference to a new #GCClosure
Packit ae235b
 */
Packit ae235b
GClosure*
Packit ae235b
g_cclosure_new_swap (GCallback      callback_func,
Packit ae235b
		     gpointer       user_data,
Packit ae235b
		     GClosureNotify destroy_data)
Packit ae235b
{
Packit ae235b
  GClosure *closure;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (callback_func != NULL, NULL);
Packit ae235b
  
Packit ae235b
  closure = g_closure_new_simple (sizeof (GCClosure), user_data);
Packit ae235b
  if (destroy_data)
Packit ae235b
    g_closure_add_finalize_notifier (closure, user_data, destroy_data);
Packit ae235b
  ((GCClosure*) closure)->callback = (gpointer) callback_func;
Packit ae235b
  SET (closure, derivative_flag, TRUE);
Packit ae235b
  
Packit ae235b
  return closure;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_type_class_meta_marshal (GClosure       *closure,
Packit ae235b
			   GValue /*out*/ *return_value,
Packit ae235b
			   guint           n_param_values,
Packit ae235b
			   const GValue   *param_values,
Packit ae235b
			   gpointer        invocation_hint,
Packit ae235b
			   gpointer        marshal_data)
Packit ae235b
{
Packit ae235b
  GTypeClass *class;
Packit ae235b
  gpointer callback;
Packit ae235b
  /* GType itype = (GType) closure->data; */
Packit ae235b
  guint offset = GPOINTER_TO_UINT (marshal_data);
Packit ae235b
  
Packit ae235b
  class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
Packit ae235b
  callback = G_STRUCT_MEMBER (gpointer, class, offset);
Packit ae235b
  if (callback)
Packit ae235b
    closure->marshal (closure,
Packit ae235b
		      return_value,
Packit ae235b
		      n_param_values, param_values,
Packit ae235b
		      invocation_hint,
Packit ae235b
		      callback);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_type_class_meta_marshalv (GClosure *closure,
Packit ae235b
			    GValue   *return_value,
Packit ae235b
			    gpointer  instance,
Packit ae235b
			    va_list   args,
Packit ae235b
			    gpointer  marshal_data,
Packit ae235b
			    int       n_params,
Packit ae235b
			    GType    *param_types)
Packit ae235b
{
Packit ae235b
  GRealClosure *real_closure;
Packit ae235b
  GTypeClass *class;
Packit ae235b
  gpointer callback;
Packit ae235b
  /* GType itype = (GType) closure->data; */
Packit ae235b
  guint offset = GPOINTER_TO_UINT (marshal_data);
Packit ae235b
Packit ae235b
  real_closure = G_REAL_CLOSURE (closure);
Packit ae235b
Packit ae235b
  class = G_TYPE_INSTANCE_GET_CLASS (instance, itype, GTypeClass);
Packit ae235b
  callback = G_STRUCT_MEMBER (gpointer, class, offset);
Packit ae235b
  if (callback)
Packit ae235b
    real_closure->va_marshal (closure,
Packit ae235b
			      return_value,
Packit ae235b
			      instance, args,
Packit ae235b
			      callback,
Packit ae235b
			      n_params,
Packit ae235b
			      param_types);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_type_iface_meta_marshal (GClosure       *closure,
Packit ae235b
			   GValue /*out*/ *return_value,
Packit ae235b
			   guint           n_param_values,
Packit ae235b
			   const GValue   *param_values,
Packit ae235b
			   gpointer        invocation_hint,
Packit ae235b
			   gpointer        marshal_data)
Packit ae235b
{
Packit ae235b
  GTypeClass *class;
Packit ae235b
  gpointer callback;
Packit ae235b
  GType itype = (GType) closure->data;
Packit ae235b
  guint offset = GPOINTER_TO_UINT (marshal_data);
Packit ae235b
  
Packit ae235b
  class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass);
Packit ae235b
  callback = G_STRUCT_MEMBER (gpointer, class, offset);
Packit ae235b
  if (callback)
Packit ae235b
    closure->marshal (closure,
Packit ae235b
		      return_value,
Packit ae235b
		      n_param_values, param_values,
Packit ae235b
		      invocation_hint,
Packit ae235b
		      callback);
Packit ae235b
}
Packit ae235b
Packit ae235b
gboolean
Packit ae235b
_g_closure_is_void (GClosure *closure,
Packit ae235b
		    gpointer instance)
Packit ae235b
{
Packit ae235b
  GRealClosure *real_closure;
Packit ae235b
  GTypeClass *class;
Packit ae235b
  gpointer callback;
Packit ae235b
  GType itype;
Packit ae235b
  guint offset;
Packit ae235b
Packit ae235b
  if (closure->is_invalid)
Packit ae235b
    return TRUE;
Packit ae235b
Packit ae235b
  real_closure = G_REAL_CLOSURE (closure);
Packit ae235b
Packit ae235b
  if (real_closure->meta_marshal == g_type_iface_meta_marshal)
Packit ae235b
    {
Packit ae235b
      itype = (GType) closure->data;
Packit ae235b
      offset = GPOINTER_TO_UINT (real_closure->meta_marshal_data);
Packit ae235b
Packit ae235b
      class = G_TYPE_INSTANCE_GET_INTERFACE (instance, itype, GTypeClass);
Packit ae235b
      callback = G_STRUCT_MEMBER (gpointer, class, offset);
Packit ae235b
      return callback == NULL;
Packit ae235b
    }
Packit ae235b
  else if (real_closure->meta_marshal == g_type_class_meta_marshal)
Packit ae235b
    {
Packit ae235b
      offset = GPOINTER_TO_UINT (real_closure->meta_marshal_data);
Packit ae235b
Packit ae235b
      class = G_TYPE_INSTANCE_GET_CLASS (instance, itype, GTypeClass);
Packit ae235b
      callback = G_STRUCT_MEMBER (gpointer, class, offset);
Packit ae235b
      return callback == NULL;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_type_iface_meta_marshalv (GClosure *closure,
Packit ae235b
			    GValue   *return_value,
Packit ae235b
			    gpointer  instance,
Packit ae235b
			    va_list   args,
Packit ae235b
			    gpointer  marshal_data,
Packit ae235b
			    int       n_params,
Packit ae235b
			    GType    *param_types)
Packit ae235b
{
Packit ae235b
  GRealClosure *real_closure;
Packit ae235b
  GTypeClass *class;
Packit ae235b
  gpointer callback;
Packit ae235b
  GType itype = (GType) closure->data;
Packit ae235b
  guint offset = GPOINTER_TO_UINT (marshal_data);
Packit ae235b
Packit ae235b
  real_closure = G_REAL_CLOSURE (closure);
Packit ae235b
Packit ae235b
  class = G_TYPE_INSTANCE_GET_INTERFACE (instance, itype, GTypeClass);
Packit ae235b
  callback = G_STRUCT_MEMBER (gpointer, class, offset);
Packit ae235b
  if (callback)
Packit ae235b
    real_closure->va_marshal (closure,
Packit ae235b
			      return_value,
Packit ae235b
			      instance, args,
Packit ae235b
			      callback,
Packit ae235b
			      n_params,
Packit ae235b
			      param_types);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_signal_type_cclosure_new:
Packit ae235b
 * @itype: the #GType identifier of an interface or classed type
Packit ae235b
 * @struct_offset: the offset of the member function of @itype's class
Packit ae235b
 *  structure which is to be invoked by the new closure
Packit ae235b
 *
Packit ae235b
 * Creates a new closure which invokes the function found at the offset
Packit ae235b
 * @struct_offset in the class structure of the interface or classed type
Packit ae235b
 * identified by @itype.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): a floating reference to a new #GCClosure
Packit ae235b
 */
Packit ae235b
GClosure*
Packit ae235b
g_signal_type_cclosure_new (GType    itype,
Packit ae235b
			    guint    struct_offset)
Packit ae235b
{
Packit ae235b
  GClosure *closure;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_TYPE_IS_CLASSED (itype) || G_TYPE_IS_INTERFACE (itype), NULL);
Packit ae235b
  g_return_val_if_fail (struct_offset >= sizeof (GTypeClass), NULL);
Packit ae235b
  
Packit ae235b
  closure = g_closure_new_simple (sizeof (GClosure), (gpointer) itype);
Packit ae235b
  if (G_TYPE_IS_INTERFACE (itype))
Packit ae235b
    {
Packit ae235b
      g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_iface_meta_marshal);
Packit ae235b
      g_closure_set_meta_va_marshal (closure, g_type_iface_meta_marshalv);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (struct_offset), g_type_class_meta_marshal);
Packit ae235b
      g_closure_set_meta_va_marshal (closure, g_type_class_meta_marshalv);
Packit ae235b
    }
Packit ae235b
  return closure;
Packit ae235b
}
Packit ae235b
Packit ae235b
#include <ffi.h>
Packit ae235b
static ffi_type *
Packit ae235b
value_to_ffi_type (const GValue *gvalue,
Packit ae235b
                   gpointer *value,
Packit ae235b
                   gint *enum_tmpval,
Packit ae235b
                   gboolean *tmpval_used)
Packit ae235b
{
Packit ae235b
  ffi_type *rettype = NULL;
Packit ae235b
  GType type = g_type_fundamental (G_VALUE_TYPE (gvalue));
Packit ae235b
  g_assert (type != G_TYPE_INVALID);
Packit ae235b
Packit ae235b
  if (enum_tmpval)
Packit ae235b
    {
Packit ae235b
      g_assert (tmpval_used != NULL);
Packit ae235b
      *tmpval_used = FALSE;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  switch (type)
Packit ae235b
    {
Packit ae235b
    case G_TYPE_BOOLEAN:
Packit ae235b
    case G_TYPE_CHAR:
Packit ae235b
    case G_TYPE_INT:
Packit ae235b
      rettype = &ffi_type_sint;
Packit ae235b
      *value = (gpointer)&(gvalue->data[0].v_int);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_ENUM:
Packit ae235b
      /* enums are stored in v_long even though they are integers, which makes
Packit ae235b
       * marshalling through libffi somewhat complicated.  They need to be
Packit ae235b
       * marshalled as signed ints, but we need to use a temporary int sized
Packit ae235b
       * value to pass to libffi otherwise it'll pull the wrong value on
Packit ae235b
       * BE machines with 32-bit integers when treating v_long as 32-bit int.
Packit ae235b
       */
Packit ae235b
      g_assert (enum_tmpval != NULL);
Packit ae235b
      rettype = &ffi_type_sint;
Packit ae235b
      *enum_tmpval = g_value_get_enum (gvalue);
Packit ae235b
      *value = enum_tmpval;
Packit ae235b
      *tmpval_used = TRUE;
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_FLAGS:
Packit ae235b
      g_assert (enum_tmpval != NULL);
Packit ae235b
      rettype = &ffi_type_uint;
Packit ae235b
      *enum_tmpval = g_value_get_flags (gvalue);
Packit ae235b
      *value = enum_tmpval;
Packit ae235b
      *tmpval_used = TRUE;
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_UCHAR:
Packit ae235b
    case G_TYPE_UINT:
Packit ae235b
      rettype = &ffi_type_uint;
Packit ae235b
      *value = (gpointer)&(gvalue->data[0].v_uint);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_STRING:
Packit ae235b
    case G_TYPE_OBJECT:
Packit ae235b
    case G_TYPE_BOXED:
Packit ae235b
    case G_TYPE_PARAM:
Packit ae235b
    case G_TYPE_POINTER:
Packit ae235b
    case G_TYPE_INTERFACE:
Packit ae235b
    case G_TYPE_VARIANT:
Packit ae235b
      rettype = &ffi_type_pointer;
Packit ae235b
      *value = (gpointer)&(gvalue->data[0].v_pointer);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_FLOAT:
Packit ae235b
      rettype = &ffi_type_float;
Packit ae235b
      *value = (gpointer)&(gvalue->data[0].v_float);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_DOUBLE:
Packit ae235b
      rettype = &ffi_type_double;
Packit ae235b
      *value = (gpointer)&(gvalue->data[0].v_double);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_LONG:
Packit ae235b
      rettype = &ffi_type_slong;
Packit ae235b
      *value = (gpointer)&(gvalue->data[0].v_long);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_ULONG:
Packit ae235b
      rettype = &ffi_type_ulong;
Packit ae235b
      *value = (gpointer)&(gvalue->data[0].v_ulong);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_INT64:
Packit ae235b
      rettype = &ffi_type_sint64;
Packit ae235b
      *value = (gpointer)&(gvalue->data[0].v_int64);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_UINT64:
Packit ae235b
      rettype = &ffi_type_uint64;
Packit ae235b
      *value = (gpointer)&(gvalue->data[0].v_uint64);
Packit ae235b
      break;
Packit ae235b
    default:
Packit ae235b
      rettype = &ffi_type_pointer;
Packit ae235b
      *value = NULL;
Packit ae235b
      g_warning ("value_to_ffi_type: Unsupported fundamental type: %s", g_type_name (type));
Packit ae235b
      break;
Packit ae235b
    }
Packit ae235b
  return rettype;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
value_from_ffi_type (GValue *gvalue, gpointer *value)
Packit ae235b
{
Packit ae235b
  ffi_arg *int_val = (ffi_arg*) value;
Packit ae235b
Packit ae235b
  switch (g_type_fundamental (G_VALUE_TYPE (gvalue)))
Packit ae235b
    {
Packit ae235b
    case G_TYPE_INT:
Packit ae235b
      g_value_set_int (gvalue, (gint) *int_val);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_FLOAT:
Packit ae235b
      g_value_set_float (gvalue, *(gfloat*)value);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_DOUBLE:
Packit ae235b
      g_value_set_double (gvalue, *(gdouble*)value);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_BOOLEAN:
Packit ae235b
      g_value_set_boolean (gvalue, (gboolean) *int_val);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_STRING:
Packit ae235b
      g_value_take_string (gvalue, *(gchar**)value);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_CHAR:
Packit ae235b
      g_value_set_schar (gvalue, (gint8) *int_val);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_UCHAR:
Packit ae235b
      g_value_set_uchar (gvalue, (guchar) *int_val);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_UINT:
Packit ae235b
      g_value_set_uint (gvalue, (guint) *int_val);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_POINTER:
Packit ae235b
      g_value_set_pointer (gvalue, *(gpointer*)value);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_LONG:
Packit ae235b
      g_value_set_long (gvalue, (glong) *int_val);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_ULONG:
Packit ae235b
      g_value_set_ulong (gvalue, (gulong) *int_val);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_INT64:
Packit ae235b
      g_value_set_int64 (gvalue, (gint64) *int_val);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_UINT64:
Packit ae235b
      g_value_set_uint64 (gvalue, (guint64) *int_val);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_BOXED:
Packit ae235b
      g_value_take_boxed (gvalue, *(gpointer*)value);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_ENUM:
Packit ae235b
      g_value_set_enum (gvalue, (gint) *int_val);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_FLAGS:
Packit ae235b
      g_value_set_flags (gvalue, (guint) *int_val);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_PARAM:
Packit ae235b
      g_value_take_param (gvalue, *(gpointer*)value);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_OBJECT:
Packit ae235b
      g_value_take_object (gvalue, *(gpointer*)value);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_VARIANT:
Packit ae235b
      g_value_take_variant (gvalue, *(gpointer*)value);
Packit ae235b
      break;
Packit ae235b
    default:
Packit ae235b
      g_warning ("value_from_ffi_type: Unsupported fundamental type: %s",
Packit ae235b
                g_type_name (g_type_fundamental (G_VALUE_TYPE (gvalue))));
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
typedef union {
Packit ae235b
  gpointer _gpointer;
Packit ae235b
  float _float;
Packit ae235b
  double _double;
Packit ae235b
  gint _gint;
Packit ae235b
  guint _guint;
Packit ae235b
  glong _glong;
Packit ae235b
  gulong _gulong;
Packit ae235b
  gint64 _gint64;
Packit ae235b
  guint64 _guint64;
Packit ae235b
} va_arg_storage;
Packit ae235b
Packit ae235b
static ffi_type *
Packit ae235b
va_to_ffi_type (GType gtype,
Packit ae235b
		va_list *va,
Packit ae235b
		va_arg_storage *storage)
Packit ae235b
{
Packit ae235b
  ffi_type *rettype = NULL;
Packit ae235b
  GType type = g_type_fundamental (gtype);
Packit ae235b
  g_assert (type != G_TYPE_INVALID);
Packit ae235b
Packit ae235b
  switch (type)
Packit ae235b
    {
Packit ae235b
    case G_TYPE_BOOLEAN:
Packit ae235b
    case G_TYPE_CHAR:
Packit ae235b
    case G_TYPE_INT:
Packit ae235b
    case G_TYPE_ENUM:
Packit ae235b
      rettype = &ffi_type_sint;
Packit ae235b
      storage->_gint = va_arg (*va, gint);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_UCHAR:
Packit ae235b
    case G_TYPE_UINT:
Packit ae235b
    case G_TYPE_FLAGS:
Packit ae235b
      rettype = &ffi_type_uint;
Packit ae235b
      storage->_guint = va_arg (*va, guint);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_STRING:
Packit ae235b
    case G_TYPE_OBJECT:
Packit ae235b
    case G_TYPE_BOXED:
Packit ae235b
    case G_TYPE_PARAM:
Packit ae235b
    case G_TYPE_POINTER:
Packit ae235b
    case G_TYPE_INTERFACE:
Packit ae235b
    case G_TYPE_VARIANT:
Packit ae235b
      rettype = &ffi_type_pointer;
Packit ae235b
      storage->_gpointer = va_arg (*va, gpointer);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_FLOAT:
Packit ae235b
      /* Float args are passed as doubles in varargs */
Packit ae235b
      rettype = &ffi_type_float;
Packit ae235b
      storage->_float = (float)va_arg (*va, double);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_DOUBLE:
Packit ae235b
      rettype = &ffi_type_double;
Packit ae235b
      storage->_double = va_arg (*va, double);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_LONG:
Packit ae235b
      rettype = &ffi_type_slong;
Packit ae235b
      storage->_glong = va_arg (*va, glong);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_ULONG:
Packit ae235b
      rettype = &ffi_type_ulong;
Packit ae235b
      storage->_gulong = va_arg (*va, gulong);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_INT64:
Packit ae235b
      rettype = &ffi_type_sint64;
Packit ae235b
      storage->_gint64 = va_arg (*va, gint64);
Packit ae235b
      break;
Packit ae235b
    case G_TYPE_UINT64:
Packit ae235b
      rettype = &ffi_type_uint64;
Packit ae235b
      storage->_guint64 = va_arg (*va, guint64);
Packit ae235b
      break;
Packit ae235b
    default:
Packit ae235b
      rettype = &ffi_type_pointer;
Packit ae235b
      storage->_guint64  = 0;
Packit ae235b
      g_warning ("va_to_ffi_type: Unsupported fundamental type: %s", g_type_name (type));
Packit ae235b
      break;
Packit ae235b
    }
Packit ae235b
  return rettype;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_generic:
Packit ae235b
 * @closure: A #GClosure.
Packit ae235b
 * @return_gvalue: A #GValue to store the return value. May be %NULL
Packit ae235b
 *   if the callback of closure doesn't return a value.
Packit ae235b
 * @n_param_values: The length of the @param_values array.
Packit ae235b
 * @param_values: An array of #GValues holding the arguments
Packit ae235b
 *   on which to invoke the callback of closure.
Packit ae235b
 * @invocation_hint: The invocation hint given as the last argument to
Packit ae235b
 *   g_closure_invoke().
Packit ae235b
 * @marshal_data: Additional data specified when registering the
Packit ae235b
 *   marshaller, see g_closure_set_marshal() and
Packit ae235b
 *   g_closure_set_meta_marshal()
Packit ae235b
 *
Packit ae235b
 * A generic marshaller function implemented via
Packit ae235b
 * [libffi](http://sourceware.org/libffi/).
Packit ae235b
 *
Packit ae235b
 * Normally this function is not passed explicitly to g_signal_new(),
Packit ae235b
 * but used automatically by GLib when specifying a %NULL marshaller.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_cclosure_marshal_generic (GClosure     *closure,
Packit ae235b
                            GValue       *return_gvalue,
Packit ae235b
                            guint         n_param_values,
Packit ae235b
                            const GValue *param_values,
Packit ae235b
                            gpointer      invocation_hint,
Packit ae235b
                            gpointer      marshal_data)
Packit ae235b
{
Packit ae235b
  ffi_type *rtype;
Packit ae235b
  void *rvalue;
Packit ae235b
  int n_args;
Packit ae235b
  ffi_type **atypes;
Packit ae235b
  void **args;
Packit ae235b
  int i;
Packit ae235b
  ffi_cif cif;
Packit ae235b
  GCClosure *cc = (GCClosure*) closure;
Packit ae235b
  gint *enum_tmpval;
Packit ae235b
  gboolean tmpval_used = FALSE;
Packit ae235b
Packit ae235b
  enum_tmpval = g_alloca (sizeof (gint));
Packit ae235b
  if (return_gvalue && G_VALUE_TYPE (return_gvalue))
Packit ae235b
    {
Packit ae235b
      rtype = value_to_ffi_type (return_gvalue, &rvalue, enum_tmpval, &tmpval_used);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      rtype = &ffi_type_void;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg)));
Packit ae235b
Packit ae235b
  n_args = n_param_values + 1;
Packit ae235b
  atypes = g_alloca (sizeof (ffi_type *) * n_args);
Packit ae235b
  args =  g_alloca (sizeof (gpointer) * n_args);
Packit ae235b
Packit ae235b
  if (tmpval_used)
Packit ae235b
    enum_tmpval = g_alloca (sizeof (gint));
Packit ae235b
Packit ae235b
  if (G_CCLOSURE_SWAP_DATA (closure))
Packit ae235b
    {
Packit ae235b
      atypes[n_args-1] = value_to_ffi_type (param_values + 0,
Packit ae235b
                                            &args[n_args-1],
Packit ae235b
                                            enum_tmpval,
Packit ae235b
                                            &tmpval_used);
Packit ae235b
      atypes[0] = &ffi_type_pointer;
Packit ae235b
      args[0] = &closure->data;
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      atypes[0] = value_to_ffi_type (param_values + 0,
Packit ae235b
                                     &args[0],
Packit ae235b
                                     enum_tmpval,
Packit ae235b
                                     &tmpval_used);
Packit ae235b
      atypes[n_args-1] = &ffi_type_pointer;
Packit ae235b
      args[n_args-1] = &closure->data;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  for (i = 1; i < n_args - 1; i++)
Packit ae235b
    {
Packit ae235b
      if (tmpval_used)
Packit ae235b
        enum_tmpval = g_alloca (sizeof (gint));
Packit ae235b
Packit ae235b
      atypes[i] = value_to_ffi_type (param_values + i,
Packit ae235b
                                     &args[i],
Packit ae235b
                                     enum_tmpval,
Packit ae235b
                                     &tmpval_used);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, n_args, rtype, atypes) != FFI_OK)
Packit ae235b
    return;
Packit ae235b
Packit ae235b
  ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args);
Packit ae235b
Packit ae235b
  if (return_gvalue && G_VALUE_TYPE (return_gvalue))
Packit ae235b
    value_from_ffi_type (return_gvalue, rvalue);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_generic_va:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: (nullable): a #GValue to store the return
Packit ae235b
 *  value. May be %NULL if the callback of @closure doesn't return a
Packit ae235b
 *  value.
Packit ae235b
 * @instance: (type GObject.TypeInstance): the instance on which the closure is
Packit ae235b
 *  invoked.
Packit ae235b
 * @args_list: va_list of arguments to be passed to the closure.
Packit ae235b
 * @marshal_data: (nullable): additional data specified when
Packit ae235b
 *  registering the marshaller, see g_closure_set_marshal() and
Packit ae235b
 *  g_closure_set_meta_marshal()
Packit ae235b
 * @n_params: the length of the @param_types array
Packit ae235b
 * @param_types: (array length=n_params): the #GType of each argument from
Packit ae235b
 *  @args_list.
Packit ae235b
 *
Packit ae235b
 * A generic #GVaClosureMarshal function implemented via
Packit ae235b
 * [libffi](http://sourceware.org/libffi/).
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_cclosure_marshal_generic_va (GClosure *closure,
Packit ae235b
			       GValue   *return_value,
Packit ae235b
			       gpointer  instance,
Packit ae235b
			       va_list   args_list,
Packit ae235b
			       gpointer  marshal_data,
Packit ae235b
			       int       n_params,
Packit ae235b
			       GType    *param_types)
Packit ae235b
{
Packit ae235b
  ffi_type *rtype;
Packit ae235b
  void *rvalue;
Packit ae235b
  int n_args;
Packit ae235b
  ffi_type **atypes;
Packit ae235b
  void **args;
Packit ae235b
  va_arg_storage *storage;
Packit ae235b
  int i;
Packit ae235b
  ffi_cif cif;
Packit ae235b
  GCClosure *cc = (GCClosure*) closure;
Packit ae235b
  gint *enum_tmpval;
Packit ae235b
  gboolean tmpval_used = FALSE;
Packit ae235b
  va_list args_copy;
Packit ae235b
Packit ae235b
  enum_tmpval = g_alloca (sizeof (gint));
Packit ae235b
  if (return_value && G_VALUE_TYPE (return_value))
Packit ae235b
    {
Packit ae235b
      rtype = value_to_ffi_type (return_value, &rvalue, enum_tmpval, &tmpval_used);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      rtype = &ffi_type_void;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg)));
Packit ae235b
Packit ae235b
  n_args = n_params + 2;
Packit ae235b
  atypes = g_alloca (sizeof (ffi_type *) * n_args);
Packit ae235b
  args =  g_alloca (sizeof (gpointer) * n_args);
Packit ae235b
  storage = g_alloca (sizeof (va_arg_storage) * n_params);
Packit ae235b
Packit ae235b
  if (G_CCLOSURE_SWAP_DATA (closure))
Packit ae235b
    {
Packit ae235b
      atypes[n_args-1] = &ffi_type_pointer;
Packit ae235b
      args[n_args-1] = &instance;
Packit ae235b
      atypes[0] = &ffi_type_pointer;
Packit ae235b
      args[0] = &closure->data;
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      atypes[0] = &ffi_type_pointer;
Packit ae235b
      args[0] = &instance;
Packit ae235b
      atypes[n_args-1] = &ffi_type_pointer;
Packit ae235b
      args[n_args-1] = &closure->data;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  G_VA_COPY (args_copy, args_list);
Packit ae235b
Packit ae235b
  /* Box non-primitive arguments */
Packit ae235b
  for (i = 0; i < n_params; i++)
Packit ae235b
    {
Packit ae235b
      GType type = param_types[i]  & ~G_SIGNAL_TYPE_STATIC_SCOPE;
Packit ae235b
      GType fundamental = G_TYPE_FUNDAMENTAL (type);
Packit ae235b
Packit ae235b
      atypes[i+1] = va_to_ffi_type (type,
Packit ae235b
				    &args_copy,
Packit ae235b
				    &storage[i]);
Packit ae235b
      args[i+1] = &storage[i];
Packit ae235b
Packit ae235b
      if ((param_types[i]  & G_SIGNAL_TYPE_STATIC_SCOPE) == 0)
Packit ae235b
	{
Packit ae235b
	  if (fundamental == G_TYPE_STRING && storage[i]._gpointer != NULL)
Packit ae235b
	    storage[i]._gpointer = g_strdup (storage[i]._gpointer);
Packit ae235b
	  else if (fundamental == G_TYPE_PARAM && storage[i]._gpointer != NULL)
Packit ae235b
	    storage[i]._gpointer = g_param_spec_ref (storage[i]._gpointer);
Packit ae235b
	  else if (fundamental == G_TYPE_BOXED && storage[i]._gpointer != NULL)
Packit ae235b
	    storage[i]._gpointer = g_boxed_copy (type, storage[i]._gpointer);
Packit ae235b
	  else if (fundamental == G_TYPE_VARIANT && storage[i]._gpointer != NULL)
Packit ae235b
	    storage[i]._gpointer = g_variant_ref_sink (storage[i]._gpointer);
Packit ae235b
	}
Packit ae235b
      if (fundamental == G_TYPE_OBJECT && storage[i]._gpointer != NULL)
Packit ae235b
	storage[i]._gpointer = g_object_ref (storage[i]._gpointer);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  va_end (args_copy);
Packit ae235b
  
Packit ae235b
  if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, n_args, rtype, atypes) != FFI_OK)
Packit ae235b
    return;
Packit ae235b
Packit ae235b
  ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args);
Packit ae235b
Packit ae235b
  /* Unbox non-primitive arguments */
Packit ae235b
  for (i = 0; i < n_params; i++)
Packit ae235b
    {
Packit ae235b
      GType type = param_types[i]  & ~G_SIGNAL_TYPE_STATIC_SCOPE;
Packit ae235b
      GType fundamental = G_TYPE_FUNDAMENTAL (type);
Packit ae235b
Packit ae235b
      if ((param_types[i]  & G_SIGNAL_TYPE_STATIC_SCOPE) == 0)
Packit ae235b
	{
Packit ae235b
	  if (fundamental == G_TYPE_STRING && storage[i]._gpointer != NULL)
Packit ae235b
	    g_free (storage[i]._gpointer);
Packit ae235b
	  else if (fundamental == G_TYPE_PARAM && storage[i]._gpointer != NULL)
Packit ae235b
	    g_param_spec_unref (storage[i]._gpointer);
Packit ae235b
	  else if (fundamental == G_TYPE_BOXED && storage[i]._gpointer != NULL)
Packit ae235b
	    g_boxed_free (type, storage[i]._gpointer);
Packit ae235b
	  else if (fundamental == G_TYPE_VARIANT && storage[i]._gpointer != NULL)
Packit ae235b
	    g_variant_unref (storage[i]._gpointer);
Packit ae235b
	}
Packit ae235b
      if (fundamental == G_TYPE_OBJECT && storage[i]._gpointer != NULL)
Packit ae235b
	g_object_unref (storage[i]._gpointer);
Packit ae235b
    }
Packit ae235b
  
Packit ae235b
  if (return_value && G_VALUE_TYPE (return_value))
Packit ae235b
    value_from_ffi_type (return_value, rvalue);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__VOID:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 1
Packit ae235b
 * @param_values: a #GValue array holding only the instance
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__BOOLEAN:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #gboolean parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, gboolean arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__CHAR:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #gchar parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, gchar arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__UCHAR:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #guchar parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, guchar arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__INT:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #gint parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, gint arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__UINT:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #guint parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, guint arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__LONG:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #glong parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, glong arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__ULONG:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #gulong parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, gulong arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__ENUM:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the enumeration parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, gint arg1, gpointer user_data)` where the #gint parameter denotes an enumeration type..
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__FLAGS:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the flags parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, gint arg1, gpointer user_data)` where the #gint parameter denotes a flags type.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__FLOAT:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #gfloat parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, gfloat arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__DOUBLE:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #gdouble parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, gdouble arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__STRING:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #gchar* parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, const gchar *arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__PARAM:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #GParamSpec* parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, GParamSpec *arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__BOXED:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #GBoxed* parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, GBoxed *arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__POINTER:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #gpointer parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, gpointer arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__OBJECT:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #GObject* parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, GObject *arg1, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__VARIANT:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding the instance and the #GVariant* parameter
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, GVariant *arg1, gpointer user_data)`.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_VOID__UINT_POINTER:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: ignored
Packit ae235b
 * @n_param_values: 3
Packit ae235b
 * @param_values: a #GValue array holding instance, arg1 and arg2
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `void (*callback) (gpointer instance, guint arg1, gpointer arg2, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_BOOLEAN__FLAGS:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: a #GValue which can store the returned #gboolean
Packit ae235b
 * @n_param_values: 2
Packit ae235b
 * @param_values: a #GValue array holding instance and arg1
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `gboolean (*callback) (gpointer instance, gint arg1, gpointer user_data)` where the #gint parameter
Packit ae235b
 * denotes a flags type.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_BOOL__FLAGS:
Packit ae235b
 *
Packit ae235b
 * Another name for g_cclosure_marshal_BOOLEAN__FLAGS().
Packit ae235b
 */
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_STRING__OBJECT_POINTER:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: a #GValue, which can store the returned string
Packit ae235b
 * @n_param_values: 3
Packit ae235b
 * @param_values: a #GValue array holding instance, arg1 and arg2
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)`.
Packit ae235b
 */
Packit ae235b
/**
Packit ae235b
 * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED:
Packit ae235b
 * @closure: the #GClosure to which the marshaller belongs
Packit ae235b
 * @return_value: a #GValue, which can store the returned string
Packit ae235b
 * @n_param_values: 3
Packit ae235b
 * @param_values: a #GValue array holding instance, arg1 and arg2
Packit ae235b
 * @invocation_hint: the invocation hint given as the last argument
Packit ae235b
 *  to g_closure_invoke()
Packit ae235b
 * @marshal_data: additional data specified when registering the marshaller
Packit ae235b
 *
Packit ae235b
 * A marshaller for a #GCClosure with a callback of type
Packit ae235b
 * `gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)`.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */