From a4c08e997e9b53fe884179963730459dd8c6cd01 Mon Sep 17 00:00:00 2001 From: maxirmx Date: Sun, 25 Jun 2023 18:22:05 +0300 Subject: [PATCH] Added symbol visibility filter for shared library --- CMakeLists.txt | 5 +++++ include/sexpp/ext-key-format.h | 7 ++++--- include/sexpp/sexp-error.h | 8 +++++--- include/sexpp/sexp-public.h | 30 ++++++++++++++++++++++++++++++ include/sexpp/sexp.h | 19 +++++++++++-------- src/ext-key-format.cpp | 2 +- src/sexp-char-defs.cpp | 2 +- src/sexp-depth-manager.cpp | 2 +- src/sexp-error.cpp | 2 +- src/sexp-input.cpp | 2 +- src/sexp-main.cpp | 2 +- src/sexp-object.cpp | 2 +- src/sexp-output.cpp | 2 +- src/sexp-simple-string.cpp | 2 +- 14 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 include/sexpp/sexp-public.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d88547e..9ac363c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,6 +130,11 @@ target_include_directories(sexpp PUBLIC $ ) +if (BUILD_SHARED_LIBS) + target_compile_definitions(sexpp PUBLIC BUILD_SHARED_LIBS) + set_target_properties(sexpp PROPERTIES CXX_VISIBILITY_PRESET "hidden") +endif (BUILD_SHARED_LIBS) + set_target_properties(sexpp PROPERTIES POSITION_INDEPENDENT_CODE ON RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" diff --git a/include/sexpp/ext-key-format.h b/include/sexpp/ext-key-format.h index 1fcaf49..bef746f 100644 --- a/include/sexpp/ext-key-format.h +++ b/include/sexpp/ext-key-format.h @@ -25,16 +25,17 @@ #include +#include "sexp-public.h" #include "sexp.h" namespace ext_key_format { -void ext_key_error( +void SEXP_PUBLIC_SYMBOL ext_key_error( sexp::sexp_exception_t::severity level, const char *msg, size_t c1, size_t c2, int pos); class ext_key_input_stream_t; -class extended_private_key_t { +class SEXP_PUBLIC_SYMBOL extended_private_key_t { public: // Comparison of names is done case insensitively !!! struct ci_less { @@ -68,7 +69,7 @@ class extended_private_key_t { void parse(ext_key_input_stream_t &is); }; -class ext_key_input_stream_t : public sexp::sexp_input_stream_t { +class SEXP_PUBLIC_SYMBOL ext_key_input_stream_t : public sexp::sexp_input_stream_t { private: static const bool namechar[256]; /* true if allowed in the name field */ diff --git a/include/sexpp/sexp-error.h b/include/sexpp/sexp-error.h index 58bd780..3ed345f 100644 --- a/include/sexpp/sexp-error.h +++ b/include/sexpp/sexp-error.h @@ -28,9 +28,11 @@ #include #include +#include "sexp-public.h" + namespace sexp { -class sexp_exception_t : public std::exception { +class SEXP_PUBLIC_SYMBOL sexp_exception_t : public std::exception { public: enum severity { error = 0, warning = 1 }; @@ -65,7 +67,7 @@ class sexp_exception_t : public std::exception { static void set_interactive(bool new_interactive) { interactive = new_interactive; }; }; -void sexp_error( - sexp_exception_t::severity level, const char *msg, size_t c1, size_t c2, int pos); +void SEXP_PUBLIC_SYMBOL +sexp_error(sexp_exception_t::severity level, const char *msg, size_t c1, size_t c2, int pos); } // namespace sexp diff --git a/include/sexpp/sexp-public.h b/include/sexpp/sexp-public.h new file mode 100644 index 0000000..ab0674e --- /dev/null +++ b/include/sexpp/sexp-public.h @@ -0,0 +1,30 @@ +/** + * + * Copyright 2023 Ribose Inc. (https://www.ribose.com) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#pragma once + +#ifdef BUILD_SHARED_LIBS +#define SEXP_PUBLIC_SYMBOL __attribute__((visibility("default"))) +#else +#define SEXP_PUBLIC_SYMBOL +#endif diff --git a/include/sexpp/sexp.h b/include/sexpp/sexp.h index d97a45e..bb6ae4e 100644 --- a/include/sexpp/sexp.h +++ b/include/sexpp/sexp.h @@ -41,6 +41,7 @@ #include #include +#include "sexp-public.h" #include "sexp-error.h" namespace sexp { @@ -51,7 +52,7 @@ namespace sexp { * However, we do enforce 'C' locale this way */ -class sexp_char_defs_t { +class SEXP_PUBLIC_SYMBOL sexp_char_defs_t { protected: static const bool base64digit[256]; /* true if c is base64 digit */ static const bool tokenchar[256]; /* true if c can be in a token */ @@ -100,7 +101,8 @@ class sexp_input_stream_t; typedef uint8_t octet_t; -class sexp_simple_string_t : public std::basic_string, private sexp_char_defs_t { +class SEXP_PUBLIC_SYMBOL sexp_simple_string_t : public std::basic_string, + private sexp_char_defs_t { public: sexp_simple_string_t(void) = default; sexp_simple_string_t(const octet_t *dt) : std::basic_string{dt} {} @@ -161,7 +163,7 @@ inline bool operator!=(const sexp_simple_string_t *left, const std::string &righ * SEXP object */ -class sexp_object_t { +class SEXP_PUBLIC_SYMBOL sexp_object_t { public: virtual ~sexp_object_t(){}; @@ -201,7 +203,7 @@ class sexp_object_t { * SEXP string */ -class sexp_string_t : public sexp_object_t { +class SEXP_PUBLIC_SYMBOL sexp_string_t : public sexp_object_t { protected: bool with_presentation_hint; sexp_simple_string_t presentation_hint; @@ -265,7 +267,8 @@ inline bool operator!=(const sexp_string_t *left, const std::string &right) noex * SEXP list */ -class sexp_list_t : public sexp_object_t, public std::vector> { +class SEXP_PUBLIC_SYMBOL sexp_list_t : public sexp_object_t, + public std::vector> { public: virtual ~sexp_list_t() {} @@ -299,7 +302,7 @@ class sexp_list_t : public sexp_object_t, public std::vector +#include "sexpp/ext-key-format.h" using namespace sexp; diff --git a/src/sexp-char-defs.cpp b/src/sexp-char-defs.cpp index 0dd7011..f31b62d 100644 --- a/src/sexp-char-defs.cpp +++ b/src/sexp-char-defs.cpp @@ -26,7 +26,7 @@ * 7/21/1997 */ -#include +#include "sexpp/sexp.h" namespace sexp { diff --git a/src/sexp-depth-manager.cpp b/src/sexp-depth-manager.cpp index 6694cb6..2f26e27 100644 --- a/src/sexp-depth-manager.cpp +++ b/src/sexp-depth-manager.cpp @@ -21,7 +21,7 @@ * **/ -#include +#include "sexpp/sexp.h" namespace sexp { diff --git a/src/sexp-error.cpp b/src/sexp-error.cpp index ad1458d..3558f02 100644 --- a/src/sexp-error.cpp +++ b/src/sexp-error.cpp @@ -21,7 +21,7 @@ * */ -#include +#include "sexpp/sexp-error.h" namespace sexp { diff --git a/src/sexp-input.cpp b/src/sexp-input.cpp index 2508331..cb21686 100644 --- a/src/sexp-input.cpp +++ b/src/sexp-input.cpp @@ -26,7 +26,7 @@ * 7/21/1997 */ -#include +#include "sexpp/sexp.h" namespace sexp { diff --git a/src/sexp-main.cpp b/src/sexp-main.cpp index 937fa4c..46fae63 100644 --- a/src/sexp-main.cpp +++ b/src/sexp-main.cpp @@ -28,7 +28,7 @@ #include -#include +#include "sexpp/sexp.h" using namespace sexp; diff --git a/src/sexp-object.cpp b/src/sexp-object.cpp index 0099d19..d01ae11 100644 --- a/src/sexp-object.cpp +++ b/src/sexp-object.cpp @@ -26,7 +26,7 @@ * 5/5/1997 */ -#include +#include "sexpp/sexp.h" namespace sexp { diff --git a/src/sexp-output.cpp b/src/sexp-output.cpp index f1acd13..07b476c 100644 --- a/src/sexp-output.cpp +++ b/src/sexp-output.cpp @@ -26,7 +26,7 @@ * 5/5/1997 */ -#include +#include "sexpp/sexp.h" namespace sexp { diff --git a/src/sexp-simple-string.cpp b/src/sexp-simple-string.cpp index ad585f0..0e4c869 100644 --- a/src/sexp-simple-string.cpp +++ b/src/sexp-simple-string.cpp @@ -26,7 +26,7 @@ * 5/5/1997 */ -#include +#include "sexpp/sexp.h" namespace sexp { /*