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