[glib: 3/4] glib_typeof: It is an API break that should be opt-in




commit 4273c43902a7e6b22cea0041436ee5715c93be76
Author: Xavier Claessens <xavier claessens collabora com>
Date:   Tue Oct 20 11:57:05 2020 -0400

    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.

 docs/reference/glib/glib-sections.txt | 1 +
 glib/gmacros.h                        | 1 +
 glib/gmem.h                           | 4 ++--
 glib/grcbox.h                         | 2 +-
 gobject/gobject.h                     | 2 +-
 5 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 35ba9af4d..d0121801a 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -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
diff --git a/glib/gmacros.h b/glib/gmacros.h
index ced69a75f..ca1ecbd0a 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -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
 
 /*
diff --git a/glib/gmem.h b/glib/gmem.h
index 924299b20..e2720c765 100644
--- a/glib/gmem.h
+++ b/glib/gmem.h
@@ -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
diff --git a/glib/grcbox.h b/glib/grcbox.h
index f78f5cb3b..0eb80da12 100644
--- a/glib/grcbox.h
+++ b/glib/grcbox.h
@@ -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))
diff --git a/gobject/gobject.h b/gobject/gobject.h
index aec8975e4..2db5f2fff 100644
--- a/gobject/gobject.h
+++ b/gobject/gobject.h
@@ -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))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]