glib/libgobject/src/gboxed.c
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /* GObject - GLib Type, Object, Parameter and Signal Library
       
     2  * Copyright (C) 2000-2001 Red Hat, Inc.
       
     3  * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
       
     4  *
       
     5  * This library is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU Lesser General Public
       
     7  * License as published by the Free Software Foundation; either
       
     8  * version 2 of the License, or (at your option) any later version.
       
     9  *
       
    10  * This library is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13  * Lesser General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU Lesser General
       
    16  * Public License along with this library; if not, write to the
       
    17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
       
    18  * Boston, MA 02111-1307, USA.
       
    19  */
       
    20 #include	"gboxed.h"
       
    21 
       
    22 #include	"gbsearcharray.h"
       
    23 #include	"gvalue.h"
       
    24 #include	"gvaluearray.h"
       
    25 #include	"gclosure.h"
       
    26 #include	"gvaluecollector.h"
       
    27 
       
    28 #include	"gobjectalias.h"
       
    29 
       
    30 #include <string.h>
       
    31 
       
    32 #ifdef __SYMBIAN32__
       
    33 #include <gobject_wsd.h>
       
    34 #endif /* __SYMBIAN32__ */
       
    35 
       
    36 
       
    37 /* --- typedefs & structures --- */
       
    38 typedef struct
       
    39 {
       
    40   GType		 type;
       
    41   GBoxedCopyFunc copy;
       
    42   GBoxedFreeFunc free;
       
    43 } BoxedNode;
       
    44 
       
    45 
       
    46 /* --- prototypes --- */
       
    47 static gint	boxed_nodes_cmp		(gconstpointer	p1,
       
    48 					 gconstpointer	p2);
       
    49 
       
    50 
       
    51 /* --- variables --- */
       
    52 #if EMULATOR
       
    53 
       
    54 PLS(boxed_bsa,gboxed,GBSearchArray *)
       
    55 #define boxed_bsa (*FUNCTION_NAME(boxed_bsa,gboxed)())
       
    56 
       
    57 #else
       
    58 
       
    59 static GBSearchArray *boxed_bsa = NULL;
       
    60 
       
    61 #endif /*EMULATOR */
       
    62 static const GBSearchConfig boxed_bconfig = {
       
    63   sizeof (BoxedNode),
       
    64   boxed_nodes_cmp,
       
    65   0,
       
    66 };
       
    67 
       
    68 
       
    69 /* --- functions --- */
       
    70 static gint
       
    71 boxed_nodes_cmp	(gconstpointer p1,
       
    72 		 gconstpointer p2)
       
    73 {
       
    74   const BoxedNode *node1 = p1, *node2 = p2;
       
    75 
       
    76   return G_BSEARCH_ARRAY_CMP (node1->type, node2->type);
       
    77 }
       
    78 
       
    79 static inline void              /* keep this function in sync with gvalue.c */
       
    80 value_meminit (GValue *value,
       
    81 	       GType   value_type)
       
    82 {
       
    83   value->g_type = value_type;
       
    84   memset (value->data, 0, sizeof (value->data));
       
    85 }
       
    86 
       
    87 static gpointer
       
    88 value_copy (gpointer boxed)
       
    89 {
       
    90   const GValue *src_value = boxed;    
       
    91   GValue *dest_value = g_new0 (GValue, 1); 
       
    92 
       
    93   if (G_VALUE_TYPE (src_value))
       
    94     {
       
    95       g_value_init (dest_value, G_VALUE_TYPE (src_value));
       
    96       g_value_copy (src_value, dest_value);
       
    97     }
       
    98   return dest_value;
       
    99 }
       
   100 
       
   101 static void
       
   102 value_free (gpointer boxed)
       
   103 {
       
   104   GValue *value = boxed;
       
   105 
       
   106   if (G_VALUE_TYPE (value))
       
   107     g_value_unset (value);
       
   108   g_free (value);
       
   109 }
       
   110 
       
   111 void
       
   112 g_boxed_type_init (void) 
       
   113 {
       
   114   static const GTypeInfo info = {
       
   115     0,                          /* class_size */
       
   116     NULL,                       /* base_init */
       
   117     NULL,                       /* base_destroy */
       
   118     NULL,                       /* class_init */
       
   119     NULL,                       /* class_destroy */
       
   120     NULL,                       /* class_data */
       
   121     0,                          /* instance_size */
       
   122     0,                          /* n_preallocs */
       
   123     NULL,                       /* instance_init */
       
   124     NULL,                       /* value_table */
       
   125   };
       
   126   const GTypeFundamentalInfo finfo = { G_TYPE_FLAG_DERIVABLE, };
       
   127   GType type;
       
   128 
       
   129   boxed_bsa = g_bsearch_array_create (&boxed_bconfig);
       
   130 
       
   131   /* G_TYPE_BOXED
       
   132    */
       
   133   type = g_type_register_fundamental (G_TYPE_BOXED, g_intern_static_string ("GBoxed"), &info, &finfo,
       
   134 				      G_TYPE_FLAG_ABSTRACT | G_TYPE_FLAG_VALUE_ABSTRACT);
       
   135   g_assert (type == G_TYPE_BOXED);
       
   136 }
       
   137 
       
   138 #if EMULATOR
       
   139 
       
   140 PLS(type_id,g_closure_get_type ,GType)
       
   141 #define type_id (*FUNCTION_NAME(type_id,g_closure_get_type )())
       
   142 
       
   143 #endif /* EMULATOR */
       
   144 
       
   145 EXPORT_C GType
       
   146 g_closure_get_type (void)
       
   147 {
       
   148   #if !(EMULATOR)
       
   149   static GType type_id = 0;
       
   150   #endif /* EMULATOR */
       
   151 
       
   152   if (!type_id)
       
   153     type_id = g_boxed_type_register_static (g_intern_static_string ("GClosure"),
       
   154 					    (GBoxedCopyFunc) g_closure_ref,
       
   155 					    (GBoxedFreeFunc) g_closure_unref);
       
   156   return type_id;
       
   157 }
       
   158 
       
   159 #if EMULATOR
       
   160 
       
   161 #undef type_id
       
   162 PLS(type_id,g_value_get_type ,GType)
       
   163 #define type_id (*FUNCTION_NAME(type_id,g_value_get_type )())
       
   164 
       
   165 #endif /* EMULATOR */
       
   166 
       
   167 EXPORT_C GType
       
   168 g_value_get_type (void)
       
   169 {
       
   170   #if !(EMULATOR)
       
   171   static GType type_id = 0;
       
   172   #endif /* EMULATOR */
       
   173 
       
   174   if (!type_id)
       
   175     type_id = g_boxed_type_register_static (g_intern_static_string ("GValue"),
       
   176 					    value_copy,
       
   177 					    value_free);
       
   178   return type_id;
       
   179 }
       
   180 
       
   181 #if EMULATOR
       
   182 
       
   183 #undef type_id
       
   184 PLS(type_id,g_value_array_get_type ,GType)
       
   185 #define type_id (*FUNCTION_NAME(type_id,g_value_array_get_type )())
       
   186 
       
   187 #endif /* EMULATOR */
       
   188 
       
   189 
       
   190 EXPORT_C GType
       
   191 g_value_array_get_type (void)
       
   192 {
       
   193   #if !(EMULATOR)
       
   194   static GType type_id = 0;
       
   195   #endif /* EMULATOR */
       
   196 
       
   197   if (!type_id)
       
   198     type_id = g_boxed_type_register_static (g_intern_static_string ("GValueArray"),
       
   199 					    (GBoxedCopyFunc) g_value_array_copy,
       
   200 					    (GBoxedFreeFunc) g_value_array_free);
       
   201   return type_id;
       
   202 }
       
   203 
       
   204 static gpointer
       
   205 gdate_copy (gpointer boxed)
       
   206 {
       
   207   const GDate *date = (const GDate*) boxed;
       
   208 
       
   209   return g_date_new_julian (g_date_get_julian (date));
       
   210 }
       
   211 
       
   212 
       
   213 #if EMULATOR
       
   214 
       
   215 #undef type_id
       
   216 PLS(type_id,g_date_get_type ,GType)
       
   217 #define type_id (*FUNCTION_NAME(type_id,g_date_get_type )())
       
   218 
       
   219 #endif /* EMULATOR */
       
   220 
       
   221 
       
   222 EXPORT_C GType
       
   223 g_date_get_type (void)
       
   224 {
       
   225   #if !(EMULATOR)
       
   226   static GType type_id = 0;
       
   227   #endif /* EMULATOR */
       
   228 
       
   229   if (!type_id)
       
   230     type_id = g_boxed_type_register_static (g_intern_static_string ("GDate"),
       
   231 					    (GBoxedCopyFunc) gdate_copy,
       
   232 					    (GBoxedFreeFunc) g_date_free);
       
   233   return type_id;
       
   234 }
       
   235 
       
   236 #if EMULATOR
       
   237 
       
   238 #undef type_id
       
   239 PLS(type_id,g_strv_get_type ,GType)
       
   240 #define type_id (*FUNCTION_NAME(type_id,g_strv_get_type )())
       
   241 
       
   242 #endif /* EMULATOR */
       
   243 
       
   244 EXPORT_C GType
       
   245 g_strv_get_type (void)
       
   246 {
       
   247   #if !(EMULATOR)
       
   248   static GType type_id = 0;
       
   249   #endif /* EMULATOR */
       
   250 
       
   251   if (!type_id)
       
   252     type_id = g_boxed_type_register_static (g_intern_static_string ("GStrv"),
       
   253 					    (GBoxedCopyFunc) g_strdupv,
       
   254 					    (GBoxedFreeFunc) g_strfreev);
       
   255   return type_id;
       
   256 }
       
   257 
       
   258 static gpointer
       
   259 gstring_copy (gpointer boxed)
       
   260 {
       
   261   const GString *src_gstring = boxed;
       
   262 
       
   263   return g_string_new_len (src_gstring->str, src_gstring->len);
       
   264 }
       
   265 
       
   266 static void
       
   267 gstring_free (gpointer boxed)
       
   268 {
       
   269   GString *gstring = boxed;
       
   270 
       
   271   g_string_free (gstring, TRUE);
       
   272 }
       
   273 
       
   274 #if EMULATOR
       
   275 
       
   276 #undef type_id
       
   277 PLS(type_id,g_gstring_get_type ,GType)
       
   278 #define type_id (*FUNCTION_NAME(type_id,g_gstring_get_type )())
       
   279 
       
   280 #endif /* EMULATOR */
       
   281 
       
   282 EXPORT_C GType
       
   283 g_gstring_get_type (void)
       
   284 {
       
   285   #if !(EMULATOR)
       
   286   static GType type_id = 0;
       
   287   #endif /* !(EMULATOR) */
       
   288 
       
   289   if (!type_id)
       
   290     type_id = g_boxed_type_register_static (g_intern_static_string ("GString"),
       
   291                                             /* the naming is a bit odd, but GString is obviously not G_TYPE_STRING */
       
   292 					    gstring_copy,
       
   293 					    gstring_free);
       
   294   return type_id;
       
   295 }
       
   296 
       
   297 static gpointer
       
   298 hash_table_copy (gpointer boxed)
       
   299 {
       
   300   GHashTable *hash_table = boxed;
       
   301   return g_hash_table_ref (hash_table);
       
   302 }
       
   303 
       
   304 static void
       
   305 hash_table_free (gpointer boxed)
       
   306 {
       
   307   GHashTable *hash_table = boxed;
       
   308   g_hash_table_unref (hash_table);
       
   309 }
       
   310 
       
   311 #if EMULATOR
       
   312 
       
   313 #undef type_id
       
   314 PLS(type_id,g_hash_table_get_type ,GType)
       
   315 #define type_id (*FUNCTION_NAME(type_id,g_hash_table_get_type )())
       
   316 
       
   317 #endif /* EMULATOR */
       
   318 
       
   319 EXPORT_C GType
       
   320 g_hash_table_get_type (void)
       
   321 {
       
   322   #if !(EMULATOR)
       
   323   static GType type_id = 0;
       
   324   #endif */ !(EMULATOR) */
       
   325   if (!type_id)
       
   326     type_id = g_boxed_type_register_static (g_intern_static_string ("GHashTable"),
       
   327 					    hash_table_copy, hash_table_free);
       
   328   return type_id;
       
   329 }
       
   330 
       
   331 #if EMULATOR
       
   332 #undef type_id
       
   333 #endif /* EMULATOR */
       
   334 
       
   335 static void
       
   336 boxed_proxy_value_init (GValue *value)
       
   337 {
       
   338   value->data[0].v_pointer = NULL;
       
   339 }
       
   340 
       
   341 static void
       
   342 boxed_proxy_value_free (GValue *value)
       
   343 {
       
   344   if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
       
   345     {
       
   346       BoxedNode key, *node;
       
   347 
       
   348       key.type = G_VALUE_TYPE (value);
       
   349       node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
       
   350       node->free (value->data[0].v_pointer);
       
   351     }
       
   352 }
       
   353 
       
   354 static void
       
   355 boxed_proxy_value_copy (const GValue *src_value,
       
   356 			GValue       *dest_value)
       
   357 {
       
   358   if (src_value->data[0].v_pointer)
       
   359     {
       
   360       BoxedNode key, *node;
       
   361 
       
   362       key.type = G_VALUE_TYPE (src_value);
       
   363       node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
       
   364       dest_value->data[0].v_pointer = node->copy (src_value->data[0].v_pointer);
       
   365     }
       
   366   else
       
   367     dest_value->data[0].v_pointer = src_value->data[0].v_pointer;
       
   368 }
       
   369 
       
   370 static gpointer
       
   371 boxed_proxy_value_peek_pointer (const GValue *value)
       
   372 {
       
   373   return value->data[0].v_pointer;
       
   374 }
       
   375 
       
   376 static gchar*
       
   377 boxed_proxy_collect_value (GValue      *value,
       
   378 			   guint        n_collect_values,
       
   379 			   GTypeCValue *collect_values,
       
   380 			   guint        collect_flags)
       
   381 {
       
   382   BoxedNode key, *node;
       
   383 
       
   384   key.type = G_VALUE_TYPE (value);
       
   385   node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
       
   386 
       
   387   if (!collect_values[0].v_pointer)
       
   388     value->data[0].v_pointer = NULL;
       
   389   else
       
   390     {
       
   391       if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
       
   392 	{
       
   393 	  value->data[0].v_pointer = collect_values[0].v_pointer;
       
   394 	  value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
       
   395 	}
       
   396       else
       
   397 	value->data[0].v_pointer = node->copy (collect_values[0].v_pointer);
       
   398     }
       
   399 
       
   400   return NULL;
       
   401 }
       
   402 
       
   403 static gchar*
       
   404 boxed_proxy_lcopy_value (const GValue *value,
       
   405 			 guint         n_collect_values,
       
   406 			 GTypeCValue  *collect_values,
       
   407 			 guint         collect_flags)
       
   408 {
       
   409   gpointer *boxed_p = collect_values[0].v_pointer;
       
   410 
       
   411   if (!boxed_p)
       
   412     return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
       
   413 
       
   414   if (!value->data[0].v_pointer)
       
   415     *boxed_p = NULL;
       
   416   else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
       
   417     *boxed_p = value->data[0].v_pointer;
       
   418   else
       
   419     {
       
   420       BoxedNode key, *node;
       
   421 
       
   422       key.type = G_VALUE_TYPE (value);
       
   423       node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
       
   424       *boxed_p = node->copy (value->data[0].v_pointer);
       
   425     }
       
   426 
       
   427   return NULL;
       
   428 }
       
   429 
       
   430 EXPORT_C GType
       
   431 g_boxed_type_register_static (const gchar   *name,
       
   432 			      GBoxedCopyFunc boxed_copy,
       
   433 			      GBoxedFreeFunc boxed_free)
       
   434 {
       
   435   static const GTypeValueTable vtable = {
       
   436     boxed_proxy_value_init,
       
   437     boxed_proxy_value_free,
       
   438     boxed_proxy_value_copy,
       
   439     boxed_proxy_value_peek_pointer,
       
   440     "p",
       
   441     boxed_proxy_collect_value,
       
   442     "p",
       
   443     boxed_proxy_lcopy_value,
       
   444   };
       
   445   static const GTypeInfo type_info = {
       
   446     0,			/* class_size */
       
   447     NULL,		/* base_init */
       
   448     NULL,		/* base_finalize */
       
   449     NULL,		/* class_init */
       
   450     NULL,		/* class_finalize */
       
   451     NULL,		/* class_data */
       
   452     0,			/* instance_size */
       
   453     0,			/* n_preallocs */
       
   454     NULL,		/* instance_init */
       
   455     &vtable,		/* value_table */
       
   456   };
       
   457   GType type;
       
   458 
       
   459   g_return_val_if_fail (name != NULL, 0);
       
   460   g_return_val_if_fail (boxed_copy != NULL, 0);
       
   461   g_return_val_if_fail (boxed_free != NULL, 0);
       
   462   g_return_val_if_fail (g_type_from_name (name) == 0, 0);
       
   463 
       
   464   type = g_type_register_static (G_TYPE_BOXED, name, &type_info, 0);
       
   465 
       
   466   /* install proxy functions upon successfull registration */
       
   467   if (type)
       
   468     {
       
   469       BoxedNode key;
       
   470 
       
   471       key.type = type;
       
   472       key.copy = boxed_copy;
       
   473       key.free = boxed_free;
       
   474       boxed_bsa = g_bsearch_array_insert (boxed_bsa, &boxed_bconfig, &key);
       
   475     }
       
   476 
       
   477   return type;
       
   478 }
       
   479 
       
   480 EXPORT_C gpointer
       
   481 g_boxed_copy (GType         boxed_type,
       
   482 	      gconstpointer src_boxed)
       
   483 {
       
   484   GTypeValueTable *value_table;
       
   485   gpointer dest_boxed;
       
   486 
       
   487   g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
       
   488   g_return_val_if_fail (G_TYPE_IS_ABSTRACT (boxed_type) == FALSE, NULL);
       
   489   g_return_val_if_fail (src_boxed != NULL, NULL);
       
   490 
       
   491   value_table = g_type_value_table_peek (boxed_type);
       
   492   if (!value_table)
       
   493     g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL);
       
   494 
       
   495   /* check if our proxying implementation is used, we can short-cut here */
       
   496   if (value_table->value_copy == boxed_proxy_value_copy)
       
   497     {
       
   498       BoxedNode key, *node;
       
   499 
       
   500       key.type = boxed_type;
       
   501       node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
       
   502       dest_boxed = node->copy ((gpointer) src_boxed);
       
   503     }
       
   504   else
       
   505     {
       
   506       GValue src_value, dest_value;
       
   507       
       
   508       /* we heavily rely on third-party boxed type value vtable
       
   509        * implementations to follow normal boxed value storage
       
   510        * (data[0].v_pointer is the boxed struct, and
       
   511        * data[1].v_uint holds the G_VALUE_NOCOPY_CONTENTS flag,
       
   512        * rest zero).
       
   513        * but then, we can expect that since we layed out the
       
   514        * g_boxed_*() API.
       
   515        * data[1].v_uint&G_VALUE_NOCOPY_CONTENTS shouldn't be set
       
   516        * after a copy.
       
   517        */
       
   518       /* equiv. to g_value_set_static_boxed() */
       
   519       value_meminit (&src_value, boxed_type);
       
   520       src_value.data[0].v_pointer = (gpointer) src_boxed;
       
   521       src_value.data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
       
   522 
       
   523       /* call third-party code copy function, fingers-crossed */
       
   524       value_meminit (&dest_value, boxed_type);
       
   525       value_table->value_copy (&src_value, &dest_value);
       
   526 
       
   527       /* double check and grouse if things went wrong */
       
   528       if (dest_value.data[1].v_ulong)
       
   529 	g_warning ("the copy_value() implementation of type `%s' seems to make use of reserved GValue fields",
       
   530 		   g_type_name (boxed_type));
       
   531 
       
   532       dest_boxed = dest_value.data[0].v_pointer;
       
   533     }
       
   534 
       
   535   return dest_boxed;
       
   536 }
       
   537 
       
   538 EXPORT_C void
       
   539 g_boxed_free (GType    boxed_type,
       
   540 	      gpointer boxed)
       
   541 {
       
   542   GTypeValueTable *value_table;
       
   543 
       
   544   g_return_if_fail (G_TYPE_IS_BOXED (boxed_type));
       
   545   g_return_if_fail (G_TYPE_IS_ABSTRACT (boxed_type) == FALSE);
       
   546   g_return_if_fail (boxed != NULL);
       
   547 
       
   548   value_table = g_type_value_table_peek (boxed_type);
       
   549   if (!value_table)
       
   550     g_return_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type));
       
   551 
       
   552   /* check if our proxying implementation is used, we can short-cut here */
       
   553   if (value_table->value_free == boxed_proxy_value_free)
       
   554     {
       
   555       BoxedNode key, *node;
       
   556 
       
   557       key.type = boxed_type;
       
   558       node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
       
   559       node->free (boxed);
       
   560     }
       
   561   else
       
   562     {
       
   563       GValue value;
       
   564 
       
   565       /* see g_boxed_copy() on why we think we can do this */
       
   566       value_meminit (&value, boxed_type);
       
   567       value.data[0].v_pointer = boxed;
       
   568       value_table->value_free (&value);
       
   569     }
       
   570 }
       
   571 
       
   572 EXPORT_C gpointer
       
   573 g_value_get_boxed (const GValue *value)
       
   574 {
       
   575   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), NULL);
       
   576   g_return_val_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)), NULL);
       
   577 
       
   578   return value->data[0].v_pointer;
       
   579 }
       
   580 
       
   581 EXPORT_C gpointer
       
   582 g_value_dup_boxed (const GValue *value)
       
   583 {
       
   584   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), NULL);
       
   585   g_return_val_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)), NULL);
       
   586 
       
   587   return value->data[0].v_pointer ? g_boxed_copy (G_VALUE_TYPE (value), value->data[0].v_pointer) : NULL;
       
   588 }
       
   589 
       
   590 static inline void
       
   591 value_set_boxed_internal (GValue       *value,
       
   592 			  gconstpointer const_boxed,
       
   593 			  gboolean      need_copy,
       
   594 			  gboolean      need_free)
       
   595 {
       
   596   BoxedNode key, *node;
       
   597   gpointer boxed = (gpointer) const_boxed;
       
   598 
       
   599   if (!boxed)
       
   600     {
       
   601       /* just resetting to NULL might not be desired, need to
       
   602        * have value reinitialized also (for values defaulting
       
   603        * to other default value states than a NULL data pointer),
       
   604        * g_value_reset() will handle this
       
   605        */
       
   606       g_value_reset (value);
       
   607       return;
       
   608     }
       
   609 
       
   610   key.type = G_VALUE_TYPE (value);
       
   611   node = g_bsearch_array_lookup (boxed_bsa, &boxed_bconfig, &key);
       
   612 
       
   613   if (node)
       
   614     {
       
   615       /* we proxy this type, free contents and copy right away */
       
   616       if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
       
   617 	node->free (value->data[0].v_pointer);
       
   618       value->data[1].v_uint = need_free ? 0 : G_VALUE_NOCOPY_CONTENTS;
       
   619       value->data[0].v_pointer = need_copy ? node->copy (boxed) : boxed;
       
   620     }
       
   621   else
       
   622     {
       
   623       /* we don't handle this type, free contents and let g_boxed_copy()
       
   624        * figure what's required
       
   625        */
       
   626       if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
       
   627 	g_boxed_free (G_VALUE_TYPE (value), value->data[0].v_pointer);
       
   628       value->data[1].v_uint = need_free ? 0 : G_VALUE_NOCOPY_CONTENTS;
       
   629       value->data[0].v_pointer = need_copy ? g_boxed_copy (G_VALUE_TYPE (value), boxed) : boxed;
       
   630     }
       
   631 }
       
   632 
       
   633 EXPORT_C void
       
   634 g_value_set_boxed (GValue       *value,
       
   635 		   gconstpointer boxed)
       
   636 {
       
   637   g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
       
   638   g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)));
       
   639 
       
   640   value_set_boxed_internal (value, boxed, TRUE, TRUE);
       
   641 }
       
   642 
       
   643 EXPORT_C void
       
   644 g_value_set_static_boxed (GValue       *value,
       
   645 			  gconstpointer boxed)
       
   646 {
       
   647   g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
       
   648   g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)));
       
   649 
       
   650   value_set_boxed_internal (value, boxed, FALSE, FALSE);
       
   651 }
       
   652 
       
   653 EXPORT_C void
       
   654 g_value_set_boxed_take_ownership (GValue       *value,
       
   655 				  gconstpointer boxed)
       
   656 {
       
   657   g_value_take_boxed (value, boxed);
       
   658 }
       
   659 
       
   660 EXPORT_C void
       
   661 g_value_take_boxed (GValue       *value,
       
   662 		    gconstpointer boxed)
       
   663 {
       
   664   g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
       
   665   g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)));
       
   666 
       
   667   value_set_boxed_internal (value, boxed, FALSE, TRUE);
       
   668 }
       
   669 
       
   670 #define __G_BOXED_C__
       
   671 #include "gobjectaliasdef.c"