glib, gio: Use GLIB_DEPRECATED_MACRO instead of G_DISABLE_DEPRECATED

When defining deprecated macros, annotate them with
`GLIB_DEPRECATED_MACRO_IN_*()` and `GLIB_DEPRECATED_MACRO_IN_*_FOR()` to
conditionally emit warnings if people use them, depending on their
declared minimum and maximum GLib version requirements (see
`GLIB_VERSION_MIN_REQUIRED` and `GLIB_VERSION_MAX_ALLOWED`).

The old way of doing this was for users to define `G_DISABLE_DEPRECATED`
if they didn’t want to use deprecated APIs, but it reported errors via
missing symbols, and wasn’t version-dependent. It’s being phased out.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2019-05-27 18:14:15 +01:00
parent db270e3c2d
commit b4d58a7105
12 changed files with 58 additions and 94 deletions

View File

@ -106,12 +106,10 @@ GLIB_AVAILABLE_IN_2_38
gchar * g_desktop_app_info_get_action_name (GDesktopAppInfo *info,
const gchar *action_name);
#ifndef G_DISABLE_DEPRECATED
#define G_TYPE_DESKTOP_APP_INFO_LOOKUP (g_desktop_app_info_lookup_get_type ())
#define G_DESKTOP_APP_INFO_LOOKUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_DESKTOP_APP_INFO_LOOKUP, GDesktopAppInfoLookup))
#define G_IS_DESKTOP_APP_INFO_LOOKUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_DESKTOP_APP_INFO_LOOKUP))
#define G_DESKTOP_APP_INFO_LOOKUP_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), G_TYPE_DESKTOP_APP_INFO_LOOKUP, GDesktopAppInfoLookupIface))
#define G_TYPE_DESKTOP_APP_INFO_LOOKUP (g_desktop_app_info_lookup_get_type ()) GLIB_DEPRECATED_MACRO_IN_2_28
#define G_DESKTOP_APP_INFO_LOOKUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_DESKTOP_APP_INFO_LOOKUP, GDesktopAppInfoLookup)) GLIB_DEPRECATED_MACRO_IN_2_28
#define G_IS_DESKTOP_APP_INFO_LOOKUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_DESKTOP_APP_INFO_LOOKUP)) GLIB_DEPRECATED_MACRO_IN_2_28
#define G_DESKTOP_APP_INFO_LOOKUP_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), G_TYPE_DESKTOP_APP_INFO_LOOKUP, GDesktopAppInfoLookupIface)) GLIB_DEPRECATED_MACRO_IN_2_28
/**
* G_DESKTOP_APP_INFO_LOOKUP_EXTENSION_POINT_NAME:
@ -122,9 +120,7 @@ gchar * g_desktop_app_info_get_action_name (GDeskto
* Deprecated: 2.28: The #GDesktopAppInfoLookup interface is deprecated and
* unused by GIO.
*/
#define G_DESKTOP_APP_INFO_LOOKUP_EXTENSION_POINT_NAME "gio-desktop-app-info-lookup"
#endif /* G_DISABLE_DEPRECATED */
#define G_DESKTOP_APP_INFO_LOOKUP_EXTENSION_POINT_NAME "gio-desktop-app-info-lookup" GLIB_DEPRECATED_MACRO_IN_2_28
/**
* GDesktopAppInfoLookupIface:

View File

@ -30,7 +30,6 @@
G_BEGIN_DECLS
#ifndef G_DISABLE_DEPRECATED
/**
* G_VOLUME_IDENTIFIER_KIND_HAL_UDI:
*
@ -38,8 +37,7 @@ G_BEGIN_DECLS
*
* Deprecated: 2.58: Do not use, HAL is deprecated.
*/
#define G_VOLUME_IDENTIFIER_KIND_HAL_UDI "hal-udi"
#endif /* G_DISABLE_DEPRECATED */
#define G_VOLUME_IDENTIFIER_KIND_HAL_UDI "hal-udi" GLIB_DEPRECATED_MACRO_IN_2_58
/**
* G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE:

View File

@ -33,8 +33,6 @@
G_BEGIN_DECLS
#ifndef G_DISABLE_DEPRECATED
/* ============== Compat main loop stuff ================== */
/**
@ -49,7 +47,7 @@ G_BEGIN_DECLS
*
* Deprecated: 2.2: Use g_main_loop_new() instead
*/
#define g_main_new(is_running) g_main_loop_new (NULL, is_running)
#define g_main_new(is_running) g_main_loop_new (NULL, is_running) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_loop_new)
/**
* g_main_run:
@ -59,7 +57,7 @@ G_BEGIN_DECLS
*
* Deprecated: 2.2: Use g_main_loop_run() instead
*/
#define g_main_run(loop) g_main_loop_run(loop)
#define g_main_run(loop) g_main_loop_run(loop) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_loop_run)
/**
* g_main_quit:
@ -70,7 +68,7 @@ G_BEGIN_DECLS
*
* Deprecated: 2.2: Use g_main_loop_quit() instead
*/
#define g_main_quit(loop) g_main_loop_quit(loop)
#define g_main_quit(loop) g_main_loop_quit(loop) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_loop_quit)
/**
* g_main_destroy:
@ -80,7 +78,7 @@ G_BEGIN_DECLS
*
* Deprecated: 2.2: Use g_main_loop_unref() instead
*/
#define g_main_destroy(loop) g_main_loop_unref(loop)
#define g_main_destroy(loop) g_main_loop_unref(loop) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_loop_unref)
/**
* g_main_is_running:
@ -92,7 +90,7 @@ G_BEGIN_DECLS
*
* Deprecated: 2.2: Use g_main_loop_is_running() instead
*/
#define g_main_is_running(loop) g_main_loop_is_running(loop)
#define g_main_is_running(loop) g_main_loop_is_running(loop) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_loop_is_running)
/**
* g_main_iteration:
@ -107,7 +105,7 @@ G_BEGIN_DECLS
*
* Deprecated: 2.2: Use g_main_context_iteration() instead.
*/
#define g_main_iteration(may_block) g_main_context_iteration (NULL, may_block)
#define g_main_iteration(may_block) g_main_context_iteration (NULL, may_block) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_context_iteration)
/**
* g_main_pending:
@ -119,7 +117,7 @@ G_BEGIN_DECLS
*
* Deprected: 2.2: Use g_main_context_pending() instead.
*/
#define g_main_pending() g_main_context_pending (NULL)
#define g_main_pending() g_main_context_pending (NULL) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_context_pending)
/**
* g_main_set_poll_func:
@ -130,9 +128,7 @@ G_BEGIN_DECLS
*
* Deprecated: 2.2: Use g_main_context_set_poll_func() again
*/
#define g_main_set_poll_func(func) g_main_context_set_poll_func (NULL, func)
#endif
#define g_main_set_poll_func(func) g_main_context_set_poll_func (NULL, func) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_context_set_poll_func)
G_END_DECLS

View File

@ -128,8 +128,8 @@ void g_thread_foreach (GFunc thread_func,
#include <pthread.h>
#endif
#define g_static_mutex_get_mutex g_static_mutex_get_mutex_impl
#define G_STATIC_MUTEX_INIT { NULL }
#define g_static_mutex_get_mutex g_static_mutex_get_mutex_impl GLIB_DEPRECATED_MACRO_IN_2_32
#define G_STATIC_MUTEX_INIT { NULL } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_init)
typedef struct
{
GMutex *mutex;
@ -140,11 +140,11 @@ typedef struct
} GStaticMutex;
#define g_static_mutex_lock(mutex) \
g_mutex_lock (g_static_mutex_get_mutex (mutex))
g_mutex_lock (g_static_mutex_get_mutex (mutex)) GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_lock)
#define g_static_mutex_trylock(mutex) \
g_mutex_trylock (g_static_mutex_get_mutex (mutex))
g_mutex_trylock (g_static_mutex_get_mutex (mutex)) GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_trylock)
#define g_static_mutex_unlock(mutex) \
g_mutex_unlock (g_static_mutex_get_mutex (mutex))
g_mutex_unlock (g_static_mutex_get_mutex (mutex)) GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_unlock)
GLIB_DEPRECATED_IN_2_32_FOR(g_mutex_init)
void g_static_mutex_init (GStaticMutex *mutex);
@ -171,7 +171,7 @@ struct _GStaticRecMutex
} unused;
};
#define G_STATIC_REC_MUTEX_INIT { G_STATIC_MUTEX_INIT, 0, { 0 } }
#define G_STATIC_REC_MUTEX_INIT { G_STATIC_MUTEX_INIT, 0, { 0 } } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_rec_mutex_init)
GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_init)
void g_static_rec_mutex_init (GStaticRecMutex *mutex);
@ -207,7 +207,7 @@ struct _GStaticRWLock
guint want_to_write;
};
#define G_STATIC_RW_LOCK_INIT { G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, 0, 0 }
#define G_STATIC_RW_LOCK_INIT { G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, 0, 0 } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_rw_lock_init)
GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_init)
void g_static_rw_lock_init (GStaticRWLock *lock);
@ -243,7 +243,7 @@ struct _GStaticPrivate
guint index;
};
#define G_STATIC_PRIVATE_INIT { 0 }
#define G_STATIC_PRIVATE_INIT { 0 } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(G_PRIVATE_INIT)
GLIB_DEPRECATED_IN_2_32
void g_static_private_init (GStaticPrivate *private_key);
@ -271,7 +271,7 @@ gboolean g_thread_get_initialized (void);
GLIB_VAR gboolean g_threads_got_initialized;
#define g_thread_supported() (1)
#define g_thread_supported() (1) GLIB_DEPRECATED_MACRO_IN_2_32
GLIB_DEPRECATED_IN_2_32
GMutex * g_mutex_new (void);

View File

@ -290,21 +290,17 @@ gsize g_date_strftime (gchar *s,
const gchar *format,
const GDate *date);
#ifndef G_DISABLE_DEPRECATED
#define g_date_weekday g_date_get_weekday
#define g_date_month g_date_get_month
#define g_date_year g_date_get_year
#define g_date_day g_date_get_day
#define g_date_julian g_date_get_julian
#define g_date_day_of_year g_date_get_day_of_year
#define g_date_monday_week_of_year g_date_get_monday_week_of_year
#define g_date_sunday_week_of_year g_date_get_sunday_week_of_year
#define g_date_days_in_month g_date_get_days_in_month
#define g_date_monday_weeks_in_year g_date_get_monday_weeks_in_year
#define g_date_sunday_weeks_in_year g_date_get_sunday_weeks_in_year
#endif /* G_DISABLE_DEPRECATED */
#define g_date_weekday g_date_get_weekday GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_date_get_weekday)
#define g_date_month g_date_get_month GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_date_get_month)
#define g_date_year g_date_get_year GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_date_get_year)
#define g_date_day g_date_get_day GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_date_get_day)
#define g_date_julian g_date_get_julian GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_date_get_julian)
#define g_date_day_of_year g_date_get_day_of_year GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_date_get_day_of_year)
#define g_date_monday_week_of_year g_date_get_monday_week_of_year GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_date_get_monday_week_of_year)
#define g_date_sunday_week_of_year g_date_get_sunday_week_of_year GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_date_get_sunday_week_of_year)
#define g_date_days_in_month g_date_get_days_in_month GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_date_get_days_in_month)
#define g_date_monday_weeks_in_year g_date_get_monday_weeks_in_year GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_date_get_monday_weeks_in_year)
#define g_date_sunday_weeks_in_year g_date_get_sunday_weeks_in_year GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_date_get_sunday_weeks_in_year)
G_END_DECLS

View File

@ -161,9 +161,7 @@ const gchar *g_path_skip_root (const gchar *file_name);
GLIB_DEPRECATED_FOR(g_path_get_basename)
const gchar *g_basename (const gchar *file_name);
#ifndef G_DISABLE_DEPRECATED
#define g_dirname g_path_get_dirname
#endif
#define g_dirname g_path_get_dirname GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_path_get_dirname)
GLIB_AVAILABLE_IN_ALL
gchar *g_get_current_dir (void);

View File

@ -148,10 +148,8 @@ GHashTable* g_hash_table_ref (GHashTable *hash_table);
GLIB_AVAILABLE_IN_ALL
void g_hash_table_unref (GHashTable *hash_table);
#ifndef G_DISABLE_DEPRECATED
#define g_hash_table_freeze(hash_table) ((void)0)
#define g_hash_table_thaw(hash_table) ((void)0)
#endif
#define g_hash_table_freeze(hash_table) ((void)0) GLIB_DEPRECATED_MACRO_IN_2_26
#define g_hash_table_thaw(hash_table) ((void)0) GLIB_DEPRECATED_MACRO_IN_2_26
/* Hash Functions
*/

View File

@ -96,17 +96,15 @@
* Deprecated: 2.48: Use "static inline" instead
*/
#ifndef G_DISABLE_DEPRECATED
/* For historical reasons we need to continue to support those who
* define G_IMPLEMENT_INLINES to mean "don't implement this here".
*/
#ifdef G_IMPLEMENT_INLINES
# define G_INLINE_FUNC extern
# define G_INLINE_FUNC extern GLIB_DEPRECATED_MACRO_IN_2_48_FOR(static inline)
# undef G_CAN_INLINE
#else
# define G_INLINE_FUNC static inline
# define G_INLINE_FUNC static inline GLIB_DEPRECATED_MACRO_IN_2_48_FOR(static inline)
#endif /* G_IMPLEMENT_INLINES */
#endif /* !G_DISABLE_DEPRECATED */
/* Provide macros to feature the GCC function attribute.
*/
@ -707,19 +705,20 @@
* Deprecated: 2.16: Use G_STRFUNC() instead
*/
#ifndef G_DISABLE_DEPRECATED
/* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
* macros, so we can refer to them as strings unconditionally.
* usage not-recommended since gcc-3.0
*
* Mark them as deprecated since 2.26, since thats when version macros were
* introduced.
*/
#if defined (__GNUC__) && (__GNUC__ < 3)
#define G_GNUC_FUNCTION __FUNCTION__
#define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
#define G_GNUC_FUNCTION __FUNCTION__ GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
#define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__ GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
#else /* !__GNUC__ */
#define G_GNUC_FUNCTION ""
#define G_GNUC_PRETTY_FUNCTION ""
#define G_GNUC_FUNCTION "" GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
#define G_GNUC_PRETTY_FUNCTION "" GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
#endif /* !__GNUC__ */
#endif /* !G_DISABLE_DEPRECATED */
#if g_macro__has_feature(attribute_analyzer_noreturn) && defined(__clang_analyzer__)
#define G_ANALYZER_ANALYZING 1
@ -900,15 +899,11 @@
* Deprecated: 2.30: API providers should replace all existing uses with
* const and API consumers should adjust their code accordingly
*/
/* Deprecated -- do not use. */
#ifndef G_DISABLE_DEPRECATED
#ifdef G_DISABLE_CONST_RETURNS
#define G_CONST_RETURN
#define G_CONST_RETURN GLIB_DEPRECATED_MACRO_IN_2_30_FOR(const)
#else
#define G_CONST_RETURN const
#define G_CONST_RETURN const GLIB_DEPRECATED_MACRO_IN_2_30_FOR(const)
#endif
#endif /* !G_DISABLE_DEPRECATED */
/*
* The G_LIKELY and G_UNLIKELY macros let the programmer give hints to

View File

@ -278,25 +278,21 @@ void g_scanner_warn (GScanner *scanner,
const gchar *format,
...) G_GNUC_PRINTF (2,3);
#ifndef G_DISABLE_DEPRECATED
/* keep downward source compatibility */
#define g_scanner_add_symbol( scanner, symbol, value ) G_STMT_START { \
g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
} G_STMT_END
} G_STMT_END GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_scanner_scope_add_symbol)
#define g_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \
g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
} G_STMT_END
} G_STMT_END GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_scanner_scope_remove_symbol)
#define g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
} G_STMT_END
} G_STMT_END GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_scanner_scope_foreach_symbol)
/* The following two functions are deprecated and will be removed in
* the next major release. They do no good. */
#define g_scanner_freeze_symbol_table(scanner) ((void)0)
#define g_scanner_thaw_symbol_table(scanner) ((void)0)
#endif /* G_DISABLE_DEPRECATED */
#define g_scanner_freeze_symbol_table(scanner) ((void)0) GLIB_DEPRECATED_MACRO_IN_2_26
#define g_scanner_thaw_symbol_table(scanner) ((void)0) GLIB_DEPRECATED_MACRO_IN_2_26
G_END_DECLS

View File

@ -179,10 +179,8 @@ GString *g_string_down (GString *string);
GLIB_DEPRECATED
GString *g_string_up (GString *string);
#ifndef G_DISABLE_DEPRECATED
#define g_string_sprintf g_string_printf
#define g_string_sprintfa g_string_append_printf
#endif
#define g_string_sprintf g_string_printf GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_string_printf)
#define g_string_sprintfa g_string_append_printf GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_string_append_printf)
G_END_DECLS

View File

@ -154,9 +154,7 @@ typedef enum
*
* Deprecated: 2.30: Use %G_UNICODE_SPACING_MARK.
*/
#ifndef G_DISABLE_DEPRECATED
#define G_UNICODE_COMBINING_MARK G_UNICODE_SPACING_MARK
#endif
#define G_UNICODE_COMBINING_MARK G_UNICODE_SPACING_MARK GLIB_DEPRECATED_MACRO_IN_2_30_FOR(G_UNICODE_SPACING_MARK)
/**
* GUnicodeBreakType:

View File

@ -311,8 +311,6 @@ void g_abort (void) G_GNUC_NORETURN G_ANALYZER_NORETURN;
#endif
#endif
#ifndef G_DISABLE_DEPRECATED
/*
* This macro is deprecated. This DllMain() is too complex. It is
* recommended to write an explicit minimal DLlMain() that just saves
@ -331,7 +329,7 @@ void g_abort (void) G_GNUC_NORETURN G_ANALYZER_NORETURN;
*/
#ifndef G_PLATFORM_WIN32
# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) GLIB_DEPRECATED_MACRO_IN_2_26
#else
# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) \
static char *dll_name; \
@ -354,10 +352,7 @@ DllMain (HINSTANCE hinstDLL, \
} \
\
return TRUE; \
}
#endif /* !G_DISABLE_DEPRECATED */
} GLIB_DEPRECATED_MACRO_IN_2_26
#endif /* G_PLATFORM_WIN32 */
G_END_DECLS