mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
gstdio: Silence "Not available before" warnings for inline functions
Whenever a static inline calls a GLib function that was added since
we started tracking versions, we need to silence the "Not available
before" warnings, otherwise compiling code that includes this header
with GLIB_VERSION_MAX_ALLOWED set to an old version will emit warnings,
even if the static inline is never actually called.
If the static inline is API, we also need to ensure it is annotated with
GLIB_AVAILABLE_STATIC_INLINE_IN_2_76 or similar, so that callers get
the appropriate "Not available before" warnings to alert them to their
unintended use of newer API.
g_clear_fd() calls a function that was introduced in 2.36. It already
issues its own warning if called with GLIB_VERSION_MAX_ALLOWED less
than 2.76.
Similarly, g_autofd uses internal function _g_clear_fd_ignore_error
which calls g_clear_fd(), but it issues its own warning if used with
GLIB_VERSION_MAX_ALLOWED less than 2.76.
Fixes: b3934133
"gstdio: Add g_clear_fd() and g_autofd"
Resolves: #2796
Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
d0ff4055af
commit
c59d553890
@ -190,7 +190,10 @@ g_clear_fd (int *fd_ptr,
|
||||
if (fd < 0)
|
||||
return TRUE;
|
||||
|
||||
/* Suppress "Not available before" warning */
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
return g_close (fd, error);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
|
||||
/* g_autofd should be defined on the same compilers where g_autofree is
|
||||
@ -200,11 +203,14 @@ g_clear_fd (int *fd_ptr,
|
||||
static inline void
|
||||
_g_clear_fd_ignore_error (int *fd_ptr)
|
||||
{
|
||||
/* Suppress "Not available before" warning */
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
if (!g_clear_fd (fd_ptr, NULL))
|
||||
{
|
||||
/* Do nothing: we ignore all errors, except for EBADF which
|
||||
* is a programming error, checked for by g_close(). */
|
||||
}
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
|
||||
#define g_autofd _GLIB_CLEANUP(_g_clear_fd_ignore_error) GLIB_AVAILABLE_MACRO_IN_2_76
|
||||
|
Loading…
Reference in New Issue
Block a user