From ca05902a5883020add334e542a63d7f9381a3117 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 10 Feb 2012 08:49:17 -0500 Subject: [PATCH] Add G_GNUC_BEGIN/END_IGNORE_DEPRECATIONS Add new macros to disable -Wdeprecated-declarations around a piece of code, using the C99 (and GNU89) _Pragma() operator. Replace the existing use of #pragma for this in gio, and suppress the warnings in gvaluearray.c as well. https://bugzilla.gnome.org/show_bug.cgi?id=669671 --- docs/reference/glib/glib-sections.txt | 2 ++ gio/gdesktopappinfo.c | 7 ++++--- gio/giomodule.c | 5 ++--- glib/docs.c | 33 +++++++++++++++++++++++++++++++++ glib/gmacros.h | 11 +++++++++++ gobject/gvaluearray.c | 4 ++++ 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 0d87c4b..1f829f0 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -336,6 +336,8 @@ G_GNUC_ALLOC_SIZE G_GNUC_ALLOC_SIZE2 G_GNUC_DEPRECATED G_GNUC_DEPRECATED_FOR +G_GNUC_BEGIN_IGNORE_DEPRECATIONS +G_GNUC_END_IGNORE_DEPRECATIONS G_GNUC_NORETURN G_GNUC_UNUSED G_GNUC_PRINTF diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c index 5980c3f..449c114 100644 --- a/gio/gdesktopappinfo.c +++ b/gio/gdesktopappinfo.c @@ -3352,6 +3352,8 @@ get_all_desktop_entries_for_mime_type (const char *base_mime_type, /* GDesktopAppInfoLookup interface: */ +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + typedef GDesktopAppInfoLookupIface GDesktopAppInfoLookupInterface; G_DEFINE_INTERFACE (GDesktopAppInfoLookup, g_desktop_app_info_lookup, G_TYPE_OBJECT) @@ -3378,8 +3380,6 @@ g_desktop_app_info_lookup_default_init (GDesktopAppInfoLookupInterface *iface) * * Deprecated: The #GDesktopAppInfoLookup interface is deprecated and unused by gio. */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" GAppInfo * g_desktop_app_info_lookup_get_default_for_uri_scheme (GDesktopAppInfoLookup *lookup, const char *uri_scheme) @@ -3392,4 +3392,5 @@ g_desktop_app_info_lookup_get_default_for_uri_scheme (GDesktopAppInfoLookup *loo return (* iface->get_default_for_uri_scheme) (lookup, uri_scheme); } -#pragma GCC diagnostic pop + +G_GNUC_END_IGNORE_DEPRECATIONS diff --git a/gio/giomodule.c b/gio/giomodule.c index 9ccc3e3..02c2db6 100644 --- a/gio/giomodule.c +++ b/gio/giomodule.c @@ -809,8 +809,6 @@ DllMain (HINSTANCE hinstDLL, #endif -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" void _g_io_modules_ensure_extension_points_registered (void) { @@ -826,7 +824,9 @@ _g_io_modules_ensure_extension_points_registered (void) #ifdef G_OS_UNIX #if !GLIB_CHECK_VERSION (3, 0, 0) ep = g_io_extension_point_register (G_DESKTOP_APP_INFO_LOOKUP_EXTENSION_POINT_NAME); + G_GNUC_BEGIN_IGNORE_DEPRECATIONS g_io_extension_point_set_required_type (ep, G_TYPE_DESKTOP_APP_INFO_LOOKUP); + G_GNUC_END_IGNORE_DEPRECATIONS #endif #endif @@ -863,7 +863,6 @@ _g_io_modules_ensure_extension_points_registered (void) G_UNLOCK (registered_extensions); } -#pragma GCC diagnostic pop void _g_io_modules_ensure_loaded (void) diff --git a/glib/docs.c b/glib/docs.c index 97d41cd..f680ae0 100644 --- a/glib/docs.c +++ b/glib/docs.c @@ -1987,6 +1987,39 @@ */ /** + * G_GNUC_BEGIN_IGNORE_DEPRECATIONS: + * + * Tells gcc (if it is a new enough version) to + * temporarily stop emitting warnings when functions marked with + * %G_GNUC_DEPRECATED or %G_GNUC_DEPRECATED_FOR are called. This is + * useful for when you have one deprecated function calling another + * one, or when you still have regression tests for deprecated + * functions. + * + * Use %G_GNUC_END_IGNORE_DEPRECATIONS to begin warning again. (If you + * are not compiling with -Wdeprecated-declarations + * then neither macro has any effect.) + * + * This macro can be used either inside or outside of a function body, + * but must appear on a line by itself. + * + * Since: 2.32 + */ + +/** + * G_GNUC_END_IGNORE_DEPRECATIONS: + * + * Undoes the effect of %G_GNUC_BEGIN_IGNORE_DEPRECATIONS, telling + * gcc to begin outputting warnings again + * (assuming those warnings had been enabled to begin with). + * + * This macro can be used either inside or outside of a function body, + * but must appear on a line by itself. + * + * Since: 2.32 + */ + +/** * G_GNUC_NORETURN: * * Expands to the GNU C noreturn function attribute diff --git a/glib/gmacros.h b/glib/gmacros.h index 2b340cb..e07610c 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -114,6 +114,17 @@ #define G_GNUC_DEPRECATED_FOR(f) G_GNUC_DEPRECATED #endif /* __GNUC__ */ +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define G_GNUC_END_IGNORE_DEPRECATIONS \ + _Pragma ("GCC diagnostic pop") +#else +#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS +#define G_GNUC_END_IGNORE_DEPRECATIONS +#endif + #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) # define G_GNUC_MAY_ALIAS __attribute__((may_alias)) #else diff --git a/gobject/gvaluearray.c b/gobject/gvaluearray.c index 39c9c01..db6c719 100644 --- a/gobject/gvaluearray.c +++ b/gobject/gvaluearray.c @@ -228,7 +228,9 @@ g_value_array_prepend (GValueArray *value_array, { g_return_val_if_fail (value_array != NULL, NULL); + G_GNUC_BEGIN_IGNORE_DEPRECATIONS return g_value_array_insert (value_array, 0, value); + G_GNUC_END_IGNORE_DEPRECATIONS } /** @@ -249,7 +251,9 @@ g_value_array_append (GValueArray *value_array, { g_return_val_if_fail (value_array != NULL, NULL); + G_GNUC_BEGIN_IGNORE_DEPRECATIONS return g_value_array_insert (value_array, value_array->n_values, value); + G_GNUC_END_IGNORE_DEPRECATIONS } /** -- 2.7.4