Skip to content

Commit

Permalink
Added symbol visibility filter for shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Jun 25, 2023
1 parent 9de4bba commit c6df67f
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ target_include_directories(sexpp PUBLIC
$<INSTALL_INTERFACE:include>
)

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"
Expand Down
7 changes: 4 additions & 3 deletions include/sexpp/ext-key-format.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@

#include <map>

#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 {
Expand Down Expand Up @@ -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 */

Expand Down
8 changes: 5 additions & 3 deletions include/sexpp/sexp-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
#include <iostream>
#include <string>

#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 };

Expand Down Expand Up @@ -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
30 changes: 30 additions & 0 deletions include/sexpp/sexp-public.h
Original file line number Diff line number Diff line change
@@ -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
19 changes: 11 additions & 8 deletions include/sexpp/sexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <vector>
#include <cassert>

#include "sexp-public.h"
#include "sexp-error.h"

namespace sexp {
Expand All @@ -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 */
Expand Down Expand Up @@ -100,7 +101,8 @@ class sexp_input_stream_t;

typedef uint8_t octet_t;

class sexp_simple_string_t : public std::basic_string<octet_t>, private sexp_char_defs_t {
class SEXP_PUBLIC_SYMBOL sexp_simple_string_t : public std::basic_string<octet_t>,
private sexp_char_defs_t {
public:
sexp_simple_string_t(void) = default;
sexp_simple_string_t(const octet_t *dt) : std::basic_string<octet_t>{dt} {}
Expand Down Expand Up @@ -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(){};

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::shared_ptr<sexp_object_t>> {
class SEXP_PUBLIC_SYMBOL sexp_list_t : public sexp_object_t,
public std::vector<std::shared_ptr<sexp_object_t>> {
public:
virtual ~sexp_list_t() {}

Expand Down Expand Up @@ -299,7 +302,7 @@ class sexp_list_t : public sexp_object_t, public std::vector<std::shared_ptr<sex
One still can create an object with deeper nesting manually
*/

class sexp_depth_manager {
class SEXP_PUBLIC_SYMBOL sexp_depth_manager {
public:
static const size_t DEFAULT_MAX_DEPTH = 1024;

Expand All @@ -317,7 +320,7 @@ class sexp_depth_manager {
* SEXP input stream
*/

class sexp_input_stream_t : public sexp_char_defs_t, sexp_depth_manager {
class SEXP_PUBLIC_SYMBOL sexp_input_stream_t : public sexp_char_defs_t, sexp_depth_manager {
protected:
std::istream *input_file;
uint32_t byte_size; /* 4 or 6 or 8 == currently scanning mode */
Expand Down Expand Up @@ -362,7 +365,7 @@ class sexp_input_stream_t : public sexp_char_defs_t, sexp_depth_manager {
* SEXP output stream
*/

class sexp_output_stream_t : sexp_depth_manager {
class SEXP_PUBLIC_SYMBOL sexp_output_stream_t : sexp_depth_manager {
public:
const uint32_t default_line_length = 75;
enum sexp_print_mode { /* PRINTING MODES */
Expand Down
2 changes: 1 addition & 1 deletion src/ext-key-format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/

#include <sexpp/ext-key-format.h>
#include "sexpp/ext-key-format.h"

using namespace sexp;

Expand Down
2 changes: 1 addition & 1 deletion src/sexp-char-defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* 7/21/1997
*/

#include <sexpp/sexp.h>
#include "sexpp/sexp.h"

namespace sexp {

Expand Down
2 changes: 1 addition & 1 deletion src/sexp-depth-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
**/

#include <sexpp/sexp.h>
#include "sexpp/sexp.h"

namespace sexp {

Expand Down
2 changes: 1 addition & 1 deletion src/sexp-error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/

#include <sexpp/sexp-error.h>
#include "sexpp/sexp-error.h"

namespace sexp {

Expand Down
2 changes: 1 addition & 1 deletion src/sexp-input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* 7/21/1997
*/

#include <sexpp/sexp.h>
#include "sexpp/sexp.h"

namespace sexp {

Expand Down
2 changes: 1 addition & 1 deletion src/sexp-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include <fstream>

#include <sexpp/sexp.h>
#include "sexpp/sexp.h"

using namespace sexp;

Expand Down
2 changes: 1 addition & 1 deletion src/sexp-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* 5/5/1997
*/

#include <sexpp/sexp.h>
#include "sexpp/sexp.h"

namespace sexp {

Expand Down
2 changes: 1 addition & 1 deletion src/sexp-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* 5/5/1997
*/

#include <sexpp/sexp.h>
#include "sexpp/sexp.h"

namespace sexp {

Expand Down
2 changes: 1 addition & 1 deletion src/sexp-simple-string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* 5/5/1997
*/

#include <sexpp/sexp.h>
#include "sexpp/sexp.h"

namespace sexp {
/*
Expand Down

0 comments on commit c6df67f

Please sign in to comment.