mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-30 04:44:16 +02:00
glib: annotate static inline functions with G_AVAILABLE-type macros
The public functions exposed as static inlines currently don't have annotations to describe when they were introduced. This means that compiling this file: #include <glib.h> void foo (void) { g_rec_mutex_locker_new (NULL); } with: gcc -c test.c \ -I/tmp/glib/include/glib-2.0 \ -I/tmp/glib/lib/x86_64-linux-gnu/glib-2.0/include \ -Werror \ -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_28 \ -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28 will not produce any error message, despite using `g_rec_mutex_locker_new`, a function that was introduced after 2.28. This patch adds some annotations to all the publicly exposed static inline functions I could find. I could not use the existing G_AVAILABLE* macros, because they may expand to `extern`. This would then clash with the `static` keyword and produce: ../glib/gthread.h:397:1: error: multiple storage classes in declaration specifiers 397 | static inline GRecMutexLocker * | ^~~~~~ So I opted for adding a new set of macros, GLIB_AVAILABLE_STATIC_INLINE_IN_2_XY. With this patch applied, the example from above produces the expected warning: test.c: In function ‘foo’: test.c:5:3: error: ‘g_rec_mutex_locker_new’ is deprecated: Not available before 2.60 [-Werror=deprecated-declarations] 5 | g_rec_mutex_locker_new (NULL); | ^~~~~~~~~~~~~~~~~~~~~~ In file included from /tmp/glib/include/glib-2.0/glib/gasyncqueue.h:32, from /tmp/glib/include/glib-2.0/glib.h:32, from test.c:1: /tmp/glib/include/glib-2.0/glib/gthread.h:398:1: note: declared here 398 | g_rec_mutex_locker_new (GRecMutex *rec_mutex) | ^~~~~~~~~~~~~~~~~~~~~~
This commit is contained in:
committed by
Philip Withnall
parent
06dc61ad6c
commit
5050298749
@@ -207,6 +207,11 @@ GLIB_AVAILABLE_MACRO_IN_2_60
|
||||
GLIB_AVAILABLE_MACRO_IN_2_62
|
||||
GLIB_AVAILABLE_MACRO_IN_2_64
|
||||
GLIB_AVAILABLE_MACRO_IN_2_66
|
||||
GLIB_AVAILABLE_STATIC_INLINE_IN_2_44
|
||||
GLIB_AVAILABLE_STATIC_INLINE_IN_2_60
|
||||
GLIB_AVAILABLE_STATIC_INLINE_IN_2_62
|
||||
GLIB_AVAILABLE_STATIC_INLINE_IN_2_64
|
||||
GLIB_AVAILABLE_STATIC_INLINE_IN_2_66
|
||||
GLIB_AVAILABLE_TYPE_IN_2_26
|
||||
GLIB_AVAILABLE_TYPE_IN_2_28
|
||||
GLIB_AVAILABLE_TYPE_IN_2_30
|
||||
@@ -706,6 +711,7 @@ GLIB_DEPRECATED_FOR
|
||||
GLIB_UNAVAILABLE
|
||||
GLIB_UNAVAILABLE_ENUMERATOR
|
||||
GLIB_UNAVAILABLE_MACRO
|
||||
GLIB_UNAVAILABLE_STATIC_INLINE
|
||||
GLIB_UNAVAILABLE_TYPE
|
||||
G_ANALYZER_ANALYZING
|
||||
G_ANALYZER_NORETURN
|
||||
|
@@ -26,6 +26,8 @@ foreach version : stable_2_series_versions
|
||||
'GLIB_DEPRECATED_IN_2_' + version + '_FOR()',
|
||||
'GLIB_DEPRECATED_IN_2_' + version,
|
||||
|
||||
'GLIB_AVAILABLE_STATIC_INLINE_IN_2_' + version,
|
||||
|
||||
'GLIB_AVAILABLE_ENUMERATOR_IN_2_' + version,
|
||||
'GLIB_DEPRECATED_ENUMERATOR_IN_2_' + version + '_FOR()',
|
||||
'GLIB_DEPRECATED_ENUMERATOR_IN_2_' + version,
|
||||
@@ -57,4 +59,4 @@ endif
|
||||
|
||||
subdir('gio')
|
||||
subdir('glib')
|
||||
subdir('gobject')
|
||||
subdir('gobject')
|
||||
|
Reference in New Issue
Block a user