• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1998-1999, 2000-2001 Tim Janik and 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.1 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, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef __G_TYPE_H__
18 #define __G_TYPE_H__
19 
20 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
21 #error "Only <glib-object.h> can be included directly."
22 #endif
23 
24 #include        <glib.h>
25 
26 G_BEGIN_DECLS
27 
28 /* Basic Type Macros
29  */
30 /**
31  * G_TYPE_FUNDAMENTAL:
32  * @type: A #GType value.
33  *
34  * The fundamental type which is the ancestor of @type.
35  * Fundamental types are types that serve as ultimate bases for the derived types,
36  * thus they are the roots of distinct inheritance hierarchies.
37  */
38 #define G_TYPE_FUNDAMENTAL(type)	(g_type_fundamental (type))
39 /**
40  * G_TYPE_FUNDAMENTAL_MAX:
41  *
42  * An integer constant that represents the number of identifiers reserved
43  * for types that are assigned at compile-time.
44  */
45 #define	G_TYPE_FUNDAMENTAL_MAX		(255 << G_TYPE_FUNDAMENTAL_SHIFT)
46 
47 /* Constant fundamental types,
48  */
49 /**
50  * G_TYPE_INVALID:
51  *
52  * An invalid #GType used as error return value in some functions which return
53  * a #GType.
54  */
55 #define G_TYPE_INVALID			G_TYPE_MAKE_FUNDAMENTAL (0)
56 /**
57  * G_TYPE_NONE:
58  *
59  * A fundamental type which is used as a replacement for the C
60  * void return type.
61  */
62 #define G_TYPE_NONE			G_TYPE_MAKE_FUNDAMENTAL (1)
63 /**
64  * G_TYPE_INTERFACE:
65  *
66  * The fundamental type from which all interfaces are derived.
67  */
68 #define G_TYPE_INTERFACE		G_TYPE_MAKE_FUNDAMENTAL (2)
69 /**
70  * G_TYPE_CHAR:
71  *
72  * The fundamental type corresponding to #gchar.
73  * The type designated by G_TYPE_CHAR is unconditionally an 8-bit signed integer.
74  * This may or may not be the same type a the C type "gchar".
75  */
76 #define G_TYPE_CHAR			G_TYPE_MAKE_FUNDAMENTAL (3)
77 /**
78  * G_TYPE_UCHAR:
79  *
80  * The fundamental type corresponding to #guchar.
81  */
82 #define G_TYPE_UCHAR			G_TYPE_MAKE_FUNDAMENTAL (4)
83 /**
84  * G_TYPE_BOOLEAN:
85  *
86  * The fundamental type corresponding to #gboolean.
87  */
88 #define G_TYPE_BOOLEAN			G_TYPE_MAKE_FUNDAMENTAL (5)
89 /**
90  * G_TYPE_INT:
91  *
92  * The fundamental type corresponding to #gint.
93  */
94 #define G_TYPE_INT			G_TYPE_MAKE_FUNDAMENTAL (6)
95 /**
96  * G_TYPE_UINT:
97  *
98  * The fundamental type corresponding to #guint.
99  */
100 #define G_TYPE_UINT			G_TYPE_MAKE_FUNDAMENTAL (7)
101 /**
102  * G_TYPE_LONG:
103  *
104  * The fundamental type corresponding to #glong.
105  */
106 #define G_TYPE_LONG			G_TYPE_MAKE_FUNDAMENTAL (8)
107 /**
108  * G_TYPE_ULONG:
109  *
110  * The fundamental type corresponding to #gulong.
111  */
112 #define G_TYPE_ULONG			G_TYPE_MAKE_FUNDAMENTAL (9)
113 /**
114  * G_TYPE_INT64:
115  *
116  * The fundamental type corresponding to #gint64.
117  */
118 #define G_TYPE_INT64			G_TYPE_MAKE_FUNDAMENTAL (10)
119 /**
120  * G_TYPE_UINT64:
121  *
122  * The fundamental type corresponding to #guint64.
123  */
124 #define G_TYPE_UINT64			G_TYPE_MAKE_FUNDAMENTAL (11)
125 /**
126  * G_TYPE_ENUM:
127  *
128  * The fundamental type from which all enumeration types are derived.
129  */
130 #define G_TYPE_ENUM			G_TYPE_MAKE_FUNDAMENTAL (12)
131 /**
132  * G_TYPE_FLAGS:
133  *
134  * The fundamental type from which all flags types are derived.
135  */
136 #define G_TYPE_FLAGS			G_TYPE_MAKE_FUNDAMENTAL (13)
137 /**
138  * G_TYPE_FLOAT:
139  *
140  * The fundamental type corresponding to #gfloat.
141  */
142 #define G_TYPE_FLOAT			G_TYPE_MAKE_FUNDAMENTAL (14)
143 /**
144  * G_TYPE_DOUBLE:
145  *
146  * The fundamental type corresponding to #gdouble.
147  */
148 #define G_TYPE_DOUBLE			G_TYPE_MAKE_FUNDAMENTAL (15)
149 /**
150  * G_TYPE_STRING:
151  *
152  * The fundamental type corresponding to nul-terminated C strings.
153  */
154 #define G_TYPE_STRING			G_TYPE_MAKE_FUNDAMENTAL (16)
155 /**
156  * G_TYPE_POINTER:
157  *
158  * The fundamental type corresponding to #gpointer.
159  */
160 #define G_TYPE_POINTER			G_TYPE_MAKE_FUNDAMENTAL (17)
161 /**
162  * G_TYPE_BOXED:
163  *
164  * The fundamental type from which all boxed types are derived.
165  */
166 #define G_TYPE_BOXED			G_TYPE_MAKE_FUNDAMENTAL (18)
167 /**
168  * G_TYPE_PARAM:
169  *
170  * The fundamental type from which all #GParamSpec types are derived.
171  */
172 #define G_TYPE_PARAM			G_TYPE_MAKE_FUNDAMENTAL (19)
173 /**
174  * G_TYPE_OBJECT:
175  *
176  * The fundamental type for #GObject.
177  */
178 #define G_TYPE_OBJECT			G_TYPE_MAKE_FUNDAMENTAL (20)
179 /**
180  * G_TYPE_VARIANT:
181  *
182  * The fundamental type corresponding to #GVariant.
183  *
184  * All floating #GVariant instances passed through the #GType system are
185  * consumed.
186  *
187  * Note that callbacks in closures, and signal handlers
188  * for signals of return type %G_TYPE_VARIANT, must never return floating
189  * variants.
190  *
191  * Note: GLib 2.24 did include a boxed type with this name. It was replaced
192  * with this fundamental type in 2.26.
193  *
194  * Since: 2.26
195  */
196 #define	G_TYPE_VARIANT                  G_TYPE_MAKE_FUNDAMENTAL (21)
197 
198 
199 /* Reserved fundamental type numbers to create new fundamental
200  * type IDs with G_TYPE_MAKE_FUNDAMENTAL().
201  *
202  * Open an issue on https://gitlab.gnome.org/GNOME/glib/issues/new for
203  * reservations.
204  */
205 /**
206  * G_TYPE_FUNDAMENTAL_SHIFT:
207  *
208  * Shift value used in converting numbers to type IDs.
209  */
210 #define	G_TYPE_FUNDAMENTAL_SHIFT	(2)
211 /**
212  * G_TYPE_MAKE_FUNDAMENTAL:
213  * @x: the fundamental type number.
214  *
215  * Get the type ID for the fundamental type number @x.
216  * Use g_type_fundamental_next() instead of this macro to create new fundamental
217  * types.
218  *
219  * Returns: the GType
220  */
221 #define	G_TYPE_MAKE_FUNDAMENTAL(x)	((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
222 /**
223  * G_TYPE_RESERVED_GLIB_FIRST:
224  *
225  * First fundamental type number to create a new fundamental type id with
226  * G_TYPE_MAKE_FUNDAMENTAL() reserved for GLib.
227  */
228 #define G_TYPE_RESERVED_GLIB_FIRST	(22)
229 /**
230  * G_TYPE_RESERVED_GLIB_LAST:
231  *
232  * Last fundamental type number reserved for GLib.
233  */
234 #define G_TYPE_RESERVED_GLIB_LAST	(31)
235 /**
236  * G_TYPE_RESERVED_BSE_FIRST:
237  *
238  * First fundamental type number to create a new fundamental type id with
239  * G_TYPE_MAKE_FUNDAMENTAL() reserved for BSE.
240  */
241 #define G_TYPE_RESERVED_BSE_FIRST	(32)
242 /**
243  * G_TYPE_RESERVED_BSE_LAST:
244  *
245  * Last fundamental type number reserved for BSE.
246  */
247 #define G_TYPE_RESERVED_BSE_LAST	(48)
248 /**
249  * G_TYPE_RESERVED_USER_FIRST:
250  *
251  * First available fundamental type number to create new fundamental
252  * type id with G_TYPE_MAKE_FUNDAMENTAL().
253  */
254 #define G_TYPE_RESERVED_USER_FIRST	(49)
255 
256 
257 /* Type Checking Macros
258  */
259 /**
260  * G_TYPE_IS_FUNDAMENTAL:
261  * @type: A #GType value
262  *
263  * Checks if @type is a fundamental type.
264  *
265  * Returns: %TRUE on success
266  */
267 #define G_TYPE_IS_FUNDAMENTAL(type)             ((type) <= G_TYPE_FUNDAMENTAL_MAX)
268 /**
269  * G_TYPE_IS_DERIVED:
270  * @type: A #GType value
271  *
272  * Checks if @type is derived (or in object-oriented terminology:
273  * inherited) from another type (this holds true for all non-fundamental
274  * types).
275  *
276  * Returns: %TRUE on success
277  */
278 #define G_TYPE_IS_DERIVED(type)                 ((type) > G_TYPE_FUNDAMENTAL_MAX)
279 /**
280  * G_TYPE_IS_INTERFACE:
281  * @type: A #GType value
282  *
283  * Checks if @type is an interface type.
284  * An interface type provides a pure API, the implementation
285  * of which is provided by another type (which is then said to conform
286  * to the interface).  GLib interfaces are somewhat analogous to Java
287  * interfaces and C++ classes containing only pure virtual functions,
288  * with the difference that GType interfaces are not derivable (but see
289  * g_type_interface_add_prerequisite() for an alternative).
290  *
291  * Returns: %TRUE on success
292  */
293 #define G_TYPE_IS_INTERFACE(type)               (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE)
294 /**
295  * G_TYPE_IS_CLASSED:
296  * @type: A #GType value
297  *
298  * Checks if @type is a classed type.
299  *
300  * Returns: %TRUE on success
301  */
302 #define G_TYPE_IS_CLASSED(type)                 (g_type_test_flags ((type), G_TYPE_FLAG_CLASSED))
303 /**
304  * G_TYPE_IS_INSTANTIATABLE:
305  * @type: A #GType value
306  *
307  * Checks if @type can be instantiated.  Instantiation is the
308  * process of creating an instance (object) of this type.
309  *
310  * Returns: %TRUE on success
311  */
312 #define G_TYPE_IS_INSTANTIATABLE(type)          (g_type_test_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))
313 /**
314  * G_TYPE_IS_DERIVABLE:
315  * @type: A #GType value
316  *
317  * Checks if @type is a derivable type.  A derivable type can
318  * be used as the base class of a flat (single-level) class hierarchy.
319  *
320  * Returns: %TRUE on success
321  */
322 #define G_TYPE_IS_DERIVABLE(type)               (g_type_test_flags ((type), G_TYPE_FLAG_DERIVABLE))
323 /**
324  * G_TYPE_IS_DEEP_DERIVABLE:
325  * @type: A #GType value
326  *
327  * Checks if @type is a deep derivable type.  A deep derivable type
328  * can be used as the base class of a deep (multi-level) class hierarchy.
329  *
330  * Returns: %TRUE on success
331  */
332 #define G_TYPE_IS_DEEP_DERIVABLE(type)          (g_type_test_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE))
333 /**
334  * G_TYPE_IS_ABSTRACT:
335  * @type: A #GType value
336  *
337  * Checks if @type is an abstract type.  An abstract type cannot be
338  * instantiated and is normally used as an abstract base class for
339  * derived classes.
340  *
341  * Returns: %TRUE on success
342  */
343 #define G_TYPE_IS_ABSTRACT(type)                (g_type_test_flags ((type), G_TYPE_FLAG_ABSTRACT))
344 /**
345  * G_TYPE_IS_VALUE_ABSTRACT:
346  * @type: A #GType value
347  *
348  * Checks if @type is an abstract value type.  An abstract value type introduces
349  * a value table, but can't be used for g_value_init() and is normally used as
350  * an abstract base type for derived value types.
351  *
352  * Returns: %TRUE on success
353  */
354 #define G_TYPE_IS_VALUE_ABSTRACT(type)          (g_type_test_flags ((type), G_TYPE_FLAG_VALUE_ABSTRACT))
355 /**
356  * G_TYPE_IS_VALUE_TYPE:
357  * @type: A #GType value
358  *
359  * Checks if @type is a value type and can be used with g_value_init().
360  *
361  * Returns: %TRUE on success
362  */
363 #define G_TYPE_IS_VALUE_TYPE(type)              (g_type_check_is_value_type (type))
364 /**
365  * G_TYPE_HAS_VALUE_TABLE:
366  * @type: A #GType value
367  *
368  * Checks if @type has a #GTypeValueTable.
369  *
370  * Returns: %TRUE on success
371  */
372 #define G_TYPE_HAS_VALUE_TABLE(type)            (g_type_value_table_peek (type) != NULL)
373 
374 
375 /* Typedefs
376  */
377 /**
378  * GType:
379  *
380  * A numerical value which represents the unique identifier of a registered
381  * type.
382  */
383 #if     GLIB_SIZEOF_SIZE_T != GLIB_SIZEOF_LONG || !defined __cplusplus
384 typedef gsize                           GType;
385 #else   /* for historic reasons, C++ links against gulong GTypes */
386 typedef gulong                          GType;
387 #endif
388 typedef struct _GValue                  GValue;
389 typedef union  _GTypeCValue             GTypeCValue;
390 typedef struct _GTypePlugin             GTypePlugin;
391 typedef struct _GTypeClass              GTypeClass;
392 typedef struct _GTypeInterface          GTypeInterface;
393 typedef struct _GTypeInstance           GTypeInstance;
394 typedef struct _GTypeInfo               GTypeInfo;
395 typedef struct _GTypeFundamentalInfo    GTypeFundamentalInfo;
396 typedef struct _GInterfaceInfo          GInterfaceInfo;
397 typedef struct _GTypeValueTable         GTypeValueTable;
398 typedef struct _GTypeQuery		GTypeQuery;
399 
400 
401 /* Basic Type Structures
402  */
403 /**
404  * GTypeClass:
405  *
406  * An opaque structure used as the base of all classes.
407  */
408 struct _GTypeClass
409 {
410   /*< private >*/
411   GType g_type;
412 };
413 /**
414  * GTypeInstance:
415  *
416  * An opaque structure used as the base of all type instances.
417  */
418 struct _GTypeInstance
419 {
420   /*< private >*/
421   GTypeClass *g_class;
422 };
423 /**
424  * GTypeInterface:
425  *
426  * An opaque structure used as the base of all interface types.
427  */
428 struct _GTypeInterface
429 {
430   /*< private >*/
431   GType g_type;         /* iface type */
432   GType g_instance_type;
433 };
434 /**
435  * GTypeQuery:
436  * @type: the #GType value of the type
437  * @type_name: the name of the type
438  * @class_size: the size of the class structure
439  * @instance_size: the size of the instance structure
440  *
441  * A structure holding information for a specific type.
442  * It is filled in by the g_type_query() function.
443  */
444 struct _GTypeQuery
445 {
446   GType		type;
447   const gchar  *type_name;
448   guint		class_size;
449   guint		instance_size;
450 };
451 
452 
453 /* Casts, checks and accessors for structured types
454  * usage of these macros is reserved to type implementations only
455  */
456 /*< protected >*/
457 /**
458  * G_TYPE_CHECK_INSTANCE:
459  * @instance: Location of a #GTypeInstance structure
460  *
461  * Checks if @instance is a valid #GTypeInstance structure,
462  * otherwise issues a warning and returns %FALSE. %NULL is not a valid
463  * #GTypeInstance.
464  *
465  * This macro should only be used in type implementations.
466  *
467  * Returns: %TRUE on success
468  */
469 #define G_TYPE_CHECK_INSTANCE(instance)				(_G_TYPE_CHI ((GTypeInstance*) (instance)))
470 /**
471  * G_TYPE_CHECK_INSTANCE_CAST:
472  * @instance: (nullable): Location of a #GTypeInstance structure
473  * @g_type: The type to be returned
474  * @c_type: The corresponding C type of @g_type
475  *
476  * Checks that @instance is an instance of the type identified by @g_type
477  * and issues a warning if this is not the case. Returns @instance casted
478  * to a pointer to @c_type.
479  *
480  * No warning will be issued if @instance is %NULL, and %NULL will be returned.
481  *
482  * This macro should only be used in type implementations.
483  */
484 #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type)    (_G_TYPE_CIC ((instance), (g_type), c_type))
485 /**
486  * G_TYPE_CHECK_INSTANCE_TYPE:
487  * @instance: (nullable): Location of a #GTypeInstance structure.
488  * @g_type: The type to be checked
489  *
490  * Checks if @instance is an instance of the type identified by @g_type. If
491  * @instance is %NULL, %FALSE will be returned.
492  *
493  * This macro should only be used in type implementations.
494  *
495  * Returns: %TRUE on success
496  */
497 #define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type)            (_G_TYPE_CIT ((instance), (g_type)))
498 /**
499  * G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE:
500  * @instance: (nullable): Location of a #GTypeInstance structure.
501  * @g_type: The fundamental type to be checked
502  *
503  * Checks if @instance is an instance of the fundamental type identified by @g_type.
504  * If @instance is %NULL, %FALSE will be returned.
505  *
506  * This macro should only be used in type implementations.
507  *
508  * Returns: %TRUE on success
509  */
510 #define G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE(instance, g_type)            (_G_TYPE_CIFT ((instance), (g_type)))
511 /**
512  * G_TYPE_INSTANCE_GET_CLASS:
513  * @instance: Location of the #GTypeInstance structure
514  * @g_type: The #GType of the class to be returned
515  * @c_type: The C type of the class structure
516  *
517  * Get the class structure of a given @instance, casted
518  * to a specified ancestor type @g_type of the instance.
519  *
520  * Note that while calling a GInstanceInitFunc(), the class pointer
521  * gets modified, so it might not always return the expected pointer.
522  *
523  * This macro should only be used in type implementations.
524  *
525  * Returns: a pointer to the class structure
526  */
527 #define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type)     (_G_TYPE_IGC ((instance), (g_type), c_type))
528 /**
529  * G_TYPE_INSTANCE_GET_INTERFACE:
530  * @instance: Location of the #GTypeInstance structure
531  * @g_type: The #GType of the interface to be returned
532  * @c_type: The C type of the interface structure
533  *
534  * Get the interface structure for interface @g_type of a given @instance.
535  *
536  * This macro should only be used in type implementations.
537  *
538  * Returns: a pointer to the interface structure
539  */
540 #define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type))
541 /**
542  * G_TYPE_CHECK_CLASS_CAST:
543  * @g_class: Location of a #GTypeClass structure
544  * @g_type: The type to be returned
545  * @c_type: The corresponding C type of class structure of @g_type
546  *
547  * Checks that @g_class is a class structure of the type identified by @g_type
548  * and issues a warning if this is not the case. Returns @g_class casted
549  * to a pointer to @c_type. %NULL is not a valid class structure.
550  *
551  * This macro should only be used in type implementations.
552  */
553 #define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type)        (_G_TYPE_CCC ((g_class), (g_type), c_type))
554 /**
555  * G_TYPE_CHECK_CLASS_TYPE:
556  * @g_class: (nullable): Location of a #GTypeClass structure
557  * @g_type: The type to be checked
558  *
559  * Checks if @g_class is a class structure of the type identified by
560  * @g_type. If @g_class is %NULL, %FALSE will be returned.
561  *
562  * This macro should only be used in type implementations.
563  *
564  * Returns: %TRUE on success
565  */
566 #define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type)                (_G_TYPE_CCT ((g_class), (g_type)))
567 /**
568  * G_TYPE_CHECK_VALUE:
569  * @value: a #GValue
570  *
571  * Checks if @value has been initialized to hold values
572  * of a value type.
573  *
574  * This macro should only be used in type implementations.
575  *
576  * Returns: %TRUE on success
577  */
578 #define G_TYPE_CHECK_VALUE(value)				(_G_TYPE_CHV ((value)))
579 /**
580  * G_TYPE_CHECK_VALUE_TYPE:
581  * @value: a #GValue
582  * @g_type: The type to be checked
583  *
584  * Checks if @value has been initialized to hold values
585  * of type @g_type.
586  *
587  * This macro should only be used in type implementations.
588  *
589  * Returns: %TRUE on success
590  */
591 #define G_TYPE_CHECK_VALUE_TYPE(value, g_type)			(_G_TYPE_CVH ((value), (g_type)))
592 /**
593  * G_TYPE_FROM_INSTANCE:
594  * @instance: Location of a valid #GTypeInstance structure
595  *
596  * Get the type identifier from a given @instance structure.
597  *
598  * This macro should only be used in type implementations.
599  *
600  * Returns: the #GType
601  */
602 #define G_TYPE_FROM_INSTANCE(instance)                          (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class))
603 /**
604  * G_TYPE_FROM_CLASS:
605  * @g_class: Location of a valid #GTypeClass structure
606  *
607  * Get the type identifier from a given @class structure.
608  *
609  * This macro should only be used in type implementations.
610  *
611  * Returns: the #GType
612  */
613 #define G_TYPE_FROM_CLASS(g_class)                              (((GTypeClass*) (g_class))->g_type)
614 /**
615  * G_TYPE_FROM_INTERFACE:
616  * @g_iface: Location of a valid #GTypeInterface structure
617  *
618  * Get the type identifier from a given @interface structure.
619  *
620  * This macro should only be used in type implementations.
621  *
622  * Returns: the #GType
623  */
624 #define G_TYPE_FROM_INTERFACE(g_iface)                          (((GTypeInterface*) (g_iface))->g_type)
625 
626 /**
627  * G_TYPE_INSTANCE_GET_PRIVATE:
628  * @instance: the instance of a type deriving from @private_type
629  * @g_type: the type identifying which private data to retrieve
630  * @c_type: The C type for the private structure
631  *
632  * Gets the private structure for a particular type.
633  * The private structure must have been registered in the
634  * class_init function with g_type_class_add_private().
635  *
636  * This macro should only be used in type implementations.
637  *
638  * Since: 2.4
639  * Deprecated: 2.58: Use %G_ADD_PRIVATE and the generated
640  *   `your_type_get_instance_private()` function instead
641  * Returns: (not nullable): a pointer to the private data structure
642  */
643 #define G_TYPE_INSTANCE_GET_PRIVATE(instance, g_type, c_type)   ((c_type*) g_type_instance_get_private ((GTypeInstance*) (instance), (g_type))) GLIB_DEPRECATED_MACRO_IN_2_58_FOR(G_ADD_PRIVATE)
644 
645 /**
646  * G_TYPE_CLASS_GET_PRIVATE:
647  * @klass: the class of a type deriving from @private_type
648  * @g_type: the type identifying which private data to retrieve
649  * @c_type: The C type for the private structure
650  *
651  * Gets the private class structure for a particular type.
652  * The private structure must have been registered in the
653  * get_type() function with g_type_add_class_private().
654  *
655  * This macro should only be used in type implementations.
656  *
657  * Since: 2.24
658  * Returns: (not nullable): a pointer to the private data structure
659  */
660 #define G_TYPE_CLASS_GET_PRIVATE(klass, g_type, c_type)   ((c_type*) g_type_class_get_private ((GTypeClass*) (klass), (g_type)))
661 
662 /**
663  * GTypeDebugFlags:
664  * @G_TYPE_DEBUG_NONE: Print no messages
665  * @G_TYPE_DEBUG_OBJECTS: Print messages about object bookkeeping
666  * @G_TYPE_DEBUG_SIGNALS: Print messages about signal emissions
667  * @G_TYPE_DEBUG_MASK: Mask covering all debug flags
668  * @G_TYPE_DEBUG_INSTANCE_COUNT: Keep a count of instances of each type
669  *
670  * These flags used to be passed to g_type_init_with_debug_flags() which
671  * is now deprecated.
672  *
673  * If you need to enable debugging features, use the GOBJECT_DEBUG
674  * environment variable.
675  *
676  * Deprecated: 2.36: g_type_init() is now done automatically
677  */
678 typedef enum	/*< skip >*/
679 {
680   G_TYPE_DEBUG_NONE	= 0,
681   G_TYPE_DEBUG_OBJECTS	= 1 << 0,
682   G_TYPE_DEBUG_SIGNALS	= 1 << 1,
683   G_TYPE_DEBUG_INSTANCE_COUNT = 1 << 2,
684   G_TYPE_DEBUG_MASK	= 0x07
685 } GTypeDebugFlags GLIB_DEPRECATED_TYPE_IN_2_36;
686 
687 
688 /* --- prototypes --- */
689 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
690 GLIB_DEPRECATED_IN_2_36
691 void                  g_type_init                    (void);
692 GLIB_DEPRECATED_IN_2_36
693 void                  g_type_init_with_debug_flags   (GTypeDebugFlags  debug_flags);
694 G_GNUC_END_IGNORE_DEPRECATIONS
695 
696 GLIB_AVAILABLE_IN_ALL
697 const gchar *         g_type_name                    (GType            type);
698 GLIB_AVAILABLE_IN_ALL
699 GQuark                g_type_qname                   (GType            type);
700 GLIB_AVAILABLE_IN_ALL
701 GType                 g_type_from_name               (const gchar     *name);
702 GLIB_AVAILABLE_IN_ALL
703 GType                 g_type_parent                  (GType            type);
704 GLIB_AVAILABLE_IN_ALL
705 guint                 g_type_depth                   (GType            type);
706 GLIB_AVAILABLE_IN_ALL
707 GType                 g_type_next_base               (GType            leaf_type,
708 						      GType            root_type);
709 GLIB_AVAILABLE_IN_ALL
710 gboolean              g_type_is_a                    (GType            type,
711 						      GType            is_a_type);
712 GLIB_AVAILABLE_IN_ALL
713 gpointer              g_type_class_ref               (GType            type);
714 GLIB_AVAILABLE_IN_ALL
715 gpointer              g_type_class_peek              (GType            type);
716 GLIB_AVAILABLE_IN_ALL
717 gpointer              g_type_class_peek_static       (GType            type);
718 GLIB_AVAILABLE_IN_ALL
719 void                  g_type_class_unref             (gpointer         g_class);
720 GLIB_AVAILABLE_IN_ALL
721 gpointer              g_type_class_peek_parent       (gpointer         g_class);
722 GLIB_AVAILABLE_IN_ALL
723 gpointer              g_type_interface_peek          (gpointer         instance_class,
724 						      GType            iface_type);
725 GLIB_AVAILABLE_IN_ALL
726 gpointer              g_type_interface_peek_parent   (gpointer         g_iface);
727 
728 GLIB_AVAILABLE_IN_ALL
729 gpointer              g_type_default_interface_ref   (GType            g_type);
730 GLIB_AVAILABLE_IN_ALL
731 gpointer              g_type_default_interface_peek  (GType            g_type);
732 GLIB_AVAILABLE_IN_ALL
733 void                  g_type_default_interface_unref (gpointer         g_iface);
734 
735 /* g_free() the returned arrays */
736 GLIB_AVAILABLE_IN_ALL
737 GType*                g_type_children                (GType            type,
738 						      guint           *n_children);
739 GLIB_AVAILABLE_IN_ALL
740 GType*                g_type_interfaces              (GType            type,
741 						      guint           *n_interfaces);
742 
743 /* per-type _static_ data */
744 GLIB_AVAILABLE_IN_ALL
745 void                  g_type_set_qdata               (GType            type,
746 						      GQuark           quark,
747 						      gpointer         data);
748 GLIB_AVAILABLE_IN_ALL
749 gpointer              g_type_get_qdata               (GType            type,
750 						      GQuark           quark);
751 GLIB_AVAILABLE_IN_ALL
752 void		      g_type_query		     (GType	       type,
753 						      GTypeQuery      *query);
754 
755 GLIB_AVAILABLE_IN_2_44
756 int                   g_type_get_instance_count      (GType            type);
757 
758 /* --- type registration --- */
759 /**
760  * GBaseInitFunc:
761  * @g_class: (type GObject.TypeClass): The #GTypeClass structure to initialize
762  *
763  * A callback function used by the type system to do base initialization
764  * of the class structures of derived types. It is called as part of the
765  * initialization process of all derived classes and should reallocate
766  * or reset all dynamic class members copied over from the parent class.
767  * For example, class members (such as strings) that are not sufficiently
768  * handled by a plain memory copy of the parent class into the derived class
769  * have to be altered. See GClassInitFunc() for a discussion of the class
770  * initialization process.
771  */
772 typedef void   (*GBaseInitFunc)              (gpointer         g_class);
773 /**
774  * GBaseFinalizeFunc:
775  * @g_class: (type GObject.TypeClass): The #GTypeClass structure to finalize
776  *
777  * A callback function used by the type system to finalize those portions
778  * of a derived types class structure that were setup from the corresponding
779  * GBaseInitFunc() function. Class finalization basically works the inverse
780  * way in which class initialization is performed.
781  * See GClassInitFunc() for a discussion of the class initialization process.
782  */
783 typedef void   (*GBaseFinalizeFunc)          (gpointer         g_class);
784 /**
785  * GClassInitFunc:
786  * @g_class: (type GObject.TypeClass): The #GTypeClass structure to initialize.
787  * @class_data: The @class_data member supplied via the #GTypeInfo structure.
788  *
789  * A callback function used by the type system to initialize the class
790  * of a specific type. This function should initialize all static class
791  * members.
792  *
793  * The initialization process of a class involves:
794  *
795  * - Copying common members from the parent class over to the
796  *   derived class structure.
797  * - Zero initialization of the remaining members not copied
798  *   over from the parent class.
799  * - Invocation of the GBaseInitFunc() initializers of all parent
800  *   types and the class' type.
801  * - Invocation of the class' GClassInitFunc() initializer.
802  *
803  * Since derived classes are partially initialized through a memory copy
804  * of the parent class, the general rule is that GBaseInitFunc() and
805  * GBaseFinalizeFunc() should take care of necessary reinitialization
806  * and release of those class members that were introduced by the type
807  * that specified these GBaseInitFunc()/GBaseFinalizeFunc().
808  * GClassInitFunc() should only care about initializing static
809  * class members, while dynamic class members (such as allocated strings
810  * or reference counted resources) are better handled by a GBaseInitFunc()
811  * for this type, so proper initialization of the dynamic class members
812  * is performed for class initialization of derived types as well.
813  *
814  * An example may help to correspond the intend of the different class
815  * initializers:
816  *
817  * |[<!-- language="C" -->
818  * typedef struct {
819  *   GObjectClass parent_class;
820  *   gint         static_integer;
821  *   gchar       *dynamic_string;
822  * } TypeAClass;
823  * static void
824  * type_a_base_class_init (TypeAClass *class)
825  * {
826  *   class->dynamic_string = g_strdup ("some string");
827  * }
828  * static void
829  * type_a_base_class_finalize (TypeAClass *class)
830  * {
831  *   g_free (class->dynamic_string);
832  * }
833  * static void
834  * type_a_class_init (TypeAClass *class)
835  * {
836  *   class->static_integer = 42;
837  * }
838  *
839  * typedef struct {
840  *   TypeAClass   parent_class;
841  *   gfloat       static_float;
842  *   GString     *dynamic_gstring;
843  * } TypeBClass;
844  * static void
845  * type_b_base_class_init (TypeBClass *class)
846  * {
847  *   class->dynamic_gstring = g_string_new ("some other string");
848  * }
849  * static void
850  * type_b_base_class_finalize (TypeBClass *class)
851  * {
852  *   g_string_free (class->dynamic_gstring);
853  * }
854  * static void
855  * type_b_class_init (TypeBClass *class)
856  * {
857  *   class->static_float = 3.14159265358979323846;
858  * }
859  * ]|
860  * Initialization of TypeBClass will first cause initialization of
861  * TypeAClass (derived classes reference their parent classes, see
862  * g_type_class_ref() on this).
863  *
864  * Initialization of TypeAClass roughly involves zero-initializing its fields,
865  * then calling its GBaseInitFunc() type_a_base_class_init() to allocate
866  * its dynamic members (dynamic_string), and finally calling its GClassInitFunc()
867  * type_a_class_init() to initialize its static members (static_integer).
868  * The first step in the initialization process of TypeBClass is then
869  * a plain memory copy of the contents of TypeAClass into TypeBClass and
870  * zero-initialization of the remaining fields in TypeBClass.
871  * The dynamic members of TypeAClass within TypeBClass now need
872  * reinitialization which is performed by calling type_a_base_class_init()
873  * with an argument of TypeBClass.
874  *
875  * After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init()
876  * is called to allocate the dynamic members of TypeBClass (dynamic_gstring),
877  * and finally the GClassInitFunc() of TypeBClass, type_b_class_init(),
878  * is called to complete the initialization process with the static members
879  * (static_float).
880  *
881  * Corresponding finalization counter parts to the GBaseInitFunc() functions
882  * have to be provided to release allocated resources at class finalization
883  * time.
884  */
885 typedef void   (*GClassInitFunc)             (gpointer         g_class,
886 					      gpointer         class_data);
887 /**
888  * GClassFinalizeFunc:
889  * @g_class: (type GObject.TypeClass): The #GTypeClass structure to finalize
890  * @class_data: The @class_data member supplied via the #GTypeInfo structure
891  *
892  * A callback function used by the type system to finalize a class.
893  * This function is rarely needed, as dynamically allocated class resources
894  * should be handled by GBaseInitFunc() and GBaseFinalizeFunc().
895  * Also, specification of a GClassFinalizeFunc() in the #GTypeInfo
896  * structure of a static type is invalid, because classes of static types
897  * will never be finalized (they are artificially kept alive when their
898  * reference count drops to zero).
899  */
900 typedef void   (*GClassFinalizeFunc)         (gpointer         g_class,
901 					      gpointer         class_data);
902 /**
903  * GInstanceInitFunc:
904  * @instance: The instance to initialize
905  * @g_class: (type GObject.TypeClass): The class of the type the instance is
906  *    created for
907  *
908  * A callback function used by the type system to initialize a new
909  * instance of a type. This function initializes all instance members and
910  * allocates any resources required by it.
911  *
912  * Initialization of a derived instance involves calling all its parent
913  * types instance initializers, so the class member of the instance
914  * is altered during its initialization to always point to the class that
915  * belongs to the type the current initializer was introduced for.
916  *
917  * The extended members of @instance are guaranteed to have been filled with
918  * zeros before this function is called.
919  */
920 typedef void   (*GInstanceInitFunc)          (GTypeInstance   *instance,
921 					      gpointer         g_class);
922 /**
923  * GInterfaceInitFunc:
924  * @g_iface: (type GObject.TypeInterface): The interface structure to initialize
925  * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure
926  *
927  * A callback function used by the type system to initialize a new
928  * interface.  This function should initialize all internal data and
929  * allocate any resources required by the interface.
930  *
931  * The members of @iface_data are guaranteed to have been filled with
932  * zeros before this function is called.
933  */
934 typedef void   (*GInterfaceInitFunc)         (gpointer         g_iface,
935 					      gpointer         iface_data);
936 /**
937  * GInterfaceFinalizeFunc:
938  * @g_iface: (type GObject.TypeInterface): The interface structure to finalize
939  * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure
940  *
941  * A callback function used by the type system to finalize an interface.
942  * This function should destroy any internal data and release any resources
943  * allocated by the corresponding GInterfaceInitFunc() function.
944  */
945 typedef void   (*GInterfaceFinalizeFunc)     (gpointer         g_iface,
946 					      gpointer         iface_data);
947 /**
948  * GTypeClassCacheFunc:
949  * @cache_data: data that was given to the g_type_add_class_cache_func() call
950  * @g_class: (type GObject.TypeClass): The #GTypeClass structure which is
951  *    unreferenced
952  *
953  * A callback function which is called when the reference count of a class
954  * drops to zero. It may use g_type_class_ref() to prevent the class from
955  * being freed. You should not call g_type_class_unref() from a
956  * #GTypeClassCacheFunc function to prevent infinite recursion, use
957  * g_type_class_unref_uncached() instead.
958  *
959  * The functions have to check the class id passed in to figure
960  * whether they actually want to cache the class of this type, since all
961  * classes are routed through the same #GTypeClassCacheFunc chain.
962  *
963  * Returns: %TRUE to stop further #GTypeClassCacheFuncs from being
964  *  called, %FALSE to continue
965  */
966 typedef gboolean (*GTypeClassCacheFunc)	     (gpointer	       cache_data,
967 					      GTypeClass      *g_class);
968 /**
969  * GTypeInterfaceCheckFunc:
970  * @check_data: data passed to g_type_add_interface_check()
971  * @g_iface: (type GObject.TypeInterface): the interface that has been
972  *    initialized
973  *
974  * A callback called after an interface vtable is initialized.
975  * See g_type_add_interface_check().
976  *
977  * Since: 2.4
978  */
979 typedef void     (*GTypeInterfaceCheckFunc)  (gpointer	       check_data,
980 					      gpointer         g_iface);
981 /**
982  * GTypeFundamentalFlags:
983  * @G_TYPE_FLAG_CLASSED: Indicates a classed type
984  * @G_TYPE_FLAG_INSTANTIATABLE: Indicates an instantiable type (implies classed)
985  * @G_TYPE_FLAG_DERIVABLE: Indicates a flat derivable type
986  * @G_TYPE_FLAG_DEEP_DERIVABLE: Indicates a deep derivable type (implies derivable)
987  *
988  * Bit masks used to check or determine specific characteristics of a
989  * fundamental type.
990  */
991 typedef enum    /*< skip >*/
992 {
993   G_TYPE_FLAG_CLASSED           = (1 << 0),
994   G_TYPE_FLAG_INSTANTIATABLE    = (1 << 1),
995   G_TYPE_FLAG_DERIVABLE         = (1 << 2),
996   G_TYPE_FLAG_DEEP_DERIVABLE    = (1 << 3)
997 } GTypeFundamentalFlags;
998 /**
999  * GTypeFlags:
1000  * @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be
1001  *  created for an abstract type
1002  * @G_TYPE_FLAG_VALUE_ABSTRACT: Indicates an abstract value type, i.e. a type
1003  *  that introduces a value table, but can't be used for
1004  *  g_value_init()
1005  *
1006  * Bit masks used to check or determine characteristics of a type.
1007  */
1008 typedef enum    /*< skip >*/
1009 {
1010   G_TYPE_FLAG_ABSTRACT		= (1 << 4),
1011   G_TYPE_FLAG_VALUE_ABSTRACT	= (1 << 5)
1012 } GTypeFlags;
1013 /**
1014  * GTypeInfo:
1015  * @class_size: Size of the class structure (required for interface, classed and instantiatable types)
1016  * @base_init: Location of the base initialization function (optional)
1017  * @base_finalize: Location of the base finalization function (optional)
1018  * @class_init: Location of the class initialization function for
1019  *  classed and instantiatable types. Location of the default vtable
1020  *  inititalization function for interface types. (optional) This function
1021  *  is used both to fill in virtual functions in the class or default vtable,
1022  *  and to do type-specific setup such as registering signals and object
1023  *  properties.
1024  * @class_finalize: Location of the class finalization function for
1025  *  classed and instantiatable types. Location of the default vtable
1026  *  finalization function for interface types. (optional)
1027  * @class_data: User-supplied data passed to the class init/finalize functions
1028  * @instance_size: Size of the instance (object) structure (required for instantiatable types only)
1029  * @n_preallocs: Prior to GLib 2.10, it specified the number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching). Since GLib 2.10, it is ignored, since instances are allocated with the [slice allocator][glib-Memory-Slices] now.
1030  * @instance_init: Location of the instance initialization function (optional, for instantiatable types only)
1031  * @value_table: A #GTypeValueTable function table for generic handling of GValues
1032  *  of this type (usually only useful for fundamental types)
1033  *
1034  * This structure is used to provide the type system with the information
1035  * required to initialize and destruct (finalize) a type's class and
1036  * its instances.
1037  *
1038  * The initialized structure is passed to the g_type_register_static() function
1039  * (or is copied into the provided #GTypeInfo structure in the
1040  * g_type_plugin_complete_type_info()). The type system will perform a deep
1041  * copy of this structure, so its memory does not need to be persistent
1042  * across invocation of g_type_register_static().
1043  */
1044 struct _GTypeInfo
1045 {
1046   /* interface types, classed types, instantiated types */
1047   guint16                class_size;
1048 
1049   GBaseInitFunc          base_init;
1050   GBaseFinalizeFunc      base_finalize;
1051 
1052   /* interface types, classed types, instantiated types */
1053   GClassInitFunc         class_init;
1054   GClassFinalizeFunc     class_finalize;
1055   gconstpointer          class_data;
1056 
1057   /* instantiated types */
1058   guint16                instance_size;
1059   guint16                n_preallocs;
1060   GInstanceInitFunc      instance_init;
1061 
1062   /* value handling */
1063   const GTypeValueTable	*value_table;
1064 };
1065 /**
1066  * GTypeFundamentalInfo:
1067  * @type_flags: #GTypeFundamentalFlags describing the characteristics of the fundamental type
1068  *
1069  * A structure that provides information to the type system which is
1070  * used specifically for managing fundamental types.
1071  */
1072 struct _GTypeFundamentalInfo
1073 {
1074   GTypeFundamentalFlags  type_flags;
1075 };
1076 /**
1077  * GInterfaceInfo:
1078  * @interface_init: location of the interface initialization function
1079  * @interface_finalize: location of the interface finalization function
1080  * @interface_data: user-supplied data passed to the interface init/finalize functions
1081  *
1082  * A structure that provides information to the type system which is
1083  * used specifically for managing interface types.
1084  */
1085 struct _GInterfaceInfo
1086 {
1087   GInterfaceInitFunc     interface_init;
1088   GInterfaceFinalizeFunc interface_finalize;
1089   gpointer               interface_data;
1090 };
1091 /**
1092  * GTypeValueTable:
1093  * @value_init: Default initialize @values contents by poking values
1094  *  directly into the value->data array. The data array of
1095  *  the #GValue passed into this function was zero-filled
1096  *  with `memset()`, so no care has to be taken to free any
1097  *  old contents. E.g. for the implementation of a string
1098  *  value that may never be %NULL, the implementation might
1099  *  look like:
1100  *  |[<!-- language="C" -->
1101  *  value->data[0].v_pointer = g_strdup ("");
1102  *  ]|
1103  * @value_free: Free any old contents that might be left in the
1104  *  data array of the passed in @value. No resources may
1105  *  remain allocated through the #GValue contents after
1106  *  this function returns. E.g. for our above string type:
1107  *  |[<!-- language="C" -->
1108  *  // only free strings without a specific flag for static storage
1109  *  if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
1110  *    g_free (value->data[0].v_pointer);
1111  *  ]|
1112  * @value_copy: @dest_value is a #GValue with zero-filled data section
1113  *  and @src_value is a properly setup #GValue of same or
1114  *  derived type.
1115  *  The purpose of this function is to copy the contents of
1116  *  @src_value into @dest_value in a way, that even after
1117  *  @src_value has been freed, the contents of @dest_value
1118  *  remain valid. String type example:
1119  *  |[<!-- language="C" -->
1120  *  dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer);
1121  *  ]|
1122  * @value_peek_pointer: If the value contents fit into a pointer, such as objects
1123  *  or strings, return this pointer, so the caller can peek at
1124  *  the current contents. To extend on our above string example:
1125  *  |[<!-- language="C" -->
1126  *  return value->data[0].v_pointer;
1127  *  ]|
1128  * @collect_format: A string format describing how to collect the contents of
1129  *  this value bit-by-bit. Each character in the format represents
1130  *  an argument to be collected, and the characters themselves indicate
1131  *  the type of the argument. Currently supported arguments are:
1132  *  - 'i' - Integers. passed as collect_values[].v_int.
1133  *  - 'l' - Longs. passed as collect_values[].v_long.
1134  *  - 'd' - Doubles. passed as collect_values[].v_double.
1135  *  - 'p' - Pointers. passed as collect_values[].v_pointer.
1136  *  It should be noted that for variable argument list construction,
1137  *  ANSI C promotes every type smaller than an integer to an int, and
1138  *  floats to doubles. So for collection of short int or char, 'i'
1139  *  needs to be used, and for collection of floats 'd'.
1140  * @collect_value: The collect_value() function is responsible for converting the
1141  *  values collected from a variable argument list into contents
1142  *  suitable for storage in a GValue. This function should setup
1143  *  @value similar to value_init(); e.g. for a string value that
1144  *  does not allow %NULL pointers, it needs to either spew an error,
1145  *  or do an implicit conversion by storing an empty string.
1146  *  The @value passed in to this function has a zero-filled data
1147  *  array, so just like for value_init() it is guaranteed to not
1148  *  contain any old contents that might need freeing.
1149  *  @n_collect_values is exactly the string length of @collect_format,
1150  *  and @collect_values is an array of unions #GTypeCValue with
1151  *  length @n_collect_values, containing the collected values
1152  *  according to @collect_format.
1153  *  @collect_flags is an argument provided as a hint by the caller.
1154  *  It may contain the flag %G_VALUE_NOCOPY_CONTENTS indicating,
1155  *  that the collected value contents may be considered "static"
1156  *  for the duration of the @value lifetime.
1157  *  Thus an extra copy of the contents stored in @collect_values is
1158  *  not required for assignment to @value.
1159  *  For our above string example, we continue with:
1160  *  |[<!-- language="C" -->
1161  *  if (!collect_values[0].v_pointer)
1162  *    value->data[0].v_pointer = g_strdup ("");
1163  *  else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
1164  *  {
1165  *    value->data[0].v_pointer = collect_values[0].v_pointer;
1166  *    // keep a flag for the value_free() implementation to not free this string
1167  *    value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
1168  *  }
1169  *  else
1170  *    value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
1171  *  return NULL;
1172  *  ]|
1173  *  It should be noted, that it is generally a bad idea to follow the
1174  *  #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to
1175  *  reentrancy requirements and reference count assertions performed
1176  *  by the signal emission code, reference counts should always be
1177  *  incremented for reference counted contents stored in the value->data
1178  *  array.  To deviate from our string example for a moment, and taking
1179  *  a look at an exemplary implementation for collect_value() of
1180  *  #GObject:
1181  *  |[<!-- language="C" -->
1182  *  if (collect_values[0].v_pointer)
1183  *  {
1184  *    GObject *object = G_OBJECT (collect_values[0].v_pointer);
1185  *    // never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types
1186  *    value->data[0].v_pointer = g_object_ref (object);
1187  *    return NULL;
1188  *  }
1189  *  else
1190  *    return g_strdup_printf ("Object passed as invalid NULL pointer");
1191  *  }
1192  *  ]|
1193  *  The reference count for valid objects is always incremented,
1194  *  regardless of @collect_flags. For invalid objects, the example
1195  *  returns a newly allocated string without altering @value.
1196  *  Upon success, collect_value() needs to return %NULL. If, however,
1197  *  an error condition occurred, collect_value() may spew an
1198  *  error by returning a newly allocated non-%NULL string, giving
1199  *  a suitable description of the error condition.
1200  *  The calling code makes no assumptions about the @value
1201  *  contents being valid upon error returns, @value
1202  *  is simply thrown away without further freeing. As such, it is
1203  *  a good idea to not allocate #GValue contents, prior to returning
1204  *  an error, however, collect_values() is not obliged to return
1205  *  a correctly setup @value for error returns, simply because
1206  *  any non-%NULL return is considered a fatal condition so further
1207  *  program behaviour is undefined.
1208  * @lcopy_format: Format description of the arguments to collect for @lcopy_value,
1209  *  analogous to @collect_format. Usually, @lcopy_format string consists
1210  *  only of 'p's to provide lcopy_value() with pointers to storage locations.
1211  * @lcopy_value: This function is responsible for storing the @value contents into
1212  *  arguments passed through a variable argument list which got
1213  *  collected into @collect_values according to @lcopy_format.
1214  *  @n_collect_values equals the string length of @lcopy_format,
1215  *  and @collect_flags may contain %G_VALUE_NOCOPY_CONTENTS.
1216  *  In contrast to collect_value(), lcopy_value() is obliged to
1217  *  always properly support %G_VALUE_NOCOPY_CONTENTS.
1218  *  Similar to collect_value() the function may prematurely abort
1219  *  by returning a newly allocated string describing an error condition.
1220  *  To complete the string example:
1221  *  |[<!-- language="C" -->
1222  *  gchar **string_p = collect_values[0].v_pointer;
1223  *  if (!string_p)
1224  *    return g_strdup_printf ("string location passed as NULL");
1225  *  if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
1226  *    *string_p = value->data[0].v_pointer;
1227  *  else
1228  *    *string_p = g_strdup (value->data[0].v_pointer);
1229  *  ]|
1230  *  And an illustrative version of lcopy_value() for
1231  *  reference-counted types:
1232  *  |[<!-- language="C" -->
1233  *  GObject **object_p = collect_values[0].v_pointer;
1234  *  if (!object_p)
1235  *    return g_strdup_printf ("object location passed as NULL");
1236  *  if (!value->data[0].v_pointer)
1237  *    *object_p = NULL;
1238  *  else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) // always honour
1239  *    *object_p = value->data[0].v_pointer;
1240  *  else
1241  *    *object_p = g_object_ref (value->data[0].v_pointer);
1242  *  return NULL;
1243  *  ]|
1244  *
1245  * The #GTypeValueTable provides the functions required by the #GValue
1246  * implementation, to serve as a container for values of a type.
1247  */
1248 
1249 struct _GTypeValueTable
1250 {
1251   void     (*value_init)         (GValue       *value);
1252   void     (*value_free)         (GValue       *value);
1253   void     (*value_copy)         (const GValue *src_value,
1254 				  GValue       *dest_value);
1255   /* varargs functionality (optional) */
1256   gpointer (*value_peek_pointer) (const GValue *value);
1257   const gchar *collect_format;
1258   gchar*   (*collect_value)      (GValue       *value,
1259 				  guint         n_collect_values,
1260 				  GTypeCValue  *collect_values,
1261 				  guint		collect_flags);
1262   const gchar *lcopy_format;
1263   gchar*   (*lcopy_value)        (const GValue *value,
1264 				  guint         n_collect_values,
1265 				  GTypeCValue  *collect_values,
1266 				  guint		collect_flags);
1267 };
1268 GLIB_AVAILABLE_IN_ALL
1269 GType g_type_register_static		(GType			     parent_type,
1270 					 const gchar		    *type_name,
1271 					 const GTypeInfo	    *info,
1272 					 GTypeFlags		     flags);
1273 GLIB_AVAILABLE_IN_ALL
1274 GType g_type_register_static_simple     (GType                       parent_type,
1275 					 const gchar                *type_name,
1276 					 guint                       class_size,
1277 					 GClassInitFunc              class_init,
1278 					 guint                       instance_size,
1279 					 GInstanceInitFunc           instance_init,
1280 					 GTypeFlags	             flags);
1281 
1282 GLIB_AVAILABLE_IN_ALL
1283 GType g_type_register_dynamic		(GType			     parent_type,
1284 					 const gchar		    *type_name,
1285 					 GTypePlugin		    *plugin,
1286 					 GTypeFlags		     flags);
1287 GLIB_AVAILABLE_IN_ALL
1288 GType g_type_register_fundamental	(GType			     type_id,
1289 					 const gchar		    *type_name,
1290 					 const GTypeInfo	    *info,
1291 					 const GTypeFundamentalInfo *finfo,
1292 					 GTypeFlags		     flags);
1293 GLIB_AVAILABLE_IN_ALL
1294 void  g_type_add_interface_static	(GType			     instance_type,
1295 					 GType			     interface_type,
1296 					 const GInterfaceInfo	    *info);
1297 GLIB_AVAILABLE_IN_ALL
1298 void  g_type_add_interface_dynamic	(GType			     instance_type,
1299 					 GType			     interface_type,
1300 					 GTypePlugin		    *plugin);
1301 GLIB_AVAILABLE_IN_ALL
1302 void  g_type_interface_add_prerequisite (GType			     interface_type,
1303 					 GType			     prerequisite_type);
1304 GLIB_AVAILABLE_IN_ALL
1305 GType*g_type_interface_prerequisites    (GType                       interface_type,
1306 					 guint                      *n_prerequisites);
1307 GLIB_DEPRECATED_IN_2_58
1308 void     g_type_class_add_private       (gpointer                    g_class,
1309                                          gsize                       private_size);
1310 GLIB_AVAILABLE_IN_2_38
1311 gint     g_type_add_instance_private    (GType                       class_type,
1312                                          gsize                       private_size);
1313 GLIB_AVAILABLE_IN_ALL
1314 gpointer g_type_instance_get_private    (GTypeInstance              *instance,
1315                                          GType                       private_type);
1316 GLIB_AVAILABLE_IN_2_38
1317 void     g_type_class_adjust_private_offset (gpointer                g_class,
1318                                              gint                   *private_size_or_offset);
1319 
1320 GLIB_AVAILABLE_IN_ALL
1321 void      g_type_add_class_private      (GType    		     class_type,
1322 					 gsize    		     private_size);
1323 GLIB_AVAILABLE_IN_ALL
1324 gpointer  g_type_class_get_private      (GTypeClass 		    *klass,
1325 					 GType			     private_type);
1326 GLIB_AVAILABLE_IN_2_38
1327 gint      g_type_class_get_instance_private_offset (gpointer         g_class);
1328 
1329 GLIB_AVAILABLE_IN_2_34
1330 void      g_type_ensure                 (GType                       type);
1331 GLIB_AVAILABLE_IN_2_36
1332 guint     g_type_get_type_registration_serial (void);
1333 
1334 
1335 /* --- GType boilerplate --- */
1336 /**
1337  * G_DECLARE_FINAL_TYPE:
1338  * @ModuleObjName: The name of the new type, in camel case (like GtkWidget)
1339  * @module_obj_name: The name of the new type in lowercase, with words
1340  *  separated by '_' (like 'gtk_widget')
1341  * @MODULE: The name of the module, in all caps (like 'GTK')
1342  * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET')
1343  * @ParentName: the name of the parent type, in camel case (like GtkWidget)
1344  *
1345  * A convenience macro for emitting the usual declarations in the header file for a type which is not (at the
1346  * present time) intended to be subclassed.
1347  *
1348  * You might use it in a header as follows:
1349  *
1350  * |[
1351  * #ifndef _myapp_window_h_
1352  * #define _myapp_window_h_
1353  *
1354  * #include <gtk/gtk.h>
1355  *
1356  * #define MY_APP_TYPE_WINDOW my_app_window_get_type ()
1357  * G_DECLARE_FINAL_TYPE (MyAppWindow, my_app_window, MY_APP, WINDOW, GtkWindow)
1358  *
1359  * MyAppWindow *    my_app_window_new    (void);
1360  *
1361  * ...
1362  *
1363  * #endif
1364  * ]|
1365  *
1366  * This results in the following things happening:
1367  *
1368  * - the usual my_app_window_get_type() function is declared with a return type of #GType
1369  *
1370  * - the MyAppWindow types is defined as a typedef of struct _MyAppWindow.  The struct itself is not
1371  *   defined and should be defined from the .c file before G_DEFINE_TYPE() is used.
1372  *
1373  * - the MY_APP_WINDOW() cast is emitted as static inline function along with the MY_APP_IS_WINDOW() type
1374  *   checking function
1375  *
1376  * - the MyAppWindowClass type is defined as a struct containing GtkWindowClass.  This is done for the
1377  *   convenience of the person defining the type and should not be considered to be part of the ABI.  In
1378  *   particular, without a firm declaration of the instance structure, it is not possible to subclass the type
1379  *   and therefore the fact that the size of the class structure is exposed is not a concern and it can be
1380  *   freely changed at any point in the future.
1381  *
1382  * - g_autoptr() support being added for your type, based on the type of your parent class
1383  *
1384  * You can only use this function if your parent type also supports g_autoptr().
1385  *
1386  * Because the type macro (MY_APP_TYPE_WINDOW in the above example) is not a callable, you must continue to
1387  * manually define this as a macro for yourself.
1388  *
1389  * The declaration of the _get_type() function is the first thing emitted by the macro.  This allows this macro
1390  * to be used in the usual way with export control and API versioning macros.
1391  *
1392  * If you want to declare your own class structure, use G_DECLARE_DERIVABLE_TYPE().
1393  *
1394  * If you are writing a library, it is important to note that it is possible to convert a type from using
1395  * G_DECLARE_FINAL_TYPE() to G_DECLARE_DERIVABLE_TYPE() without breaking API or ABI.  As a precaution, you
1396  * should therefore use G_DECLARE_FINAL_TYPE() until you are sure that it makes sense for your class to be
1397  * subclassed.  Once a class structure has been exposed it is not possible to change its size or remove or
1398  * reorder items without breaking the API and/or ABI.
1399  *
1400  * Since: 2.44
1401  **/
1402 #define G_DECLARE_FINAL_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName) \
1403   GType module_obj_name##_get_type (void);                                                               \
1404   G_GNUC_BEGIN_IGNORE_DEPRECATIONS                                                                       \
1405   typedef struct _##ModuleObjName ModuleObjName;                                                         \
1406   typedef struct { ParentName##Class parent_class; } ModuleObjName##Class;                               \
1407                                                                                                          \
1408   _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName)                                               \
1409                                                                                                          \
1410   static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) {                                     \
1411     return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); }             \
1412   static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) {                                         \
1413     return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); }                            \
1414   G_GNUC_END_IGNORE_DEPRECATIONS
1415 
1416 /**
1417  * G_DECLARE_DERIVABLE_TYPE:
1418  * @ModuleObjName: The name of the new type, in camel case (like GtkWidget)
1419  * @module_obj_name: The name of the new type in lowercase, with words
1420  *  separated by '_' (like 'gtk_widget')
1421  * @MODULE: The name of the module, in all caps (like 'GTK')
1422  * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET')
1423  * @ParentName: the name of the parent type, in camel case (like GtkWidget)
1424  *
1425  * A convenience macro for emitting the usual declarations in the
1426  * header file for a type which is intended to be subclassed.
1427  *
1428  * You might use it in a header as follows:
1429  *
1430  * |[
1431  * #ifndef _gtk_frobber_h_
1432  * #define _gtk_frobber_h_
1433  *
1434  * #define GTK_TYPE_FROBBER gtk_frobber_get_type ()
1435  * GDK_AVAILABLE_IN_3_12
1436  * G_DECLARE_DERIVABLE_TYPE (GtkFrobber, gtk_frobber, GTK, FROBBER, GtkWidget)
1437  *
1438  * struct _GtkFrobberClass
1439  * {
1440  *   GtkWidgetClass parent_class;
1441  *
1442  *   void (* handle_frob)  (GtkFrobber *frobber,
1443  *                          guint       n_frobs);
1444  *
1445  *   gpointer padding[12];
1446  * };
1447  *
1448  * GtkWidget *    gtk_frobber_new   (void);
1449  *
1450  * ...
1451  *
1452  * #endif
1453  * ]|
1454  *
1455  * This results in the following things happening:
1456  *
1457  * - the usual gtk_frobber_get_type() function is declared with a return type of #GType
1458  *
1459  * - the GtkFrobber struct is created with GtkWidget as the first and only item.  You are expected to use
1460  *   a private structure from your .c file to store your instance variables.
1461  *
1462  * - the GtkFrobberClass type is defined as a typedef to struct _GtkFrobberClass, which is left undefined.
1463  *   You should do this from the header file directly after you use the macro.
1464  *
1465  * - the GTK_FROBBER() and GTK_FROBBER_CLASS() casts are emitted as static inline functions along with
1466  *   the GTK_IS_FROBBER() and GTK_IS_FROBBER_CLASS() type checking functions and GTK_FROBBER_GET_CLASS()
1467  *   function.
1468  *
1469  * - g_autoptr() support being added for your type, based on the type of your parent class
1470  *
1471  * You can only use this function if your parent type also supports g_autoptr().
1472  *
1473  * Because the type macro (GTK_TYPE_FROBBER in the above example) is not a callable, you must continue to
1474  * manually define this as a macro for yourself.
1475  *
1476  * The declaration of the _get_type() function is the first thing emitted by the macro.  This allows this macro
1477  * to be used in the usual way with export control and API versioning macros.
1478  *
1479  * If you are writing a library, it is important to note that it is possible to convert a type from using
1480  * G_DECLARE_FINAL_TYPE() to G_DECLARE_DERIVABLE_TYPE() without breaking API or ABI.  As a precaution, you
1481  * should therefore use G_DECLARE_FINAL_TYPE() until you are sure that it makes sense for your class to be
1482  * subclassed.  Once a class structure has been exposed it is not possible to change its size or remove or
1483  * reorder items without breaking the API and/or ABI.  If you want to declare your own class structure, use
1484  * G_DECLARE_DERIVABLE_TYPE().  If you want to declare a class without exposing the class or instance
1485  * structures, use G_DECLARE_FINAL_TYPE().
1486  *
1487  * If you must use G_DECLARE_DERIVABLE_TYPE() you should be sure to include some padding at the bottom of your
1488  * class structure to leave space for the addition of future virtual functions.
1489  *
1490  * Since: 2.44
1491  **/
1492 #define G_DECLARE_DERIVABLE_TYPE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, ParentName) \
1493   GType module_obj_name##_get_type (void);                                                               \
1494   G_GNUC_BEGIN_IGNORE_DEPRECATIONS                                                                       \
1495   typedef struct _##ModuleObjName ModuleObjName;                                                         \
1496   typedef struct _##ModuleObjName##Class ModuleObjName##Class;                                           \
1497   struct _##ModuleObjName { ParentName parent_instance; };                                               \
1498                                                                                                          \
1499   _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName)                                               \
1500                                                                                                          \
1501   static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) {                                     \
1502     return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); }             \
1503   static inline ModuleObjName##Class * MODULE##_##OBJ_NAME##_CLASS (gpointer ptr) {                      \
1504     return G_TYPE_CHECK_CLASS_CAST (ptr, module_obj_name##_get_type (), ModuleObjName##Class); }         \
1505   static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) {                                         \
1506     return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); }                            \
1507   static inline gboolean MODULE##_IS_##OBJ_NAME##_CLASS (gpointer ptr) {                                 \
1508     return G_TYPE_CHECK_CLASS_TYPE (ptr, module_obj_name##_get_type ()); }                               \
1509   static inline ModuleObjName##Class * MODULE##_##OBJ_NAME##_GET_CLASS (gpointer ptr) {                  \
1510     return G_TYPE_INSTANCE_GET_CLASS (ptr, module_obj_name##_get_type (), ModuleObjName##Class); }       \
1511   G_GNUC_END_IGNORE_DEPRECATIONS
1512 
1513 /**
1514  * G_DECLARE_INTERFACE:
1515  * @ModuleObjName: The name of the new type, in camel case (like GtkWidget)
1516  * @module_obj_name: The name of the new type in lowercase, with words
1517  *  separated by '_' (like 'gtk_widget')
1518  * @MODULE: The name of the module, in all caps (like 'GTK')
1519  * @OBJ_NAME: The bare name of the type, in all caps (like 'WIDGET')
1520  * @PrerequisiteName: the name of the prerequisite type, in camel case (like GtkWidget)
1521  *
1522  * A convenience macro for emitting the usual declarations in the header file for a GInterface type.
1523  *
1524  * You might use it in a header as follows:
1525  *
1526  * |[
1527  * #ifndef _my_model_h_
1528  * #define _my_model_h_
1529  *
1530  * #define MY_TYPE_MODEL my_model_get_type ()
1531  * GDK_AVAILABLE_IN_3_12
1532  * G_DECLARE_INTERFACE (MyModel, my_model, MY, MODEL, GObject)
1533  *
1534  * struct _MyModelInterface
1535  * {
1536  *   GTypeInterface g_iface;
1537  *
1538  *   gpointer (* get_item)  (MyModel *model);
1539  * };
1540  *
1541  * gpointer my_model_get_item (MyModel *model);
1542  *
1543  * ...
1544  *
1545  * #endif
1546  * ]|
1547  *
1548  * This results in the following things happening:
1549  *
1550  * - the usual my_model_get_type() function is declared with a return type of #GType
1551  *
1552  * - the MyModelInterface type is defined as a typedef to struct _MyModelInterface,
1553  *   which is left undefined. You should do this from the header file directly after
1554  *   you use the macro.
1555  *
1556  * - the MY_MODEL() cast is emitted as static inline functions along with
1557  *   the MY_IS_MODEL() type checking function and MY_MODEL_GET_IFACE() function.
1558  *
1559  * - g_autoptr() support being added for your type, based on your prerequisite type.
1560  *
1561  * You can only use this function if your prerequisite type also supports g_autoptr().
1562  *
1563  * Because the type macro (MY_TYPE_MODEL in the above example) is not a callable, you must continue to
1564  * manually define this as a macro for yourself.
1565  *
1566  * The declaration of the _get_type() function is the first thing emitted by the macro.  This allows this macro
1567  * to be used in the usual way with export control and API versioning macros.
1568  *
1569  * Since: 2.44
1570  **/
1571 #define G_DECLARE_INTERFACE(ModuleObjName, module_obj_name, MODULE, OBJ_NAME, PrerequisiteName) \
1572   GType module_obj_name##_get_type (void);                                                                 \
1573   G_GNUC_BEGIN_IGNORE_DEPRECATIONS                                                                         \
1574   typedef struct _##ModuleObjName ModuleObjName;                                                           \
1575   typedef struct _##ModuleObjName##Interface ModuleObjName##Interface;                                     \
1576                                                                                                            \
1577   _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, PrerequisiteName)                                           \
1578                                                                                                            \
1579   static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) {                                       \
1580     return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); }               \
1581   static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) {                                           \
1582     return G_TYPE_CHECK_INSTANCE_TYPE (ptr, module_obj_name##_get_type ()); }                              \
1583   static inline ModuleObjName##Interface * MODULE##_##OBJ_NAME##_GET_IFACE (gpointer ptr) {                \
1584     return G_TYPE_INSTANCE_GET_INTERFACE (ptr, module_obj_name##_get_type (), ModuleObjName##Interface); } \
1585   G_GNUC_END_IGNORE_DEPRECATIONS
1586 
1587 /**
1588  * G_DEFINE_TYPE:
1589  * @TN: The name of the new type, in Camel case.
1590  * @t_n: The name of the new type, in lowercase, with words
1591  *  separated by '_'.
1592  * @T_P: The #GType of the parent type.
1593  *
1594  * A convenience macro for type implementations, which declares a class
1595  * initialization function, an instance initialization function (see #GTypeInfo
1596  * for information about these) and a static variable named `t_n_parent_class`
1597  * pointing to the parent class. Furthermore, it defines  a *_get_type() function.
1598  * See G_DEFINE_TYPE_EXTENDED() for an example.
1599  *
1600  * Since: 2.4
1601  */
1602 #define G_DEFINE_TYPE(TN, t_n, T_P)			    G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
1603 /**
1604  * G_DEFINE_TYPE_WITH_CODE:
1605  * @TN: The name of the new type, in Camel case.
1606  * @t_n: The name of the new type in lowercase, with words separated by '_'.
1607  * @T_P: The #GType of the parent type.
1608  * @_C_: Custom code that gets inserted in the *_get_type() function.
1609  *
1610  * A convenience macro for type implementations.
1611  * Similar to G_DEFINE_TYPE(), but allows you to insert custom code into the
1612  * *_get_type() function, e.g. interface implementations via G_IMPLEMENT_INTERFACE().
1613  * See G_DEFINE_TYPE_EXTENDED() for an example.
1614  *
1615  * Since: 2.4
1616  */
1617 #define G_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_)	    _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 0) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
1618 /**
1619  * G_DEFINE_TYPE_WITH_PRIVATE:
1620  * @TN: The name of the new type, in Camel case.
1621  * @t_n: The name of the new type, in lowercase, with words
1622  *  separated by '_'.
1623  * @T_P: The #GType of the parent type.
1624  *
1625  * A convenience macro for type implementations, which declares a class
1626  * initialization function, an instance initialization function (see #GTypeInfo
1627  * for information about these), a static variable named `t_n_parent_class`
1628  * pointing to the parent class, and adds private instance data to the type.
1629  * Furthermore, it defines a *_get_type() function. See G_DEFINE_TYPE_EXTENDED()
1630  * for an example.
1631  *
1632  * Note that private structs added with this macros must have a struct
1633  * name of the form @TN Private.
1634  *
1635  * The private instance data can be retrieved using the automatically generated
1636  * getter function `t_n_get_instance_private()`.
1637  *
1638  * See also: G_ADD_PRIVATE()
1639  *
1640  * Since: 2.38
1641  */
1642 #define G_DEFINE_TYPE_WITH_PRIVATE(TN, t_n, T_P)            G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, G_ADD_PRIVATE (TN))
1643 /**
1644  * G_DEFINE_ABSTRACT_TYPE:
1645  * @TN: The name of the new type, in Camel case.
1646  * @t_n: The name of the new type, in lowercase, with words
1647  *  separated by '_'.
1648  * @T_P: The #GType of the parent type.
1649  *
1650  * A convenience macro for type implementations.
1651  * Similar to G_DEFINE_TYPE(), but defines an abstract type.
1652  * See G_DEFINE_TYPE_EXTENDED() for an example.
1653  *
1654  * Since: 2.4
1655  */
1656 #define G_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P)		    G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {})
1657 /**
1658  * G_DEFINE_ABSTRACT_TYPE_WITH_CODE:
1659  * @TN: The name of the new type, in Camel case.
1660  * @t_n: The name of the new type, in lowercase, with words
1661  *  separated by '_'.
1662  * @T_P: The #GType of the parent type.
1663  * @_C_: Custom code that gets inserted in the @type_name_get_type() function.
1664  *
1665  * A convenience macro for type implementations.
1666  * Similar to G_DEFINE_TYPE_WITH_CODE(), but defines an abstract type and
1667  * allows you to insert custom code into the *_get_type() function, e.g.
1668  * interface implementations  via G_IMPLEMENT_INTERFACE().
1669  * See G_DEFINE_TYPE_EXTENDED() for an example.
1670  *
1671  * Since: 2.4
1672  */
1673 #define G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
1674 /**
1675  * G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE:
1676  * @TN: The name of the new type, in Camel case.
1677  * @t_n: The name of the new type, in lowercase, with words
1678  *  separated by '_'.
1679  * @T_P: The #GType of the parent type.
1680  *
1681  * Similar to G_DEFINE_TYPE_WITH_PRIVATE(), but defines an abstract type.
1682  * See G_DEFINE_TYPE_EXTENDED() for an example.
1683  *
1684  * Since: 2.38
1685  */
1686 #define G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(TN, t_n, T_P)   G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, G_ADD_PRIVATE (TN))
1687 /**
1688  * G_DEFINE_TYPE_EXTENDED:
1689  * @TN: The name of the new type, in Camel case.
1690  * @t_n: The name of the new type, in lowercase, with words
1691  *    separated by '_'.
1692  * @T_P: The #GType of the parent type.
1693  * @_f_: #GTypeFlags to pass to g_type_register_static()
1694  * @_C_: Custom code that gets inserted in the *_get_type() function.
1695  *
1696  * The most general convenience macro for type implementations, on which
1697  * G_DEFINE_TYPE(), etc are based.
1698  *
1699  * |[<!-- language="C" -->
1700  * G_DEFINE_TYPE_EXTENDED (GtkGadget,
1701  *                         gtk_gadget,
1702  *                         GTK_TYPE_WIDGET,
1703  *                         0,
1704  *                         G_ADD_PRIVATE (GtkGadget)
1705  *                         G_IMPLEMENT_INTERFACE (TYPE_GIZMO,
1706  *                                                gtk_gadget_gizmo_init));
1707  * ]|
1708  * expands to
1709  * |[<!-- language="C" -->
1710  * static void     gtk_gadget_init       (GtkGadget      *self);
1711  * static void     gtk_gadget_class_init (GtkGadgetClass *klass);
1712  * static gpointer gtk_gadget_parent_class = NULL;
1713  * static gint     GtkGadget_private_offset;
1714  * static void     gtk_gadget_class_intern_init (gpointer klass)
1715  * {
1716  *   gtk_gadget_parent_class = g_type_class_peek_parent (klass);
1717  *   if (GtkGadget_private_offset != 0)
1718  *     g_type_class_adjust_private_offset (klass, &GtkGadget_private_offset);
1719  *   gtk_gadget_class_init ((GtkGadgetClass*) klass);
1720  * }
1721  * static inline gpointer gtk_gadget_get_instance_private (GtkGadget *self)
1722  * {
1723  *   return (G_STRUCT_MEMBER_P (self, GtkGadget_private_offset));
1724  * }
1725  *
1726  * GType
1727  * gtk_gadget_get_type (void)
1728  * {
1729  *   static volatile gsize g_define_type_id__volatile = 0;
1730  *   if (g_once_init_enter (&g_define_type_id__volatile))
1731  *     {
1732  *       GType g_define_type_id =
1733  *         g_type_register_static_simple (GTK_TYPE_WIDGET,
1734  *                                        g_intern_static_string ("GtkGadget"),
1735  *                                        sizeof (GtkGadgetClass),
1736  *                                        (GClassInitFunc) gtk_gadget_class_intern_init,
1737  *                                        sizeof (GtkGadget),
1738  *                                        (GInstanceInitFunc) gtk_gadget_init,
1739  *                                        0);
1740  *       {
1741  *         GtkGadget_private_offset =
1742  *           g_type_add_instance_private (g_define_type_id, sizeof (GtkGadgetPrivate));
1743  *       }
1744  *       {
1745  *         const GInterfaceInfo g_implement_interface_info = {
1746  *           (GInterfaceInitFunc) gtk_gadget_gizmo_init
1747  *         };
1748  *         g_type_add_interface_static (g_define_type_id, TYPE_GIZMO, &g_implement_interface_info);
1749  *       }
1750  *       g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
1751  *     }
1752  *   return g_define_type_id__volatile;
1753  * }
1754  * ]|
1755  * The only pieces which have to be manually provided are the definitions of
1756  * the instance and class structure and the definitions of the instance and
1757  * class init functions.
1758  *
1759  * Since: 2.4
1760  */
1761 #define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)	    _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
1762 
1763 /**
1764  * G_DEFINE_INTERFACE:
1765  * @TN: The name of the new type, in Camel case.
1766  * @t_n: The name of the new type, in lowercase, with words separated by '_'.
1767  * @T_P: The #GType of the prerequisite type for the interface, or 0
1768  * (%G_TYPE_INVALID) for no prerequisite type.
1769  *
1770  * A convenience macro for #GTypeInterface definitions, which declares
1771  * a default vtable initialization function and defines a *_get_type()
1772  * function.
1773  *
1774  * The macro expects the interface initialization function to have the
1775  * name `t_n ## _default_init`, and the interface structure to have the
1776  * name `TN ## Interface`.
1777  *
1778  * The initialization function has signature
1779  * `static void t_n ## _default_init (TypeName##Interface *klass);`, rather than
1780  * the full #GInterfaceInitFunc signature, for brevity and convenience. If you
1781  * need to use an initialization function with an `iface_data` argument, you
1782  * must write the #GTypeInterface definitions manually.
1783  *
1784  * Since: 2.24
1785  */
1786 #define G_DEFINE_INTERFACE(TN, t_n, T_P)		    G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, ;)
1787 
1788 /**
1789  * G_DEFINE_INTERFACE_WITH_CODE:
1790  * @TN: The name of the new type, in Camel case.
1791  * @t_n: The name of the new type, in lowercase, with words separated by '_'.
1792  * @T_P: The #GType of the prerequisite type for the interface, or 0
1793  * (%G_TYPE_INVALID) for no prerequisite type.
1794  * @_C_: Custom code that gets inserted in the *_get_type() function.
1795  *
1796  * A convenience macro for #GTypeInterface definitions. Similar to
1797  * G_DEFINE_INTERFACE(), but allows you to insert custom code into the
1798  * *_get_type() function, e.g. additional interface implementations
1799  * via G_IMPLEMENT_INTERFACE(), or additional prerequisite types. See
1800  * G_DEFINE_TYPE_EXTENDED() for a similar example using
1801  * G_DEFINE_TYPE_WITH_CODE().
1802  *
1803  * Since: 2.24
1804  */
1805 #define G_DEFINE_INTERFACE_WITH_CODE(TN, t_n, T_P, _C_)     _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TN, t_n, T_P) {_C_;} _G_DEFINE_INTERFACE_EXTENDED_END()
1806 
1807 /**
1808  * G_IMPLEMENT_INTERFACE:
1809  * @TYPE_IFACE: The #GType of the interface to add
1810  * @iface_init: (type GInterfaceInitFunc): The interface init function, of type #GInterfaceInitFunc
1811  *
1812  * A convenience macro to ease interface addition in the `_C_` section
1813  * of G_DEFINE_TYPE_WITH_CODE() or G_DEFINE_ABSTRACT_TYPE_WITH_CODE().
1814  * See G_DEFINE_TYPE_EXTENDED() for an example.
1815  *
1816  * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1817  * macros, since it depends on variable names from those macros.
1818  *
1819  * Since: 2.4
1820  */
1821 #define G_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init)       { \
1822   const GInterfaceInfo g_implement_interface_info = { \
1823     (GInterfaceInitFunc)(void (*)(void)) iface_init, NULL, NULL \
1824   }; \
1825   g_type_add_interface_static (g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \
1826 }
1827 
1828 /**
1829  * G_ADD_PRIVATE:
1830  * @TypeName: the name of the type in CamelCase
1831  *
1832  * A convenience macro to ease adding private data to instances of a new type
1833  * in the @_C_ section of G_DEFINE_TYPE_WITH_CODE() or
1834  * G_DEFINE_ABSTRACT_TYPE_WITH_CODE().
1835  *
1836  * For instance:
1837  *
1838  * |[<!-- language="C" -->
1839  *   typedef struct _MyObject MyObject;
1840  *   typedef struct _MyObjectClass MyObjectClass;
1841  *
1842  *   typedef struct {
1843  *     gint foo;
1844  *     gint bar;
1845  *   } MyObjectPrivate;
1846  *
1847  *   G_DEFINE_TYPE_WITH_CODE (MyObject, my_object, G_TYPE_OBJECT,
1848  *                            G_ADD_PRIVATE (MyObject))
1849  * ]|
1850  *
1851  * Will add MyObjectPrivate as the private data to any instance of the MyObject
1852  * type.
1853  *
1854  * G_DEFINE_TYPE_* macros will automatically create a private function
1855  * based on the arguments to this macro, which can be used to safely
1856  * retrieve the private data from an instance of the type; for instance:
1857  *
1858  * |[<!-- language="C" -->
1859  *   gint
1860  *   my_object_get_foo (MyObject *obj)
1861  *   {
1862  *     MyObjectPrivate *priv = my_object_get_instance_private (obj);
1863  *
1864  *     g_return_val_if_fail (MY_IS_OBJECT (obj), 0);
1865  *
1866  *     return priv->foo;
1867  *   }
1868  *
1869  *   void
1870  *   my_object_set_bar (MyObject *obj,
1871  *                      gint      bar)
1872  *   {
1873  *     MyObjectPrivate *priv = my_object_get_instance_private (obj);
1874  *
1875  *     g_return_if_fail (MY_IS_OBJECT (obj));
1876  *
1877  *     if (priv->bar != bar)
1878  *       priv->bar = bar;
1879  *   }
1880  * ]|
1881  *
1882  * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1883  * macros, since it depends on variable names from those macros.
1884  *
1885  * Also note that private structs added with these macros must have a struct
1886  * name of the form `TypeNamePrivate`.
1887  *
1888  * It is safe to call the `_get_instance_private` function on %NULL or invalid
1889  * objects since it's only adding an offset to the instance pointer. In that
1890  * case the returned pointer must not be dereferenced.
1891  *
1892  * Since: 2.38
1893  */
1894 #define G_ADD_PRIVATE(TypeName) { \
1895   TypeName##_private_offset = \
1896     g_type_add_instance_private (g_define_type_id, sizeof (TypeName##Private)); \
1897 }
1898 
1899 /**
1900  * G_PRIVATE_OFFSET:
1901  * @TypeName: the name of the type in CamelCase
1902  * @field: the name of the field in the private data structure
1903  *
1904  * Evaluates to the offset of the @field inside the instance private data
1905  * structure for @TypeName.
1906  *
1907  * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1908  * and G_ADD_PRIVATE() macros, since it depends on variable names from
1909  * those macros.
1910  *
1911  * Since: 2.38
1912  */
1913 #define G_PRIVATE_OFFSET(TypeName, field) \
1914   (TypeName##_private_offset + (G_STRUCT_OFFSET (TypeName##Private, field)))
1915 
1916 /**
1917  * G_PRIVATE_FIELD_P:
1918  * @TypeName: the name of the type in CamelCase
1919  * @inst: the instance of @TypeName you wish to access
1920  * @field_name: the name of the field in the private data structure
1921  *
1922  * Evaluates to a pointer to the @field_name inside the @inst private data
1923  * structure for @TypeName.
1924  *
1925  * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1926  * and G_ADD_PRIVATE() macros, since it depends on variable names from
1927  * those macros.
1928  *
1929  * Since: 2.38
1930  */
1931 #define G_PRIVATE_FIELD_P(TypeName, inst, field_name) \
1932   G_STRUCT_MEMBER_P (inst, G_PRIVATE_OFFSET (TypeName, field_name))
1933 
1934 /**
1935  * G_PRIVATE_FIELD:
1936  * @TypeName: the name of the type in CamelCase
1937  * @inst: the instance of @TypeName you wish to access
1938  * @field_type: the type of the field in the private data structure
1939  * @field_name: the name of the field in the private data structure
1940  *
1941  * Evaluates to the @field_name inside the @inst private data
1942  * structure for @TypeName.
1943  *
1944  * Note that this macro can only be used together with the G_DEFINE_TYPE_*
1945  * and G_ADD_PRIVATE() macros, since it depends on variable names from
1946  * those macros.
1947  *
1948  * Since: 2.38
1949  */
1950 #define G_PRIVATE_FIELD(TypeName, inst, field_type, field_name) \
1951   G_STRUCT_MEMBER (field_type, inst, G_PRIVATE_OFFSET (TypeName, field_name))
1952 
1953 /* we need to have this macro under conditional expansion, as it references
1954  * a function that has been added in 2.38. see bug:
1955  * https://bugzilla.gnome.org/show_bug.cgi?id=703191
1956  */
1957 #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38
1958 #define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
1959 static void     type_name##_class_intern_init (gpointer klass) \
1960 { \
1961   type_name##_parent_class = g_type_class_peek_parent (klass); \
1962   if (TypeName##_private_offset != 0) \
1963     g_type_class_adjust_private_offset (klass, &TypeName##_private_offset); \
1964   type_name##_class_init ((TypeName##Class*) klass); \
1965 }
1966 
1967 #else
1968 #define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
1969 static void     type_name##_class_intern_init (gpointer klass) \
1970 { \
1971   type_name##_parent_class = g_type_class_peek_parent (klass); \
1972   type_name##_class_init ((TypeName##Class*) klass); \
1973 }
1974 #endif /* GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 */
1975 
1976 /* Added for _G_DEFINE_TYPE_EXTENDED_WITH_PRELUDE */
1977 #define _G_DEFINE_TYPE_EXTENDED_BEGIN_PRE(TypeName, type_name, TYPE_PARENT) \
1978 \
1979 static void     type_name##_init              (TypeName        *self); \
1980 static void     type_name##_class_init        (TypeName##Class *klass); \
1981 static GType    type_name##_get_type_once     (void); \
1982 static gpointer type_name##_parent_class = NULL; \
1983 static gint     TypeName##_private_offset; \
1984 \
1985 _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
1986 \
1987 G_GNUC_UNUSED \
1988 static inline gpointer \
1989 type_name##_get_instance_private (TypeName *self) \
1990 { \
1991   return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \
1992 } \
1993 \
1994 GType \
1995 type_name##_get_type (void) \
1996 { \
1997   static volatile gsize g_define_type_id__volatile = 0;
1998   /* Prelude goes here */
1999 
2000 /* Added for _G_DEFINE_TYPE_EXTENDED_WITH_PRELUDE */
2001 #define _G_DEFINE_TYPE_EXTENDED_BEGIN_REGISTER(TypeName, type_name, TYPE_PARENT, flags) \
2002   if (g_once_init_enter (&g_define_type_id__volatile))  \
2003     { \
2004       GType g_define_type_id = type_name##_get_type_once (); \
2005       g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
2006     }					\
2007   return g_define_type_id__volatile;	\
2008 } /* closes type_name##_get_type() */ \
2009 \
2010 G_GNUC_NO_INLINE \
2011 static GType \
2012 type_name##_get_type_once (void) \
2013 { \
2014   GType g_define_type_id = \
2015         g_type_register_static_simple (TYPE_PARENT, \
2016                                        g_intern_static_string (#TypeName), \
2017                                        sizeof (TypeName##Class), \
2018                                        (GClassInitFunc)(void (*)(void)) type_name##_class_intern_init, \
2019                                        sizeof (TypeName), \
2020                                        (GInstanceInitFunc)(void (*)(void)) type_name##_init, \
2021                                        (GTypeFlags) flags); \
2022     { /* custom code follows */
2023 #define _G_DEFINE_TYPE_EXTENDED_END()	\
2024       /* following custom code */	\
2025     }					\
2026   return g_define_type_id; \
2027 } /* closes type_name##_get_type_once() */
2028 
2029 /* This was defined before we had G_DEFINE_TYPE_WITH_CODE_AND_PRELUDE, it's simplest
2030  * to keep it.
2031  */
2032 #define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
2033   _G_DEFINE_TYPE_EXTENDED_BEGIN_PRE(TypeName, type_name, TYPE_PARENT) \
2034   _G_DEFINE_TYPE_EXTENDED_BEGIN_REGISTER(TypeName, type_name, TYPE_PARENT, flags) \
2035 
2036 #define _G_DEFINE_INTERFACE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PREREQ) \
2037 \
2038 static void     type_name##_default_init        (TypeName##Interface *klass); \
2039 \
2040 GType \
2041 type_name##_get_type (void) \
2042 { \
2043   static volatile gsize g_define_type_id__volatile = 0; \
2044   if (g_once_init_enter (&g_define_type_id__volatile))  \
2045     { \
2046       GType g_define_type_id = \
2047         g_type_register_static_simple (G_TYPE_INTERFACE, \
2048                                        g_intern_static_string (#TypeName), \
2049                                        sizeof (TypeName##Interface), \
2050                                        (GClassInitFunc)(void (*)(void)) type_name##_default_init, \
2051                                        0, \
2052                                        (GInstanceInitFunc)NULL, \
2053                                        (GTypeFlags) 0); \
2054       if (TYPE_PREREQ != G_TYPE_INVALID) \
2055         g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \
2056       { /* custom code follows */
2057 #define _G_DEFINE_INTERFACE_EXTENDED_END()	\
2058         /* following custom code */		\
2059       }						\
2060       g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
2061     }						\
2062   return g_define_type_id__volatile;			\
2063 } /* closes type_name##_get_type() */
2064 
2065 /**
2066  * G_DEFINE_BOXED_TYPE:
2067  * @TypeName: The name of the new type, in Camel case
2068  * @type_name: The name of the new type, in lowercase, with words
2069  *  separated by '_'
2070  * @copy_func: the #GBoxedCopyFunc for the new type
2071  * @free_func: the #GBoxedFreeFunc for the new type
2072  *
2073  * A convenience macro for boxed type implementations, which defines a
2074  * type_name_get_type() function registering the boxed type.
2075  *
2076  * Since: 2.26
2077  */
2078 #define G_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) G_DEFINE_BOXED_TYPE_WITH_CODE (TypeName, type_name, copy_func, free_func, {})
2079 /**
2080  * G_DEFINE_BOXED_TYPE_WITH_CODE:
2081  * @TypeName: The name of the new type, in Camel case
2082  * @type_name: The name of the new type, in lowercase, with words
2083  *  separated by '_'
2084  * @copy_func: the #GBoxedCopyFunc for the new type
2085  * @free_func: the #GBoxedFreeFunc for the new type
2086  * @_C_: Custom code that gets inserted in the *_get_type() function
2087  *
2088  * A convenience macro for boxed type implementations.
2089  * Similar to G_DEFINE_BOXED_TYPE(), but allows to insert custom code into the
2090  * type_name_get_type() function, e.g. to register value transformations with
2091  * g_value_register_transform_func(), for instance:
2092  *
2093  * |[<!-- language="C" -->
2094  * G_DEFINE_BOXED_TYPE_WITH_CODE (GdkRectangle, gdk_rectangle,
2095  *                                gdk_rectangle_copy,
2096  *                                gdk_rectangle_free,
2097  *                                register_rectangle_transform_funcs (g_define_type_id))
2098  * ]|
2099  *
2100  * Similarly to the %G_DEFINE_TYPE family of macros, the #GType of the newly
2101  * defined boxed type is exposed in the `g_define_type_id` variable.
2102  *
2103  * Since: 2.26
2104  */
2105 #define G_DEFINE_BOXED_TYPE_WITH_CODE(TypeName, type_name, copy_func, free_func, _C_) _G_DEFINE_BOXED_TYPE_BEGIN (TypeName, type_name, copy_func, free_func) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
2106 
2107 /* Only use this in non-C++ on GCC >= 2.7, except for Darwin/ppc64.
2108  * See https://bugzilla.gnome.org/show_bug.cgi?id=647145
2109  */
2110 #if !defined (__cplusplus) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) && !(defined (__APPLE__) && defined (__ppc64__))
2111 #define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \
2112 static GType type_name##_get_type_once (void); \
2113 \
2114 GType \
2115 type_name##_get_type (void) \
2116 { \
2117   static volatile gsize g_define_type_id__volatile = 0; \
2118   if (g_once_init_enter (&g_define_type_id__volatile))  \
2119     { \
2120       GType g_define_type_id = type_name##_get_type_once (); \
2121       g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
2122     } \
2123   return g_define_type_id__volatile; \
2124 } \
2125 \
2126 G_GNUC_NO_INLINE \
2127 static GType \
2128 type_name##_get_type_once (void) \
2129 { \
2130   GType (* _g_register_boxed) \
2131     (const gchar *, \
2132      union \
2133        { \
2134          TypeName * (*do_copy_type) (TypeName *); \
2135          TypeName * (*do_const_copy_type) (const TypeName *); \
2136          GBoxedCopyFunc do_copy_boxed; \
2137        } __attribute__((__transparent_union__)), \
2138      union \
2139        { \
2140          void (* do_free_type) (TypeName *); \
2141          GBoxedFreeFunc do_free_boxed; \
2142        } __attribute__((__transparent_union__)) \
2143     ) = g_boxed_type_register_static; \
2144   GType g_define_type_id = \
2145     _g_register_boxed (g_intern_static_string (#TypeName), copy_func, free_func); \
2146   { /* custom code follows */
2147 #else
2148 #define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \
2149 static GType type_name##_get_type_once (void); \
2150 \
2151 GType \
2152 type_name##_get_type (void) \
2153 { \
2154   static volatile gsize g_define_type_id__volatile = 0; \
2155   if (g_once_init_enter (&g_define_type_id__volatile))  \
2156     { \
2157       GType g_define_type_id = type_name##_get_type_once (); \
2158       g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
2159     } \
2160   return g_define_type_id__volatile; \
2161 } \
2162 \
2163 G_GNUC_NO_INLINE \
2164 static GType \
2165 type_name##_get_type_once (void) \
2166 { \
2167   GType g_define_type_id = \
2168     g_boxed_type_register_static (g_intern_static_string (#TypeName), \
2169                                   (GBoxedCopyFunc) copy_func, \
2170                                   (GBoxedFreeFunc) free_func); \
2171   { /* custom code follows */
2172 #endif /* __GNUC__ */
2173 
2174 /**
2175  * G_DEFINE_POINTER_TYPE:
2176  * @TypeName: The name of the new type, in Camel case
2177  * @type_name: The name of the new type, in lowercase, with words
2178  *  separated by '_'
2179  *
2180  * A convenience macro for pointer type implementations, which defines a
2181  * type_name_get_type() function registering the pointer type.
2182  *
2183  * Since: 2.26
2184  */
2185 #define G_DEFINE_POINTER_TYPE(TypeName, type_name) G_DEFINE_POINTER_TYPE_WITH_CODE (TypeName, type_name, {})
2186 /**
2187  * G_DEFINE_POINTER_TYPE_WITH_CODE:
2188  * @TypeName: The name of the new type, in Camel case
2189  * @type_name: The name of the new type, in lowercase, with words
2190  *  separated by '_'
2191  * @_C_: Custom code that gets inserted in the *_get_type() function
2192  *
2193  * A convenience macro for pointer type implementations.
2194  * Similar to G_DEFINE_POINTER_TYPE(), but allows to insert
2195  * custom code into the type_name_get_type() function.
2196  *
2197  * Since: 2.26
2198  */
2199 #define G_DEFINE_POINTER_TYPE_WITH_CODE(TypeName, type_name, _C_) _G_DEFINE_POINTER_TYPE_BEGIN (TypeName, type_name) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
2200 
2201 #define _G_DEFINE_POINTER_TYPE_BEGIN(TypeName, type_name) \
2202 static GType type_name##_get_type_once (void); \
2203 \
2204 GType \
2205 type_name##_get_type (void) \
2206 { \
2207   static volatile gsize g_define_type_id__volatile = 0; \
2208   if (g_once_init_enter (&g_define_type_id__volatile))  \
2209     { \
2210       GType g_define_type_id = type_name##_get_type_once (); \
2211       g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
2212     } \
2213   return g_define_type_id__volatile; \
2214 } \
2215 \
2216 G_GNUC_NO_INLINE \
2217 static GType \
2218 type_name##_get_type_once (void) \
2219 { \
2220   GType g_define_type_id = \
2221     g_pointer_type_register_static (g_intern_static_string (#TypeName)); \
2222   { /* custom code follows */
2223 
2224 /* --- protected (for fundamental type implementations) --- */
2225 GLIB_AVAILABLE_IN_ALL
2226 GTypePlugin*	 g_type_get_plugin		(GType		     type);
2227 GLIB_AVAILABLE_IN_ALL
2228 GTypePlugin*	 g_type_interface_get_plugin	(GType		     instance_type,
2229 						 GType               interface_type);
2230 GLIB_AVAILABLE_IN_ALL
2231 GType		 g_type_fundamental_next	(void);
2232 GLIB_AVAILABLE_IN_ALL
2233 GType		 g_type_fundamental		(GType		     type_id);
2234 GLIB_AVAILABLE_IN_ALL
2235 GTypeInstance*   g_type_create_instance         (GType               type);
2236 GLIB_AVAILABLE_IN_ALL
2237 void             g_type_free_instance           (GTypeInstance      *instance);
2238 
2239 GLIB_AVAILABLE_IN_ALL
2240 void		 g_type_add_class_cache_func    (gpointer	     cache_data,
2241 						 GTypeClassCacheFunc cache_func);
2242 GLIB_AVAILABLE_IN_ALL
2243 void		 g_type_remove_class_cache_func (gpointer	     cache_data,
2244 						 GTypeClassCacheFunc cache_func);
2245 GLIB_AVAILABLE_IN_ALL
2246 void             g_type_class_unref_uncached    (gpointer            g_class);
2247 
2248 GLIB_AVAILABLE_IN_ALL
2249 void             g_type_add_interface_check     (gpointer	         check_data,
2250 						 GTypeInterfaceCheckFunc check_func);
2251 GLIB_AVAILABLE_IN_ALL
2252 void             g_type_remove_interface_check  (gpointer	         check_data,
2253 						 GTypeInterfaceCheckFunc check_func);
2254 
2255 GLIB_AVAILABLE_IN_ALL
2256 GTypeValueTable* g_type_value_table_peek        (GType		     type);
2257 
2258 
2259 /*< private >*/
2260 GLIB_AVAILABLE_IN_ALL
2261 gboolean	 g_type_check_instance          (GTypeInstance      *instance) G_GNUC_PURE;
2262 GLIB_AVAILABLE_IN_ALL
2263 GTypeInstance*   g_type_check_instance_cast     (GTypeInstance      *instance,
2264 						 GType               iface_type);
2265 GLIB_AVAILABLE_IN_ALL
2266 gboolean         g_type_check_instance_is_a	(GTypeInstance      *instance,
2267 						 GType               iface_type) G_GNUC_PURE;
2268 GLIB_AVAILABLE_IN_2_42
2269 gboolean         g_type_check_instance_is_fundamentally_a (GTypeInstance *instance,
2270                                                            GType          fundamental_type) G_GNUC_PURE;
2271 GLIB_AVAILABLE_IN_ALL
2272 GTypeClass*      g_type_check_class_cast        (GTypeClass         *g_class,
2273 						 GType               is_a_type);
2274 GLIB_AVAILABLE_IN_ALL
2275 gboolean         g_type_check_class_is_a        (GTypeClass         *g_class,
2276 						 GType               is_a_type) G_GNUC_PURE;
2277 GLIB_AVAILABLE_IN_ALL
2278 gboolean	 g_type_check_is_value_type     (GType		     type) G_GNUC_CONST;
2279 GLIB_AVAILABLE_IN_ALL
2280 gboolean	 g_type_check_value             (const GValue       *value) G_GNUC_PURE;
2281 GLIB_AVAILABLE_IN_ALL
2282 gboolean	 g_type_check_value_holds	(const GValue	    *value,
2283 						 GType		     type) G_GNUC_PURE;
2284 GLIB_AVAILABLE_IN_ALL
2285 gboolean         g_type_test_flags              (GType               type,
2286 						 guint               flags) G_GNUC_CONST;
2287 
2288 
2289 /* --- debugging functions --- */
2290 GLIB_AVAILABLE_IN_ALL
2291 const gchar *    g_type_name_from_instance      (GTypeInstance	*instance);
2292 GLIB_AVAILABLE_IN_ALL
2293 const gchar *    g_type_name_from_class         (GTypeClass	*g_class);
2294 
2295 
2296 /* --- implementation bits --- */
2297 #ifndef G_DISABLE_CAST_CHECKS
2298 #  define _G_TYPE_CIC(ip, gt, ct) \
2299     ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
2300 #  define _G_TYPE_CCC(cp, gt, ct) \
2301     ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt))
2302 #else /* G_DISABLE_CAST_CHECKS */
2303 #  define _G_TYPE_CIC(ip, gt, ct)       ((ct*) ip)
2304 #  define _G_TYPE_CCC(cp, gt, ct)       ((ct*) cp)
2305 #endif /* G_DISABLE_CAST_CHECKS */
2306 #define _G_TYPE_CHI(ip)			(g_type_check_instance ((GTypeInstance*) ip))
2307 #define _G_TYPE_CHV(vl)			(g_type_check_value ((GValue*) vl))
2308 #define _G_TYPE_IGC(ip, gt, ct)         ((ct*) (((GTypeInstance*) ip)->g_class))
2309 #define _G_TYPE_IGI(ip, gt, ct)         ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt))
2310 #define _G_TYPE_CIFT(ip, ft)            (g_type_check_instance_is_fundamentally_a ((GTypeInstance*) ip, ft))
2311 #ifdef	__GNUC__
2312 #  define _G_TYPE_CIT(ip, gt)             (G_GNUC_EXTENSION ({ \
2313   GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; gboolean __r; \
2314   if (!__inst) \
2315     __r = FALSE; \
2316   else if (__inst->g_class && __inst->g_class->g_type == __t) \
2317     __r = TRUE; \
2318   else \
2319     __r = g_type_check_instance_is_a (__inst, __t); \
2320   __r; \
2321 }))
2322 #  define _G_TYPE_CCT(cp, gt)             (G_GNUC_EXTENSION ({ \
2323   GTypeClass *__class = (GTypeClass*) cp; GType __t = gt; gboolean __r; \
2324   if (!__class) \
2325     __r = FALSE; \
2326   else if (__class->g_type == __t) \
2327     __r = TRUE; \
2328   else \
2329     __r = g_type_check_class_is_a (__class, __t); \
2330   __r; \
2331 }))
2332 #  define _G_TYPE_CVH(vl, gt)             (G_GNUC_EXTENSION ({ \
2333   const GValue *__val = (const GValue*) vl; GType __t = gt; gboolean __r; \
2334   if (!__val) \
2335     __r = FALSE; \
2336   else if (__val->g_type == __t)		\
2337     __r = TRUE; \
2338   else \
2339     __r = g_type_check_value_holds (__val, __t); \
2340   __r; \
2341 }))
2342 #else  /* !__GNUC__ */
2343 #  define _G_TYPE_CIT(ip, gt)             (g_type_check_instance_is_a ((GTypeInstance*) ip, gt))
2344 #  define _G_TYPE_CCT(cp, gt)             (g_type_check_class_is_a ((GTypeClass*) cp, gt))
2345 #  define _G_TYPE_CVH(vl, gt)             (g_type_check_value_holds ((const GValue*) vl, gt))
2346 #endif /* !__GNUC__ */
2347 /**
2348  * G_TYPE_FLAG_RESERVED_ID_BIT:
2349  *
2350  * A bit in the type number that's supposed to be left untouched.
2351  */
2352 #define	G_TYPE_FLAG_RESERVED_ID_BIT	((GType) (1 << 0))
2353 
2354 G_END_DECLS
2355 
2356 #endif /* __G_TYPE_H__ */
2357