os/ossrv/glib/gobject/gvalue.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/glib/gobject/gvalue.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,582 @@
     1.4 +/* GObject - GLib Type, Object, Parameter and Signal Library
     1.5 + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
     1.6 + * Portions copyright (c) 2006-2009 Nokia Corporation.  All rights reserved.
     1.7 + *
     1.8 + * This library is free software; you can redistribute it and/or
     1.9 + * modify it under the terms of the GNU Lesser General Public
    1.10 + * License as published by the Free Software Foundation; either
    1.11 + * version 2 of the License, or (at your option) any later version.
    1.12 + *
    1.13 + * This library is distributed in the hope that it will be useful,
    1.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 + * Lesser General Public License for more details.
    1.17 + *
    1.18 + * You should have received a copy of the GNU Lesser General
    1.19 + * Public License along with this library; if not, write to the
    1.20 + * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
    1.21 + * Boston, MA 02111-1307, USA.
    1.22 + */
    1.23 +
    1.24 +/*
    1.25 + * FIXME: MT-safety
    1.26 + */
    1.27 +
    1.28 +#include "config.h"
    1.29 +
    1.30 +#include <string.h>
    1.31 +
    1.32 +#include "gvalue.h"
    1.33 +#include "gvaluecollector.h"
    1.34 +#include "gbsearcharray.h"
    1.35 +#include "gobjectalias.h"
    1.36 +
    1.37 +#ifdef __SYMBIAN32__
    1.38 +#include "gobject_wsd.h"
    1.39 +#endif /* __SYMBIAN32__ */
    1.40 +
    1.41 +/**
    1.42 + * SECTION:generic_values
    1.43 + * @short_description: A polymorphic type that can hold values of any
    1.44 + *     other type
    1.45 + * @see_also: The fundamental types which all support #GValue
    1.46 + *     operations and thus can be used as a type initializer for
    1.47 + *     g_value_init() are defined by a separate interface.  See the <link
    1.48 + *     linkend="gobject-Standard-Parameter-and-Value-Types">Standard
    1.49 + *     Values API</link> for details.
    1.50 + * @title: Generic values
    1.51 + *
    1.52 + * The #GValue structure is basically a variable container that consists
    1.53 + * of a type identifier and a specific value of that type.
    1.54 + * The type identifier within a #GValue structure always determines the
    1.55 + * type of the associated value.
    1.56 + * To create a undefined #GValue structure, simply create a zero-filled
    1.57 + * #GValue structure. To initialize the #GValue, use the g_value_init()
    1.58 + * function. A #GValue cannot be used until it is initialized.
    1.59 + * The basic type operations (such as freeing and copying) are determined
    1.60 + * by the #GTypeValueTable associated with the type ID stored in the #GValue.
    1.61 + * Other #GValue operations (such as converting values between types) are
    1.62 + * provided by this interface.
    1.63 + *
    1.64 + * The code in the example program below demonstrates #GValue's
    1.65 + * features.
    1.66 + *
    1.67 + * |[
    1.68 + * #include &lt;glib-object.h&gt;
    1.69 + *
    1.70 + * static void
    1.71 + * int2string (const GValue *src_value,
    1.72 + *             GValue       *dest_value)
    1.73 + * {
    1.74 + *   if (g_value_get_int (src_value) == 42)
    1.75 + *     g_value_set_static_string (dest_value, "An important number");
    1.76 + *   else
    1.77 + *     g_value_set_static_string (dest_value, "What's that?");
    1.78 + * }
    1.79 + *
    1.80 + * int
    1.81 + * main (int   argc,
    1.82 + *       char *argv[])
    1.83 + * {
    1.84 + *   /&ast; GValues must start zero-filled &ast;/
    1.85 + *   GValue a = {0};
    1.86 + *   GValue b = {0};
    1.87 + *   const gchar *message;
    1.88 + *
    1.89 + *   g_type_init ();
    1.90 + *
    1.91 + *   /&ast; The GValue starts empty &ast;/
    1.92 + *   g_assert (!G_VALUE_HOLDS_STRING (&amp;a));
    1.93 + *
    1.94 + *   /&ast; Put a string in it &ast;/
    1.95 + *   g_value_init (&amp;a, G_TYPE_STRING);
    1.96 + *   g_assert (G_VALUE_HOLDS_STRING (&amp;a));
    1.97 + *   g_value_set_static_string (&amp;a, "Hello, world!");
    1.98 + *   g_printf ("%s\n", g_value_get_string (&amp;a));
    1.99 + *
   1.100 + *   /&ast; Reset it to its pristine state &ast;/
   1.101 + *   g_value_unset (&amp;a);
   1.102 + *
   1.103 + *   /&ast; It can then be reused for another type &ast;/
   1.104 + *   g_value_init (&amp;a, G_TYPE_INT);
   1.105 + *   g_value_set_int (&amp;a, 42);
   1.106 + *
   1.107 + *   /&ast; Attempt to transform it into a GValue of type STRING &ast;/
   1.108 + *   g_value_init (&amp;b, G_TYPE_STRING);
   1.109 + *
   1.110 + *   /&ast; An INT is transformable to a STRING &ast;/
   1.111 + *   g_assert (g_value_type_transformable (G_TYPE_INT, G_TYPE_STRING));
   1.112 + *
   1.113 + *   g_value_transform (&amp;a, &amp;b);
   1.114 + *   g_printf ("%s\n", g_value_get_string (&amp;b));
   1.115 + *
   1.116 + *   /&ast; Attempt to transform it again using a custom transform function &ast;/
   1.117 + *   g_value_register_transform_func (G_TYPE_INT, G_TYPE_STRING, int2string);
   1.118 + *   g_value_transform (&amp;a, &amp;b);
   1.119 + *   g_printf ("%s\n", g_value_get_string (&amp;b));
   1.120 + *   return 0;
   1.121 + * }
   1.122 + * ]|
   1.123 + */
   1.124 +
   1.125 +
   1.126 +/* --- typedefs & structures --- */
   1.127 +typedef struct {
   1.128 +  GType src_type;
   1.129 +  GType dest_type;
   1.130 +  GValueTransform func;
   1.131 +} TransformEntry;
   1.132 +
   1.133 +
   1.134 +/* --- prototypes --- */
   1.135 +static gint	transform_entries_cmp	(gconstpointer bsearch_node1,
   1.136 +					 gconstpointer bsearch_node2);
   1.137 +
   1.138 +
   1.139 +/* --- variables --- */
   1.140 +#if EMULATOR
   1.141 +
   1.142 +PLS(transform_array,gvalue,GBSearchArray *) 
   1.143 +PLS(transform_bconfig,gvalue,GBSearchConfig )
   1.144 +
   1.145 +#define transform_array (*FUNCTION_NAME(transform_array,gvalue)())
   1.146 +#define transform_bconfig  (*FUNCTION_NAME(transform_bconfig ,gvalue)())
   1.147 +
   1.148 +const GBSearchConfig temp_transform_bconfig = {
   1.149 +  sizeof (TransformEntry),
   1.150 +  transform_entries_cmp,
   1.151 +  0,
   1.152 +};
   1.153 +
   1.154 +
   1.155 +#else
   1.156 +
   1.157 +static GBSearchArray *transform_array = NULL;
   1.158 +static GBSearchConfig transform_bconfig = {
   1.159 +  sizeof (TransformEntry),
   1.160 +  transform_entries_cmp,
   1.161 +  0,
   1.162 +};
   1.163 +
   1.164 +#endif /* EMULATOR */
   1.165 +
   1.166 +
   1.167 +/* --- functions --- */
   1.168 +void
   1.169 +g_value_c_init (void)
   1.170 +{
   1.171 +  transform_array = g_bsearch_array_create (&transform_bconfig);
   1.172 +}
   1.173 +
   1.174 +static inline void		/* keep this function in sync with gvaluecollector.h and gboxed.c */
   1.175 +value_meminit (GValue *value,
   1.176 +	       GType   value_type)
   1.177 +{
   1.178 +  value->g_type = value_type;
   1.179 +  memset (value->data, 0, sizeof (value->data));
   1.180 +}
   1.181 +
   1.182 +/**
   1.183 + * g_value_init:
   1.184 + * @value: A zero-filled (uninitialized) #GValue structure.
   1.185 + * @g_type: Type the #GValue should hold values of.
   1.186 + *
   1.187 + * Initializes @value with the default value of @type.
   1.188 + *
   1.189 + * Returns: the #GValue structure that has been passed in
   1.190 + */
   1.191 +EXPORT_C GValue*
   1.192 +g_value_init (GValue *value,
   1.193 +	      GType   g_type)
   1.194 +{
   1.195 +  /* g_return_val_if_fail (G_TYPE_IS_VALUE (g_type), NULL);	be more elaborate below */
   1.196 +  g_return_val_if_fail (value != NULL, NULL);
   1.197 +  /* g_return_val_if_fail (G_VALUE_TYPE (value) == 0, NULL);	be more elaborate below */
   1.198 +
   1.199 +  if (G_TYPE_IS_VALUE (g_type) && G_VALUE_TYPE (value) == 0)
   1.200 +    {
   1.201 +      GTypeValueTable *value_table = g_type_value_table_peek (g_type);
   1.202 +
   1.203 +      /* setup and init */
   1.204 +      value_meminit (value, g_type);
   1.205 +      value_table->value_init (value);
   1.206 +    }
   1.207 +  else if (G_VALUE_TYPE (value))
   1.208 +    g_warning ("%s: cannot initialize GValue with type `%s', the value has already been initialized as `%s'",
   1.209 +	       G_STRLOC,
   1.210 +	       g_type_name (g_type),
   1.211 +	       g_type_name (G_VALUE_TYPE (value)));
   1.212 +  else /* !G_TYPE_IS_VALUE (g_type) */
   1.213 +    g_warning ("%s: cannot initialize GValue with type `%s', %s",
   1.214 +	       G_STRLOC,
   1.215 +	       g_type_name (g_type),
   1.216 +	       g_type_value_table_peek (g_type) ?
   1.217 +	       "this type is abstract with regards to GValue use, use a more specific (derived) type" :
   1.218 +	       "this type has no GTypeValueTable implementation");
   1.219 +  return value;
   1.220 +}
   1.221 +
   1.222 +/**
   1.223 + * g_value_copy:
   1.224 + * @src_value: An initialized #GValue structure.
   1.225 + * @dest_value: An initialized #GValue structure of the same type as @src_value.
   1.226 + *
   1.227 + * Copies the value of @src_value into @dest_value.
   1.228 + */
   1.229 +EXPORT_C void
   1.230 +g_value_copy (const GValue *src_value,
   1.231 +	      GValue       *dest_value)
   1.232 +{
   1.233 +  g_return_if_fail (G_IS_VALUE (src_value));
   1.234 +  g_return_if_fail (G_IS_VALUE (dest_value));
   1.235 +  g_return_if_fail (g_value_type_compatible (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)));
   1.236 +  
   1.237 +  if (src_value != dest_value)
   1.238 +    {
   1.239 +      GType dest_type = G_VALUE_TYPE (dest_value);
   1.240 +      GTypeValueTable *value_table = g_type_value_table_peek (dest_type);
   1.241 +
   1.242 +      /* make sure dest_value's value is free()d */
   1.243 +      if (value_table->value_free)
   1.244 +	value_table->value_free (dest_value);
   1.245 +
   1.246 +      /* setup and copy */
   1.247 +      value_meminit (dest_value, dest_type);
   1.248 +      value_table->value_copy (src_value, dest_value);
   1.249 +    }
   1.250 +}
   1.251 +
   1.252 +/**
   1.253 + * g_value_reset:
   1.254 + * @value: An initialized #GValue structure.
   1.255 + *
   1.256 + * Clears the current value in @value and resets it to the default value
   1.257 + * (as if the value had just been initialized).
   1.258 + *
   1.259 + * Returns: the #GValue structure that has been passed in
   1.260 + */
   1.261 +EXPORT_C GValue*
   1.262 +g_value_reset (GValue *value)
   1.263 +{
   1.264 +  GTypeValueTable *value_table;
   1.265 +  GType g_type;
   1.266 +  
   1.267 +  g_return_val_if_fail (G_IS_VALUE (value), NULL);
   1.268 +  
   1.269 +  g_type = G_VALUE_TYPE (value);
   1.270 +  value_table = g_type_value_table_peek (g_type);
   1.271 +
   1.272 +  /* make sure value's value is free()d */
   1.273 +  if (value_table->value_free)
   1.274 +    value_table->value_free (value);
   1.275 +
   1.276 +  /* setup and init */
   1.277 +  value_meminit (value, g_type);
   1.278 +  value_table->value_init (value);
   1.279 +
   1.280 +  return value;
   1.281 +}
   1.282 +
   1.283 +/**
   1.284 + * g_value_unset:
   1.285 + * @value: An initialized #GValue structure.
   1.286 + *
   1.287 + * Clears the current value in @value and "unsets" the type,
   1.288 + * this releases all resources associated with this GValue.
   1.289 + * An unset value is the same as an uninitialized (zero-filled)
   1.290 + * #GValue structure.
   1.291 + */
   1.292 +EXPORT_C void
   1.293 +g_value_unset (GValue *value)
   1.294 +{
   1.295 +  GTypeValueTable *value_table;
   1.296 +  
   1.297 +  g_return_if_fail (G_IS_VALUE (value));
   1.298 +
   1.299 +  value_table = g_type_value_table_peek (G_VALUE_TYPE (value));
   1.300 +
   1.301 +  if (value_table->value_free)
   1.302 +    value_table->value_free (value);
   1.303 +  memset (value, 0, sizeof (*value));
   1.304 +}
   1.305 +
   1.306 +/**
   1.307 + * g_value_fits_pointer:
   1.308 + * @value: An initialized #GValue structure.
   1.309 + *
   1.310 + * Determines if @value will fit inside the size of a pointer value.
   1.311 + * This is an internal function introduced mainly for C marshallers.
   1.312 + *
   1.313 + * Returns: %TRUE if @value will fit inside a pointer value.
   1.314 + */
   1.315 +EXPORT_C gboolean
   1.316 +g_value_fits_pointer (const GValue *value)
   1.317 +{
   1.318 +  GTypeValueTable *value_table;
   1.319 +
   1.320 +  g_return_val_if_fail (G_IS_VALUE (value), FALSE);
   1.321 +
   1.322 +  value_table = g_type_value_table_peek (G_VALUE_TYPE (value));
   1.323 +
   1.324 +  return value_table->value_peek_pointer != NULL;
   1.325 +}
   1.326 +
   1.327 +/**
   1.328 + * g_value_peek_pointer:
   1.329 + * @value: An initialized #GValue structure.
   1.330 + *
   1.331 + * Return the value contents as pointer. This function asserts that
   1.332 + * g_value_fits_pointer() returned %TRUE for the passed in value.
   1.333 + * This is an internal function introduced mainly for C marshallers.
   1.334 + *
   1.335 + * Returns: %TRUE if @value will fit inside a pointer value.
   1.336 + */
   1.337 +EXPORT_C gpointer
   1.338 +g_value_peek_pointer (const GValue *value)
   1.339 +{
   1.340 +  GTypeValueTable *value_table;
   1.341 +
   1.342 +  g_return_val_if_fail (G_IS_VALUE (value), NULL);
   1.343 +
   1.344 +  value_table = g_type_value_table_peek (G_VALUE_TYPE (value));
   1.345 +  if (!value_table->value_peek_pointer)
   1.346 +    {
   1.347 +      g_return_val_if_fail (g_value_fits_pointer (value) == TRUE, NULL);
   1.348 +      return NULL;
   1.349 +    }
   1.350 +
   1.351 +  return value_table->value_peek_pointer (value);
   1.352 +}
   1.353 +
   1.354 +/**
   1.355 + * g_value_set_instance:
   1.356 + * @value: An initialized #GValue structure.
   1.357 + * @instance: the instance
   1.358 + *
   1.359 + * Sets @value from an instantiatable type via the
   1.360 + * value_table's collect_value() function.
   1.361 + */
   1.362 +EXPORT_C void
   1.363 +g_value_set_instance (GValue  *value,
   1.364 +		      gpointer instance)
   1.365 +{
   1.366 +  GType g_type;
   1.367 +  GTypeValueTable *value_table;
   1.368 +  GTypeCValue cvalue;
   1.369 +  gchar *error_msg;
   1.370 +  
   1.371 +  g_return_if_fail (G_IS_VALUE (value));
   1.372 +  if (instance)
   1.373 +    {
   1.374 +      g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
   1.375 +      g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (instance), G_VALUE_TYPE (value)));
   1.376 +    }
   1.377 +  
   1.378 +  g_type = G_VALUE_TYPE (value);
   1.379 +  value_table = g_type_value_table_peek (g_type);
   1.380 +  
   1.381 +  g_return_if_fail (strcmp (value_table->collect_format, "p") == 0);
   1.382 +  
   1.383 +  memset (&cvalue, 0, sizeof (cvalue));
   1.384 +  cvalue.v_pointer = instance;
   1.385 +  
   1.386 +  /* make sure value's value is free()d */
   1.387 +  if (value_table->value_free)
   1.388 +    value_table->value_free (value);
   1.389 +
   1.390 +  /* setup and collect */
   1.391 +  value_meminit (value, g_type);
   1.392 +  error_msg = value_table->collect_value (value, 1, &cvalue, 0);
   1.393 +  if (error_msg)
   1.394 +    {
   1.395 +      g_warning ("%s: %s", G_STRLOC, error_msg);
   1.396 +      g_free (error_msg);
   1.397 +      
   1.398 +      /* we purposely leak the value here, it might not be
   1.399 +       * in a sane state if an error condition occoured
   1.400 +       */
   1.401 +      value_meminit (value, g_type);
   1.402 +      value_table->value_init (value);
   1.403 +    }
   1.404 +}
   1.405 +
   1.406 +static GValueTransform
   1.407 +transform_func_lookup (GType src_type,
   1.408 +		       GType dest_type)
   1.409 +{
   1.410 +  TransformEntry entry;
   1.411 +
   1.412 +  entry.src_type = src_type;
   1.413 +  do
   1.414 +    {
   1.415 +      entry.dest_type = dest_type;
   1.416 +      do
   1.417 +	{
   1.418 +	  TransformEntry *e;
   1.419 +	  
   1.420 +	  e = g_bsearch_array_lookup (transform_array, &transform_bconfig, &entry);
   1.421 +	  if (e)
   1.422 +	    {
   1.423 +	      /* need to check that there hasn't been a change in value handling */
   1.424 +	      if (g_type_value_table_peek (entry.dest_type) == g_type_value_table_peek (dest_type) &&
   1.425 +		  g_type_value_table_peek (entry.src_type) == g_type_value_table_peek (src_type))
   1.426 +		return e->func;
   1.427 +	    }
   1.428 +	  entry.dest_type = g_type_parent (entry.dest_type);
   1.429 +	}
   1.430 +      while (entry.dest_type);
   1.431 +      
   1.432 +      entry.src_type = g_type_parent (entry.src_type);
   1.433 +    }
   1.434 +  while (entry.src_type);
   1.435 +
   1.436 +  return NULL;
   1.437 +}
   1.438 +
   1.439 +static gint
   1.440 +transform_entries_cmp (gconstpointer bsearch_node1,
   1.441 +		       gconstpointer bsearch_node2)
   1.442 +{
   1.443 +  const TransformEntry *e1 = bsearch_node1;
   1.444 +  const TransformEntry *e2 = bsearch_node2;
   1.445 +  gint cmp = G_BSEARCH_ARRAY_CMP (e1->src_type, e2->src_type);
   1.446 +
   1.447 +  if (cmp)
   1.448 +    return cmp;
   1.449 +  else
   1.450 +    return G_BSEARCH_ARRAY_CMP (e1->dest_type, e2->dest_type);
   1.451 +}
   1.452 +
   1.453 +/**
   1.454 + * g_value_register_transform_func:
   1.455 + * @src_type: Source type.
   1.456 + * @dest_type: Target type.
   1.457 + * @transform_func: a function which transforms values of type @src_type
   1.458 + *  into value of type @dest_type
   1.459 + *
   1.460 + * Registers a value transformation function for use in g_value_transform().
   1.461 + * A previously registered transformation function for @src_type and @dest_type
   1.462 + * will be replaced.
   1.463 + */
   1.464 +EXPORT_C void
   1.465 +g_value_register_transform_func (GType           src_type,
   1.466 +				 GType           dest_type,
   1.467 +				 GValueTransform transform_func)
   1.468 +{
   1.469 +  TransformEntry entry;
   1.470 +
   1.471 +  /* these checks won't pass for dynamic types.
   1.472 +   * g_return_if_fail (G_TYPE_HAS_VALUE_TABLE (src_type));
   1.473 +   * g_return_if_fail (G_TYPE_HAS_VALUE_TABLE (dest_type));
   1.474 +   */
   1.475 +  g_return_if_fail (transform_func != NULL);
   1.476 +
   1.477 +  entry.src_type = src_type;
   1.478 +  entry.dest_type = dest_type;
   1.479 +
   1.480 +#if 0 /* let transform function replacement be a valid operation */
   1.481 +  if (g_bsearch_array_lookup (transform_array, &transform_bconfig, &entry))
   1.482 +    g_warning ("reregistering value transformation function (%p) for `%s' to `%s'",
   1.483 +	       transform_func,
   1.484 +	       g_type_name (src_type),
   1.485 +	       g_type_name (dest_type));
   1.486 +#endif
   1.487 +
   1.488 +  entry.func = transform_func;
   1.489 +  transform_array = g_bsearch_array_replace (transform_array, &transform_bconfig, &entry);
   1.490 +}
   1.491 +
   1.492 +/**
   1.493 + * g_value_type_transformable:
   1.494 + * @src_type: Source type.
   1.495 + * @dest_type: Target type.
   1.496 + *
   1.497 + * Check whether g_value_transform() is able to transform values
   1.498 + * of type @src_type into values of type @dest_type.
   1.499 + *
   1.500 + * Returns: %TRUE if the transformation is possible, %FALSE otherwise.
   1.501 + */
   1.502 +EXPORT_C gboolean
   1.503 +g_value_type_transformable (GType src_type,
   1.504 +			    GType dest_type)
   1.505 +{
   1.506 +  g_return_val_if_fail (G_TYPE_IS_VALUE (src_type), FALSE);
   1.507 +  g_return_val_if_fail (G_TYPE_IS_VALUE (dest_type), FALSE);
   1.508 +
   1.509 +  return (g_value_type_compatible (src_type, dest_type) ||
   1.510 +	  transform_func_lookup (src_type, dest_type) != NULL);
   1.511 +}
   1.512 +
   1.513 +/**
   1.514 + * g_value_type_compatible:
   1.515 + * @src_type: source type to be copied.
   1.516 + * @dest_type: destination type for copying.
   1.517 + *
   1.518 + * Returns whether a #GValue of type @src_type can be copied into
   1.519 + * a #GValue of type @dest_type.
   1.520 + *
   1.521 + * Returns: %TRUE if g_value_copy() is possible with @src_type and @dest_type.
   1.522 + */
   1.523 +EXPORT_C gboolean
   1.524 +g_value_type_compatible (GType src_type,
   1.525 +			 GType dest_type)
   1.526 +{
   1.527 +  g_return_val_if_fail (G_TYPE_IS_VALUE (src_type), FALSE);
   1.528 +  g_return_val_if_fail (G_TYPE_IS_VALUE (dest_type), FALSE);
   1.529 +
   1.530 +  return (g_type_is_a (src_type, dest_type) &&
   1.531 +	  g_type_value_table_peek (dest_type) == g_type_value_table_peek (src_type));
   1.532 +}
   1.533 +
   1.534 +/**
   1.535 + * g_value_transform:
   1.536 + * @src_value: Source value.
   1.537 + * @dest_value: Target value.
   1.538 + *
   1.539 + * Tries to cast the contents of @src_value into a type appropriate
   1.540 + * to store in @dest_value, e.g. to transform a %G_TYPE_INT value
   1.541 + * into a %G_TYPE_FLOAT value. Performing transformations between
   1.542 + * value types might incur precision lossage. Especially
   1.543 + * transformations into strings might reveal seemingly arbitrary
   1.544 + * results and shouldn't be relied upon for production code (such
   1.545 + * as rcfile value or object property serialization).
   1.546 + *
   1.547 + * Returns: Whether a transformation rule was found and could be applied.
   1.548 + *  Upon failing transformations, @dest_value is left untouched.
   1.549 + */
   1.550 +EXPORT_C gboolean
   1.551 +g_value_transform (const GValue *src_value,
   1.552 +		   GValue       *dest_value)
   1.553 +{
   1.554 +  GType dest_type;
   1.555 +
   1.556 +  g_return_val_if_fail (G_IS_VALUE (src_value), FALSE);
   1.557 +  g_return_val_if_fail (G_IS_VALUE (dest_value), FALSE);
   1.558 +
   1.559 +  dest_type = G_VALUE_TYPE (dest_value);
   1.560 +  if (g_value_type_compatible (G_VALUE_TYPE (src_value), dest_type))
   1.561 +    {
   1.562 +      g_value_copy (src_value, dest_value);
   1.563 +      
   1.564 +      return TRUE;
   1.565 +    }
   1.566 +  else
   1.567 +    {
   1.568 +      GValueTransform transform = transform_func_lookup (G_VALUE_TYPE (src_value), dest_type);
   1.569 +
   1.570 +      if (transform)
   1.571 +	{
   1.572 +	  g_value_unset (dest_value);
   1.573 +	  
   1.574 +	  /* setup and transform */
   1.575 +	  value_meminit (dest_value, dest_type);
   1.576 +	  transform (src_value, dest_value);
   1.577 +	  
   1.578 +	  return TRUE;
   1.579 +	}
   1.580 +    }
   1.581 +  return FALSE;
   1.582 +}
   1.583 +
   1.584 +#define __G_VALUE_C__
   1.585 +#include "gobjectaliasdef.c"