1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
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.
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.
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/>.
17 #ifndef __G_OBJECT_H__
18 #define __G_OBJECT_H__
20 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
21 #error "Only <glib-object.h> can be included directly."
24 #include <gobject/gtype.h>
25 #include <gobject/gvalue.h>
26 #include <gobject/gparam.h>
27 #include <gobject/gclosure.h>
28 #include <gobject/gsignal.h>
29 #include <gobject/gboxed.h>
33 /* --- type macros --- */
36 * @type: Type id to check
38 * Check if the passed in type id is a %G_TYPE_OBJECT or derived from it.
40 * Returns: %FALSE or %TRUE, indicating whether @type is a %G_TYPE_OBJECT.
42 #define G_TYPE_IS_OBJECT(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
45 * @object: Object which is subject to casting.
47 * Casts a #GObject or derived pointer into a (GObject*) pointer.
48 * Depending on the current debugging level, this function may invoke
49 * certain runtime checks to identify invalid casts.
51 #define G_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
54 * @class: a valid #GObjectClass
56 * Casts a derived #GObjectClass structure into a #GObjectClass structure.
58 #define G_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
61 * @object: Instance to check for being a %G_TYPE_OBJECT.
63 * Checks whether a valid #GTypeInstance pointer is of type %G_TYPE_OBJECT.
65 #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_42
66 #define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE ((object), G_TYPE_OBJECT))
68 #define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT))
72 * @class: a #GObjectClass
74 * Checks whether @class "is a" valid #GObjectClass structure of type
75 * %G_TYPE_OBJECT or derived.
77 #define G_IS_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT))
80 * @object: a #GObject instance.
82 * Get the class structure associated to a #GObject instance.
84 * Returns: pointer to object class structure.
86 #define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
89 * @object: Object to return the type id for.
91 * Get the type id of an object.
93 * Returns: Type id of @object.
95 #define G_OBJECT_TYPE(object) (G_TYPE_FROM_INSTANCE (object))
98 * @object: Object to return the type name for.
100 * Get the name of an object's type.
102 * Returns: Type name of @object. The string is owned by the type system and
103 * should not be freed.
105 #define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object)))
107 * G_OBJECT_CLASS_TYPE:
108 * @class: a valid #GObjectClass
110 * Get the type id of a class structure.
112 * Returns: Type id of @class.
114 #define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
116 * G_OBJECT_CLASS_NAME:
117 * @class: a valid #GObjectClass
119 * Return the name of a class structure's type.
121 * Returns: Type name of @class. The string is owned by the type system and
122 * should not be freed.
124 #define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class)))
126 * G_VALUE_HOLDS_OBJECT:
127 * @value: a valid #GValue structure
129 * Checks whether the given #GValue can hold values derived from type %G_TYPE_OBJECT.
131 * Returns: %TRUE on success.
133 #define G_VALUE_HOLDS_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT))
135 /* --- type macros --- */
137 * G_TYPE_INITIALLY_UNOWNED:
139 * The type for #GInitiallyUnowned.
141 #define G_TYPE_INITIALLY_UNOWNED (g_initially_unowned_get_type())
143 * G_INITIALLY_UNOWNED:
144 * @object: Object which is subject to casting.
146 * Casts a #GInitiallyUnowned or derived pointer into a (GInitiallyUnowned*)
147 * pointer. Depending on the current debugging level, this function may invoke
148 * certain runtime checks to identify invalid casts.
150 #define G_INITIALLY_UNOWNED(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnowned))
152 * G_INITIALLY_UNOWNED_CLASS:
153 * @class: a valid #GInitiallyUnownedClass
155 * Casts a derived #GInitiallyUnownedClass structure into a
156 * #GInitiallyUnownedClass structure.
158 #define G_INITIALLY_UNOWNED_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
160 * G_IS_INITIALLY_UNOWNED:
161 * @object: Instance to check for being a %G_TYPE_INITIALLY_UNOWNED.
163 * Checks whether a valid #GTypeInstance pointer is of type %G_TYPE_INITIALLY_UNOWNED.
165 #define G_IS_INITIALLY_UNOWNED(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_INITIALLY_UNOWNED))
167 * G_IS_INITIALLY_UNOWNED_CLASS:
168 * @class: a #GInitiallyUnownedClass
170 * Checks whether @class "is a" valid #GInitiallyUnownedClass structure of type
171 * %G_TYPE_INITIALLY_UNOWNED or derived.
173 #define G_IS_INITIALLY_UNOWNED_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_INITIALLY_UNOWNED))
175 * G_INITIALLY_UNOWNED_GET_CLASS:
176 * @object: a #GInitiallyUnowned instance.
178 * Get the class structure associated to a #GInitiallyUnowned instance.
180 * Returns: pointer to object class structure.
182 #define G_INITIALLY_UNOWNED_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
183 /* GInitiallyUnowned ia a GObject with initially floating reference count */
186 /* --- typedefs & structures --- */
187 typedef struct _GObject GObject
;
188 typedef struct _GObjectClass GObjectClass
;
189 typedef struct _GObject GInitiallyUnowned
;
190 typedef struct _GObjectClass GInitiallyUnownedClass
;
191 typedef struct _GObjectConstructParam GObjectConstructParam
;
193 * GObjectGetPropertyFunc:
194 * @object: a #GObject
195 * @property_id: the numeric id under which the property was registered with
196 * g_object_class_install_property().
197 * @value: a #GValue to return the property value in
198 * @pspec: the #GParamSpec describing the property
200 * The type of the @get_property function of #GObjectClass.
202 typedef void (*GObjectGetPropertyFunc
) (GObject
*object
,
207 * GObjectSetPropertyFunc:
208 * @object: a #GObject
209 * @property_id: the numeric id under which the property was registered with
210 * g_object_class_install_property().
211 * @value: the new value for the property
212 * @pspec: the #GParamSpec describing the property
214 * The type of the @set_property function of #GObjectClass.
216 typedef void (*GObjectSetPropertyFunc
) (GObject
*object
,
221 * GObjectFinalizeFunc:
222 * @object: the #GObject being finalized
224 * The type of the @finalize function of #GObjectClass.
226 typedef void (*GObjectFinalizeFunc
) (GObject
*object
);
229 * @data: data that was provided when the weak reference was established
230 * @where_the_object_was: the object being finalized
232 * A #GWeakNotify function can be added to an object as a callback that gets
233 * triggered when the object is finalized. Since the object is already being
234 * finalized when the #GWeakNotify is called, there's not much you could do
235 * with the object, apart from e.g. using its address as hash-index or the like.
237 typedef void (*GWeakNotify
) (gpointer data
,
238 GObject
*where_the_object_was
);
242 * All the fields in the GObject structure are private
243 * to the #GObject implementation and should never be accessed directly.
247 GTypeInstance g_type_instance
;
250 volatile guint ref_count
;
255 * @g_type_class: the parent class
256 * @constructor: the @constructor function is called by g_object_new () to
257 * complete the object initialization after all the construction properties are
258 * set. The first thing a @constructor implementation must do is chain up to the
259 * @constructor of the parent class. Overriding @constructor should be rarely
260 * needed, e.g. to handle construct properties, or to implement singletons.
261 * @set_property: the generic setter for all properties of this type. Should be
262 * overridden for every type with properties. If implementations of
263 * @set_property don't emit property change notification explicitly, this will
264 * be done implicitly by the type system. However, if the notify signal is
265 * emitted explicitly, the type system will not emit it a second time.
266 * @get_property: the generic getter for all properties of this type. Should be
267 * overridden for every type with properties.
268 * @dispose: the @dispose function is supposed to drop all references to other
269 * objects, but keep the instance otherwise intact, so that client method
270 * invocations still work. It may be run multiple times (due to reference
271 * loops). Before returning, @dispose should chain up to the @dispose method
272 * of the parent class.
273 * @finalize: instance finalization function, should finish the finalization of
274 * the instance begun in @dispose and chain up to the @finalize method of the
276 * @dispatch_properties_changed: emits property change notification for a bunch
277 * of properties. Overriding @dispatch_properties_changed should be rarely
279 * @notify: the class closure for the notify signal
280 * @constructed: the @constructed function is called by g_object_new() as the
281 * final step of the object creation process. At the point of the call, all
282 * construction properties have been set on the object. The purpose of this
283 * call is to allow for object initialisation steps that can only be performed
284 * after construction properties have been set. @constructed implementors
285 * should chain up to the @constructed call of their parent class to allow it
286 * to complete its initialisation.
288 * The class structure for the GObject type.
291 * <title>Implementing singletons using a constructor</title>
293 * static MySingleton *the_singleton = NULL;
296 * my_singleton_constructor (GType type,
297 * guint n_construct_params,
298 * GObjectConstructParam *construct_params)
302 * if (!the_singleton)
304 * object = G_OBJECT_CLASS (parent_class)->constructor (type,
305 * n_construct_params,
307 * the_singleton = MY_SINGLETON (object);
310 * object = g_object_ref (G_OBJECT (the_singleton));
314 * </programlisting></example>
318 GTypeClass g_type_class
;
321 GSList
*construct_properties
;
324 /* seldom overidden */
325 GObject
* (*constructor
) (GType type
,
326 guint n_construct_properties
,
327 GObjectConstructParam
*construct_properties
);
328 /* overridable methods */
329 void (*set_property
) (GObject
*object
,
333 void (*get_property
) (GObject
*object
,
337 void (*dispose
) (GObject
*object
);
338 void (*finalize
) (GObject
*object
);
339 /* seldom overidden */
340 void (*dispatch_properties_changed
) (GObject
*object
,
342 GParamSpec
**pspecs
);
344 void (*notify
) (GObject
*object
,
347 /* called when done constructing */
348 void (*constructed
) (GObject
*object
);
357 * GObjectConstructParam:
358 * @pspec: the #GParamSpec of the construct parameter
359 * @value: the value to set the parameter to
361 * The GObjectConstructParam struct is an auxiliary
362 * structure used to hand #GParamSpec/#GValue pairs to the @constructor of
365 struct _GObjectConstructParam
374 * All the fields in the GInitiallyUnowned structure
375 * are private to the #GInitiallyUnowned implementation and should never be
379 * GInitiallyUnownedClass:
381 * The class structure for the GInitiallyUnowned type.
385 /* --- prototypes --- */
386 GLIB_AVAILABLE_IN_ALL
387 GType
g_initially_unowned_get_type (void);
388 GLIB_AVAILABLE_IN_ALL
389 void g_object_class_install_property (GObjectClass
*oclass
,
392 GLIB_AVAILABLE_IN_ALL
393 GParamSpec
* g_object_class_find_property (GObjectClass
*oclass
,
394 const gchar
*property_name
);
395 GLIB_AVAILABLE_IN_ALL
396 GParamSpec
**g_object_class_list_properties (GObjectClass
*oclass
,
397 guint
*n_properties
);
398 GLIB_AVAILABLE_IN_ALL
399 void g_object_class_override_property (GObjectClass
*oclass
,
402 GLIB_AVAILABLE_IN_ALL
403 void g_object_class_install_properties (GObjectClass
*oclass
,
405 GParamSpec
**pspecs
);
407 GLIB_AVAILABLE_IN_ALL
408 void g_object_interface_install_property (gpointer g_iface
,
410 GLIB_AVAILABLE_IN_ALL
411 GParamSpec
* g_object_interface_find_property (gpointer g_iface
,
412 const gchar
*property_name
);
413 GLIB_AVAILABLE_IN_ALL
414 GParamSpec
**g_object_interface_list_properties (gpointer g_iface
,
415 guint
*n_properties_p
);
417 GLIB_AVAILABLE_IN_ALL
418 GType
g_object_get_type (void) G_GNUC_CONST
;
419 GLIB_AVAILABLE_IN_ALL
420 gpointer
g_object_new (GType object_type
,
421 const gchar
*first_property_name
,
423 GLIB_AVAILABLE_IN_2_54
424 GObject
* g_object_new_with_properties (GType object_type
,
427 const GValue values
[]);
428 GLIB_DEPRECATED_IN_2_54_FOR(g_object_new_with_properties
)
429 gpointer
g_object_newv (GType object_type
,
431 GParameter
*parameters
);
432 GLIB_AVAILABLE_IN_ALL
433 GObject
* g_object_new_valist (GType object_type
,
434 const gchar
*first_property_name
,
436 GLIB_AVAILABLE_IN_ALL
437 void g_object_set (gpointer object
,
438 const gchar
*first_property_name
,
439 ...) G_GNUC_NULL_TERMINATED
;
440 GLIB_AVAILABLE_IN_ALL
441 void g_object_get (gpointer object
,
442 const gchar
*first_property_name
,
443 ...) G_GNUC_NULL_TERMINATED
;
444 GLIB_AVAILABLE_IN_ALL
445 gpointer
g_object_connect (gpointer object
,
446 const gchar
*signal_spec
,
447 ...) G_GNUC_NULL_TERMINATED
;
448 GLIB_AVAILABLE_IN_ALL
449 void g_object_disconnect (gpointer object
,
450 const gchar
*signal_spec
,
451 ...) G_GNUC_NULL_TERMINATED
;
452 GLIB_AVAILABLE_IN_2_54
453 void g_object_setv (GObject
*object
,
455 const gchar
*names
[],
456 const GValue values
[]);
457 GLIB_AVAILABLE_IN_ALL
458 void g_object_set_valist (GObject
*object
,
459 const gchar
*first_property_name
,
461 GLIB_AVAILABLE_IN_2_54
462 void g_object_getv (GObject
*object
,
464 const gchar
*names
[],
466 GLIB_AVAILABLE_IN_ALL
467 void g_object_get_valist (GObject
*object
,
468 const gchar
*first_property_name
,
470 GLIB_AVAILABLE_IN_ALL
471 void g_object_set_property (GObject
*object
,
472 const gchar
*property_name
,
473 const GValue
*value
);
474 GLIB_AVAILABLE_IN_ALL
475 void g_object_get_property (GObject
*object
,
476 const gchar
*property_name
,
478 GLIB_AVAILABLE_IN_ALL
479 void g_object_freeze_notify (GObject
*object
);
480 GLIB_AVAILABLE_IN_ALL
481 void g_object_notify (GObject
*object
,
482 const gchar
*property_name
);
483 GLIB_AVAILABLE_IN_ALL
484 void g_object_notify_by_pspec (GObject
*object
,
486 GLIB_AVAILABLE_IN_ALL
487 void g_object_thaw_notify (GObject
*object
);
488 GLIB_AVAILABLE_IN_ALL
489 gboolean
g_object_is_floating (gpointer object
);
490 GLIB_AVAILABLE_IN_ALL
491 gpointer
g_object_ref_sink (gpointer object
);
492 GLIB_AVAILABLE_IN_ALL
493 gpointer
g_object_ref (gpointer object
);
494 GLIB_AVAILABLE_IN_ALL
495 void g_object_unref (gpointer object
);
496 GLIB_AVAILABLE_IN_ALL
497 void g_object_weak_ref (GObject
*object
,
500 GLIB_AVAILABLE_IN_ALL
501 void g_object_weak_unref (GObject
*object
,
504 GLIB_AVAILABLE_IN_ALL
505 void g_object_add_weak_pointer (GObject
*object
,
506 gpointer
*weak_pointer_location
);
507 GLIB_AVAILABLE_IN_ALL
508 void g_object_remove_weak_pointer (GObject
*object
,
509 gpointer
*weak_pointer_location
);
513 * @data: Callback data passed to g_object_add_toggle_ref()
514 * @object: The object on which g_object_add_toggle_ref() was called.
515 * @is_last_ref: %TRUE if the toggle reference is now the
516 * last reference to the object. %FALSE if the toggle
517 * reference was the last reference and there are now other
520 * A callback function used for notification when the state
521 * of a toggle reference changes. See g_object_add_toggle_ref().
523 typedef void (*GToggleNotify
) (gpointer data
,
525 gboolean is_last_ref
);
527 GLIB_AVAILABLE_IN_ALL
528 void g_object_add_toggle_ref (GObject
*object
,
529 GToggleNotify notify
,
531 GLIB_AVAILABLE_IN_ALL
532 void g_object_remove_toggle_ref (GObject
*object
,
533 GToggleNotify notify
,
536 GLIB_AVAILABLE_IN_ALL
537 gpointer
g_object_get_qdata (GObject
*object
,
539 GLIB_AVAILABLE_IN_ALL
540 void g_object_set_qdata (GObject
*object
,
543 GLIB_AVAILABLE_IN_ALL
544 void g_object_set_qdata_full (GObject
*object
,
547 GDestroyNotify destroy
);
548 GLIB_AVAILABLE_IN_ALL
549 gpointer
g_object_steal_qdata (GObject
*object
,
552 GLIB_AVAILABLE_IN_2_34
553 gpointer
g_object_dup_qdata (GObject
*object
,
555 GDuplicateFunc dup_func
,
557 GLIB_AVAILABLE_IN_2_34
558 gboolean
g_object_replace_qdata (GObject
*object
,
562 GDestroyNotify destroy
,
563 GDestroyNotify
*old_destroy
);
565 GLIB_AVAILABLE_IN_ALL
566 gpointer
g_object_get_data (GObject
*object
,
568 GLIB_AVAILABLE_IN_ALL
569 void g_object_set_data (GObject
*object
,
572 GLIB_AVAILABLE_IN_ALL
573 void g_object_set_data_full (GObject
*object
,
576 GDestroyNotify destroy
);
577 GLIB_AVAILABLE_IN_ALL
578 gpointer
g_object_steal_data (GObject
*object
,
581 GLIB_AVAILABLE_IN_2_34
582 gpointer
g_object_dup_data (GObject
*object
,
584 GDuplicateFunc dup_func
,
586 GLIB_AVAILABLE_IN_2_34
587 gboolean
g_object_replace_data (GObject
*object
,
591 GDestroyNotify destroy
,
592 GDestroyNotify
*old_destroy
);
595 GLIB_AVAILABLE_IN_ALL
596 void g_object_watch_closure (GObject
*object
,
598 GLIB_AVAILABLE_IN_ALL
599 GClosure
* g_cclosure_new_object (GCallback callback_func
,
601 GLIB_AVAILABLE_IN_ALL
602 GClosure
* g_cclosure_new_object_swap (GCallback callback_func
,
604 GLIB_AVAILABLE_IN_ALL
605 GClosure
* g_closure_new_object (guint sizeof_closure
,
607 GLIB_AVAILABLE_IN_ALL
608 void g_value_set_object (GValue
*value
,
610 GLIB_AVAILABLE_IN_ALL
611 gpointer
g_value_get_object (const GValue
*value
);
612 GLIB_AVAILABLE_IN_ALL
613 gpointer
g_value_dup_object (const GValue
*value
);
614 GLIB_AVAILABLE_IN_ALL
615 gulong
g_signal_connect_object (gpointer instance
,
616 const gchar
*detailed_signal
,
619 GConnectFlags connect_flags
);
622 GLIB_AVAILABLE_IN_ALL
623 void g_object_force_floating (GObject
*object
);
624 GLIB_AVAILABLE_IN_ALL
625 void g_object_run_dispose (GObject
*object
);
628 GLIB_AVAILABLE_IN_ALL
629 void g_value_take_object (GValue
*value
,
631 GLIB_DEPRECATED_FOR(g_value_take_object
)
632 void g_value_set_object_take_ownership (GValue
*value
,
636 gsize
g_object_compat_control (gsize what
,
639 /* --- implementation macros --- */
640 #define G_OBJECT_WARN_INVALID_PSPEC(object, pname, property_id, pspec) \
642 GObject *_glib__object = (GObject*) (object); \
643 GParamSpec *_glib__pspec = (GParamSpec*) (pspec); \
644 guint _glib__property_id = (property_id); \
645 g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'", \
646 __FILE__, __LINE__, \
648 _glib__property_id, \
649 _glib__pspec->name, \
650 g_type_name (G_PARAM_SPEC_TYPE (_glib__pspec)), \
651 G_OBJECT_TYPE_NAME (_glib__object)); \
654 * G_OBJECT_WARN_INVALID_PROPERTY_ID:
655 * @object: the #GObject on which set_property() or get_property() was called
656 * @property_id: the numeric id of the property
657 * @pspec: the #GParamSpec of the property
659 * This macro should be used to emit a standard warning about unexpected
660 * properties in set_property() and get_property() implementations.
662 #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
663 G_OBJECT_WARN_INVALID_PSPEC ((object), "property", (property_id), (pspec))
665 GLIB_AVAILABLE_IN_ALL
666 void g_clear_object (volatile GObject
**object_ptr
);
667 #define g_clear_object(object_ptr) g_clear_pointer ((object_ptr), g_object_unref)
670 * g_set_object: (skip)
671 * @object_ptr: a pointer to a #GObject reference
672 * @new_object: (nullable) (transfer none): a pointer to the new #GObject to
673 * assign to it, or %NULL to clear the pointer
675 * Updates a #GObject pointer to refer to @new_object. It increments the
676 * reference count of @new_object (if non-%NULL), decrements the reference
677 * count of the current value of @object_ptr (if non-%NULL), and assigns
678 * @new_object to @object_ptr. The assignment is not atomic.
680 * @object_ptr must not be %NULL.
682 * A macro is also included that allows this function to be used without
683 * pointer casts. The function itself is static inline, so its address may vary
684 * between compilation units.
686 * One convenient usage of this function is in implementing property setters:
689 * foo_set_bar (Foo *foo,
692 * g_return_if_fail (IS_FOO (foo));
693 * g_return_if_fail (new_bar == NULL || IS_BAR (new_bar));
695 * if (g_set_object (&foo->bar, new_bar))
696 * g_object_notify (foo, "bar");
700 * Returns: %TRUE if the value of @object_ptr changed, %FALSE otherwise
704 static inline gboolean
705 (g_set_object
) (GObject
**object_ptr
,
708 GObject
*old_object
= *object_ptr
;
710 /* rely on g_object_[un]ref() to check the pointers are actually GObjects;
711 * elide a (object_ptr != NULL) check because most of the time we will be
712 * operating on struct members with a constant offset, so a NULL check would
716 if (old_object
== new_object
)
719 if (new_object
!= NULL
)
720 g_object_ref (new_object
);
722 *object_ptr
= new_object
;
724 if (old_object
!= NULL
)
725 g_object_unref (old_object
);
730 #define g_set_object(object_ptr, new_object) \
731 (/* Check types match. */ \
732 0 ? *(object_ptr) = (new_object), FALSE : \
733 (g_set_object) ((GObject **) (object_ptr), (GObject *) (new_object)) \
738 union { gpointer p
; } priv
;
741 GLIB_AVAILABLE_IN_ALL
742 void g_weak_ref_init (GWeakRef
*weak_ref
,
744 GLIB_AVAILABLE_IN_ALL
745 void g_weak_ref_clear (GWeakRef
*weak_ref
);
746 GLIB_AVAILABLE_IN_ALL
747 gpointer
g_weak_ref_get (GWeakRef
*weak_ref
);
748 GLIB_AVAILABLE_IN_ALL
749 void g_weak_ref_set (GWeakRef
*weak_ref
,
754 #endif /* __G_OBJECT_H__ */