diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2020-04-24 11:46:39 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2020-05-01 15:11:37 -0400 |
commit | cc58ce6a74c1ec4bac862d2aa879153a6b6d30df (patch) | |
tree | 041c892d217c6162bbce0d42e60a4d12be634ac1 | |
parent | fecaa5a5ea6ca82a226c072dd1a8e986c5edcf7a (diff) | |
download | glib-cc58ce6a74c1ec4bac862d2aa879153a6b6d30df.tar.gz |
gthread: ignore deprecated declarations in static inline functions
With a trivial file that just includes glib.h:
#include <glib.h>
Compiled with:
gcc -c test.c \
-I /tmp/glib/include/glib-2.0/ \
-I /tmp/glib/lib/x86_64-linux-gnu/glib-2.0/include \
-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_28 \
-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28 \
-fmax-errors=1 \
-Werror
We get:
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: In function ‘g_rec_mutex_locker_new’:
/tmp/glib/include/glib-2.0/glib/gthread.h:396:3: error: ‘g_rec_mutex_lock’ is deprecated: Not available before 2.32 [-Werror=deprecated-declarations]
396 | g_rec_mutex_lock (rec_mutex);
| ^~~~~~~~~~~~~~~~
/tmp/glib/include/glib-2.0/glib/gthread.h:196:17: note: declared here
196 | void g_rec_mutex_lock (GRecMutex *rec_mutex);
| ^~~~~~~~~~~~~~~~
compilation terminated due to -fmax-errors=1.
The problem is that the code in the static inline functions uses
g_rec_mutex_lock, introduced after 2.28. This code is compiled
regardless of if it's actually used or not.
Suppress the warning by using G_GNUC_BEGIN_IGNORE_DEPRECATIONS /
G_GNUC_END_IGNORE_DEPRECATIONS. There are precedents for doing that,
for example g_main_context_pusher_new in gmain.h.
Tested by building with all variations of GLIB_VERSION_MIN_REQUIRED /
GLIB_VERSION_MAX_ALLOWED:
for i in $(seq 26 2 64); do
gcc -c test.c \
-I/tmp/glib/include/glib-2.0 \
-I/tmp/glib/lib/x86_64-linux-gnu/glib-2.0/include \
-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_$i \
-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_$i \
-fmax-errors=1 \
-Werror
done
Fixes: #2094
-rw-r--r-- | glib/gthread.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/glib/gthread.h b/glib/gthread.h index a8c7ac777..980522bba 100644 --- a/glib/gthread.h +++ b/glib/gthread.h @@ -390,12 +390,14 @@ typedef void GRecMutexLocker; * Returns: a #GRecMutexLocker * Since: 2.60 */ +G_GNUC_BEGIN_IGNORE_DEPRECATIONS static inline GRecMutexLocker * g_rec_mutex_locker_new (GRecMutex *rec_mutex) { g_rec_mutex_lock (rec_mutex); return (GRecMutexLocker *) rec_mutex; } +G_GNUC_END_IGNORE_DEPRECATIONS /** * g_rec_mutex_locker_free: @@ -407,11 +409,13 @@ g_rec_mutex_locker_new (GRecMutex *rec_mutex) * * Since: 2.60 */ +G_GNUC_BEGIN_IGNORE_DEPRECATIONS static inline void g_rec_mutex_locker_free (GRecMutexLocker *locker) { g_rec_mutex_unlock ((GRecMutex *) locker); } +G_GNUC_END_IGNORE_DEPRECATIONS /** * GRWLockWriterLocker: @@ -494,12 +498,14 @@ typedef void GRWLockWriterLocker; * Returns: a #GRWLockWriterLocker * Since: 2.62 */ +G_GNUC_BEGIN_IGNORE_DEPRECATIONS static inline GRWLockWriterLocker * g_rw_lock_writer_locker_new (GRWLock *rw_lock) { g_rw_lock_writer_lock (rw_lock); return (GRWLockWriterLocker *) rw_lock; } +G_GNUC_END_IGNORE_DEPRECATIONS /** * g_rw_lock_writer_locker_free: @@ -512,11 +518,13 @@ g_rw_lock_writer_locker_new (GRWLock *rw_lock) * * Since: 2.62 */ +G_GNUC_BEGIN_IGNORE_DEPRECATIONS static inline void g_rw_lock_writer_locker_free (GRWLockWriterLocker *locker) { g_rw_lock_writer_unlock ((GRWLock *) locker); } +G_GNUC_END_IGNORE_DEPRECATIONS /** * GRWLockReaderLocker: @@ -543,12 +551,14 @@ typedef void GRWLockReaderLocker; * Returns: a #GRWLockReaderLocker * Since: 2.62 */ +G_GNUC_BEGIN_IGNORE_DEPRECATIONS static inline GRWLockReaderLocker * g_rw_lock_reader_locker_new (GRWLock *rw_lock) { g_rw_lock_reader_lock (rw_lock); return (GRWLockReaderLocker *) rw_lock; } +G_GNUC_END_IGNORE_DEPRECATIONS /** * g_rw_lock_reader_locker_free: @@ -561,11 +571,13 @@ g_rw_lock_reader_locker_new (GRWLock *rw_lock) * * Since: 2.62 */ +G_GNUC_BEGIN_IGNORE_DEPRECATIONS static inline void g_rw_lock_reader_locker_free (GRWLockReaderLocker *locker) { g_rw_lock_reader_unlock ((GRWLock *) locker); } +G_GNUC_END_IGNORE_DEPRECATIONS G_END_DECLS |