mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-31 22:23:39 +02:00
gobject: add type propagation to gobject ref API
Currently, g_object_ref() and g_object_ref_sink() return a gpointer which can mask issues when assigning to fields or returning from a function. To help catch these type of programming errors, we can propagate the type of the parameter through the function call on GCC using the typeof() C language extension. This will cause offending code to have a warning, but will continue to be source and binary compatible. This is only enabled when GLIB_VERSION_MAX_ALLOWED is 2.56 or greater. https://bugzilla.gnome.org/show_bug.cgi?id=790697
This commit is contained in:
committed by
Philip Withnall
parent
018b997dd2
commit
3fae39a5d7
@@ -508,6 +508,12 @@ GLIB_AVAILABLE_IN_ALL
|
||||
void g_object_remove_weak_pointer (GObject *object,
|
||||
gpointer *weak_pointer_location);
|
||||
|
||||
#if defined(__GNUC__) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_56
|
||||
/* Make reference APIs type safe with macros */
|
||||
#define g_object_ref(Obj) ((typeof(Obj)) (g_object_ref) (Obj))
|
||||
#define g_object_ref_sink(Obj) ((typeof(Obj)) (g_object_ref_sink) (Obj))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* GToggleNotify:
|
||||
* @data: Callback data passed to g_object_add_toggle_ref()
|
||||
|
Reference in New Issue
Block a user