[PATCH 2/2 v2] compat: add compatibility definitions for old MM_MODEM_BAND_EUTRAN_* values

Ben Chan benchan at chromium.org
Wed Jun 28 07:36:56 UTC 2017


When adding this compat header, I noticed that __attribute__((deprecated)),
which G_DEPRECATED_FOR is based on, can't be associated with macros.  Both
gcc and clang associated the attribute to the next identifier found after
the macro definition, not the macro itself:

#1
    G_DEPRECATED_FOR(NEW_ENUM)
    #define OLD_ENUM NEW_NUM
    void foo() {}   // __attribute__((deprecated)) is applied to foo()
instead of OLD_ENUM
    foo();  // this triggers a deprecation warning

#2
    G_DEPRECATED_FOR(NEW_ENUM)
    #define OLD_ENUM NEW_NUM
    struct bar;   // clang fails to apply __attribute__((deprecated)) here
and throws an ignored-attribute warning

It seems like only MSVC supports deprecation attribute on macro definitions
via #pragma deprecated.  Enumerator attribute would be the solution, but
only gcc 6 or above (clang 3 or above) supports that. For example, we can
use unnamed enum to define deprecated enumerators like this:

    enum {
        OLD_ENUM G_DEPRECATED_FOR(NEW_ENUM) = NEW_ENUM
    };

Instead of relying on compiler support of enumerator attribute, I use a
`static const int` in this patch as a workaround:

    G_DEPRECATED_FOR(NEW_ENUM)
    static const int OLD_ENUM = NEW_ENUM;

We can eventually migrate to use enumerator attribute when that is widely
supported by the default toolchain.  I also posted patches to fix the
G_DEPRECATED_FOR annotations in libqmi and libmbim.



On Wed, Jun 28, 2017 at 12:13 AM, Ben Chan <benchan at chromium.org> wrote:

> Those Roman numeral suffixes in MM_MODEM_BAND_EUTRAN_* were replaced
> with 1, 2, 3, ..., etc. This patch adds a compatibility header,
> ModemManager-compat.h, to alias the old MM_MODEM_BAND_EUTRAN_* values to
> the new values.
> ---
>  include/Makefile.am           |   1 +
>  include/ModemManager-compat.h | 432 ++++++++++++++++++++++++++++++
> ++++++++++++
>  include/ModemManager.h        |   3 +
>  libmm-glib/Makefile.am        |   1 +
>  4 files changed, 437 insertions(+)
>  create mode 100644 include/ModemManager-compat.h
>
> diff --git a/include/Makefile.am b/include/Makefile.am
> index 424b51c3..237ee6bd 100644
> --- a/include/Makefile.am
> +++ b/include/Makefile.am
> @@ -8,6 +8,7 @@ include_HEADERS = \
>         ModemManager-names.h \
>         ModemManager-enums.h \
>         ModemManager-errors.h \
> +       ModemManager-compat.h \
>         ModemManager-version.h \
>         ModemManager.h
>
> diff --git a/include/ModemManager-compat.h b/include/ModemManager-compat.h
> new file mode 100644
> index 00000000..ffa366b2
> --- /dev/null
> +++ b/include/ModemManager-compat.h
> @@ -0,0 +1,432 @@
> +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4
> -*- */
> +/*
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details:
> + *
> + * Copyright (C) 2017 Google, Inc.
> + */
> +
> +#ifndef _MODEMMANAGER_COMPAT_H_
> +#define _MODEMMANAGER_COMPAT_H_
> +
> +#if !defined (__MODEM_MANAGER_H_INSIDE__)
> +#error "Only <ModemManager.h> can be included directly."
> +#endif
> +
> +#include <glib.h>
> +
> +#include <ModemManager-enums.h>
> +
> +/**
> + * SECTION:ModemManager-compat
> + * @title: API break replacements
> + *
> + * These compatibility types and methods are flagged as deprecated and
> + * therefore shouldn't be used in newly written code. They are provided to
> + * avoid unnecessary API/ABI breaks.
> + */
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_I:
> + *
> + * E-UTRAN band 1.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_1 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_1)
> +static const int MM_MODEM_BAND_EUTRAN_I = MM_MODEM_BAND_EUTRAN_1;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_II:
> + *
> + * E-UTRAN band 2.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_2 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_2)
> +static const int MM_MODEM_BAND_EUTRAN_II = MM_MODEM_BAND_EUTRAN_2;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_III:
> + *
> + * E-UTRAN band 3.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_3 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_3)
> +static const int MM_MODEM_BAND_EUTRAN_III = MM_MODEM_BAND_EUTRAN_3;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_IV:
> + *
> + * E-UTRAN band 4.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_4 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_4)
> +static const int MM_MODEM_BAND_EUTRAN_IV = MM_MODEM_BAND_EUTRAN_4;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_V:
> + *
> + * E-UTRAN band 5.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_5 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_5)
> +static const int MM_MODEM_BAND_EUTRAN_V = MM_MODEM_BAND_EUTRAN_5;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_VI:
> + *
> + * E-UTRAN band 6.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_6 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_6)
> +static const int MM_MODEM_BAND_EUTRAN_VI = MM_MODEM_BAND_EUTRAN_6;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_VII:
> + *
> + * E-UTRAN band 7.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_7 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_7)
> +static const int MM_MODEM_BAND_EUTRAN_VII = MM_MODEM_BAND_EUTRAN_7;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_VIII:
> + *
> + * E-UTRAN band 8.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_8 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_8)
> +static const int MM_MODEM_BAND_EUTRAN_VIII = MM_MODEM_BAND_EUTRAN_8;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_IX:
> + *
> + * E-UTRAN band 9.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_9 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_9)
> +static const int MM_MODEM_BAND_EUTRAN_IX = MM_MODEM_BAND_EUTRAN_9;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_X:
> + *
> + * E-UTRAN band 10.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_10 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_10)
> +static const int MM_MODEM_BAND_EUTRAN_X = MM_MODEM_BAND_EUTRAN_10;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XI:
> + *
> + * E-UTRAN band 11.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_11 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_11)
> +static const int MM_MODEM_BAND_EUTRAN_XI = MM_MODEM_BAND_EUTRAN_11;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XII:
> + *
> + * E-UTRAN band 12.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_12 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_12)
> +static const int MM_MODEM_BAND_EUTRAN_XII = MM_MODEM_BAND_EUTRAN_12;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XIII:
> + *
> + * E-UTRAN band 13.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_13 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_13)
> +static const int MM_MODEM_BAND_EUTRAN_XIII = MM_MODEM_BAND_EUTRAN_13;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XIV:
> + *
> + * E-UTRAN band 14.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_14 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_14)
> +static const int MM_MODEM_BAND_EUTRAN_XIV = MM_MODEM_BAND_EUTRAN_14;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XVII:
> + *
> + * E-UTRAN band 17.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_17 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_17)
> +static const int MM_MODEM_BAND_EUTRAN_XVII = MM_MODEM_BAND_EUTRAN_17;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XVIII:
> + *
> + * E-UTRAN band 18.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_18 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_18)
> +static const int MM_MODEM_BAND_EUTRAN_XVIII = MM_MODEM_BAND_EUTRAN_18;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XIX:
> + *
> + * E-UTRAN band 19.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_19 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_19)
> +static const int MM_MODEM_BAND_EUTRAN_XIX = MM_MODEM_BAND_EUTRAN_19;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XX:
> + *
> + * E-UTRAN band 20.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_20 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_20)
> +static const int MM_MODEM_BAND_EUTRAN_XX = MM_MODEM_BAND_EUTRAN_20;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXI:
> + *
> + * E-UTRAN band 21.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_21 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_21)
> +static const int MM_MODEM_BAND_EUTRAN_XXI = MM_MODEM_BAND_EUTRAN_21;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXII:
> + *
> + * E-UTRAN band 22.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_22 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_22)
> +static const int MM_MODEM_BAND_EUTRAN_XXII = MM_MODEM_BAND_EUTRAN_22;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXIII:
> + *
> + * E-UTRAN band 23.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_23 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_23)
> +static const int MM_MODEM_BAND_EUTRAN_XXIII = MM_MODEM_BAND_EUTRAN_23;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXIV:
> + *
> + * E-UTRAN band 24.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_24 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_24)
> +static const int MM_MODEM_BAND_EUTRAN_XXIV = MM_MODEM_BAND_EUTRAN_24;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXV:
> + *
> + * E-UTRAN band 25.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_25 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_25)
> +static const int MM_MODEM_BAND_EUTRAN_XXV = MM_MODEM_BAND_EUTRAN_25;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXVI:
> + *
> + * E-UTRAN band 26.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_26 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_26)
> +static const int MM_MODEM_BAND_EUTRAN_XXVI = MM_MODEM_BAND_EUTRAN_26;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXXIII:
> + *
> + * E-UTRAN band 33.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_33 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_33)
> +static const int MM_MODEM_BAND_EUTRAN_XXXIII = MM_MODEM_BAND_EUTRAN_33;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXXIV:
> + *
> + * E-UTRAN band 34.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_34 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_34)
> +static const int MM_MODEM_BAND_EUTRAN_XXXIV = MM_MODEM_BAND_EUTRAN_34;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXXV:
> + *
> + * E-UTRAN band 35.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_35 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_35)
> +static const int MM_MODEM_BAND_EUTRAN_XXXV = MM_MODEM_BAND_EUTRAN_35;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXXVI:
> + *
> + * E-UTRAN band 36.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_36 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_36)
> +static const int MM_MODEM_BAND_EUTRAN_XXXVI = MM_MODEM_BAND_EUTRAN_36;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXXVII:
> + *
> + * E-UTRAN band 37.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_37 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_37)
> +static const int MM_MODEM_BAND_EUTRAN_XXXVII = MM_MODEM_BAND_EUTRAN_37;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXXVIII:
> + *
> + * E-UTRAN band 38.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_38 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_38)
> +static const int MM_MODEM_BAND_EUTRAN_XXXVIII = MM_MODEM_BAND_EUTRAN_38;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XXXIX:
> + *
> + * E-UTRAN band 39.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_39 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_39)
> +static const int MM_MODEM_BAND_EUTRAN_XXXIX = MM_MODEM_BAND_EUTRAN_39;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XL:
> + *
> + * E-UTRAN band 40.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_40 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_40)
> +static const int MM_MODEM_BAND_EUTRAN_XL = MM_MODEM_BAND_EUTRAN_40;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XLI:
> + *
> + * E-UTRAN band 41.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_41 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_41)
> +static const int MM_MODEM_BAND_EUTRAN_XLI = MM_MODEM_BAND_EUTRAN_41;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XLII:
> + *
> + * E-UTRAN band 42.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_42 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_42)
> +static const int MM_MODEM_BAND_EUTRAN_XLII = MM_MODEM_BAND_EUTRAN_42;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XLIII:
> + *
> + * E-UTRAN band 43.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_43 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_43)
> +static const int MM_MODEM_BAND_EUTRAN_XLIII = MM_MODEM_BAND_EUTRAN_43;
> +
> +/**
> + * MM_MODEM_BAND_EUTRAN_XLIV:
> + *
> + * E-UTRAN band 44.
> + *
> + * Since: 1.0
> + * Deprecated: 1.18.0: Use #MM_MODEM_BAND_EUTRAN_44 instead.
> + */
> +G_DEPRECATED_FOR (MM_MODEM_BAND_EUTRAN_44)
> +static const int MM_MODEM_BAND_EUTRAN_XLIV = MM_MODEM_BAND_EUTRAN_44;
> +
> +#endif /* _MODEMMANAGER_COMPAT_H_ */
> diff --git a/include/ModemManager.h b/include/ModemManager.h
> index 3a6eb43c..3db9a664 100644
> --- a/include/ModemManager.h
> +++ b/include/ModemManager.h
> @@ -37,6 +37,9 @@
>  /* Public header with errors */
>  #include <ModemManager-errors.h>
>
> +/* Public header with compability types and methods */
> +#include <ModemManager-compat.h>
> +
>  /* Public header with version info */
>  #include <ModemManager-version.h>
>
> diff --git a/libmm-glib/Makefile.am b/libmm-glib/Makefile.am
> index 64bca40e..7d554ad0 100644
> --- a/libmm-glib/Makefile.am
> +++ b/libmm-glib/Makefile.am
> @@ -186,6 +186,7 @@ PUBLIC_H = \
>         ModemManager-version.h
>         ModemManager-enums.h \
>         ModemManager-errors.h \
> +       ModemManager-compat.h \
>         ModemManager.h \
>         $(NULL)
>
> --
> 2.13.2.725.g09c95d1e9-goog
>
> _______________________________________________
> ModemManager-devel mailing list
> ModemManager-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/modemmanager-devel/attachments/20170628/dd708387/attachment-0001.html>


More information about the ModemManager-devel mailing list