mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
glib_typeof: It is an API break that should be opt-in
That changes the return type of functions like g_object_ref() that can break C++ applications like Webkit. Note that it is not an ABI break. It must thus be opt-in the same way we did when adding this to g_object_ref() for GNU C compilers in the first place. Unfortunately it cannot be done directly in gmacros.h because GLIB_VERSION_2_68 is not defined there, and gversionmacros.h cannot be included there because there is some strict ordering in which those headers must be included. This means that applications that does not define GLIB_VERSION_MIN_REQUIRED will still get an API break, so we encourage them to declare their minimum requirement to avoir such issues in the future too.
This commit is contained in:
parent
d95885d91e
commit
4273c43902
@ -735,6 +735,7 @@ G_ANALYZER_ANALYZING
|
||||
G_ANALYZER_NORETURN
|
||||
g_autoptr_cleanup_generic_gfree
|
||||
glib_typeof
|
||||
glib_typeof_2_68
|
||||
g_macro__has_attribute
|
||||
g_macro__has_builtin
|
||||
g_macro__has_feature
|
||||
|
@ -240,6 +240,7 @@
|
||||
/* C++11 decltype() is close enough for our usage */
|
||||
#include <type_traits>
|
||||
#define glib_typeof(t) typename std::remove_reference<decltype (t)>::type
|
||||
#define glib_typeof_2_68
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -110,7 +110,7 @@ gpointer g_try_realloc_n (gpointer mem,
|
||||
gsize n_blocks,
|
||||
gsize n_block_bytes) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
#if defined(glib_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_58
|
||||
#if defined(glib_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_58 && (!defined(glib_typeof_2_68) || GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68)
|
||||
#define g_clear_pointer(pp, destroy) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
@ -213,7 +213,7 @@ g_steal_pointer (gpointer pp)
|
||||
}
|
||||
|
||||
/* type safety */
|
||||
#if defined(glib_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_58
|
||||
#if defined(glib_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_58 && (!defined(glib_typeof_2_68) || GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68)
|
||||
#define g_steal_pointer(pp) ((glib_typeof (*pp)) (g_steal_pointer) (pp))
|
||||
#else /* __GNUC__ */
|
||||
/* This version does not depend on gcc extensions, but gcc does not warn
|
||||
|
@ -71,7 +71,7 @@ gsize g_atomic_rc_box_get_size (gpointer mem_block);
|
||||
#define g_atomic_rc_box_new0(type) \
|
||||
((type *) g_atomic_rc_box_alloc0 (sizeof (type)))
|
||||
|
||||
#ifdef glib_typeof
|
||||
#if defined(glib_typeof) && (!defined(glib_typeof_2_68) || GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68)
|
||||
/* Type check to avoid assigning references to different types */
|
||||
#define g_rc_box_acquire(mem_block) \
|
||||
((glib_typeof (mem_block)) (g_rc_box_acquire) (mem_block))
|
||||
|
@ -513,7 +513,7 @@ GLIB_AVAILABLE_IN_ALL
|
||||
void g_object_remove_weak_pointer (GObject *object,
|
||||
gpointer *weak_pointer_location);
|
||||
|
||||
#if defined(glib_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_56
|
||||
#if defined(glib_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_56 && (!defined(glib_typeof_2_68) || GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68)
|
||||
/* Make reference APIs type safe with macros */
|
||||
#define g_object_ref(Obj) ((glib_typeof (Obj)) (g_object_ref) (Obj))
|
||||
#define g_object_ref_sink(Obj) ((glib_typeof (Obj)) (g_object_ref_sink) (Obj))
|
||||
|
Loading…
Reference in New Issue
Block a user