Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
gobject.h
Go to the documentation of this file.
1/* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef __G_OBJECT_H__
20#define __G_OBJECT_H__
21
22#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
23#error "Only <glib-object.h> can be included directly."
24#endif
25
26#include <gobject/gtype.h>
27#include <gobject/gvalue.h>
28#include <gobject/gparam.h>
29#include <gobject/gclosure.h>
30#include <gobject/gsignal.h>
31#include <gobject/gboxed.h>
32
34
35/* --- type macros --- */
36/**
37 * G_TYPE_IS_OBJECT:
38 * @type: Type id to check
39 *
40 * Check if the passed in type id is a %G_TYPE_OBJECT or derived from it.
41 *
42 * Returns: %FALSE or %TRUE, indicating whether @type is a %G_TYPE_OBJECT.
43 */
44#define G_TYPE_IS_OBJECT(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
45/**
46 * G_OBJECT:
47 * @object: Object which is subject to casting.
48 *
49 * Casts a #GObject or derived pointer into a (GObject*) pointer.
50 *
51 * Depending on the current debugging level, this function may invoke
52 * certain runtime checks to identify invalid casts.
53 */
54#define G_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
55/**
56 * G_OBJECT_CLASS:
57 * @class: a valid #GObjectClass
58 *
59 * Casts a derived #GObjectClass structure into a #GObjectClass structure.
60 */
61#define G_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
62/**
63 * G_IS_OBJECT:
64 * @object: Instance to check for being a %G_TYPE_OBJECT.
65 *
66 * Checks whether a valid #GTypeInstance pointer is of type %G_TYPE_OBJECT.
67 */
68#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_42
69#define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE ((object), G_TYPE_OBJECT))
70#else
71#define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT))
72#endif
73/**
74 * G_IS_OBJECT_CLASS:
75 * @class: a #GObjectClass
76 *
77 * Checks whether @class "is a" valid #GObjectClass structure of type
78 * %G_TYPE_OBJECT or derived.
79 */
80#define G_IS_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT))
81/**
82 * G_OBJECT_GET_CLASS:
83 * @object: a #GObject instance.
84 *
85 * Get the class structure associated to a #GObject instance.
86 *
87 * Returns: pointer to object class structure.
88 */
89#define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
90/**
91 * G_OBJECT_TYPE:
92 * @object: Object to return the type id for.
93 *
94 * Get the type id of an object.
95 *
96 * Returns: Type id of @object.
97 */
98#define G_OBJECT_TYPE(object) (G_TYPE_FROM_INSTANCE (object))
99/**
100 * G_OBJECT_TYPE_NAME:
101 * @object: Object to return the type name for.
102 *
103 * Get the name of an object's type.
104 *
105 * Returns: Type name of @object. The string is owned by the type system and
106 * should not be freed.
107 */
108#define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object)))
109/**
110 * G_OBJECT_CLASS_TYPE:
111 * @class: a valid #GObjectClass
112 *
113 * Get the type id of a class structure.
114 *
115 * Returns: Type id of @class.
116 */
117#define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
118/**
119 * G_OBJECT_CLASS_NAME:
120 * @class: a valid #GObjectClass
121 *
122 * Return the name of a class structure's type.
123 *
124 * Returns: Type name of @class. The string is owned by the type system and
125 * should not be freed.
126 */
127#define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class)))
128/**
129 * G_VALUE_HOLDS_OBJECT:
130 * @value: a valid #GValue structure
131 *
132 * Checks whether the given #GValue can hold values derived from type %G_TYPE_OBJECT.
133 *
134 * Returns: %TRUE on success.
135 */
136#define G_VALUE_HOLDS_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT))
137
138/* --- type macros --- */
139/**
140 * G_TYPE_INITIALLY_UNOWNED:
141 *
142 * The type for #GInitiallyUnowned.
143 */
144#define G_TYPE_INITIALLY_UNOWNED (g_initially_unowned_get_type())
145/**
146 * G_INITIALLY_UNOWNED:
147 * @object: Object which is subject to casting.
148 *
149 * Casts a #GInitiallyUnowned or derived pointer into a (GInitiallyUnowned*)
150 * pointer.
151 *
152 * Depending on the current debugging level, this function may invoke
153 * certain runtime checks to identify invalid casts.
154 */
155#define G_INITIALLY_UNOWNED(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnowned))
156/**
157 * G_INITIALLY_UNOWNED_CLASS:
158 * @class: a valid #GInitiallyUnownedClass
159 *
160 * Casts a derived #GInitiallyUnownedClass structure into a
161 * #GInitiallyUnownedClass structure.
162 */
163#define G_INITIALLY_UNOWNED_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
164/**
165 * G_IS_INITIALLY_UNOWNED:
166 * @object: Instance to check for being a %G_TYPE_INITIALLY_UNOWNED.
167 *
168 * Checks whether a valid #GTypeInstance pointer is of type %G_TYPE_INITIALLY_UNOWNED.
169 */
170#define G_IS_INITIALLY_UNOWNED(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_INITIALLY_UNOWNED))
171/**
172 * G_IS_INITIALLY_UNOWNED_CLASS:
173 * @class: a #GInitiallyUnownedClass
174 *
175 * Checks whether @class "is a" valid #GInitiallyUnownedClass structure of type
176 * %G_TYPE_INITIALLY_UNOWNED or derived.
177 */
178#define G_IS_INITIALLY_UNOWNED_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_INITIALLY_UNOWNED))
179/**
180 * G_INITIALLY_UNOWNED_GET_CLASS:
181 * @object: a #GInitiallyUnowned instance.
182 *
183 * Get the class structure associated to a #GInitiallyUnowned instance.
184 *
185 * Returns: pointer to object class structure.
186 */
187#define G_INITIALLY_UNOWNED_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_INITIALLY_UNOWNED, GInitiallyUnownedClass))
188/* GInitiallyUnowned ia a GObject with initially floating reference count */
189
190
191/* --- typedefs & structures --- */
192typedef struct _GObject GObject;
197/**
198 * GObjectGetPropertyFunc:
199 * @object: a #GObject
200 * @property_id: the numeric id under which the property was registered with
201 * g_object_class_install_property().
202 * @value: a #GValue to return the property value in
203 * @pspec: the #GParamSpec describing the property
204 *
205 * The type of the @get_property function of #GObjectClass.
206 */
207typedef void (*GObjectGetPropertyFunc) (GObject *object,
208 guint property_id,
209 GValue *value,
211/**
212 * GObjectSetPropertyFunc:
213 * @object: a #GObject
214 * @property_id: the numeric id under which the property was registered with
215 * g_object_class_install_property().
216 * @value: the new value for the property
217 * @pspec: the #GParamSpec describing the property
218 *
219 * The type of the @set_property function of #GObjectClass.
220 */
221typedef void (*GObjectSetPropertyFunc) (GObject *object,
222 guint property_id,
223 const GValue *value,
225/**
226 * GObjectFinalizeFunc:
227 * @object: the #GObject being finalized
228 *
229 * The type of the @finalize function of #GObjectClass.
230 */
231typedef void (*GObjectFinalizeFunc) (GObject *object);
232/**
233 * GWeakNotify:
234 * @data: data that was provided when the weak reference was established
235 * @where_the_object_was: the object being disposed
236 *
237 * A #GWeakNotify function can be added to an object as a callback that gets
238 * triggered when the object is finalized.
239 *
240 * Since the object is already being disposed when the #GWeakNotify is called,
241 * there's not much you could do with the object, apart from e.g. using its
242 * address as hash-index or the like.
243 *
244 * In particular, this means it’s invalid to call g_object_ref(),
245 * g_weak_ref_init(), g_weak_ref_set(), g_object_add_toggle_ref(),
246 * g_object_weak_ref(), g_object_add_weak_pointer() or any function which calls
247 * them on the object from this callback.
248 */
249typedef void (*GWeakNotify) (gpointer data,
250 GObject *where_the_object_was);
251
253{
255
256 /*< private >*/
257 guint ref_count; /* (atomic) */
259};
260/**
261 * GObjectClass:
262 * @g_type_class: the parent class
263 * @constructor: the @constructor function is called by g_object_new () to
264 * complete the object initialization after all the construction properties are
265 * set. The first thing a @constructor implementation must do is chain up to the
266 * @constructor of the parent class. Overriding @constructor should be rarely
267 * needed, e.g. to handle construct properties, or to implement singletons.
268 * @set_property: the generic setter for all properties of this type. Should be
269 * overridden for every type with properties. If implementations of
270 * @set_property don't emit property change notification explicitly, this will
271 * be done implicitly by the type system. However, if the notify signal is
272 * emitted explicitly, the type system will not emit it a second time.
273 * @get_property: the generic getter for all properties of this type. Should be
274 * overridden for every type with properties.
275 * @dispose: the @dispose function is supposed to drop all references to other
276 * objects, but keep the instance otherwise intact, so that client method
277 * invocations still work. It may be run multiple times (due to reference
278 * loops). Before returning, @dispose should chain up to the @dispose method
279 * of the parent class.
280 * @finalize: instance finalization function, should finish the finalization of
281 * the instance begun in @dispose and chain up to the @finalize method of the
282 * parent class.
283 * @dispatch_properties_changed: emits property change notification for a bunch
284 * of properties. Overriding @dispatch_properties_changed should be rarely
285 * needed.
286 * @notify: the class closure for the notify signal
287 * @constructed: the @constructed function is called by g_object_new() as the
288 * final step of the object creation process. At the point of the call, all
289 * construction properties have been set on the object. The purpose of this
290 * call is to allow for object initialisation steps that can only be performed
291 * after construction properties have been set. @constructed implementors
292 * should chain up to the @constructed call of their parent class to allow it
293 * to complete its initialisation.
294 *
295 * The class structure for the GObject type.
296 *
297 * |[<!-- language="C" -->
298 * // Example of implementing a singleton using a constructor.
299 * static MySingleton *the_singleton = NULL;
300 *
301 * static GObject*
302 * my_singleton_constructor (GType type,
303 * guint n_construct_params,
304 * GObjectConstructParam *construct_params)
305 * {
306 * GObject *object;
307 *
308 * if (!the_singleton)
309 * {
310 * object = G_OBJECT_CLASS (parent_class)->constructor (type,
311 * n_construct_params,
312 * construct_params);
313 * the_singleton = MY_SINGLETON (object);
314 * }
315 * else
316 * object = g_object_ref (G_OBJECT (the_singleton));
317 *
318 * return object;
319 * }
320 * ]|
321 */
323{
325
326 /*< private >*/
328
329 /*< public >*/
330 /* seldom overridden */
331 GObject* (*constructor) (GType type,
334 /* overridable methods */
335 void (*set_property) (GObject *object,
336 guint property_id,
337 const GValue *value,
338 GParamSpec *pspec);
339 void (*get_property) (GObject *object,
340 guint property_id,
341 GValue *value,
342 GParamSpec *pspec);
343 void (*dispose) (GObject *object);
344 void (*finalize) (GObject *object);
345 /* seldom overridden */
349 /* signals */
350 void (*notify) (GObject *object,
351 GParamSpec *pspec);
352
353 /* called when done constructing */
354 void (*constructed) (GObject *object);
355
356 /*< private >*/
358
360
363
364 /* padding */
366};
367
368/**
369 * GObjectConstructParam:
370 * @pspec: the #GParamSpec of the construct parameter
371 * @value: the value to set the parameter to
372 *
373 * The GObjectConstructParam struct is an auxiliary structure used to hand
374 * #GParamSpec/#GValue pairs to the @constructor of a #GObjectClass.
375 */
381
382/**
383 * GInitiallyUnowned:
384 *
385 * A type for objects that have an initially floating reference.
386 *
387 * All the fields in the `GInitiallyUnowned` structure are private to the
388 * implementation and should never be accessed directly.
389 */
390/**
391 * GInitiallyUnownedClass:
392 *
393 * The class structure for the GInitiallyUnowned type.
394 */
395
396
397/* --- prototypes --- */
402 guint property_id,
403 GParamSpec *pspec);
406 const gchar *property_name);
409 guint *n_properties);
412 guint property_id,
413 const gchar *name);
416 guint n_pspecs,
417 GParamSpec **pspecs);
418
421 GParamSpec *pspec);
424 const gchar *property_name);
427 guint *n_properties_p);
428
433 const gchar *first_property_name,
434 ...);
437 guint n_properties,
438 const char *names[],
439 const GValue values[]);
440
442
445 guint n_parameters,
446 GParameter *parameters);
447
449
452 const gchar *first_property_name,
453 va_list var_args);
456 const gchar *first_property_name,
460 const gchar *first_property_name,
464 const gchar *signal_spec,
468 const gchar *signal_spec,
471void g_object_setv (GObject *object,
472 guint n_properties,
473 const gchar *names[],
474 const GValue values[]);
477 const gchar *first_property_name,
478 va_list var_args);
480void g_object_getv (GObject *object,
481 guint n_properties,
482 const gchar *names[],
483 GValue values[]);
486 const gchar *first_property_name,
487 va_list var_args);
490 const gchar *property_name,
491 const GValue *value);
494 const gchar *property_name,
495 GValue *value);
500 const gchar *property_name);
503 GParamSpec *pspec);
518 GWeakNotify notify,
519 gpointer data);
522 GWeakNotify notify,
523 gpointer data);
526 gpointer *weak_pointer_location);
529 gpointer *weak_pointer_location);
530
531#if defined(glib_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_56
532/* Make reference APIs type safe with macros */
533#define g_object_ref(Obj) ((glib_typeof (Obj)) (g_object_ref) (Obj))
534#define g_object_ref_sink(Obj) ((glib_typeof (Obj)) (g_object_ref_sink) (Obj))
535#endif
536
537/**
538 * GToggleNotify:
539 * @data: Callback data passed to g_object_add_toggle_ref()
540 * @object: The object on which g_object_add_toggle_ref() was called.
541 * @is_last_ref: %TRUE if the toggle reference is now the
542 * last reference to the object. %FALSE if the toggle
543 * reference was the last reference and there are now other
544 * references.
545 *
546 * A callback function used for notification when the state
547 * of a toggle reference changes.
548 *
549 * See also: g_object_add_toggle_ref()
550 */
551typedef void (*GToggleNotify) (gpointer data,
552 GObject *object,
553 gboolean is_last_ref);
554
557 GToggleNotify notify,
558 gpointer data);
561 GToggleNotify notify,
562 gpointer data);
563
566 GQuark quark);
569 GQuark quark,
570 gpointer data);
573 GQuark quark,
574 gpointer data,
575 GDestroyNotify destroy);
578 GQuark quark);
579
582 GQuark quark,
583 GDuplicateFunc dup_func,
584 gpointer user_data);
587 GQuark quark,
588 gpointer oldval,
589 gpointer newval,
590 GDestroyNotify destroy,
591 GDestroyNotify *old_destroy);
592
595 const gchar *key);
598 const gchar *key,
599 gpointer data);
602 const gchar *key,
603 gpointer data,
604 GDestroyNotify destroy);
607 const gchar *key);
608
611 const gchar *key,
612 GDuplicateFunc dup_func,
613 gpointer user_data);
616 const gchar *key,
617 gpointer oldval,
618 gpointer newval,
619 GDestroyNotify destroy,
620 GDestroyNotify *old_destroy);
621
622
625 GClosure *closure);
628 GObject *object);
631 GObject *object);
634 GObject *object);
637 gpointer v_object);
644 const gchar *detailed_signal,
645 GCallback c_handler,
646 gpointer gobject,
647 GConnectFlags connect_flags);
648
649/*< protected >*/
654
655
658 gpointer v_object);
661 gpointer v_object);
662
665 gpointer data);
666
667/* --- implementation macros --- */
668#define G_OBJECT_WARN_INVALID_PSPEC(object, pname, property_id, pspec) \
669G_STMT_START { \
670 GObject *_glib__object = (GObject*) (object); \
671 GParamSpec *_glib__pspec = (GParamSpec*) (pspec); \
672 guint _glib__property_id = (property_id); \
673 g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'", \
674 __FILE__, __LINE__, \
675 (pname), \
676 _glib__property_id, \
677 _glib__pspec->name, \
678 g_type_name (G_PARAM_SPEC_TYPE (_glib__pspec)), \
679 G_OBJECT_TYPE_NAME (_glib__object)); \
680} G_STMT_END
681/**
682 * G_OBJECT_WARN_INVALID_PROPERTY_ID:
683 * @object: the #GObject on which set_property() or get_property() was called
684 * @property_id: the numeric id of the property
685 * @pspec: the #GParamSpec of the property
686 *
687 * This macro should be used to emit a standard warning about unexpected
688 * properties in set_property() and get_property() implementations.
689 */
690#define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
691 G_OBJECT_WARN_INVALID_PSPEC ((object), "property", (property_id), (pspec))
692
694void g_clear_object (GObject **object_ptr);
695#define g_clear_object(object_ptr) g_clear_pointer ((object_ptr), g_object_unref)
696
697/**
698 * g_set_object: (skip)
699 * @object_ptr: (inout) (not optional) (nullable): a pointer to a #GObject reference
700 * @new_object: (nullable) (transfer none): a pointer to the new #GObject to
701 * assign to @object_ptr, or %NULL to clear the pointer
702 *
703 * Updates a #GObject pointer to refer to @new_object.
704 *
705 * It increments the reference count of @new_object (if non-%NULL), decrements
706 * the reference count of the current value of @object_ptr (if non-%NULL), and
707 * assigns @new_object to @object_ptr. The assignment is not atomic.
708 *
709 * @object_ptr must not be %NULL, but can point to a %NULL value.
710 *
711 * A macro is also included that allows this function to be used without
712 * pointer casts. The function itself is static inline, so its address may vary
713 * between compilation units.
714 *
715 * One convenient usage of this function is in implementing property setters:
716 * |[
717 * void
718 * foo_set_bar (Foo *foo,
719 * Bar *new_bar)
720 * {
721 * g_return_if_fail (IS_FOO (foo));
722 * g_return_if_fail (new_bar == NULL || IS_BAR (new_bar));
723 *
724 * if (g_set_object (&foo->bar, new_bar))
725 * g_object_notify (foo, "bar");
726 * }
727 * ]|
728 *
729 * Returns: %TRUE if the value of @object_ptr changed, %FALSE otherwise
730 *
731 * Since: 2.44
732 */
733static inline gboolean
734(g_set_object) (GObject **object_ptr,
735 GObject *new_object)
736{
737 GObject *old_object = *object_ptr;
738
739 /* rely on g_object_[un]ref() to check the pointers are actually GObjects;
740 * elide a (object_ptr != NULL) check because most of the time we will be
741 * operating on struct members with a constant offset, so a NULL check would
742 * not catch bugs
743 */
744
745 if (old_object == new_object)
746 return FALSE;
747
748 if (new_object != NULL)
749 g_object_ref (new_object);
750
751 *object_ptr = new_object;
752
753 if (old_object != NULL)
754 g_object_unref (old_object);
755
756 return TRUE;
757}
758
759/* We need GCC for __extension__, which we need to sort out strict aliasing of @object_ptr */
760#if defined(__GNUC__)
761
762#define g_set_object(object_ptr, new_object) \
763 (G_GNUC_EXTENSION ({ \
764 G_STATIC_ASSERT (sizeof *(object_ptr) == sizeof (new_object)); \
765 /* Only one access, please; work around type aliasing */ \
766 union { char *in; GObject **out; } _object_ptr; \
767 _object_ptr.in = (char *) (object_ptr); \
768 /* Check types match */ \
769 (void) (0 ? *(object_ptr) = (new_object), FALSE : FALSE); \
770 (g_set_object) (_object_ptr.out, (GObject *) new_object); \
771 })) \
772 GOBJECT_AVAILABLE_MACRO_IN_2_44
773
774#else /* if !defined(__GNUC__) */
775
776#define g_set_object(object_ptr, new_object) \
777 (/* Check types match. */ \
778 0 ? *(object_ptr) = (new_object), FALSE : \
779 (g_set_object) ((GObject **) (object_ptr), (GObject *) (new_object)) \
780 )
781
782#endif /* !defined(__GNUC__) */
783
784/**
785 * g_assert_finalize_object: (skip)
786 * @object: (transfer full) (type GObject.Object): an object
787 *
788 * Assert that @object is non-%NULL, then release one reference to it with
789 * g_object_unref() and assert that it has been finalized (i.e. that there
790 * are no more references).
791 *
792 * If assertions are disabled via `G_DISABLE_ASSERT`,
793 * this macro just calls g_object_unref() without any further checks.
794 *
795 * This macro should only be used in regression tests.
796 *
797 * Since: 2.62
798 */
799static inline void
801{
802 gpointer weak_pointer = object;
803
804 g_assert_true (G_IS_OBJECT (weak_pointer));
805 g_object_add_weak_pointer (object, &weak_pointer);
806 g_object_unref (weak_pointer);
807 g_assert_null (weak_pointer);
808}
809
810#ifdef G_DISABLE_ASSERT
811#define g_assert_finalize_object(object) g_object_unref (object)
812#else
813#define g_assert_finalize_object(object) (g_assert_finalize_object ((GObject *) object))
814#endif
815
816/**
817 * g_clear_weak_pointer: (skip)
818 * @weak_pointer_location: The memory address of a pointer
819 *
820 * Clears a weak reference to a #GObject.
821 *
822 * @weak_pointer_location must not be %NULL.
823 *
824 * If the weak reference is %NULL then this function does nothing.
825 * Otherwise, the weak reference to the object is removed for that location
826 * and the pointer is set to %NULL.
827 *
828 * A macro is also included that allows this function to be used without
829 * pointer casts. The function itself is static inline, so its address may vary
830 * between compilation units.
831 *
832 * Since: 2.56
833 */
834static inline void
835(g_clear_weak_pointer) (gpointer *weak_pointer_location)
836{
837 GObject *object = (GObject *) *weak_pointer_location;
838
839 if (object != NULL)
840 {
841 g_object_remove_weak_pointer (object, weak_pointer_location);
842 *weak_pointer_location = NULL;
843 }
844}
845
846#define g_clear_weak_pointer(weak_pointer_location) \
847 (/* Check types match. */ \
848 (g_clear_weak_pointer) ((gpointer *) (weak_pointer_location)) \
849 )
850
851/**
852 * g_set_weak_pointer: (skip)
853 * @weak_pointer_location: the memory address of a pointer
854 * @new_object: (nullable) (transfer none): a pointer to the new #GObject to
855 * assign to it, or %NULL to clear the pointer
856 *
857 * Updates a pointer to weakly refer to @new_object.
858 *
859 * It assigns @new_object to @weak_pointer_location and ensures
860 * that @weak_pointer_location will automatically be set to %NULL
861 * if @new_object gets destroyed. The assignment is not atomic.
862 * The weak reference is not thread-safe, see g_object_add_weak_pointer()
863 * for details.
864 *
865 * The @weak_pointer_location argument must not be %NULL.
866 *
867 * A macro is also included that allows this function to be used without
868 * pointer casts. The function itself is static inline, so its address may vary
869 * between compilation units.
870 *
871 * One convenient usage of this function is in implementing property setters:
872 * |[
873 * void
874 * foo_set_bar (Foo *foo,
875 * Bar *new_bar)
876 * {
877 * g_return_if_fail (IS_FOO (foo));
878 * g_return_if_fail (new_bar == NULL || IS_BAR (new_bar));
879 *
880 * if (g_set_weak_pointer (&foo->bar, new_bar))
881 * g_object_notify (foo, "bar");
882 * }
883 * ]|
884 *
885 * Returns: %TRUE if the value of @weak_pointer_location changed, %FALSE otherwise
886 *
887 * Since: 2.56
888 */
889static inline gboolean
890(g_set_weak_pointer) (gpointer *weak_pointer_location,
891 GObject *new_object)
892{
893 GObject *old_object = (GObject *) *weak_pointer_location;
894
895 /* elide a (weak_pointer_location != NULL) check because most of the time we
896 * will be operating on struct members with a constant offset, so a NULL
897 * check would not catch bugs
898 */
899
900 if (old_object == new_object)
901 return FALSE;
902
903 if (old_object != NULL)
904 g_object_remove_weak_pointer (old_object, weak_pointer_location);
905
906 *weak_pointer_location = new_object;
907
908 if (new_object != NULL)
909 g_object_add_weak_pointer (new_object, weak_pointer_location);
910
911 return TRUE;
912}
913
914#define g_set_weak_pointer(weak_pointer_location, new_object) \
915 (/* Check types match. */ \
916 0 ? *(weak_pointer_location) = (new_object), FALSE : \
917 (g_set_weak_pointer) ((gpointer *) (weak_pointer_location), (GObject *) (new_object)) \
918 )
919
920typedef struct {
921 /*<private>*/
922 union { gpointer p; } priv;
923} GWeakRef;
924
926void g_weak_ref_init (GWeakRef *weak_ref,
927 gpointer object);
929void g_weak_ref_clear (GWeakRef *weak_ref);
933void g_weak_ref_set (GWeakRef *weak_ref,
934 gpointer object);
935
937
938#endif /* __G_OBJECT_H__ */
void(* GCallback)(void)
Definition gclosure.h:92
typedefG_BEGIN_DECLS struct _GData GData
Definition gdataset.h:38
gpointer(* GDuplicateFunc)(gpointer data, gpointer user_data)
Definition gdataset.h:63
unsigned long gsize
Definition glibconfig.h:83
#define NULL
Definition gmacros.h:924
#define G_END_DECLS
Definition gmacros.h:910
#define G_GNUC_NULL_TERMINATED
Definition gmacros.h:326
#define G_BEGIN_DECLS
Definition gmacros.h:909
#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS
Definition gmacros.h:771
#define G_GNUC_CONST
Definition gmacros.h:637
#define TRUE
Definition gmacros.h:933
#define FALSE
Definition gmacros.h:929
#define G_GNUC_END_IGNORE_DEPRECATIONS
Definition gmacros.h:772
#define GOBJECT_AVAILABLE_IN_2_34
#define GOBJECT_AVAILABLE_IN_2_54
#define GOBJECT_AVAILABLE_IN_2_70
#define GOBJECT_AVAILABLE_IN_ALL
#define GOBJECT_DEPRECATED_FOR(f)
#define GOBJECT_DEPRECATED
#define GOBJECT_DEPRECATED_IN_2_54_FOR(f)
GOBJECT_AVAILABLE_IN_2_54 void g_object_getv(GObject *object, guint n_properties, const gchar *names[], GValue values[])
GOBJECT_AVAILABLE_IN_ALL gpointer g_object_connect(gpointer object, const gchar *signal_spec,...) G_GNUC_NULL_TERMINATED
GOBJECT_AVAILABLE_IN_ALL void g_object_weak_unref(GObject *object, GWeakNotify notify, gpointer data)
GOBJECT_AVAILABLE_IN_ALL void g_value_set_object(GValue *value, gpointer v_object)
G_GNUC_BEGIN_IGNORE_DEPRECATIONS gpointer g_object_newv(GType object_type, guint n_parameters, GParameter *parameters)
GOBJECT_AVAILABLE_IN_ALL void g_object_thaw_notify(GObject *object)
G_GNUC_END_IGNORE_DEPRECATIONS GOBJECT_AVAILABLE_IN_ALL GObject * g_object_new_valist(GType object_type, const gchar *first_property_name, va_list var_args)
GOBJECT_AVAILABLE_IN_2_54 void g_object_setv(GObject *object, guint n_properties, const gchar *names[], const GValue values[])
GOBJECT_AVAILABLE_IN_ALL void g_object_notify(GObject *object, const gchar *property_name)
GOBJECT_AVAILABLE_IN_ALL GParamSpec * g_object_interface_find_property(gpointer g_iface, const gchar *property_name)
GOBJECT_AVAILABLE_IN_ALL gpointer g_object_steal_data(GObject *object, const gchar *key)
GOBJECT_AVAILABLE_IN_2_34 gboolean g_object_replace_qdata(GObject *object, GQuark quark, gpointer oldval, gpointer newval, GDestroyNotify destroy, GDestroyNotify *old_destroy)
void g_value_set_object_take_ownership(GValue *value, gpointer v_object)
GOBJECT_AVAILABLE_IN_2_34 gpointer g_object_dup_data(GObject *object, const gchar *key, GDuplicateFunc dup_func, gpointer user_data)
GOBJECT_AVAILABLE_IN_2_70 gpointer g_object_take_ref(gpointer object)
GOBJECT_AVAILABLE_IN_ALL gpointer g_value_dup_object(const GValue *value)
#define g_set_object(object_ptr, new_object)
Definition gobject.h:776
GOBJECT_AVAILABLE_IN_ALL void g_object_watch_closure(GObject *object, GClosure *closure)
#define g_assert_finalize_object(object)
Definition gobject.h:813
GOBJECT_AVAILABLE_IN_ALL gpointer g_object_get_data(GObject *object, const gchar *key)
GOBJECT_AVAILABLE_IN_ALL gulong g_signal_connect_object(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer gobject, GConnectFlags connect_flags)
#define g_clear_object(object_ptr)
Definition gobject.h:695
GOBJECT_AVAILABLE_IN_ALL void g_object_class_install_properties(GObjectClass *oclass, guint n_pspecs, GParamSpec **pspecs)
GOBJECT_AVAILABLE_IN_ALL void g_object_notify_by_pspec(GObject *object, GParamSpec *pspec)
GOBJECT_AVAILABLE_IN_ALL gpointer g_object_ref(gpointer object)
GOBJECT_AVAILABLE_IN_ALL GClosure * g_cclosure_new_object(GCallback callback_func, GObject *object)
GOBJECT_AVAILABLE_IN_ALL gpointer g_weak_ref_get(GWeakRef *weak_ref)
GOBJECT_AVAILABLE_IN_ALL GParamSpec ** g_object_class_list_properties(GObjectClass *oclass, guint *n_properties)
GOBJECT_AVAILABLE_IN_ALL void g_object_freeze_notify(GObject *object)
GOBJECT_AVAILABLE_IN_ALL void g_object_class_override_property(GObjectClass *oclass, guint property_id, const gchar *name)
GOBJECT_AVAILABLE_IN_ALL void g_object_set_qdata(GObject *object, GQuark quark, gpointer data)
GOBJECT_AVAILABLE_IN_ALL void g_object_get(gpointer object, const gchar *first_property_name,...) G_GNUC_NULL_TERMINATED
GOBJECT_AVAILABLE_IN_ALL void g_object_get_property(GObject *object, const gchar *property_name, GValue *value)
GOBJECT_AVAILABLE_IN_ALL GClosure * g_closure_new_object(guint sizeof_closure, GObject *object)
void(* GWeakNotify)(gpointer data, GObject *where_the_object_was)
Definition gobject.h:249
GOBJECT_AVAILABLE_IN_ALL void g_object_force_floating(GObject *object)
GOBJECT_AVAILABLE_IN_ALL void g_object_set_property(GObject *object, const gchar *property_name, const GValue *value)
GOBJECT_AVAILABLE_IN_ALL void g_value_take_object(GValue *value, gpointer v_object)
GOBJECT_AVAILABLE_IN_ALL void g_object_set_data_full(GObject *object, const gchar *key, gpointer data, GDestroyNotify destroy)
GOBJECT_AVAILABLE_IN_2_34 gpointer g_object_dup_qdata(GObject *object, GQuark quark, GDuplicateFunc dup_func, gpointer user_data)
void(* GObjectFinalizeFunc)(GObject *object)
Definition gobject.h:231
GOBJECT_AVAILABLE_IN_ALL void g_weak_ref_clear(GWeakRef *weak_ref)
GOBJECT_AVAILABLE_IN_ALL gpointer g_object_get_qdata(GObject *object, GQuark quark)
GOBJECT_AVAILABLE_IN_ALL GType g_object_get_type(void) G_GNUC_CONST
GOBJECT_AVAILABLE_IN_ALL void g_object_add_toggle_ref(GObject *object, GToggleNotify notify, gpointer data)
GOBJECT_AVAILABLE_IN_ALL void g_object_class_install_property(GObjectClass *oclass, guint property_id, GParamSpec *pspec)
GOBJECT_AVAILABLE_IN_ALL void g_object_disconnect(gpointer object, const gchar *signal_spec,...) G_GNUC_NULL_TERMINATED
GOBJECT_DEPRECATED gsize g_object_compat_control(gsize what, gpointer data)
GOBJECT_AVAILABLE_IN_ALL void g_object_remove_weak_pointer(GObject *object, gpointer *weak_pointer_location)
GOBJECT_AVAILABLE_IN_ALL gboolean g_object_is_floating(gpointer object)
GOBJECT_AVAILABLE_IN_ALL void g_object_remove_toggle_ref(GObject *object, GToggleNotify notify, gpointer data)
#define G_IS_OBJECT(object)
Definition gobject.h:69
GOBJECT_AVAILABLE_IN_ALL void g_object_set_valist(GObject *object, const gchar *first_property_name, va_list var_args)
GOBJECT_AVAILABLE_IN_2_54 GObject * g_object_new_with_properties(GType object_type, guint n_properties, const char *names[], const GValue values[])
GOBJECT_AVAILABLE_IN_ALL GClosure * g_cclosure_new_object_swap(GCallback callback_func, GObject *object)
GOBJECT_AVAILABLE_IN_ALL GType g_initially_unowned_get_type(void)
GOBJECT_AVAILABLE_IN_ALL GParamSpec ** g_object_interface_list_properties(gpointer g_iface, guint *n_properties_p)
GOBJECT_AVAILABLE_IN_ALL gpointer g_value_get_object(const GValue *value)
#define g_set_weak_pointer(weak_pointer_location, new_object)
Definition gobject.h:914
GOBJECT_AVAILABLE_IN_2_34 gboolean g_object_replace_data(GObject *object, const gchar *key, gpointer oldval, gpointer newval, GDestroyNotify destroy, GDestroyNotify *old_destroy)
GOBJECT_AVAILABLE_IN_ALL GParamSpec * g_object_class_find_property(GObjectClass *oclass, const gchar *property_name)
GOBJECT_AVAILABLE_IN_ALL void g_object_get_valist(GObject *object, const gchar *first_property_name, va_list var_args)
GOBJECT_AVAILABLE_IN_ALL void g_object_set(gpointer object, const gchar *first_property_name,...) G_GNUC_NULL_TERMINATED
GOBJECT_AVAILABLE_IN_ALL gpointer g_object_steal_qdata(GObject *object, GQuark quark)
GOBJECT_AVAILABLE_IN_ALL void g_object_interface_install_property(gpointer g_iface, GParamSpec *pspec)
GOBJECT_AVAILABLE_IN_ALL void g_object_set_data(GObject *object, const gchar *key, gpointer data)
GOBJECT_AVAILABLE_IN_ALL void g_object_weak_ref(GObject *object, GWeakNotify notify, gpointer data)
#define g_clear_weak_pointer(weak_pointer_location)
Definition gobject.h:846
void(* GObjectGetPropertyFunc)(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
Definition gobject.h:207
GOBJECT_AVAILABLE_IN_ALL void g_object_add_weak_pointer(GObject *object, gpointer *weak_pointer_location)
void(* GObjectSetPropertyFunc)(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
Definition gobject.h:221
GOBJECT_AVAILABLE_IN_ALL void g_object_set_qdata_full(GObject *object, GQuark quark, gpointer data, GDestroyNotify destroy)
GOBJECT_AVAILABLE_IN_ALL void g_weak_ref_init(GWeakRef *weak_ref, gpointer object)
GOBJECT_AVAILABLE_IN_ALL void g_weak_ref_set(GWeakRef *weak_ref, gpointer object)
void(* GToggleNotify)(gpointer data, GObject *object, gboolean is_last_ref)
Definition gobject.h:551
GOBJECT_AVAILABLE_IN_ALL gpointer g_object_ref_sink(gpointer object)
GOBJECT_AVAILABLE_IN_ALL gpointer g_object_new(GType object_type, const gchar *first_property_name,...)
GOBJECT_AVAILABLE_IN_ALL void g_object_unref(gpointer object)
GOBJECT_AVAILABLE_IN_ALL void g_object_run_dispose(GObject *object)
G_BEGIN_DECLS typedef guint32 GQuark
Definition gquark.h:38
GConnectFlags
Definition gsignal.h:171
typedefG_BEGIN_DECLS struct _GSList GSList
Definition gslist.h:39
#define g_assert_true(expr)
Definition gtestutils.h:227
#define g_assert_null(expr)
Definition gtestutils.h:250
gsize GType
Definition gtype.h:427
gint gboolean
Definition gtypes.h:56
unsigned long gulong
Definition gtypes.h:60
G_BEGIN_DECLS typedef char gchar
Definition gtypes.h:52
void * gpointer
Definition gtypes.h:109
void(* GDestroyNotify)(gpointer data)
Definition gtypes.h:140
unsigned int guint
Definition gtypes.h:61
const char * name
Definition lsqlite3.c:2154
int value
Definition lsqlite3.c:2155
gpointer p
Definition gobject.h:922
gsize flags
Definition gobject.h:357
gsize n_pspecs
Definition gobject.h:362
void(* finalize)(GObject *object)
Definition gobject.h:344
gpointer pdummy[3]
Definition gobject.h:365
void(* constructed)(GObject *object)
Definition gobject.h:354
GTypeClass g_type_class
Definition gobject.h:324
void(* dispatch_properties_changed)(GObject *object, guint n_pspecs, GParamSpec **pspecs)
Definition gobject.h:346
gsize n_construct_properties
Definition gobject.h:359
GSList * construct_properties
Definition gobject.h:327
void(* set_property)(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
Definition gobject.h:335
void(* notify)(GObject *object, GParamSpec *pspec)
Definition gobject.h:350
void(* get_property)(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
Definition gobject.h:339
void(* dispose)(GObject *object)
Definition gobject.h:343
gpointer pspecs
Definition gobject.h:361
GParamSpec * pspec
Definition gobject.h:378
GData * qdata
Definition gobject.h:258
GTypeInstance g_type_instance
Definition gobject.h:254
guint ref_count
Definition gobject.h:257