diff options
| author | krasimir <krasimir@chalmers.se> | 2017-04-12 10:24:56 +0000 |
|---|---|---|
| committer | krasimir <krasimir@chalmers.se> | 2017-04-12 10:24:56 +0000 |
| commit | a8eaa2f2e560547e63c7976960435e1ae23a22b1 (patch) | |
| tree | 06ce5fd0bc77a16113b5a53118843216fd3c1aea /src/runtime/c/gu | |
| parent | 915747efa793e53a7b7e9cfd861b4b4a46ace4a4 (diff) | |
a patch from Bjørnar Luteberget for compatibility with MSVC
Diffstat (limited to 'src/runtime/c/gu')
| -rw-r--r-- | src/runtime/c/gu/defs.c | 2 | ||||
| -rw-r--r-- | src/runtime/c/gu/defs.h | 20 | ||||
| -rw-r--r-- | src/runtime/c/gu/hash.c | 6 | ||||
| -rw-r--r-- | src/runtime/c/gu/hash.h | 6 | ||||
| -rw-r--r-- | src/runtime/c/gu/mem.c | 2 | ||||
| -rw-r--r-- | src/runtime/c/gu/seq.c | 2 | ||||
| -rw-r--r-- | src/runtime/c/gu/string.c | 8 | ||||
| -rw-r--r-- | src/runtime/c/gu/string.h | 6 | ||||
| -rw-r--r-- | src/runtime/c/gu/variant.c | 2 | ||||
| -rw-r--r-- | src/runtime/c/gu/variant.h | 2 |
10 files changed, 38 insertions, 18 deletions
diff --git a/src/runtime/c/gu/defs.c b/src/runtime/c/gu/defs.c index 2c3772b7c..5e78e797b 100644 --- a/src/runtime/c/gu/defs.c +++ b/src/runtime/c/gu/defs.c @@ -1,4 +1,4 @@ #include <gu/defs.h> void* const gu_null = NULL; -GuStruct* const gu_null_struct = NULL; +GU_API_DATA GuStruct* const gu_null_struct = NULL; diff --git a/src/runtime/c/gu/defs.h b/src/runtime/c/gu/defs.h index 51a2293e3..f302481d6 100644 --- a/src/runtime/c/gu/defs.h +++ b/src/runtime/c/gu/defs.h @@ -25,6 +25,24 @@ #ifndef GU_DEFS_H_ #define GU_DEFS_H_ +// MSVC requires explicit export/import of +// symbols in DLLs. CMake takes care of this +// for functions, but not for data/variables. +#if defined(_MSC_VER) +#if defined(COMPILING_GU) +#define GU_API_DATA_DECL __declspec(dllexport) +#define GU_API_DATA __declspec(dllexport) +#else +#define GU_API_DATA_DECL __declspec(dllimport) +#define GU_API_DATA ERROR_NOT_COMPILING_LIBGU +#endif + +#else +#define GU_API_DATA_DECL extern +#define GU_API_DATA +#endif +// end MSVC workaround + #include <stddef.h> #include <inttypes.h> #include <stdbool.h> @@ -154,7 +172,7 @@ extern void* const gu_null; // Dummy struct used for generic struct pointers typedef struct GuStruct GuStruct; -extern GuStruct* const gu_null_struct; +GU_API_DATA_DECL GuStruct* const gu_null_struct; typedef uintptr_t GuWord; diff --git a/src/runtime/c/gu/hash.c b/src/runtime/c/gu/hash.c index 1666263e6..0057d0f42 100644 --- a/src/runtime/c/gu/hash.c +++ b/src/runtime/c/gu/hash.c @@ -25,7 +25,7 @@ gu_int_hash_fn(GuHasher* self, const void* p) return (GuHash) *(const int*) p; } -GuHasher gu_int_hasher[1] = { +GU_API_DATA GuHasher gu_int_hasher[1] = { { { gu_int_eq_fn }, gu_int_hash_fn @@ -46,7 +46,7 @@ gu_addr_hash_fn(GuHasher* self, const void* p) return (GuHash) (uintptr_t) p; } -GuHasher gu_addr_hasher[1] = { +GU_API_DATA GuHasher gu_addr_hasher[1] = { { { gu_addr_eq_fn }, gu_addr_hash_fn @@ -69,7 +69,7 @@ gu_word_hash_fn(GuHasher* self, const void* p) return (GuHash) (uintptr_t) p; } -GuHasher gu_word_hasher[1] = { +GU_API_DATA GuHasher gu_word_hasher[1] = { { { gu_word_eq_fn }, gu_word_hash_fn diff --git a/src/runtime/c/gu/hash.h b/src/runtime/c/gu/hash.h index e16c2f454..da612f3f4 100644 --- a/src/runtime/c/gu/hash.h +++ b/src/runtime/c/gu/hash.h @@ -31,10 +31,10 @@ struct GuHasher { }; -extern GuHasher gu_int_hasher[1]; +GU_API_DATA GuHasher gu_int_hasher[1]; -extern GuHasher gu_addr_hasher[1]; +GU_API_DATA GuHasher gu_addr_hasher[1]; -extern GuHasher gu_word_hasher[1]; +GU_API_DATA GuHasher gu_word_hasher[1]; #endif // GU_HASH_H_ diff --git a/src/runtime/c/gu/mem.c b/src/runtime/c/gu/mem.c index 0fc315a4f..325eaea77 100644 --- a/src/runtime/c/gu/mem.c +++ b/src/runtime/c/gu/mem.c @@ -8,7 +8,9 @@ #include <sys/mman.h> #include <sys/stat.h> #endif +#if !defined(_MSC_VER) #include <unistd.h> +#endif #include <fcntl.h> #ifdef USE_VALGRIND diff --git a/src/runtime/c/gu/seq.c b/src/runtime/c/gu/seq.c index 88b762a04..8cf55929b 100644 --- a/src/runtime/c/gu/seq.c +++ b/src/runtime/c/gu/seq.c @@ -3,7 +3,7 @@ #include <gu/fun.h> #include <gu/assert.h> #include <stdlib.h> -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) #include <malloc.h> #endif diff --git a/src/runtime/c/gu/string.c b/src/runtime/c/gu/string.c index 5a31c8806..3e754a72c 100644 --- a/src/runtime/c/gu/string.c +++ b/src/runtime/c/gu/string.c @@ -5,7 +5,7 @@ #include <gu/utf8.h> #include <gu/assert.h> #include <stdlib.h> -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) #include <malloc.h> #endif @@ -273,7 +273,7 @@ gu_string_eq_fn(GuEquality* self, const void* p1, const void* p2) return strcmp((GuString) p1, (GuString) p2) == 0; } -GuEquality gu_string_equality[1] = { { gu_string_eq_fn } }; +GU_API_DATA GuEquality gu_string_equality[1] = { { gu_string_eq_fn } }; static int gu_string_cmp_fn(GuOrder* self, const void* p1, const void* p2) @@ -282,7 +282,7 @@ gu_string_cmp_fn(GuOrder* self, const void* p1, const void* p2) return strcmp((GuString) p1, (GuString) p2); } -GuOrder gu_string_order[1] = { { gu_string_cmp_fn } }; +GU_API_DATA GuOrder gu_string_order[1] = { { gu_string_cmp_fn } }; static GuHash gu_string_hasher_hash(GuHasher* self, const void* p) @@ -291,7 +291,7 @@ gu_string_hasher_hash(GuHasher* self, const void* p) return gu_string_hash(0, (GuString) p); } -GuHasher gu_string_hasher[1] = { +GU_API_DATA GuHasher gu_string_hasher[1] = { { .eq = { gu_string_eq_fn }, .hash = gu_string_hasher_hash diff --git a/src/runtime/c/gu/string.h b/src/runtime/c/gu/string.h index 4064286a9..2bf1aef45 100644 --- a/src/runtime/c/gu/string.h +++ b/src/runtime/c/gu/string.h @@ -58,9 +58,9 @@ gu_string_is_prefix(GuString s1, GuString s2); #if defined(GU_FUN_H_) && !defined(GU_STRING_H_FUN_) #define GU_STRING_H_FUN_ -extern GuEquality gu_string_equality[1]; +GU_API_DATA GuEquality gu_string_equality[1]; -extern GuOrder gu_string_order[1]; +GU_API_DATA GuOrder gu_string_order[1]; #endif #if defined(GU_HASH_H_) && !defined(GU_STRING_H_HASH_) @@ -69,7 +69,7 @@ extern GuOrder gu_string_order[1]; GuHash gu_string_hash(GuHash h, GuString s); -extern GuHasher gu_string_hasher[1]; +GU_API_DATA GuHasher gu_string_hasher[1]; #endif #if defined(GU_SEQ_H_) && !defined(GU_STRING_H_SEQ_) diff --git a/src/runtime/c/gu/variant.c b/src/runtime/c/gu/variant.c index dd4149429..75b75c086 100644 --- a/src/runtime/c/gu/variant.c +++ b/src/runtime/c/gu/variant.c @@ -108,4 +108,4 @@ gu_variant_intval(GuVariant variant) return (variant / GU_VARIANT_ALIGNMENT); } -const GuVariant gu_null_variant = { (GuWord) NULL }; +GU_API_DATA const GuVariant gu_null_variant = { (GuWord) NULL }; diff --git a/src/runtime/c/gu/variant.h b/src/runtime/c/gu/variant.h index a4c24b4af..8e7741694 100644 --- a/src/runtime/c/gu/variant.h +++ b/src/runtime/c/gu/variant.h @@ -97,7 +97,7 @@ gu_variant_from_ptr(const void* p) return (uintptr_t) p; } -extern const GuVariant gu_null_variant; +GU_API_DATA const GuVariant gu_null_variant; static inline bool gu_variant_is_null(GuVariant v) { |
