Add flexible API version boundaries

There are cases when it should be possible to define at compile time
what range of functions and types should be used, in order to get,
or restrict, the compiler warnings for deprecated or newly added
types or functions.

For instance, if GLib introduces a deprecation warning on a type in
version 2.32, application code can decide to specify the minimum and
maximum boundary of the used API to be 2.30; when compiling against
a new version of GLib, this would produce the following results:

  - all deprecations introduced prior to 2.32 would emit compiler
    warnings when used by the application code;
  - all deprecations introduced in 2.32 would not emit compiler
    warnings when used by the application code;
  - all new symbols introduced in 2.32 would emit a compiler warning.

Using this scheme it should be possible to have fairly complex
situations, like the following one:

  assuming that an application is compiled with:
    GLIB_VERSION_MIN_REQUIRED = GLIB_VERSION_2_30
    GLIB_VERSION_MAX_ALLOWED  = GLIB_VERSION_2_32

  and a GLib header containing:

    void function_A (void) GLIB_DEPRECATED_IN_2_26;
    void function_B (void) GLIB_DEPRECATED_IN_2_28;
    void function_C (void) GLIB_DEPRECATED_IN_2_30;
    void function_D (void) GLIB_AVAILABLE_IN_2_32;
    void function_E (void) GLIB_AVAILABLE_IN_2_34;

  any application code using the above functions will get the following
  compiler warnings:

    function_A: deprecated symbol warning
    function_B: deprecated symbol warning
    function_C: no warning
    function_D: no warning
    function_E: undefined symbol warning

This means that it should be possible to gradually port code towards
non-deprecated API gradually, on a per-release basis.

https://bugzilla.gnome.org/show_bug.cgi?id=670542
This commit is contained in:
Emmanuele Bassi
2012-02-20 16:20:15 +00:00
committed by Matthias Clasen
parent d70634526d
commit 34aeeb7d64
10 changed files with 284 additions and 0 deletions

View File

@@ -78,6 +78,15 @@ problematic, they can be turned off by defining the preprocessor
symbol GLIB_DISABLE_DEPRECATION_WARNINGS by using the commandline
option <literal>-DGLIB_DISABLE_DEPRECATION_WARNINGS</literal>
</para>
<para>
GLib deprecation annotations are versioned; by defining the
macros %GLIB_VERSION_MIN_REQUIRED and %GLIB_VERSION_MAX_ALLOWED,
you can specify the range of GLib versions whose API you want
to use. APIs that were deprecated before or introduced after
this range will trigger compiler warnings.
</para>
<para>
The older deprecation mechanism of hiding deprecated interfaces
entirely from the compiler by using the preprocessor symbol

View File

@@ -112,6 +112,14 @@ GLIB_MAJOR_VERSION
GLIB_MINOR_VERSION
GLIB_MICRO_VERSION
GLIB_CHECK_VERSION
<SUBSECTION>
GLIB_VERSION_2_26
GLIB_VERSION_2_28
GLIB_VERSION_2_30
GLIB_VERSION_2_32
GLIB_VERSION_MIN_REQUIRED
GLIB_VERSION_MAX_ALLOWED
</SECTION>
<SECTION>
@@ -355,6 +363,7 @@ G_GNUC_MAY_ALIAS
<SUBSECTION>
G_DEPRECATED
G_DEPRECATED_FOR
G_UNAVAILABLE
<SUBSECTION>
G_LIKELY