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:
Xavier Claessens 2020-10-20 11:57:05 -04:00
parent d95885d91e
commit 4273c43902
5 changed files with 6 additions and 4 deletions

View File

@ -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

View File

@ -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
/*

View File

@ -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

View File

@ -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))

View File

@ -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))