Blame gobject/gparam.c

Packit ae235b
/* GObject - GLib Type, Object, Parameter and Signal Library
Packit ae235b
 * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
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
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include <string.h>
Packit ae235b
Packit ae235b
#include "gparam.h"
Packit ae235b
#include "gparamspecs.h"
Packit ae235b
#include "gvaluecollector.h"
Packit ae235b
#include "gtype-private.h"
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gparamspec
Packit ae235b
 * @short_description: Metadata for parameter specifications
Packit ae235b
 * @see_also: g_object_class_install_property(), g_object_set(),
Packit ae235b
 *     g_object_get(), g_object_set_property(), g_object_get_property(),
Packit ae235b
 *     g_value_register_transform_func()
Packit ae235b
 * @title: GParamSpec
Packit ae235b
 *
Packit ae235b
 * #GParamSpec is an object structure that encapsulates the metadata
Packit ae235b
 * required to specify parameters, such as e.g. #GObject properties.
Packit ae235b
 *
Packit ae235b
 * ## Parameter names # {#canonical-parameter-names}
Packit ae235b
 *
Packit ae235b
 * Parameter names need to start with a letter (a-z or A-Z).
Packit ae235b
 * Subsequent characters can be letters, numbers or a '-'.
Packit ae235b
 * All other characters are replaced by a '-' during construction.
Packit ae235b
 * The result of this replacement is called the canonical name of
Packit ae235b
 * the parameter.
Packit ae235b
 */
Packit ae235b
Packit ae235b
Packit ae235b
/* --- defines --- */
Packit ae235b
#define PARAM_FLOATING_FLAG                     0x2
Packit ae235b
#define	G_PARAM_USER_MASK			(~0U << G_PARAM_USER_SHIFT)
Packit ae235b
#define PSPEC_APPLIES_TO_VALUE(pspec, value)	(G_TYPE_CHECK_VALUE_TYPE ((value), G_PARAM_SPEC_VALUE_TYPE (pspec)))
Packit ae235b
Packit ae235b
/* --- prototypes --- */
Packit ae235b
static void	g_param_spec_class_base_init	 (GParamSpecClass	*class);
Packit ae235b
static void	g_param_spec_class_base_finalize (GParamSpecClass	*class);
Packit ae235b
static void	g_param_spec_class_init		 (GParamSpecClass	*class,
Packit ae235b
						  gpointer               class_data);
Packit ae235b
static void	g_param_spec_init		 (GParamSpec		*pspec,
Packit ae235b
						  GParamSpecClass	*class);
Packit ae235b
static void	g_param_spec_finalize		 (GParamSpec		*pspec);
Packit ae235b
static void	value_param_init		(GValue		*value);
Packit ae235b
static void	value_param_free_value		(GValue		*value);
Packit ae235b
static void	value_param_copy_value		(const GValue	*src_value,
Packit ae235b
						 GValue		*dest_value);
Packit ae235b
static void	value_param_transform_value	(const GValue	*src_value,
Packit ae235b
						 GValue		*dest_value);
Packit ae235b
static gpointer	value_param_peek_pointer	(const GValue	*value);
Packit ae235b
static gchar*	value_param_collect_value	(GValue		*value,
Packit ae235b
						 guint           n_collect_values,
Packit ae235b
						 GTypeCValue    *collect_values,
Packit ae235b
						 guint           collect_flags);
Packit ae235b
static gchar*	value_param_lcopy_value		(const GValue	*value,
Packit ae235b
						 guint           n_collect_values,
Packit ae235b
						 GTypeCValue    *collect_values,
Packit ae235b
						 guint           collect_flags);
Packit ae235b
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  GValue default_value;
Packit ae235b
  GQuark name_quark;
Packit ae235b
} GParamSpecPrivate;
Packit ae235b
Packit ae235b
static gint g_param_private_offset;
Packit ae235b
Packit ae235b
/* --- functions --- */
Packit ae235b
static inline GParamSpecPrivate *
Packit ae235b
g_param_spec_get_private (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  return &G_STRUCT_MEMBER (GParamSpecPrivate, pspec, g_param_private_offset);
Packit ae235b
}
Packit ae235b
Packit ae235b
void
Packit ae235b
_g_param_type_init (void)
Packit ae235b
{
Packit ae235b
  static const GTypeFundamentalInfo finfo = {
Packit ae235b
    (G_TYPE_FLAG_CLASSED |
Packit ae235b
     G_TYPE_FLAG_INSTANTIATABLE |
Packit ae235b
     G_TYPE_FLAG_DERIVABLE |
Packit ae235b
     G_TYPE_FLAG_DEEP_DERIVABLE),
Packit ae235b
  };
Packit ae235b
  static const GTypeValueTable param_value_table = {
Packit ae235b
    value_param_init,           /* value_init */
Packit ae235b
    value_param_free_value,     /* value_free */
Packit ae235b
    value_param_copy_value,     /* value_copy */
Packit ae235b
    value_param_peek_pointer,   /* value_peek_pointer */
Packit ae235b
    "p",			/* collect_format */
Packit ae235b
    value_param_collect_value,  /* collect_value */
Packit ae235b
    "p",			/* lcopy_format */
Packit ae235b
    value_param_lcopy_value,    /* lcopy_value */
Packit ae235b
  };
Packit ae235b
  const GTypeInfo param_spec_info = {
Packit ae235b
    sizeof (GParamSpecClass),
Packit ae235b
Packit ae235b
    (GBaseInitFunc) g_param_spec_class_base_init,
Packit ae235b
    (GBaseFinalizeFunc) g_param_spec_class_base_finalize,
Packit ae235b
    (GClassInitFunc) g_param_spec_class_init,
Packit ae235b
    (GClassFinalizeFunc) NULL,
Packit ae235b
    NULL,	/* class_data */
Packit ae235b
Packit ae235b
    sizeof (GParamSpec),
Packit ae235b
    0,		/* n_preallocs */
Packit ae235b
    (GInstanceInitFunc) g_param_spec_init,
Packit ae235b
Packit ae235b
    &param_value_table,
Packit ae235b
  };
Packit ae235b
  GType type;
Packit ae235b
Packit ae235b
  /* This should be registered as GParamSpec instead of GParam, for
Packit ae235b
   * consistency sake, so that type name can be mapped to struct name,
Packit ae235b
   * However, some language bindings, most noticeable the python ones
Packit ae235b
   * depends on the "GParam" identifier, see #548689
Packit ae235b
   */
Packit ae235b
  type = g_type_register_fundamental (G_TYPE_PARAM, g_intern_static_string ("GParam"), &param_spec_info, &finfo, G_TYPE_FLAG_ABSTRACT);
Packit ae235b
  g_assert (type == G_TYPE_PARAM);
Packit ae235b
  g_param_private_offset = g_type_add_instance_private (type, sizeof (GParamSpecPrivate));
Packit ae235b
  g_value_register_transform_func (G_TYPE_PARAM, G_TYPE_PARAM, value_param_transform_value);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_param_spec_class_base_init (GParamSpecClass *class)
Packit ae235b
{
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_param_spec_class_base_finalize (GParamSpecClass *class)
Packit ae235b
{
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_param_spec_class_init (GParamSpecClass *class,
Packit ae235b
			 gpointer         class_data)
Packit ae235b
{
Packit ae235b
  class->value_type = G_TYPE_NONE;
Packit ae235b
  class->finalize = g_param_spec_finalize;
Packit ae235b
  class->value_set_default = NULL;
Packit ae235b
  class->value_validate = NULL;
Packit ae235b
  class->values_cmp = NULL;
Packit ae235b
Packit ae235b
  g_type_class_adjust_private_offset (class, &g_param_private_offset);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_param_spec_init (GParamSpec      *pspec,
Packit ae235b
		   GParamSpecClass *class)
Packit ae235b
{
Packit ae235b
  pspec->name = NULL;
Packit ae235b
  pspec->_nick = NULL;
Packit ae235b
  pspec->_blurb = NULL;
Packit ae235b
  pspec->flags = 0;
Packit ae235b
  pspec->value_type = class->value_type;
Packit ae235b
  pspec->owner_type = 0;
Packit ae235b
  pspec->qdata = NULL;
Packit ae235b
  g_datalist_set_flags (&pspec->qdata, PARAM_FLOATING_FLAG);
Packit ae235b
  pspec->ref_count = 1;
Packit ae235b
  pspec->param_id = 0;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_param_spec_finalize (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  GParamSpecPrivate *priv = g_param_spec_get_private (pspec);
Packit ae235b
Packit ae235b
  if (priv->default_value.g_type)
Packit ae235b
    g_value_reset (&priv->default_value);
Packit ae235b
Packit ae235b
  g_datalist_clear (&pspec->qdata);
Packit ae235b
Packit ae235b
  if (!(pspec->flags & G_PARAM_STATIC_NICK))
Packit ae235b
    g_free (pspec->_nick);
Packit ae235b
Packit ae235b
  if (!(pspec->flags & G_PARAM_STATIC_BLURB))
Packit ae235b
    g_free (pspec->_blurb);
Packit ae235b
Packit ae235b
  g_type_free_instance ((GTypeInstance*) pspec);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_ref: (skip)
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 *
Packit ae235b
 * Increments the reference count of @pspec.
Packit ae235b
 *
Packit ae235b
 * Returns: the #GParamSpec that was passed into this function
Packit ae235b
 */
Packit ae235b
GParamSpec*
Packit ae235b
g_param_spec_ref (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
Packit ae235b
Packit ae235b
  g_atomic_int_inc ((int *)&pspec->ref_count);
Packit ae235b
Packit ae235b
  return pspec;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_unref: (skip)
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 *
Packit ae235b
 * Decrements the reference count of a @pspec.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_param_spec_unref (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  gboolean is_zero;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_PARAM_SPEC (pspec));
Packit ae235b
Packit ae235b
  is_zero = g_atomic_int_dec_and_test ((int *)&pspec->ref_count);
Packit ae235b
Packit ae235b
  if (G_UNLIKELY (is_zero))
Packit ae235b
    {
Packit ae235b
      G_PARAM_SPEC_GET_CLASS (pspec)->finalize (pspec);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_sink:
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 *
Packit ae235b
 * The initial reference count of a newly created #GParamSpec is 1,
Packit ae235b
 * even though no one has explicitly called g_param_spec_ref() on it
Packit ae235b
 * yet. So the initial reference count is flagged as "floating", until
Packit ae235b
 * someone calls `g_param_spec_ref (pspec); g_param_spec_sink
Packit ae235b
 * (pspec);` in sequence on it, taking over the initial
Packit ae235b
 * reference count (thus ending up with a @pspec that has a reference
Packit ae235b
 * count of 1 still, but is not flagged "floating" anymore).
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_param_spec_sink (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  gsize oldvalue;
Packit ae235b
  g_return_if_fail (G_IS_PARAM_SPEC (pspec));
Packit ae235b
Packit ae235b
  oldvalue = g_atomic_pointer_and (&pspec->qdata, ~(gsize)PARAM_FLOATING_FLAG);
Packit ae235b
  if (oldvalue & PARAM_FLOATING_FLAG)
Packit ae235b
    g_param_spec_unref (pspec);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_ref_sink: (skip)
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 *
Packit ae235b
 * Convenience function to ref and sink a #GParamSpec.
Packit ae235b
 *
Packit ae235b
 * Since: 2.10
Packit ae235b
 * Returns: the #GParamSpec that was passed into this function
Packit ae235b
 */
Packit ae235b
GParamSpec*
Packit ae235b
g_param_spec_ref_sink (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  gsize oldvalue;
Packit ae235b
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
Packit ae235b
Packit ae235b
  oldvalue = g_atomic_pointer_and (&pspec->qdata, ~(gsize)PARAM_FLOATING_FLAG);
Packit ae235b
  if (!(oldvalue & PARAM_FLOATING_FLAG))
Packit ae235b
    g_param_spec_ref (pspec);
Packit ae235b
Packit ae235b
  return pspec;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_get_name:
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 *
Packit ae235b
 * Get the name of a #GParamSpec.
Packit ae235b
 *
Packit ae235b
 * The name is always an "interned" string (as per g_intern_string()).
Packit ae235b
 * This allows for pointer-value comparisons.
Packit ae235b
 *
Packit ae235b
 * Returns: the name of @pspec.
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_param_spec_get_name (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
Packit ae235b
Packit ae235b
  return pspec->name;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_get_nick:
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 *
Packit ae235b
 * Get the nickname of a #GParamSpec.
Packit ae235b
 *
Packit ae235b
 * Returns: the nickname of @pspec.
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_param_spec_get_nick (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
Packit ae235b
Packit ae235b
  if (pspec->_nick)
Packit ae235b
    return pspec->_nick;
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      GParamSpec *redirect_target;
Packit ae235b
Packit ae235b
      redirect_target = g_param_spec_get_redirect_target (pspec);
Packit ae235b
      if (redirect_target && redirect_target->_nick)
Packit ae235b
	return redirect_target->_nick;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return pspec->name;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_get_blurb:
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 *
Packit ae235b
 * Get the short description of a #GParamSpec.
Packit ae235b
 *
Packit ae235b
 * Returns: the short description of @pspec.
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_param_spec_get_blurb (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
Packit ae235b
Packit ae235b
  if (pspec->_blurb)
Packit ae235b
    return pspec->_blurb;
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      GParamSpec *redirect_target;
Packit ae235b
Packit ae235b
      redirect_target = g_param_spec_get_redirect_target (pspec);
Packit ae235b
      if (redirect_target && redirect_target->_blurb)
Packit ae235b
	return redirect_target->_blurb;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
canonicalize_key (gchar *key)
Packit ae235b
{
Packit ae235b
  gchar *p;
Packit ae235b
  
Packit ae235b
  for (p = key; *p != 0; p++)
Packit ae235b
    {
Packit ae235b
      gchar c = *p;
Packit ae235b
      
Packit ae235b
      if (c != '-' &&
Packit ae235b
	  (c < '0' || c > '9') &&
Packit ae235b
	  (c < 'A' || c > 'Z') &&
Packit ae235b
	  (c < 'a' || c > 'z'))
Packit ae235b
	*p = '-';
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
is_canonical (const gchar *key)
Packit ae235b
{
Packit ae235b
  const gchar *p;
Packit ae235b
Packit ae235b
  for (p = key; *p != 0; p++)
Packit ae235b
    {
Packit ae235b
      gchar c = *p;
Packit ae235b
      
Packit ae235b
      if (c != '-' &&
Packit ae235b
	  (c < '0' || c > '9') &&
Packit ae235b
	  (c < 'A' || c > 'Z') &&
Packit ae235b
	  (c < 'a' || c > 'z'))
Packit ae235b
	return FALSE;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return TRUE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_internal: (skip)
Packit ae235b
 * @param_type: the #GType for the property; must be derived from #G_TYPE_PARAM
Packit ae235b
 * @name: the canonical name of the property
Packit ae235b
 * @nick: the nickname of the property
Packit ae235b
 * @blurb: a short description of the property
Packit ae235b
 * @flags: a combination of #GParamFlags
Packit ae235b
 *
Packit ae235b
 * Creates a new #GParamSpec instance.
Packit ae235b
 *
Packit ae235b
 * A property name consists of segments consisting of ASCII letters and
Packit ae235b
 * digits, separated by either the '-' or '_' character. The first
Packit ae235b
 * character of a property name must be a letter. Names which violate these
Packit ae235b
 * rules lead to undefined behaviour.
Packit ae235b
 *
Packit ae235b
 * When creating and looking up a #GParamSpec, either separator can be
Packit ae235b
 * used, but they cannot be mixed. Using '-' is considerably more
Packit ae235b
 * efficient and in fact required when using property names as detail
Packit ae235b
 * strings for signals.
Packit ae235b
 *
Packit ae235b
 * Beyond the name, #GParamSpecs have two more descriptive
Packit ae235b
 * strings associated with them, the @nick, which should be suitable
Packit ae235b
 * for use as a label for the property in a property editor, and the
Packit ae235b
 * @blurb, which should be a somewhat longer description, suitable for
Packit ae235b
 * e.g. a tooltip. The @nick and @blurb should ideally be localized.
Packit ae235b
 *
Packit ae235b
 * Returns: (type GObject.ParamSpec): a newly allocated #GParamSpec instance
Packit ae235b
 */
Packit ae235b
gpointer
Packit ae235b
g_param_spec_internal (GType        param_type,
Packit ae235b
		       const gchar *name,
Packit ae235b
		       const gchar *nick,
Packit ae235b
		       const gchar *blurb,
Packit ae235b
		       GParamFlags  flags)
Packit ae235b
{
Packit ae235b
  GParamSpec *pspec;
Packit ae235b
  GParamSpecPrivate *priv;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_TYPE_IS_PARAM (param_type) && param_type != G_TYPE_PARAM, NULL);
Packit ae235b
  g_return_val_if_fail (name != NULL, NULL);
Packit ae235b
  g_return_val_if_fail ((name[0] >= 'A' && name[0] <= 'Z') || (name[0] >= 'a' && name[0] <= 'z'), NULL);
Packit ae235b
  g_return_val_if_fail (!(flags & G_PARAM_STATIC_NAME) || is_canonical (name), NULL);
Packit ae235b
  
Packit ae235b
  pspec = (gpointer) g_type_create_instance (param_type);
Packit ae235b
Packit ae235b
  if (flags & G_PARAM_STATIC_NAME)
Packit ae235b
    {
Packit ae235b
      /* pspec->name is not freed if (flags & G_PARAM_STATIC_NAME) */
Packit ae235b
      pspec->name = (gchar *) g_intern_static_string (name);
Packit ae235b
      if (!is_canonical (pspec->name))
Packit ae235b
        g_warning ("G_PARAM_STATIC_NAME used with non-canonical pspec name: %s", pspec->name);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      if (is_canonical (name))
Packit ae235b
        pspec->name = (gchar *) g_intern_string (name);
Packit ae235b
      else
Packit ae235b
        {
Packit ae235b
          gchar *tmp = g_strdup (name);
Packit ae235b
          canonicalize_key (tmp);
Packit ae235b
          pspec->name = (gchar *) g_intern_string (tmp);
Packit ae235b
          g_free (tmp);
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  priv = g_param_spec_get_private (pspec);
Packit ae235b
  priv->name_quark = g_quark_from_string (pspec->name);
Packit ae235b
Packit ae235b
  if (flags & G_PARAM_STATIC_NICK)
Packit ae235b
    pspec->_nick = (gchar*) nick;
Packit ae235b
  else
Packit ae235b
    pspec->_nick = g_strdup (nick);
Packit ae235b
Packit ae235b
  if (flags & G_PARAM_STATIC_BLURB)
Packit ae235b
    pspec->_blurb = (gchar*) blurb;
Packit ae235b
  else
Packit ae235b
    pspec->_blurb = g_strdup (blurb);
Packit ae235b
Packit ae235b
  pspec->flags = (flags & G_PARAM_USER_MASK) | (flags & G_PARAM_MASK);
Packit ae235b
  
Packit ae235b
  return pspec;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_get_qdata:
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 * @quark: a #GQuark, naming the user data pointer
Packit ae235b
 *
Packit ae235b
 * Gets back user data pointers stored via g_param_spec_set_qdata().
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): the user data pointer set, or %NULL
Packit ae235b
 */
Packit ae235b
gpointer
Packit ae235b
g_param_spec_get_qdata (GParamSpec *pspec,
Packit ae235b
			GQuark      quark)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
Packit ae235b
  
Packit ae235b
  return quark ? g_datalist_id_get_data (&pspec->qdata, quark) : NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_set_qdata:
Packit ae235b
 * @pspec: the #GParamSpec to set store a user data pointer
Packit ae235b
 * @quark: a #GQuark, naming the user data pointer
Packit ae235b
 * @data: an opaque user data pointer
Packit ae235b
 *
Packit ae235b
 * Sets an opaque, named pointer on a #GParamSpec. The name is
Packit ae235b
 * specified through a #GQuark (retrieved e.g. via
Packit ae235b
 * g_quark_from_static_string()), and the pointer can be gotten back
Packit ae235b
 * from the @pspec with g_param_spec_get_qdata().  Setting a
Packit ae235b
 * previously set user data pointer, overrides (frees) the old pointer
Packit ae235b
 * set, using %NULL as pointer essentially removes the data stored.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_param_spec_set_qdata (GParamSpec *pspec,
Packit ae235b
			GQuark      quark,
Packit ae235b
			gpointer    data)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_PARAM_SPEC (pspec));
Packit ae235b
  g_return_if_fail (quark > 0);
Packit ae235b
Packit ae235b
  g_datalist_id_set_data (&pspec->qdata, quark, data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_set_qdata_full: (skip)
Packit ae235b
 * @pspec: the #GParamSpec to set store a user data pointer
Packit ae235b
 * @quark: a #GQuark, naming the user data pointer
Packit ae235b
 * @data: an opaque user data pointer
Packit ae235b
 * @destroy: function to invoke with @data as argument, when @data needs to
Packit ae235b
 *  be freed
Packit ae235b
 *
Packit ae235b
 * This function works like g_param_spec_set_qdata(), but in addition,
Packit ae235b
 * a `void (*destroy) (gpointer)` function may be
Packit ae235b
 * specified which is called with @data as argument when the @pspec is
Packit ae235b
 * finalized, or the data is being overwritten by a call to
Packit ae235b
 * g_param_spec_set_qdata() with the same @quark.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_param_spec_set_qdata_full (GParamSpec    *pspec,
Packit ae235b
			     GQuark         quark,
Packit ae235b
			     gpointer       data,
Packit ae235b
			     GDestroyNotify destroy)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_PARAM_SPEC (pspec));
Packit ae235b
  g_return_if_fail (quark > 0);
Packit ae235b
Packit ae235b
  g_datalist_id_set_data_full (&pspec->qdata, quark, data, data ? destroy : (GDestroyNotify) NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_steal_qdata:
Packit ae235b
 * @pspec: the #GParamSpec to get a stored user data pointer from
Packit ae235b
 * @quark: a #GQuark, naming the user data pointer
Packit ae235b
 *
Packit ae235b
 * Gets back user data pointers stored via g_param_spec_set_qdata()
Packit ae235b
 * and removes the @data from @pspec without invoking its destroy()
Packit ae235b
 * function (if any was set).  Usually, calling this function is only
Packit ae235b
 * required to update user data pointers with a destroy notifier.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): the user data pointer set, or %NULL
Packit ae235b
 */
Packit ae235b
gpointer
Packit ae235b
g_param_spec_steal_qdata (GParamSpec *pspec,
Packit ae235b
			  GQuark      quark)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
Packit ae235b
  g_return_val_if_fail (quark > 0, NULL);
Packit ae235b
  
Packit ae235b
  return g_datalist_id_remove_no_notify (&pspec->qdata, quark);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_get_redirect_target:
Packit ae235b
 * @pspec: a #GParamSpec
Packit ae235b
 *
Packit ae235b
 * If the paramspec redirects operations to another paramspec,
Packit ae235b
 * returns that paramspec. Redirect is used typically for
Packit ae235b
 * providing a new implementation of a property in a derived
Packit ae235b
 * type while preserving all the properties from the parent
Packit ae235b
 * type. Redirection is established by creating a property
Packit ae235b
 * of type #GParamSpecOverride. See g_object_class_override_property()
Packit ae235b
 * for an example of the use of this capability.
Packit ae235b
 *
Packit ae235b
 * Since: 2.4
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): paramspec to which requests on this
Packit ae235b
 *          paramspec should be redirected, or %NULL if none.
Packit ae235b
 */
Packit ae235b
GParamSpec*
Packit ae235b
g_param_spec_get_redirect_target (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  GTypeInstance *inst = (GTypeInstance *)pspec;
Packit ae235b
Packit ae235b
  if (inst && inst->g_class && inst->g_class->g_type == G_TYPE_PARAM_OVERRIDE)
Packit ae235b
    return ((GParamSpecOverride*)pspec)->overridden;
Packit ae235b
  else
Packit ae235b
    return NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_value_set_default:
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 * @value: a #GValue of correct type for @pspec
Packit ae235b
 *
Packit ae235b
 * Sets @value to its default value as specified in @pspec.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_param_value_set_default (GParamSpec *pspec,
Packit ae235b
			   GValue     *value)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_PARAM_SPEC (pspec));
Packit ae235b
  g_return_if_fail (G_IS_VALUE (value));
Packit ae235b
  g_return_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value));
Packit ae235b
Packit ae235b
  g_value_reset (value);
Packit ae235b
  G_PARAM_SPEC_GET_CLASS (pspec)->value_set_default (pspec, value);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_value_defaults:
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 * @value: a #GValue of correct type for @pspec
Packit ae235b
 *
Packit ae235b
 * Checks whether @value contains the default value as specified in @pspec.
Packit ae235b
 *
Packit ae235b
 * Returns: whether @value contains the canonical default for this @pspec
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_param_value_defaults (GParamSpec *pspec,
Packit ae235b
			GValue     *value)
Packit ae235b
{
Packit ae235b
  GValue dflt_value = G_VALUE_INIT;
Packit ae235b
  gboolean defaults;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
Packit ae235b
  g_return_val_if_fail (G_IS_VALUE (value), FALSE);
Packit ae235b
  g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value), FALSE);
Packit ae235b
Packit ae235b
  g_value_init (&dflt_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
Packit ae235b
  G_PARAM_SPEC_GET_CLASS (pspec)->value_set_default (pspec, &dflt_value);
Packit ae235b
  defaults = G_PARAM_SPEC_GET_CLASS (pspec)->values_cmp (pspec, value, &dflt_value) == 0;
Packit ae235b
  g_value_unset (&dflt_value);
Packit ae235b
Packit ae235b
  return defaults;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_value_validate:
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 * @value: a #GValue of correct type for @pspec
Packit ae235b
 *
Packit ae235b
 * Ensures that the contents of @value comply with the specifications
Packit ae235b
 * set out by @pspec. For example, a #GParamSpecInt might require
Packit ae235b
 * that integers stored in @value may not be smaller than -42 and not be
Packit ae235b
 * greater than +42. If @value contains an integer outside of this range,
Packit ae235b
 * it is modified accordingly, so the resulting value will fit into the
Packit ae235b
 * range -42 .. +42.
Packit ae235b
 *
Packit ae235b
 * Returns: whether modifying @value was necessary to ensure validity
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_param_value_validate (GParamSpec *pspec,
Packit ae235b
			GValue     *value)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
Packit ae235b
  g_return_val_if_fail (G_IS_VALUE (value), FALSE);
Packit ae235b
  g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value), FALSE);
Packit ae235b
Packit ae235b
  if (G_PARAM_SPEC_GET_CLASS (pspec)->value_validate)
Packit ae235b
    {
Packit ae235b
      GValue oval = *value;
Packit ae235b
Packit ae235b
      if (G_PARAM_SPEC_GET_CLASS (pspec)->value_validate (pspec, value) ||
Packit ae235b
	  memcmp (&oval.data, &value->data, sizeof (oval.data)))
Packit ae235b
	return TRUE;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_value_convert:
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 * @src_value: souce #GValue
Packit ae235b
 * @dest_value: destination #GValue of correct type for @pspec
Packit ae235b
 * @strict_validation: %TRUE requires @dest_value to conform to @pspec
Packit ae235b
 * without modifications
Packit ae235b
 *
Packit ae235b
 * Transforms @src_value into @dest_value if possible, and then
Packit ae235b
 * validates @dest_value, in order for it to conform to @pspec.  If
Packit ae235b
 * @strict_validation is %TRUE this function will only succeed if the
Packit ae235b
 * transformed @dest_value complied to @pspec without modifications.
Packit ae235b
 *
Packit ae235b
 * See also g_value_type_transformable(), g_value_transform() and
Packit ae235b
 * g_param_value_validate().
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if transformation and validation were successful,
Packit ae235b
 *  %FALSE otherwise and @dest_value is left untouched.
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_param_value_convert (GParamSpec   *pspec,
Packit ae235b
		       const GValue *src_value,
Packit ae235b
		       GValue       *dest_value,
Packit ae235b
		       gboolean	     strict_validation)
Packit ae235b
{
Packit ae235b
  GValue tmp_value = G_VALUE_INIT;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
Packit ae235b
  g_return_val_if_fail (G_IS_VALUE (src_value), FALSE);
Packit ae235b
  g_return_val_if_fail (G_IS_VALUE (dest_value), FALSE);
Packit ae235b
  g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, dest_value), FALSE);
Packit ae235b
Packit ae235b
  /* better leave dest_value untouched when returning FALSE */
Packit ae235b
Packit ae235b
  g_value_init (&tmp_value, G_VALUE_TYPE (dest_value));
Packit ae235b
  if (g_value_transform (src_value, &tmp_value) &&
Packit ae235b
      (!g_param_value_validate (pspec, &tmp_value) || !strict_validation))
Packit ae235b
    {
Packit ae235b
      g_value_unset (dest_value);
Packit ae235b
      
Packit ae235b
      /* values are relocatable */
Packit ae235b
      memcpy (dest_value, &tmp_value, sizeof (tmp_value));
Packit ae235b
      
Packit ae235b
      return TRUE;
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_value_unset (&tmp_value);
Packit ae235b
      
Packit ae235b
      return FALSE;
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_values_cmp:
Packit ae235b
 * @pspec: a valid #GParamSpec
Packit ae235b
 * @value1: a #GValue of correct type for @pspec
Packit ae235b
 * @value2: a #GValue of correct type for @pspec
Packit ae235b
 *
Packit ae235b
 * Compares @value1 with @value2 according to @pspec, and return -1, 0 or +1,
Packit ae235b
 * if @value1 is found to be less than, equal to or greater than @value2,
Packit ae235b
 * respectively.
Packit ae235b
 *
Packit ae235b
 * Returns: -1, 0 or +1, for a less than, equal to or greater than result
Packit ae235b
 */
Packit ae235b
gint
Packit ae235b
g_param_values_cmp (GParamSpec   *pspec,
Packit ae235b
		    const GValue *value1,
Packit ae235b
		    const GValue *value2)
Packit ae235b
{
Packit ae235b
  gint cmp;
Packit ae235b
Packit ae235b
  /* param_values_cmp() effectively does: value1 - value2
Packit ae235b
   * so the return values are:
Packit ae235b
   * -1)  value1 < value2
Packit ae235b
   *  0)  value1 == value2
Packit ae235b
   *  1)  value1 > value2
Packit ae235b
   */
Packit ae235b
  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), 0);
Packit ae235b
  g_return_val_if_fail (G_IS_VALUE (value1), 0);
Packit ae235b
  g_return_val_if_fail (G_IS_VALUE (value2), 0);
Packit ae235b
  g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value1), 0);
Packit ae235b
  g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, value2), 0);
Packit ae235b
Packit ae235b
  cmp = G_PARAM_SPEC_GET_CLASS (pspec)->values_cmp (pspec, value1, value2);
Packit ae235b
Packit ae235b
  return CLAMP (cmp, -1, 1);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
value_param_init (GValue *value)
Packit ae235b
{
Packit ae235b
  value->data[0].v_pointer = NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
value_param_free_value (GValue *value)
Packit ae235b
{
Packit ae235b
  if (value->data[0].v_pointer)
Packit ae235b
    g_param_spec_unref (value->data[0].v_pointer);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
value_param_copy_value (const GValue *src_value,
Packit ae235b
			GValue       *dest_value)
Packit ae235b
{
Packit ae235b
  if (src_value->data[0].v_pointer)
Packit ae235b
    dest_value->data[0].v_pointer = g_param_spec_ref (src_value->data[0].v_pointer);
Packit ae235b
  else
Packit ae235b
    dest_value->data[0].v_pointer = NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
value_param_transform_value (const GValue *src_value,
Packit ae235b
			     GValue       *dest_value)
Packit ae235b
{
Packit ae235b
  if (src_value->data[0].v_pointer &&
Packit ae235b
      g_type_is_a (G_PARAM_SPEC_TYPE (dest_value->data[0].v_pointer), G_VALUE_TYPE (dest_value)))
Packit ae235b
    dest_value->data[0].v_pointer = g_param_spec_ref (src_value->data[0].v_pointer);
Packit ae235b
  else
Packit ae235b
    dest_value->data[0].v_pointer = NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gpointer
Packit ae235b
value_param_peek_pointer (const GValue *value)
Packit ae235b
{
Packit ae235b
  return value->data[0].v_pointer;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gchar*
Packit ae235b
value_param_collect_value (GValue      *value,
Packit ae235b
			   guint        n_collect_values,
Packit ae235b
			   GTypeCValue *collect_values,
Packit ae235b
			   guint        collect_flags)
Packit ae235b
{
Packit ae235b
  if (collect_values[0].v_pointer)
Packit ae235b
    {
Packit ae235b
      GParamSpec *param = collect_values[0].v_pointer;
Packit ae235b
Packit ae235b
      if (param->g_type_instance.g_class == NULL)
Packit ae235b
	return g_strconcat ("invalid unclassed param spec pointer for value type '",
Packit ae235b
			    G_VALUE_TYPE_NAME (value),
Packit ae235b
			    "'",
Packit ae235b
			    NULL);
Packit ae235b
      else if (!g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_VALUE_TYPE (value)))
Packit ae235b
	return g_strconcat ("invalid param spec type '",
Packit ae235b
			    G_PARAM_SPEC_TYPE_NAME (param),
Packit ae235b
			    "' for value type '",
Packit ae235b
			    G_VALUE_TYPE_NAME (value),
Packit ae235b
			    "'",
Packit ae235b
			    NULL);
Packit ae235b
      value->data[0].v_pointer = g_param_spec_ref (param);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    value->data[0].v_pointer = NULL;
Packit ae235b
Packit ae235b
  return NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gchar*
Packit ae235b
value_param_lcopy_value (const GValue *value,
Packit ae235b
			 guint         n_collect_values,
Packit ae235b
			 GTypeCValue  *collect_values,
Packit ae235b
			 guint         collect_flags)
Packit ae235b
{
Packit ae235b
  GParamSpec **param_p = collect_values[0].v_pointer;
Packit ae235b
Packit ae235b
  if (!param_p)
Packit ae235b
    return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value));
Packit ae235b
Packit ae235b
  if (!value->data[0].v_pointer)
Packit ae235b
    *param_p = NULL;
Packit ae235b
  else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
Packit ae235b
    *param_p = value->data[0].v_pointer;
Packit ae235b
  else
Packit ae235b
    *param_p = g_param_spec_ref (value->data[0].v_pointer);
Packit ae235b
Packit ae235b
  return NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/* --- param spec pool --- */
Packit ae235b
/**
Packit ae235b
 * GParamSpecPool:
Packit ae235b
 *
Packit ae235b
 * A #GParamSpecPool maintains a collection of #GParamSpecs which can be
Packit ae235b
 * quickly accessed by owner and name. The implementation of the #GObject property
Packit ae235b
 * system uses such a pool to store the #GParamSpecs of the properties all object
Packit ae235b
 * types.
Packit ae235b
 */
Packit ae235b
struct _GParamSpecPool
Packit ae235b
{
Packit ae235b
  GMutex       mutex;
Packit ae235b
  gboolean     type_prefixing;
Packit ae235b
  GHashTable  *hash_table;
Packit ae235b
};
Packit ae235b
Packit ae235b
static guint
Packit ae235b
param_spec_pool_hash (gconstpointer key_spec)
Packit ae235b
{
Packit ae235b
  const GParamSpec *key = key_spec;
Packit ae235b
  const gchar *p;
Packit ae235b
  guint h = key->owner_type;
Packit ae235b
Packit ae235b
  for (p = key->name; *p; p++)
Packit ae235b
    h = (h << 5) - h + *p;
Packit ae235b
Packit ae235b
  return h;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
param_spec_pool_equals (gconstpointer key_spec_1,
Packit ae235b
			gconstpointer key_spec_2)
Packit ae235b
{
Packit ae235b
  const GParamSpec *key1 = key_spec_1;
Packit ae235b
  const GParamSpec *key2 = key_spec_2;
Packit ae235b
Packit ae235b
  return (key1->owner_type == key2->owner_type &&
Packit ae235b
	  strcmp (key1->name, key2->name) == 0);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_pool_new:
Packit ae235b
 * @type_prefixing: Whether the pool will support type-prefixed property names.
Packit ae235b
 *
Packit ae235b
 * Creates a new #GParamSpecPool.
Packit ae235b
 *
Packit ae235b
 * If @type_prefixing is %TRUE, lookups in the newly created pool will
Packit ae235b
 * allow to specify the owner as a colon-separated prefix of the
Packit ae235b
 * property name, like "GtkContainer:border-width". This feature is
Packit ae235b
 * deprecated, so you should always set @type_prefixing to %FALSE.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): a newly allocated #GParamSpecPool.
Packit ae235b
 */
Packit ae235b
GParamSpecPool*
Packit ae235b
g_param_spec_pool_new (gboolean type_prefixing)
Packit ae235b
{
Packit ae235b
  static GMutex init_mutex;
Packit ae235b
  GParamSpecPool *pool = g_new (GParamSpecPool, 1);
Packit ae235b
Packit ae235b
  memcpy (&pool->mutex, &init_mutex, sizeof (init_mutex));
Packit ae235b
  pool->type_prefixing = type_prefixing != FALSE;
Packit ae235b
  pool->hash_table = g_hash_table_new (param_spec_pool_hash, param_spec_pool_equals);
Packit ae235b
Packit ae235b
  return pool;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_pool_insert:
Packit ae235b
 * @pool: a #GParamSpecPool.
Packit ae235b
 * @pspec: the #GParamSpec to insert
Packit ae235b
 * @owner_type: a #GType identifying the owner of @pspec
Packit ae235b
 *
Packit ae235b
 * Inserts a #GParamSpec in the pool.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_param_spec_pool_insert (GParamSpecPool *pool,
Packit ae235b
			  GParamSpec     *pspec,
Packit ae235b
			  GType           owner_type)
Packit ae235b
{
Packit ae235b
  const gchar *p;
Packit ae235b
  
Packit ae235b
  if (pool && pspec && owner_type > 0 && pspec->owner_type == 0)
Packit ae235b
    {
Packit ae235b
      for (p = pspec->name; *p; p++)
Packit ae235b
	{
Packit ae235b
	  if (!strchr (G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-_", *p))
Packit ae235b
	    {
Packit ae235b
	      g_warning (G_STRLOC ": pspec name \"%s\" contains invalid characters", pspec->name);
Packit ae235b
	      return;
Packit ae235b
	    }
Packit ae235b
	}
Packit ae235b
      g_mutex_lock (&pool->mutex);
Packit ae235b
      pspec->owner_type = owner_type;
Packit ae235b
      g_param_spec_ref (pspec);
Packit ae235b
      g_hash_table_add (pool->hash_table, pspec);
Packit ae235b
      g_mutex_unlock (&pool->mutex);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_return_if_fail (pool != NULL);
Packit ae235b
      g_return_if_fail (pspec);
Packit ae235b
      g_return_if_fail (owner_type > 0);
Packit ae235b
      g_return_if_fail (pspec->owner_type == 0);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_pool_remove:
Packit ae235b
 * @pool: a #GParamSpecPool
Packit ae235b
 * @pspec: the #GParamSpec to remove
Packit ae235b
 *
Packit ae235b
 * Removes a #GParamSpec from the pool.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_param_spec_pool_remove (GParamSpecPool *pool,
Packit ae235b
			  GParamSpec     *pspec)
Packit ae235b
{
Packit ae235b
  if (pool && pspec)
Packit ae235b
    {
Packit ae235b
      g_mutex_lock (&pool->mutex);
Packit ae235b
      if (g_hash_table_remove (pool->hash_table, pspec))
Packit ae235b
	g_param_spec_unref (pspec);
Packit ae235b
      else
Packit ae235b
	g_warning (G_STRLOC ": attempt to remove unknown pspec '%s' from pool", pspec->name);
Packit ae235b
      g_mutex_unlock (&pool->mutex);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_return_if_fail (pool != NULL);
Packit ae235b
      g_return_if_fail (pspec);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static inline GParamSpec*
Packit ae235b
param_spec_ht_lookup (GHashTable  *hash_table,
Packit ae235b
		      const gchar *param_name,
Packit ae235b
		      GType        owner_type,
Packit ae235b
		      gboolean     walk_ancestors)
Packit ae235b
{
Packit ae235b
  GParamSpec key, *pspec;
Packit ae235b
Packit ae235b
  key.owner_type = owner_type;
Packit ae235b
  key.name = (gchar*) param_name;
Packit ae235b
  if (walk_ancestors)
Packit ae235b
    do
Packit ae235b
      {
Packit ae235b
	pspec = g_hash_table_lookup (hash_table, &key);
Packit ae235b
	if (pspec)
Packit ae235b
	  return pspec;
Packit ae235b
	key.owner_type = g_type_parent (key.owner_type);
Packit ae235b
      }
Packit ae235b
    while (key.owner_type);
Packit ae235b
  else
Packit ae235b
    pspec = g_hash_table_lookup (hash_table, &key);
Packit ae235b
Packit ae235b
  if (!pspec && !is_canonical (param_name))
Packit ae235b
    {
Packit ae235b
      gchar *canonical;
Packit ae235b
Packit ae235b
      canonical = g_strdup (key.name);
Packit ae235b
      canonicalize_key (canonical);
Packit ae235b
Packit ae235b
      /* try canonicalized form */
Packit ae235b
      key.name = canonical;
Packit ae235b
      key.owner_type = owner_type;
Packit ae235b
Packit ae235b
      if (walk_ancestors)
Packit ae235b
        do
Packit ae235b
          {
Packit ae235b
            pspec = g_hash_table_lookup (hash_table, &key);
Packit ae235b
            if (pspec)
Packit ae235b
              {
Packit ae235b
                g_free (canonical);
Packit ae235b
                return pspec;
Packit ae235b
              }
Packit ae235b
            key.owner_type = g_type_parent (key.owner_type);
Packit ae235b
          }
Packit ae235b
        while (key.owner_type);
Packit ae235b
      else
Packit ae235b
        pspec = g_hash_table_lookup (hash_table, &key);
Packit ae235b
Packit ae235b
      g_free (canonical);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return pspec;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_pool_lookup:
Packit ae235b
 * @pool: a #GParamSpecPool
Packit ae235b
 * @param_name: the name to look for
Packit ae235b
 * @owner_type: the owner to look for
Packit ae235b
 * @walk_ancestors: If %TRUE, also try to find a #GParamSpec with @param_name
Packit ae235b
 *  owned by an ancestor of @owner_type.
Packit ae235b
 *
Packit ae235b
 * Looks up a #GParamSpec in the pool.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): The found #GParamSpec, or %NULL if no
Packit ae235b
 * matching #GParamSpec was found.
Packit ae235b
 */
Packit ae235b
GParamSpec*
Packit ae235b
g_param_spec_pool_lookup (GParamSpecPool *pool,
Packit ae235b
			  const gchar    *param_name,
Packit ae235b
			  GType           owner_type,
Packit ae235b
			  gboolean        walk_ancestors)
Packit ae235b
{
Packit ae235b
  GParamSpec *pspec;
Packit ae235b
  gchar *delim;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (pool != NULL, NULL);
Packit ae235b
  g_return_val_if_fail (param_name != NULL, NULL);
Packit ae235b
Packit ae235b
  g_mutex_lock (&pool->mutex);
Packit ae235b
Packit ae235b
  delim = pool->type_prefixing ? strchr (param_name, ':') : NULL;
Packit ae235b
Packit ae235b
  /* try quick and away, i.e. without prefix */
Packit ae235b
  if (!delim)
Packit ae235b
    {
Packit ae235b
      pspec = param_spec_ht_lookup (pool->hash_table, param_name, owner_type, walk_ancestors);
Packit ae235b
      g_mutex_unlock (&pool->mutex);
Packit ae235b
Packit ae235b
      return pspec;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  /* strip type prefix */
Packit ae235b
  if (pool->type_prefixing && delim[1] == ':')
Packit ae235b
    {
Packit ae235b
      guint l = delim - param_name;
Packit ae235b
      gchar stack_buffer[32], *buffer = l < 32 ? stack_buffer : g_new (gchar, l + 1);
Packit ae235b
      GType type;
Packit ae235b
      
Packit ae235b
      strncpy (buffer, param_name, delim - param_name);
Packit ae235b
      buffer[l] = 0;
Packit ae235b
      type = g_type_from_name (buffer);
Packit ae235b
      if (l >= 32)
Packit ae235b
	g_free (buffer);
Packit ae235b
      if (type)		/* type==0 isn't a valid type pefix */
Packit ae235b
	{
Packit ae235b
	  /* sanity check, these cases don't make a whole lot of sense */
Packit ae235b
	  if ((!walk_ancestors && type != owner_type) || !g_type_is_a (owner_type, type))
Packit ae235b
	    {
Packit ae235b
	      g_mutex_unlock (&pool->mutex);
Packit ae235b
Packit ae235b
	      return NULL;
Packit ae235b
	    }
Packit ae235b
	  owner_type = type;
Packit ae235b
	  param_name += l + 2;
Packit ae235b
	  pspec = param_spec_ht_lookup (pool->hash_table, param_name, owner_type, walk_ancestors);
Packit ae235b
	  g_mutex_unlock (&pool->mutex);
Packit ae235b
Packit ae235b
	  return pspec;
Packit ae235b
	}
Packit ae235b
    }
Packit ae235b
  /* malformed param_name */
Packit ae235b
Packit ae235b
  g_mutex_unlock (&pool->mutex);
Packit ae235b
Packit ae235b
  return NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
pool_list (gpointer key,
Packit ae235b
	   gpointer value,
Packit ae235b
	   gpointer user_data)
Packit ae235b
{
Packit ae235b
  GParamSpec *pspec = value;
Packit ae235b
  gpointer *data = user_data;
Packit ae235b
  GType owner_type = (GType) data[1];
Packit ae235b
Packit ae235b
  if (owner_type == pspec->owner_type)
Packit ae235b
    data[0] = g_list_prepend (data[0], pspec);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_pool_list_owned:
Packit ae235b
 * @pool: a #GParamSpecPool
Packit ae235b
 * @owner_type: the owner to look for
Packit ae235b
 *
Packit ae235b
 * Gets an #GList of all #GParamSpecs owned by @owner_type in
Packit ae235b
 * the pool.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer container) (element-type GObject.ParamSpec): a
Packit ae235b
 *          #GList of all #GParamSpecs owned by @owner_type in
Packit ae235b
 *          the pool#GParamSpecs.
Packit ae235b
 */
Packit ae235b
GList*
Packit ae235b
g_param_spec_pool_list_owned (GParamSpecPool *pool,
Packit ae235b
			      GType           owner_type)
Packit ae235b
{
Packit ae235b
  gpointer data[2];
Packit ae235b
Packit ae235b
  g_return_val_if_fail (pool != NULL, NULL);
Packit ae235b
  g_return_val_if_fail (owner_type > 0, NULL);
Packit ae235b
  
Packit ae235b
  g_mutex_lock (&pool->mutex);
Packit ae235b
  data[0] = NULL;
Packit ae235b
  data[1] = (gpointer) owner_type;
Packit ae235b
  g_hash_table_foreach (pool->hash_table, pool_list, &data);
Packit ae235b
  g_mutex_unlock (&pool->mutex);
Packit ae235b
Packit ae235b
  return data[0];
Packit ae235b
}
Packit ae235b
Packit ae235b
static gint
Packit ae235b
pspec_compare_id (gconstpointer a,
Packit ae235b
		  gconstpointer b)
Packit ae235b
{
Packit ae235b
  const GParamSpec *pspec1 = a, *pspec2 = b;
Packit ae235b
Packit ae235b
  if (pspec1->param_id < pspec2->param_id)
Packit ae235b
    return -1;
Packit ae235b
Packit ae235b
  if (pspec1->param_id > pspec2->param_id)
Packit ae235b
    return 1;
Packit ae235b
Packit ae235b
  return strcmp (pspec1->name, pspec2->name);
Packit ae235b
}
Packit ae235b
Packit ae235b
static inline GSList*
Packit ae235b
pspec_list_remove_overridden_and_redirected (GSList     *plist,
Packit ae235b
					     GHashTable *ht,
Packit ae235b
					     GType       owner_type,
Packit ae235b
					     guint      *n_p)
Packit ae235b
{
Packit ae235b
  GSList *rlist = NULL;
Packit ae235b
Packit ae235b
  while (plist)
Packit ae235b
    {
Packit ae235b
      GSList *tmp = plist->next;
Packit ae235b
      GParamSpec *pspec = plist->data;
Packit ae235b
      GParamSpec *found;
Packit ae235b
      gboolean remove = FALSE;
Packit ae235b
Packit ae235b
      /* Remove paramspecs that are redirected, and also paramspecs
Packit ae235b
       * that have are overridden by non-redirected properties.
Packit ae235b
       * The idea is to get the single paramspec for each name that
Packit ae235b
       * best corresponds to what the application sees.
Packit ae235b
       */
Packit ae235b
      if (g_param_spec_get_redirect_target (pspec))
Packit ae235b
	remove = TRUE;
Packit ae235b
      else
Packit ae235b
	{
Packit ae235b
	  found = param_spec_ht_lookup (ht, pspec->name, owner_type, TRUE);
Packit ae235b
	  if (found != pspec)
Packit ae235b
	    {
Packit ae235b
	      GParamSpec *redirect = g_param_spec_get_redirect_target (found);
Packit ae235b
	      if (redirect != pspec)
Packit ae235b
		remove = TRUE;
Packit ae235b
	    }
Packit ae235b
	}
Packit ae235b
Packit ae235b
      if (remove)
Packit ae235b
	{
Packit ae235b
	  g_slist_free_1 (plist);
Packit ae235b
	}
Packit ae235b
      else
Packit ae235b
	{
Packit ae235b
	  plist->next = rlist;
Packit ae235b
	  rlist = plist;
Packit ae235b
	  *n_p += 1;
Packit ae235b
	}
Packit ae235b
      plist = tmp;
Packit ae235b
    }
Packit ae235b
  return rlist;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
pool_depth_list (gpointer key,
Packit ae235b
		 gpointer value,
Packit ae235b
		 gpointer user_data)
Packit ae235b
{
Packit ae235b
  GParamSpec *pspec = value;
Packit ae235b
  gpointer *data = user_data;
Packit ae235b
  GSList **slists = data[0];
Packit ae235b
  GType owner_type = (GType) data[1];
Packit ae235b
Packit ae235b
  if (g_type_is_a (owner_type, pspec->owner_type))
Packit ae235b
    {
Packit ae235b
      if (G_TYPE_IS_INTERFACE (pspec->owner_type))
Packit ae235b
	{
Packit ae235b
	  slists[0] = g_slist_prepend (slists[0], pspec);
Packit ae235b
	}
Packit ae235b
      else
Packit ae235b
	{
Packit ae235b
	  guint d = g_type_depth (pspec->owner_type);
Packit ae235b
Packit ae235b
	  slists[d - 1] = g_slist_prepend (slists[d - 1], pspec);
Packit ae235b
	}
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/* We handle interfaces specially since we don't want to
Packit ae235b
 * count interface prerequisites like normal inheritance;
Packit ae235b
 * the property comes from the direct inheritance from
Packit ae235b
 * the prerequisite class, not from the interface that
Packit ae235b
 * prerequires it.
Packit ae235b
 * 
Packit ae235b
 * also 'depth' isn't a meaningful concept for interface
Packit ae235b
 * prerequites.
Packit ae235b
 */
Packit ae235b
static void
Packit ae235b
pool_depth_list_for_interface (gpointer key,
Packit ae235b
			       gpointer value,
Packit ae235b
			       gpointer user_data)
Packit ae235b
{
Packit ae235b
  GParamSpec *pspec = value;
Packit ae235b
  gpointer *data = user_data;
Packit ae235b
  GSList **slists = data[0];
Packit ae235b
  GType owner_type = (GType) data[1];
Packit ae235b
Packit ae235b
  if (pspec->owner_type == owner_type)
Packit ae235b
    slists[0] = g_slist_prepend (slists[0], pspec);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_pool_list:
Packit ae235b
 * @pool: a #GParamSpecPool
Packit ae235b
 * @owner_type: the owner to look for
Packit ae235b
 * @n_pspecs_p: (out): return location for the length of the returned array
Packit ae235b
 *
Packit ae235b
 * Gets an array of all #GParamSpecs owned by @owner_type in
Packit ae235b
 * the pool.
Packit ae235b
 *
Packit ae235b
 * Returns: (array length=n_pspecs_p) (transfer container): a newly
Packit ae235b
 *          allocated array containing pointers to all #GParamSpecs
Packit ae235b
 *          owned by @owner_type in the pool
Packit ae235b
 */
Packit ae235b
GParamSpec**
Packit ae235b
g_param_spec_pool_list (GParamSpecPool *pool,
Packit ae235b
			GType           owner_type,
Packit ae235b
			guint          *n_pspecs_p)
Packit ae235b
{
Packit ae235b
  GParamSpec **pspecs, **p;
Packit ae235b
  GSList **slists, *node;
Packit ae235b
  gpointer data[2];
Packit ae235b
  guint d, i;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (pool != NULL, NULL);
Packit ae235b
  g_return_val_if_fail (owner_type > 0, NULL);
Packit ae235b
  g_return_val_if_fail (n_pspecs_p != NULL, NULL);
Packit ae235b
  
Packit ae235b
  g_mutex_lock (&pool->mutex);
Packit ae235b
  *n_pspecs_p = 0;
Packit ae235b
  d = g_type_depth (owner_type);
Packit ae235b
  slists = g_new0 (GSList*, d);
Packit ae235b
  data[0] = slists;
Packit ae235b
  data[1] = (gpointer) owner_type;
Packit ae235b
Packit ae235b
  g_hash_table_foreach (pool->hash_table,
Packit ae235b
			G_TYPE_IS_INTERFACE (owner_type) ?
Packit ae235b
			   pool_depth_list_for_interface :
Packit ae235b
			   pool_depth_list,
Packit ae235b
			&data);
Packit ae235b
  
Packit ae235b
  for (i = 0; i < d; i++)
Packit ae235b
    slists[i] = pspec_list_remove_overridden_and_redirected (slists[i], pool->hash_table, owner_type, n_pspecs_p);
Packit ae235b
  pspecs = g_new (GParamSpec*, *n_pspecs_p + 1);
Packit ae235b
  p = pspecs;
Packit ae235b
  for (i = 0; i < d; i++)
Packit ae235b
    {
Packit ae235b
      slists[i] = g_slist_sort (slists[i], pspec_compare_id);
Packit ae235b
      for (node = slists[i]; node; node = node->next)
Packit ae235b
	*p++ = node->data;
Packit ae235b
      g_slist_free (slists[i]);
Packit ae235b
    }
Packit ae235b
  *p++ = NULL;
Packit ae235b
  g_free (slists);
Packit ae235b
  g_mutex_unlock (&pool->mutex);
Packit ae235b
Packit ae235b
  return pspecs;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/* --- auxiliary functions --- */
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  /* class portion */
Packit ae235b
  GType           value_type;
Packit ae235b
  void          (*finalize)             (GParamSpec   *pspec);
Packit ae235b
  void          (*value_set_default)    (GParamSpec   *pspec,
Packit ae235b
					 GValue       *value);
Packit ae235b
  gboolean      (*value_validate)       (GParamSpec   *pspec,
Packit ae235b
					 GValue       *value);
Packit ae235b
  gint          (*values_cmp)           (GParamSpec   *pspec,
Packit ae235b
					 const GValue *value1,
Packit ae235b
					 const GValue *value2);
Packit ae235b
} ParamSpecClassInfo;
Packit ae235b
Packit ae235b
static void
Packit ae235b
param_spec_generic_class_init (gpointer g_class,
Packit ae235b
			       gpointer class_data)
Packit ae235b
{
Packit ae235b
  GParamSpecClass *class = g_class;
Packit ae235b
  ParamSpecClassInfo *info = class_data;
Packit ae235b
Packit ae235b
  class->value_type = info->value_type;
Packit ae235b
  if (info->finalize)
Packit ae235b
    class->finalize = info->finalize;			/* optional */
Packit ae235b
  class->value_set_default = info->value_set_default;
Packit ae235b
  if (info->value_validate)
Packit ae235b
    class->value_validate = info->value_validate;	/* optional */
Packit ae235b
  class->values_cmp = info->values_cmp;
Packit ae235b
  g_free (class_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
default_value_set_default (GParamSpec *pspec,
Packit ae235b
			   GValue     *value)
Packit ae235b
{
Packit ae235b
  /* value is already zero initialized */
Packit ae235b
}
Packit ae235b
Packit ae235b
static gint
Packit ae235b
default_values_cmp (GParamSpec   *pspec,
Packit ae235b
		    const GValue *value1,
Packit ae235b
		    const GValue *value2)
Packit ae235b
{
Packit ae235b
  return memcmp (&value1->data, &value2->data, sizeof (value1->data));
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_type_register_static:
Packit ae235b
 * @name: 0-terminated string used as the name of the new #GParamSpec type.
Packit ae235b
 * @pspec_info: The #GParamSpecTypeInfo for this #GParamSpec type.
Packit ae235b
 *
Packit ae235b
 * Registers @name as the name of a new static type derived from
Packit ae235b
 * #G_TYPE_PARAM. The type system uses the information contained in
Packit ae235b
 * the #GParamSpecTypeInfo structure pointed to by @info to manage the
Packit ae235b
 * #GParamSpec type and its instances.
Packit ae235b
 *
Packit ae235b
 * Returns: The new type identifier.
Packit ae235b
 */
Packit ae235b
GType
Packit ae235b
g_param_type_register_static (const gchar              *name,
Packit ae235b
			      const GParamSpecTypeInfo *pspec_info)
Packit ae235b
{
Packit ae235b
  GTypeInfo info = {
Packit ae235b
    sizeof (GParamSpecClass),      /* class_size */
Packit ae235b
    NULL,                          /* base_init */
Packit ae235b
    NULL,                          /* base_destroy */
Packit ae235b
    param_spec_generic_class_init, /* class_init */
Packit ae235b
    NULL,                          /* class_destroy */
Packit ae235b
    NULL,                          /* class_data */
Packit ae235b
    0,                             /* instance_size */
Packit ae235b
    16,                            /* n_preallocs */
Packit ae235b
    NULL,                          /* instance_init */
Packit ae235b
  };
Packit ae235b
  ParamSpecClassInfo *cinfo;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (name != NULL, 0);
Packit ae235b
  g_return_val_if_fail (pspec_info != NULL, 0);
Packit ae235b
  g_return_val_if_fail (g_type_from_name (name) == 0, 0);
Packit ae235b
  g_return_val_if_fail (pspec_info->instance_size >= sizeof (GParamSpec), 0);
Packit ae235b
  g_return_val_if_fail (g_type_name (pspec_info->value_type) != NULL, 0);
Packit ae235b
  /* default: g_return_val_if_fail (pspec_info->value_set_default != NULL, 0); */
Packit ae235b
  /* optional: g_return_val_if_fail (pspec_info->value_validate != NULL, 0); */
Packit ae235b
  /* default: g_return_val_if_fail (pspec_info->values_cmp != NULL, 0); */
Packit ae235b
Packit ae235b
  info.instance_size = pspec_info->instance_size;
Packit ae235b
  info.n_preallocs = pspec_info->n_preallocs;
Packit ae235b
  info.instance_init = (GInstanceInitFunc) pspec_info->instance_init;
Packit ae235b
  cinfo = g_new (ParamSpecClassInfo, 1);
Packit ae235b
  cinfo->value_type = pspec_info->value_type;
Packit ae235b
  cinfo->finalize = pspec_info->finalize;
Packit ae235b
  cinfo->value_set_default = pspec_info->value_set_default ? pspec_info->value_set_default : default_value_set_default;
Packit ae235b
  cinfo->value_validate = pspec_info->value_validate;
Packit ae235b
  cinfo->values_cmp = pspec_info->values_cmp ? pspec_info->values_cmp : default_values_cmp;
Packit ae235b
  info.class_data = cinfo;
Packit ae235b
Packit ae235b
  return g_type_register_static (G_TYPE_PARAM, name, &info, 0);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_value_set_param:
Packit ae235b
 * @value: a valid #GValue of type %G_TYPE_PARAM
Packit ae235b
 * @param: (nullable): the #GParamSpec to be set
Packit ae235b
 *
Packit ae235b
 * Set the contents of a %G_TYPE_PARAM #GValue to @param.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_value_set_param (GValue     *value,
Packit ae235b
		   GParamSpec *param)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_VALUE_HOLDS_PARAM (value));
Packit ae235b
  if (param)
Packit ae235b
    g_return_if_fail (G_IS_PARAM_SPEC (param));
Packit ae235b
Packit ae235b
  if (value->data[0].v_pointer)
Packit ae235b
    g_param_spec_unref (value->data[0].v_pointer);
Packit ae235b
  value->data[0].v_pointer = param;
Packit ae235b
  if (value->data[0].v_pointer)
Packit ae235b
    g_param_spec_ref (value->data[0].v_pointer);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_value_set_param_take_ownership: (skip)
Packit ae235b
 * @value: a valid #GValue of type %G_TYPE_PARAM
Packit ae235b
 * @param: (nullable): the #GParamSpec to be set
Packit ae235b
 *
Packit ae235b
 * This is an internal function introduced mainly for C marshallers.
Packit ae235b
 *
Packit ae235b
 * Deprecated: 2.4: Use g_value_take_param() instead.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_value_set_param_take_ownership (GValue     *value,
Packit ae235b
				  GParamSpec *param)
Packit ae235b
{
Packit ae235b
  g_value_take_param (value, param);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_value_take_param: (skip)
Packit ae235b
 * @value: a valid #GValue of type %G_TYPE_PARAM
Packit ae235b
 * @param: (nullable): the #GParamSpec to be set
Packit ae235b
 *
Packit ae235b
 * Sets the contents of a %G_TYPE_PARAM #GValue to @param and takes
Packit ae235b
 * over the ownership of the callers reference to @param; the caller
Packit ae235b
 * doesn't have to unref it any more.
Packit ae235b
 *
Packit ae235b
 * Since: 2.4
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_value_take_param (GValue     *value,
Packit ae235b
		    GParamSpec *param)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_VALUE_HOLDS_PARAM (value));
Packit ae235b
  if (param)
Packit ae235b
    g_return_if_fail (G_IS_PARAM_SPEC (param));
Packit ae235b
Packit ae235b
  if (value->data[0].v_pointer)
Packit ae235b
    g_param_spec_unref (value->data[0].v_pointer);
Packit ae235b
  value->data[0].v_pointer = param; /* we take over the reference count */
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_value_get_param:
Packit ae235b
 * @value: a valid #GValue whose type is derived from %G_TYPE_PARAM
Packit ae235b
 *
Packit ae235b
 * Get the contents of a %G_TYPE_PARAM #GValue.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): #GParamSpec content of @value
Packit ae235b
 */
Packit ae235b
GParamSpec*
Packit ae235b
g_value_get_param (const GValue *value)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_VALUE_HOLDS_PARAM (value), NULL);
Packit ae235b
Packit ae235b
  return value->data[0].v_pointer;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_value_dup_param: (skip)
Packit ae235b
 * @value: a valid #GValue whose type is derived from %G_TYPE_PARAM
Packit ae235b
 *
Packit ae235b
 * Get the contents of a %G_TYPE_PARAM #GValue, increasing its
Packit ae235b
 * reference count.
Packit ae235b
 *
Packit ae235b
 * Returns: #GParamSpec content of @value, should be unreferenced when
Packit ae235b
 *          no longer needed.
Packit ae235b
 */
Packit ae235b
GParamSpec*
Packit ae235b
g_value_dup_param (const GValue *value)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_VALUE_HOLDS_PARAM (value), NULL);
Packit ae235b
Packit ae235b
  return value->data[0].v_pointer ? g_param_spec_ref (value->data[0].v_pointer) : NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_get_default_value:
Packit ae235b
 * @pspec: a #GParamSpec
Packit ae235b
 *
Packit ae235b
 * Gets the default value of @pspec as a pointer to a #GValue.
Packit ae235b
 *
Packit ae235b
 * The #GValue will remain valid for the life of @pspec.
Packit ae235b
 *
Packit ae235b
 * Returns: a pointer to a #GValue which must not be modified
Packit ae235b
 *
Packit ae235b
 * Since: 2.38
Packit ae235b
 **/
Packit ae235b
const GValue *
Packit ae235b
g_param_spec_get_default_value (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  GParamSpecPrivate *priv = g_param_spec_get_private (pspec);
Packit ae235b
Packit ae235b
  /* We use the type field of the GValue as the key for the once because
Packit ae235b
   * it will be zero before it is initialised and non-zero after.  We
Packit ae235b
   * have to take care that we don't write a non-zero value to the type
Packit ae235b
   * field before we are completely done, however, because then another
Packit ae235b
   * thread could come along and find the value partially-initialised.
Packit ae235b
   *
Packit ae235b
   * In order to accomplish this we store the default value in a
Packit ae235b
   * stack-allocated GValue.  We then set the type field in that value
Packit ae235b
   * to zero and copy the contents into place.  We then end by storing
Packit ae235b
   * the type as the last step in order to ensure that we're completely
Packit ae235b
   * done before a g_once_init_enter() could take the fast path in
Packit ae235b
   * another thread.
Packit ae235b
   */
Packit ae235b
  if (g_once_init_enter (&priv->default_value.g_type))
Packit ae235b
    {
Packit ae235b
      GValue default_value = G_VALUE_INIT;
Packit ae235b
Packit ae235b
      g_value_init (&default_value, pspec->value_type);
Packit ae235b
      g_param_value_set_default (pspec, &default_value);
Packit ae235b
Packit ae235b
      /* store all but the type */
Packit ae235b
      default_value.g_type = 0;
Packit ae235b
      priv->default_value = default_value;
Packit ae235b
Packit ae235b
      g_once_init_leave (&priv->default_value.g_type, pspec->value_type);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return &priv->default_value;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_param_spec_get_name_quark:
Packit ae235b
 * @pspec: a #GParamSpec
Packit ae235b
 *
Packit ae235b
 * Gets the GQuark for the name.
Packit ae235b
 *
Packit ae235b
 * Returns: the GQuark for @pspec->name.
Packit ae235b
 *
Packit ae235b
 * Since: 2.46
Packit ae235b
 */
Packit ae235b
GQuark
Packit ae235b
g_param_spec_get_name_quark (GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  GParamSpecPrivate *priv = g_param_spec_get_private (pspec);
Packit ae235b
Packit ae235b
  /* Return the quark that we've stashed away at creation time.
Packit ae235b
   * This lets us avoid a lock and a hash table lookup when
Packit ae235b
   * dispatching property change notification.
Packit ae235b
   */
Packit ae235b
Packit ae235b
  return priv->name_quark;
Packit ae235b
}