Skip to content

Commit 0d9e09c

Browse files
[C++] Allow using symbol visibility annotations also on non-Windows platforms
In GCC and clang the symbol visibility behavior of MSVC can be mirror using `-fvisibility=hidden`. This allows to more easily test that symbol visbility annotations work correctly and can potentially lead to smaller binaries. The default behavior on non-Windows platforms is not changed with this commit. See also https://gcc.gnu.org/wiki/Visibility Also fixes a tiny mistake where the _WIN32 macro was used to silence a MSVC warning where the _MSC_VER macro should have been used instead.
1 parent 99c7379 commit 0d9e09c

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

lang/c++/impl/json/JsonDom.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
namespace avro {
3333

34-
class AVRO_DECL InputStream;
34+
class InputStream;
3535

3636
namespace json {
3737
class Entity;

lang/c++/include/avro/Compiler.hh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626

2727
namespace avro {
2828

29-
class AVRO_DECL InputStream;
29+
class InputStream;
3030

3131
/// This class is used to implement an avro spec parser using a flex/bison
3232
/// compiler. In order for the lexer to be reentrant, this class provides a
3333
/// lexer object for each parse. The bison parser also uses this class to
3434
/// build up an avro parse tree as the avro spec is parsed.
3535

36-
class AVRO_DECL Name;
37-
class AVRO_DECL ValidSchema;
36+
class Name;
37+
class ValidSchema;
3838

3939
/// Given a stream containing a JSON schema, compiles the schema to a
4040
/// ValidSchema object. Throws if the schema cannot be compiled to a valid
@@ -60,7 +60,7 @@ AVRO_DECL ValidSchema compileJsonSchemaFromString(const std::string &input);
6060

6161
AVRO_DECL ValidSchema compileJsonSchemaFromFile(const char *filename);
6262

63-
AVRO_DECL ValidSchema compileJsonSchemaWithNamedReferences(std::istream &is,
63+
AVRO_DECL ValidSchema compileJsonSchemaWithNamedReferences(std::istream &is,
6464
const std::map<Name, ValidSchema> &namedReferences);
6565

6666
} // namespace avro

lang/c++/include/avro/Config.hh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,29 @@
2121

2222
// Windows DLL support
2323

24-
#ifdef _WIN32
24+
#ifdef _MSC_VER
2525
#pragma warning(disable : 4275 4251)
26+
#endif // _MSC_VER
27+
28+
#if defined _WIN32 || defined __CYGWIN__
29+
#define AVRO_DLL_EXPORT __declspec(dllexport)
30+
#define AVRO_DLL_IMPORT __declspec(dllimport)
31+
#define AVRO_DLL_HIDDEN
32+
#else
33+
#define AVRO_DLL_EXPORT [[gnu::visibility("default")]]
34+
#define AVRO_DLL_IMPORT [[gnu::visibility("default")]]
35+
#define AVRO_DLL_HIDDEN [[gnu::visibility("hidden")]]
36+
#endif // _WIN32 || __CYGWIN__
2637

27-
#if defined(AVRO_DYN_LINK)
38+
#ifdef AVRO_DYN_LINK
2839
#ifdef AVRO_SOURCE
29-
#define AVRO_DECL __declspec(dllexport)
40+
#define AVRO_DECL AVRO_DLL_EXPORT
3041
#else
31-
#define AVRO_DECL __declspec(dllimport)
42+
#define AVRO_DECL AVRO_DLL_IMPORT
3243
#endif // AVRO_SOURCE
3344
#endif // AVRO_DYN_LINK
3445

46+
#ifdef _WIN32
3547
#include <intsafe.h>
3648
using ssize_t = SSIZE_T;
3749
#endif // _WIN32

0 commit comments

Comments
 (0)