summaryrefslogtreecommitdiff
path: root/json-glib/json-version-macros.h
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2014-03-06 14:35:49 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2014-03-18 16:27:59 +0000
commit794664746dcbe8894255f9615357dd51f7f836c3 (patch)
tree05bc7f153bd80a904111d2aee0ada361bc32bc8f /json-glib/json-version-macros.h
parent50bf9cd2f6bc9fb21d9793377f0fd534732d215d (diff)
downloadjson-glib-794664746dcbe8894255f9615357dd51f7f836c3.tar.gz
Use compiler annotations to determine symbol visibility
Instead of relying on a separate file that requires being update every time we add a new public function we should use compiler annotations to let the linker know which symbols are public and exported. In order to achieve this we have to: * check for the visibility=hidden attribute * add -fvisibility=hidden to the linker flags * add a macro to annotate all public symbols While we're at it, we should copy the versioned symbols macro layout already used by GLib, GTK+, and other G* libraries, including the ability to express the range of allowed versions of JSON-GLib that third party code can compile against.
Diffstat (limited to 'json-glib/json-version-macros.h')
-rw-r--r--json-glib/json-version-macros.h135
1 files changed, 135 insertions, 0 deletions
diff --git a/json-glib/json-version-macros.h b/json-glib/json-version-macros.h
new file mode 100644
index 0000000..dd2ae1c
--- /dev/null
+++ b/json-glib/json-version-macros.h
@@ -0,0 +1,135 @@
+/* json-version-macros.h - JSON-GLib symbol versioning macros
+ *
+ * This file is part of JSON-GLib
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __JSON_VERSION_MACROS_H__
+#define __JSON_VERSION_MACROS_H__
+
+#if !defined(__JSON_GLIB_INSIDE__) && !defined(JSON_COMPILATION)
+#error "Only <json-glib/json-glib.h> can be included directly."
+#endif
+
+#include "json-version.h"
+
+#ifndef _JSON_EXTERN
+#define _JSON_EXTERN extern
+#endif
+
+#ifdef JSON_DISABLE_DEPRECATION_WARNINGS
+#define JSON_DEPRECATED _JSON_EXTERN
+#define JSON_DEPRECATED_FOR(f) _JSON_EXTERN
+#define JSON_UNAVAILABLE(maj,min) _JSON_EXTERN
+#else
+#define JSON_DEPRECATED G_DEPRECATED _JSON_EXTERN
+#define JSON_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _JSON_EXTERN
+#define JSON_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _JSON_EXTERN
+#endif
+
+/* XXX: Each new cycle should add a new version symbol here */
+#define JSON_VERSION_1_0 (G_ENCODE_VERSION (1, 0))
+
+/* evaluates to the current stable version; for development cycles,
+ * this means the next stable target
+ */
+#if (JSON_MINOR_VERSION == 99)
+#define JSON_VERSION_CUR_STABLE (G_ENCODE_VERSION (JSON_MAJOR_VERSION + 1, 0))
+#elif (JSON_MINOR_VERSION % 2)
+#define JSON_VERSION_CUR_STABLE (G_ENCODE_VERSION (JSON_MAJOR_VERSION, JSON_MINOR_VERSION + 1))
+#else
+#define JSON_VERSION_CUR_STABLE (G_ENCODE_VERSION (JSON_MAJOR_VERSION, JSON_MINOR_VERSION))
+#endif
+
+/* evaluates to the previous stable version */
+#if (JSON_MINOR_VERSION == 99)
+#define JSON_VERSION_PREV_STABLE (G_ENCODE_VERSION (JSON_MAJOR_VERSION + 1, 0))
+#elif (JSON_MINOR_VERSION % 2)
+#define JSON_VERSION_PREV_STABLE (G_ENCODE_VERSION (JSON_MAJOR_VERSION, JSON_MINOR_VERSION - 1))
+#else
+#define JSON_VERSION_PREV_STABLE (G_ENCODE_VERSION (JSON_MAJOR_VERSION, JSON_MINOR_VERSION - 2))
+#endif
+
+/**
+ * JSON_VERSION_MIN_REQUIRED:
+ *
+ * A macro that should be defined by the user prior to including
+ * the gdk.h header.
+ * The definition should be one of the predefined JSON version
+ * macros: %JSON_VERSION_1_0, %JSON_VERSION_1_2,...
+ *
+ * This macro defines the lower bound for the JSON-GLib API to use.
+ *
+ * If a function has been deprecated in a newer version of JSON-GLib,
+ * it is possible to use this symbol to avoid the compiler warnings
+ * without disabling warning for every deprecated function.
+ *
+ * Since: 1.0
+ */
+#ifndef JSON_VERSION_MIN_REQUIRED
+# define JSON_VERSION_MIN_REQUIRED (JSON_VERSION_CUR_STABLE)
+#endif
+
+/**
+ * JSON_VERSION_MAX_ALLOWED:
+ *
+ * A macro that should be defined by the user prior to including
+ * the json-glib.h header.
+
+ * The definition should be one of the predefined JSON-GLib version
+ * macros: %JSON_VERSION_1_0, %JSON_VERSION_1_2,...
+ *
+ * This macro defines the upper bound for the JSON API-GLib to use.
+ *
+ * If a function has been introduced in a newer version of JSON-GLib,
+ * it is possible to use this symbol to get compiler warnings when
+ * trying to use that function.
+ *
+ * Since: 1.0
+ */
+#ifndef JSON_VERSION_MAX_ALLOWED
+# if JSON_VERSION_MIN_REQUIRED > JSON_VERSION_PREV_STABLE
+# define JSON_VERSION_MAX_ALLOWED (JSON_VERSION_MIN_REQUIRED)
+# else
+# define JSON_VERSION_MAX_ALLOWED (JSON_VERSION_CUR_STABLE)
+# endif
+#endif
+
+/* sanity checks */
+#if JSON_VERSION_MAX_ALLOWED < JSON_VERSION_MIN_REQUIRED
+#error "JSON_VERSION_MAX_ALLOWED must be >= JSON_VERSION_MIN_REQUIRED"
+#endif
+#if JSON_VERSION_MIN_REQUIRED < JSON_VERSION_1_0
+#error "JSON_VERSION_MIN_REQUIRED must be >= JSON_VERSION_1_0"
+#endif
+
+/* XXX: Every new stable minor release should add a set of macros here */
+
+#if JSON_VERSION_MIN_REQUIRED >= JSON_VERSION_1_0
+# define JSON_DEPRECATED_IN_1_0 JSON_DEPRECATED
+# define JSON_DEPRECATED_IN_1_0_FOR(f) JSON_DEPRECATED_FOR(f)
+#else
+# define JSON_DEPRECATED_IN_1_0 _JSON_EXTERN
+# define JSON_DEPRECATED_IN_1_0_FOR(f) _JSON_EXTERN
+#endif
+
+#if JSON_VERSION_MAX_ALLOWED < JSON_VERSION_1_0
+# define JSON_AVAILABLE_IN_1_0 JSON_UNAVAILABLE(1, 0)
+#else
+# define JSON_AVAILABLE_IN_1_0 _JSON_EXTERN
+#endif
+
+#endif /* __JSON_VERSION_MACROS_H__ */