[jsonrpc-glib] version: add versioning macros and use them



commit e71eaf300544959f0b9e81c39280ec59b9e16a1f
Author: Christian Hergert <chergert redhat com>
Date:   Sun Sep 24 19:16:46 2017 -0700

    version: add versioning macros and use them
    
    This adds version macros so that we do not need to use linker
    scripts to specify the symbol visibility.

 meson.build                        |    6 --
 src/jsonrpc-client.h               |   19 +++++
 src/jsonrpc-glib.h                 |    1 +
 src/jsonrpc-glib.map               |    6 --
 src/jsonrpc-input-stream-private.h |    2 +-
 src/jsonrpc-input-stream.h         |    6 ++
 src/jsonrpc-message.h              |    7 ++
 src/jsonrpc-output-stream.h        |    8 ++
 src/jsonrpc-server.h               |    5 +
 src/jsonrpc-version-macros.h       |  143 ++++++++++++++++++++++++++++++++++++
 src/meson.build                    |    7 --
 11 files changed, 190 insertions(+), 20 deletions(-)
---
diff --git a/meson.build b/meson.build
index ed9e9d6..6e45fc6 100644
--- a/meson.build
+++ b/meson.build
@@ -82,12 +82,6 @@ add_project_arguments(
   language: 'c'
 )
 
-# Check if we can use version scripts for ABI exports
-ld_supports_version_script = cc.links('''
-  int main (void) { return 0; }
-''', args: '-Wl,--version-script,' + join_paths(meson.source_root(), 'src/jsonrpc-glib.map'))
-message('Linker supports --version-script: @0@'.format(ld_supports_version_script))
-
 # Setup various paths that subdirectory meson.build files need
 package_subdir = get_option('package_subdir')
 girdir = join_paths(get_option('datadir'), package_subdir, 'gir-1.0')
diff --git a/src/jsonrpc-client.h b/src/jsonrpc-client.h
index ee4f36f..d596600 100644
--- a/src/jsonrpc-client.h
+++ b/src/jsonrpc-client.h
@@ -21,6 +21,8 @@
 
 #include <gio/gio.h>
 
+#include "jsonrpc-version-macros.h"
+
 G_BEGIN_DECLS
 
 #define JSONRPC_TYPE_CLIENT  (jsonrpc_client_get_type())
@@ -50,65 +52,82 @@ struct _JsonrpcClientClass
   gpointer _reserved8;
 };
 
+JSONRPC_AVAILABLE_IN_3_26
 GQuark         jsonrpc_client_error_quark              (void);
+JSONRPC_AVAILABLE_IN_3_26
 JsonrpcClient *jsonrpc_client_new                      (GIOStream            *io_stream);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean       jsonrpc_client_get_use_gvariant         (JsonrpcClient        *self);
+JSONRPC_AVAILABLE_IN_3_26
 void           jsonrpc_client_set_use_gvariant         (JsonrpcClient        *self,
                                                         gboolean              use_gvariant);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean       jsonrpc_client_close                    (JsonrpcClient        *self,
                                                         GCancellable         *cancellable,
                                                         GError              **error);
+JSONRPC_AVAILABLE_IN_3_26
 void           jsonrpc_client_close_async              (JsonrpcClient        *self,
                                                         GCancellable         *cancellable,
                                                         GAsyncReadyCallback   callback,
                                                         gpointer              user_data);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean       jsonrpc_client_close_finish             (JsonrpcClient        *self,
                                                         GAsyncResult         *result,
                                                         GError              **error);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean       jsonrpc_client_call                     (JsonrpcClient        *self,
                                                         const gchar          *method,
                                                         GVariant             *params,
                                                         GCancellable         *cancellable,
                                                         GVariant            **return_value,
                                                         GError              **error);
+JSONRPC_AVAILABLE_IN_3_26
 void           jsonrpc_client_call_async               (JsonrpcClient        *self,
                                                         const gchar          *method,
                                                         GVariant             *params,
                                                         GCancellable         *cancellable,
                                                         GAsyncReadyCallback   callback,
                                                         gpointer              user_data);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean       jsonrpc_client_call_finish              (JsonrpcClient        *self,
                                                         GAsyncResult         *result,
                                                         GVariant            **return_value,
                                                         GError              **error);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean       jsonrpc_client_send_notification        (JsonrpcClient        *self,
                                                         const gchar          *method,
                                                         GVariant             *params,
                                                         GCancellable         *cancellable,
                                                         GError              **error);
+JSONRPC_AVAILABLE_IN_3_26
 void           jsonrpc_client_send_notification_async  (JsonrpcClient        *self,
                                                         const gchar          *method,
                                                         GVariant             *params,
                                                         GCancellable         *cancellable,
                                                         GAsyncReadyCallback   callback,
                                                         gpointer              user_data);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean       jsonrpc_client_send_notification_finish (JsonrpcClient        *self,
                                                         GAsyncResult         *result,
                                                         GError              **error);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean       jsonrpc_client_reply                    (JsonrpcClient        *self,
                                                         GVariant             *id,
                                                         GVariant             *result,
                                                         GCancellable         *cancellable,
                                                         GError              **error);
+JSONRPC_AVAILABLE_IN_3_26
 void           jsonrpc_client_reply_async              (JsonrpcClient        *self,
                                                         GVariant             *id,
                                                         GVariant             *result,
                                                         GCancellable         *cancellable,
                                                         GAsyncReadyCallback   callback,
                                                         gpointer              user_data);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean       jsonrpc_client_reply_finish             (JsonrpcClient        *self,
                                                         GAsyncResult         *result,
                                                         GError              **error);
+JSONRPC_AVAILABLE_IN_3_26
 void           jsonrpc_client_start_listening          (JsonrpcClient        *self);
 
 G_END_DECLS
diff --git a/src/jsonrpc-glib.h b/src/jsonrpc-glib.h
index 4aed245..e7c0fc7 100644
--- a/src/jsonrpc-glib.h
+++ b/src/jsonrpc-glib.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 # include "jsonrpc-output-stream.h"
 # include "jsonrpc-server.h"
 # include "jsonrpc-version.h"
+# include "jsonrpc-version-macros.h"
 #undef JSONRPC_GLIB_INSIDE
 
 G_END_DECLS
diff --git a/src/jsonrpc-input-stream-private.h b/src/jsonrpc-input-stream-private.h
index 04915d9..e9cbee8 100644
--- a/src/jsonrpc-input-stream-private.h
+++ b/src/jsonrpc-input-stream-private.h
@@ -23,7 +23,7 @@
 
 G_BEGIN_DECLS
 
-gboolean _jsonrpc_input_stream_get_has_seen_gvariant (JsonrpcInputStream *self);
+gboolean _jsonrpc_input_stream_get_has_seen_gvariant (JsonrpcInputStream *self) G_GNUC_INTERNAL;
 
 G_END_DECLS
 
diff --git a/src/jsonrpc-input-stream.h b/src/jsonrpc-input-stream.h
index 043b3e2..d69fb38 100644
--- a/src/jsonrpc-input-stream.h
+++ b/src/jsonrpc-input-stream.h
@@ -21,6 +21,8 @@
 
 #include <gio/gio.h>
 
+#include "jsonrpc-version-macros.h"
+
 G_BEGIN_DECLS
 
 #define JSONRPC_TYPE_INPUT_STREAM (jsonrpc_input_stream_get_type())
@@ -41,15 +43,19 @@ struct _JsonrpcInputStreamClass
   gpointer _reserved8;
 };
 
+JSONRPC_AVAILABLE_IN_3_26
 JsonrpcInputStream *jsonrpc_input_stream_new                 (GInputStream         *base_stream);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean            jsonrpc_input_stream_read_message        (JsonrpcInputStream   *self,
                                                               GCancellable         *cancellable,
                                                               GVariant            **message,
                                                               GError              **error);
+JSONRPC_AVAILABLE_IN_3_26
 void                jsonrpc_input_stream_read_message_async  (JsonrpcInputStream   *self,
                                                               GCancellable         *cancellable,
                                                               GAsyncReadyCallback   callback,
                                                               gpointer              user_data);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean            jsonrpc_input_stream_read_message_finish (JsonrpcInputStream   *self,
                                                               GAsyncResult         *result,
                                                               GVariant            **message,
diff --git a/src/jsonrpc-message.h b/src/jsonrpc-message.h
index 6c10ae4..85b3716 100644
--- a/src/jsonrpc-message.h
+++ b/src/jsonrpc-message.h
@@ -21,6 +21,8 @@
 
 #include <glib.h>
 
+#include "jsonrpc-version-macros.h"
+
 G_BEGIN_DECLS
 
 typedef struct
@@ -183,8 +185,13 @@ typedef struct
 #define JSONRPC_MESSAGE_GET_VARIANT(_valptr) \
   (&((JsonrpcMessageGetVariant) { .magic = {_JSONRPC_MESSAGE_GET_VARIANT_MAGIC_C}, .variantptr = _valptr }))
 
+JSONRPC_AVAILABLE_IN_3_26
 GVariant *jsonrpc_message_new         (gpointer first_param, ...) G_GNUC_NULL_TERMINATED;
+
+JSONRPC_AVAILABLE_IN_3_26
 gboolean  jsonrpc_message_parse       (GVariant *message, ...) G_GNUC_NULL_TERMINATED;
+
+JSONRPC_AVAILABLE_IN_3_26
 gboolean  jsonrpc_message_parse_array (GVariantIter *iter, ...) G_GNUC_NULL_TERMINATED;
 
 G_END_DECLS
diff --git a/src/jsonrpc-output-stream.h b/src/jsonrpc-output-stream.h
index 1d53ae5..9de2d93 100644
--- a/src/jsonrpc-output-stream.h
+++ b/src/jsonrpc-output-stream.h
@@ -22,6 +22,8 @@
 #include <gio/gio.h>
 #include <json-glib/json-glib.h>
 
+#include "jsonrpc-version-macros.h"
+
 G_BEGIN_DECLS
 
 #define JSONRPC_TYPE_OUTPUT_STREAM (jsonrpc_output_stream_get_type())
@@ -46,19 +48,25 @@ struct _JsonrpcOutputStreamClass
   gpointer _reserved12;
 };
 
+JSONRPC_AVAILABLE_IN_3_26
 JsonrpcOutputStream *jsonrpc_output_stream_new                  (GOutputStream        *base_stream);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean             jsonrpc_output_stream_get_use_gvariant     (JsonrpcOutputStream  *self);
+JSONRPC_AVAILABLE_IN_3_26
 void                 jsonrpc_output_stream_set_use_gvariant     (JsonrpcOutputStream  *self,
                                                                  gboolean              use_gvariant);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean             jsonrpc_output_stream_write_message        (JsonrpcOutputStream  *self,
                                                                  GVariant             *message,
                                                                  GCancellable         *cancellable,
                                                                  GError              **error);
+JSONRPC_AVAILABLE_IN_3_26
 void                 jsonrpc_output_stream_write_message_async  (JsonrpcOutputStream  *self,
                                                                  GVariant             *message,
                                                                  GCancellable         *cancellable,
                                                                  GAsyncReadyCallback   callback,
                                                                  gpointer              user_data);
+JSONRPC_AVAILABLE_IN_3_26
 gboolean             jsonrpc_output_stream_write_message_finish (JsonrpcOutputStream  *self,
                                                                  GAsyncResult         *result,
                                                                  GError              **error);
diff --git a/src/jsonrpc-server.h b/src/jsonrpc-server.h
index 6fec94e..c74833e 100644
--- a/src/jsonrpc-server.h
+++ b/src/jsonrpc-server.h
@@ -22,6 +22,7 @@
 #include <gio/gio.h>
 
 #include "jsonrpc-client.h"
+#include "jsonrpc-version-macros.h"
 
 G_BEGIN_DECLS
 
@@ -60,14 +61,18 @@ typedef void (*JsonrpcServerHandler) (JsonrpcServer *self,
                                       GVariant      *params,
                                       gpointer       user_data);
 
+JSONRPC_AVAILABLE_IN_3_26
 JsonrpcServer *jsonrpc_server_new              (void);
+JSONRPC_AVAILABLE_IN_3_26
 void           jsonrpc_server_accept_io_stream (JsonrpcServer        *self,
                                                 GIOStream            *io_stream);
+JSONRPC_AVAILABLE_IN_3_26
 guint          jsonrpc_server_add_handler      (JsonrpcServer        *self,
                                                 const gchar          *method,
                                                 JsonrpcServerHandler  handler,
                                                 gpointer              handler_data,
                                                 GDestroyNotify        handler_data_destroy);
+JSONRPC_AVAILABLE_IN_3_26
 void           jsonrpc_server_remove_handler   (JsonrpcServer        *self,
                                                 guint                 handler_id);
 
diff --git a/src/jsonrpc-version-macros.h b/src/jsonrpc-version-macros.h
new file mode 100644
index 0000000..dfaad1d
--- /dev/null
+++ b/src/jsonrpc-version-macros.h
@@ -0,0 +1,143 @@
+/* jsonrpc-version-macros.h
+ *
+ * Copyright © 2014 Emmanuele Bassi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef JSONRPC_VERSION_MACROS_H
+#define JSONRPC_VERSION_MACROS_H
+
+#if !defined(JSONRPC_GLIB_INSIDE) && !defined(JSONRPC_GLIB_COMPILATION)
+# error "Only <jsonrpc-glib.h> can be included directly."
+#endif
+
+#include "jsonrpc-version.h"
+
+#ifndef _JSONRPC_EXTERN
+#define _JSONRPC_EXTERN extern
+#endif
+
+#ifdef JSONRPC_DISABLE_DEPRECATION_WARNINGS
+#define JSONRPC_DEPRECATED _JSONRPC_EXTERN
+#define JSONRPC_DEPRECATED_FOR(f) _JSONRPC_EXTERN
+#define JSONRPC_UNAVAILABLE(maj,min) _JSONRPC_EXTERN
+#else
+#define JSONRPC_DEPRECATED G_DEPRECATED _JSONRPC_EXTERN
+#define JSONRPC_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _JSONRPC_EXTERN
+#define JSONRPC_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _JSONRPC_EXTERN
+#endif
+
+#define JSONRPC_VERSION_3_26 (G_ENCODE_VERSION (3, 26))
+#define JSONRPC_VERSION_3_28 (G_ENCODE_VERSION (3, 28))
+
+#if (JSONRPC_MINOR_VERSION == 99)
+# define JSONRPC_VERSION_CUR_STABLE (G_ENCODE_VERSION (JSONRPC_MAJOR_VERSION + 1, 0))
+#elif (JSONRPC_MINOR_VERSION % 2)
+# define JSONRPC_VERSION_CUR_STABLE (G_ENCODE_VERSION (JSONRPC_MAJOR_VERSION, JSONRPC_MINOR_VERSION + 1))
+#else
+# define JSONRPC_VERSION_CUR_STABLE (G_ENCODE_VERSION (JSONRPC_MAJOR_VERSION, JSONRPC_MINOR_VERSION))
+#endif
+
+#if (JSONRPC_MINOR_VERSION == 99)
+# define JSONRPC_VERSION_PREV_STABLE (G_ENCODE_VERSION (JSONRPC_MAJOR_VERSION + 1, 0))
+#elif (JSONRPC_MINOR_VERSION % 2)
+# define JSONRPC_VERSION_PREV_STABLE (G_ENCODE_VERSION (JSONRPC_MAJOR_VERSION, JSONRPC_MINOR_VERSION - 1))
+#else
+# define JSONRPC_VERSION_PREV_STABLE (G_ENCODE_VERSION (JSONRPC_MAJOR_VERSION, JSONRPC_MINOR_VERSION - 2))
+#endif
+
+/**
+ * JSONRPC_VERSION_MIN_REQUIRED:
+ *
+ * A macro that should be defined by the user prior to including
+ * the jsonrpc-glib.h header.
+ *
+ * The definition should be one of the predefined JSONRPC version
+ * macros: %JSONRPC_VERSION_3_26, JSONRPC_VERSION_3_28, ...
+ *
+ * This macro defines the lower bound for the JSONRPC-GLib API to use.
+ *
+ * If a function has been deprecated in a newer version of JSONRPC-GLib,
+ * it is possible to use this symbol to avoid the compiler warnings
+ * without disabling warning for every deprecated function.
+ *
+ * Since: 3.28
+ */
+#ifndef JSONRPC_VERSION_MIN_REQUIRED
+# define JSONRPC_VERSION_MIN_REQUIRED (JSONRPC_VERSION_CUR_STABLE)
+#endif
+
+/**
+ * JSONRPC_VERSION_MAX_ALLOWED:
+ *
+ * A macro that should be defined by the user prior to including
+ * the jsonrpc-glib.h header.
+
+ * The definition should be one of the predefined JSONRPC-GLib version
+ * macros: %JSONRPC_VERSION_1_0, %JSONRPC_VERSION_1_2,...
+ *
+ * This macro defines the upper bound for the JSONRPC API to use.
+ *
+ * If a function has been introduced in a newer version of JSONRPC-GLib,
+ * it is possible to use this symbol to get compiler warnings when
+ * trying to use that function.
+ *
+ * Since: 3.26
+ */
+#ifndef JSONRPC_VERSION_MAX_ALLOWED
+# if JSONRPC_VERSION_MIN_REQUIRED > JSONRPC_VERSION_PREV_STABLE
+#  define JSONRPC_VERSION_MAX_ALLOWED (JSONRPC_VERSION_MIN_REQUIRED)
+# else
+#  define JSONRPC_VERSION_MAX_ALLOWED (JSONRPC_VERSION_CUR_STABLE)
+# endif
+#endif
+
+#if JSONRPC_VERSION_MAX_ALLOWED < JSONRPC_VERSION_MIN_REQUIRED
+#error "JSONRPC_VERSION_MAX_ALLOWED must be >= JSONRPC_VERSION_MIN_REQUIRED"
+#endif
+#if JSONRPC_VERSION_MIN_REQUIRED < JSONRPC_VERSION_3_26
+#error "JSONRPC_VERSION_MIN_REQUIRED must be >= JSONRPC_VERSION_3_26"
+#endif
+
+#if JSONRPC_VERSION_MIN_REQUIRED >= JSONRPC_VERSION_3_26
+# define JSONRPC_DEPRECATED_IN_3_26                JSONRPC_DEPRECATED
+# define JSONRPC_DEPRECATED_IN_3_26_FOR(f)         JSONRPC_DEPRECATED_FOR(f)
+#else
+# define JSONRPC_DEPRECATED_IN_3_26                _JSONRPC_EXTERN
+# define JSONRPC_DEPRECATED_IN_3_26_FOR(f)         _JSONRPC_EXTERN
+#endif
+
+#if JSONRPC_VERSION_MAX_ALLOWED < JSONRPC_VERSION_3_26
+# define JSONRPC_AVAILABLE_IN_3_26                 JSONRPC_UNAVAILABLE(3, 26)
+#else
+# define JSONRPC_AVAILABLE_IN_3_26                 _JSONRPC_EXTERN
+#endif
+
+#if JSONRPC_VERSION_MIN_REQUIRED >= JSONRPC_VERSION_3_28
+# define JSONRPC_DEPRECATED_IN_3_28                JSONRPC_DEPRECATED
+# define JSONRPC_DEPRECATED_IN_3_28_FOR(f)         JSONRPC_DEPRECATED_FOR(f)
+#else
+# define JSONRPC_DEPRECATED_IN_3_28                _JSONRPC_EXTERN
+# define JSONRPC_DEPRECATED_IN_3_28_FOR(f)         _JSONRPC_EXTERN
+#endif
+
+#if JSONRPC_VERSION_MAX_ALLOWED < JSONRPC_VERSION_3_28
+# define JSONRPC_AVAILABLE_IN_3_28                 JSONRPC_UNAVAILABLE(3, 28)
+#else
+# define JSONRPC_AVAILABLE_IN_3_28                 _JSONRPC_EXTERN
+#endif
+
+#endif /* JSONRPC_VERSION_MACROS_H */
diff --git a/src/meson.build b/src/meson.build
index c8b9c2d..36b21c9 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -47,17 +47,10 @@ libjsonrpc_glib_sources = [
   libjsonrpc_glib_public_sources,
 ]
 
-libjsonrpc_glib_link_args = []
-if ld_supports_version_script
-libjsonrpc_glib_link_args += ['-Wl,--version-script,' + join_paths(meson.current_source_dir(), 
'jsonrpc-glib.map')]
-endif
-
 libjsonrpc_glib = library(
   'jsonrpc_glib-' + apiversion,
   libjsonrpc_glib_sources,
 
-  link_depends: 'jsonrpc-glib.map',
-     link_args: libjsonrpc_glib_link_args,
   dependencies: libjsonrpc_glib_deps,
      soversion: soversion,
        version: libversion,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]