From 6a5b387387f250d9a34f9b6aba9b48545aaec9bc Mon Sep 17 00:00:00 2001 From: Isaac Saffold Date: Thu, 14 Sep 2023 20:28:56 -0400 Subject: [PATCH] now exporting symbols for error code singletons and exception subclasses --- websocketpp/common/symbol_export.hpp | 39 +++++++++++++++++++ websocketpp/error.hpp | 5 ++- websocketpp/extensions/extension.hpp | 3 +- .../extensions/permessage_deflate/enabled.hpp | 3 +- websocketpp/http/constants.hpp | 5 ++- websocketpp/transport/asio/base.hpp | 3 +- websocketpp/transport/base/connection.hpp | 3 +- websocketpp/transport/debug/base.hpp | 3 +- websocketpp/transport/iostream/base.hpp | 3 +- websocketpp/transport/stub/base.hpp | 3 +- 10 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 websocketpp/common/symbol_export.hpp diff --git a/websocketpp/common/symbol_export.hpp b/websocketpp/common/symbol_export.hpp new file mode 100644 index 000000000..9ee16c0c4 --- /dev/null +++ b/websocketpp/common/symbol_export.hpp @@ -0,0 +1,39 @@ +#ifndef WEBSOCKETPP_COMMON_SYMBOL_EXPORT_HPP +#define WEBSOCKETPP_COMMON_SYMBOL_EXPORT_HPP + +/** + * Defines `_WEBSOCKETPP_SYMBOL_EXPORT`, used to export certain symbols, such + * as exception types and `lib::error_category` singletons, that do not work + * correctly across shared library boundaries otherwise. + */ + +#if !defined(_WEBSOCKETPP_SYMBOL_EXPORT) && !defined(_WEBSOCKETPP_NO_SYMBOL_EXPORT) + // `_WEBSOCKETPP_SYMBOL_EXPORT` can be predefined, or an empty definition + // can be forced by defining `_WEBSOCKETPP_NO_SYMBOL_EXPORT`. + + #if defined(_WEBSOCKETPP_BOOST_SYMBOL_EXPORT) + // Just use `BOOST_SYMBOL_EXPORT` from Boost.Config . + + #include + #define _WEBSOCKETPP_SYMBOL_EXPORT BOOST_SYMBOL_EXPORT + + // The following is fairly portable, but there are some environments in + // which it might not work. If so, predefining `_WEBSOCKETPP_SYMBOL_EXPORT` + // or opting out entirely with `_WEBSOCKETPP_NO_SYMBOL_EXPORT` are viable + // alternatives. + #elif defined(__GNUC__) || defined(__clang__) + #if defined(_WIN32) || defined(__CYGWIN__) + #define _WEBSOCKETPP_SYMBOL_EXPORT __attribute__((dllexport)) + #else + #define _WEBSOCKETPP_SYMBOL_EXPORT __attribute__((visibility("default"))) + #endif + #elif defined(_WIN32) + #define _WEBSOCKETPP_SYMBOL_EXPORT __declspec(dllexport) + #endif +#endif + +#ifndef _WEBSOCKETPP_SYMBOL_EXPORT + #define _WEBSOCKETPP_SYMBOL_EXPORT +#endif + +#endif diff --git a/websocketpp/error.hpp b/websocketpp/error.hpp index 20f409dce..b2c8fee45 100644 --- a/websocketpp/error.hpp +++ b/websocketpp/error.hpp @@ -33,6 +33,7 @@ #include #include +#include #include namespace websocketpp { @@ -232,7 +233,7 @@ class category : public lib::error_category { } }; -inline const lib::error_category& get_category() { +inline _WEBSOCKETPP_SYMBOL_EXPORT const lib::error_category& get_category() { static category instance; return instance; } @@ -253,7 +254,7 @@ _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_ namespace websocketpp { -class exception : public std::exception { +class _WEBSOCKETPP_SYMBOL_EXPORT exception : public std::exception { public: exception(std::string const & msg, lib::error_code ec = make_error_code(error::general)) : m_msg(msg.empty() ? ec.message() : msg), m_code(ec) diff --git a/websocketpp/extensions/extension.hpp b/websocketpp/extensions/extension.hpp index f5fbd9f7b..bae7826bc 100644 --- a/websocketpp/extensions/extension.hpp +++ b/websocketpp/extensions/extension.hpp @@ -29,6 +29,7 @@ #define WEBSOCKETPP_EXTENSION_HPP #include +#include #include #include @@ -78,7 +79,7 @@ class category : public lib::error_category { } }; -inline lib::error_category const & get_category() { +inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() { static category instance; return instance; } diff --git a/websocketpp/extensions/permessage_deflate/enabled.hpp b/websocketpp/extensions/permessage_deflate/enabled.hpp index d05403a8a..da67a47e4 100644 --- a/websocketpp/extensions/permessage_deflate/enabled.hpp +++ b/websocketpp/extensions/permessage_deflate/enabled.hpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -149,7 +150,7 @@ class category : public lib::error_category { }; /// Get a reference to a static copy of the permessage-deflate error category -inline lib::error_category const & get_category() { +inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() { static category instance; return instance; } diff --git a/websocketpp/http/constants.hpp b/websocketpp/http/constants.hpp index 02382f101..50a914e77 100644 --- a/websocketpp/http/constants.hpp +++ b/websocketpp/http/constants.hpp @@ -34,6 +34,7 @@ #include #include +#include #include namespace websocketpp { @@ -297,7 +298,7 @@ inline std::string get_string(value code) { * HTTP error message, and a body to return with the HTTP * error response. */ -class exception : public std::exception { +class _WEBSOCKETPP_SYMBOL_EXPORT exception : public std::exception { public: exception(const std::string& log_msg, status_code::value error_code, @@ -435,7 +436,7 @@ class category : public lib::error_category { }; /// Get a reference to a static copy of the asio transport error category -inline lib::error_category const & get_category() { +inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() { static category instance; return instance; } diff --git a/websocketpp/transport/asio/base.hpp b/websocketpp/transport/asio/base.hpp index b945fe11f..983a6ca21 100644 --- a/websocketpp/transport/asio/base.hpp +++ b/websocketpp/transport/asio/base.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -208,7 +209,7 @@ class category : public lib::error_category { }; /// Get a reference to a static copy of the asio transport error category -inline lib::error_category const & get_category() { +inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() { static category instance; return instance; } diff --git a/websocketpp/transport/base/connection.hpp b/websocketpp/transport/base/connection.hpp index f76d40913..33d5462ab 100644 --- a/websocketpp/transport/base/connection.hpp +++ b/websocketpp/transport/base/connection.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -216,7 +217,7 @@ class category : public lib::error_category { } }; -inline lib::error_category const & get_category() { +inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() { static category instance; return instance; } diff --git a/websocketpp/transport/debug/base.hpp b/websocketpp/transport/debug/base.hpp index 2e477b501..0e0a89edd 100644 --- a/websocketpp/transport/debug/base.hpp +++ b/websocketpp/transport/debug/base.hpp @@ -30,6 +30,7 @@ #include #include +#include #include @@ -80,7 +81,7 @@ class category : public lib::error_category { }; /// Get a reference to a static copy of the debug transport error category -inline lib::error_category const & get_category() { +inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() { static category instance; return instance; } diff --git a/websocketpp/transport/iostream/base.hpp b/websocketpp/transport/iostream/base.hpp index f87839878..edac912d1 100644 --- a/websocketpp/transport/iostream/base.hpp +++ b/websocketpp/transport/iostream/base.hpp @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -109,7 +110,7 @@ class category : public lib::error_category { }; /// Get a reference to a static copy of the iostream transport error category -inline lib::error_category const & get_category() { +inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() { static category instance; return instance; } diff --git a/websocketpp/transport/stub/base.hpp b/websocketpp/transport/stub/base.hpp index 754981e29..eb083551a 100644 --- a/websocketpp/transport/stub/base.hpp +++ b/websocketpp/transport/stub/base.hpp @@ -29,6 +29,7 @@ #define WEBSOCKETPP_TRANSPORT_STUB_BASE_HPP #include +#include #include #include @@ -71,7 +72,7 @@ class category : public lib::error_category { }; /// Get a reference to a static copy of the stub transport error category -inline lib::error_category const & get_category() { +inline _WEBSOCKETPP_SYMBOL_EXPORT lib::error_category const & get_category() { static category instance; return instance; }