diff --git a/CMakeLists.txt b/CMakeLists.txt index c7e1d47e..ccfdde2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,9 +211,9 @@ IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" ST ENDIF () IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - STRING(REGEX REPLACE "/W[0-4]" "/W4 /wd4127 /wd4310" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + STRING(REGEX REPLACE "/W[0-4]" "/W3 /wd4290 /wd4309" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") ELSE () - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /wd4127 /wd4310") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /wd4290 /wd4309") ENDIF () ENDIF () diff --git a/include/msgpack/object.h b/include/msgpack/object.h index 3d0d1225..6f86cd19 100644 --- a/include/msgpack/object.h +++ b/include/msgpack/object.h @@ -97,9 +97,10 @@ typedef struct msgpack_object_kv { msgpack_object val; } msgpack_object_kv; - +MSGPACK_DLLEXPORT void msgpack_object_print(FILE* out, msgpack_object o); +MSGPACK_DLLEXPORT bool msgpack_object_equal(const msgpack_object x, const msgpack_object y); /** @} */ diff --git a/include/msgpack/sysdep.h b/include/msgpack/sysdep.h index 5b8a739e..ebbd6c88 100644 --- a/include/msgpack/sysdep.h +++ b/include/msgpack/sysdep.h @@ -36,6 +36,12 @@ typedef unsigned __int64 uint64_t; #include #endif +#if defined(_MSC_VER) +#define MSGPACK_DLLEXPORT __declspec(dllexport) +#else /* _MSC_VER */ +#define MSGPACK_DLLEXPORT +#endif /* _MSC_VER */ + #ifdef _WIN32 #define _msgpack_atomic_counter_header typedef long _msgpack_atomic_counter_t; diff --git a/include/msgpack/unpack.h b/include/msgpack/unpack.h index 66b0b0f6..01bfbcb4 100644 --- a/include/msgpack/unpack.h +++ b/include/msgpack/unpack.h @@ -47,6 +47,7 @@ typedef enum { } msgpack_unpack_return; +MSGPACK_DLLEXPORT msgpack_unpack_return msgpack_unpack_next(msgpack_unpacked* result, const char* data, size_t len, size_t* off); @@ -80,11 +81,13 @@ typedef struct msgpack_unpacker { * Initializes a streaming deserializer. * The initialized deserializer must be destroyed by msgpack_unpacker_destroy(msgpack_unpacker*). */ +MSGPACK_DLLEXPORT bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size); /** * Destroys a streaming deserializer initialized by msgpack_unpacker_init(msgpack_unpacker*, size_t). */ +MSGPACK_DLLEXPORT void msgpack_unpacker_destroy(msgpack_unpacker* mpac); @@ -92,11 +95,13 @@ void msgpack_unpacker_destroy(msgpack_unpacker* mpac); * Creates a streaming deserializer. * The created deserializer must be destroyed by msgpack_unpacker_free(msgpack_unpacker*). */ +MSGPACK_DLLEXPORT msgpack_unpacker* msgpack_unpacker_new(size_t initial_buffer_size); /** * Frees a streaming deserializer created by msgpack_unpacker_new(size_t). */ +MSGPACK_DLLEXPORT void msgpack_unpacker_free(msgpack_unpacker* mpac); @@ -146,6 +151,7 @@ static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, si * Returns true if it successes. Otherwise false is returned. * @param pac pointer to an initialized msgpack_unpacked object. */ +MSGPACK_DLLEXPORT msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* pac); /** @@ -168,14 +174,19 @@ static inline void msgpack_unpacked_destroy(msgpack_unpacked* result); static inline msgpack_zone* msgpack_unpacked_release_zone(msgpack_unpacked* result); +MSGPACK_DLLEXPORT int msgpack_unpacker_execute(msgpack_unpacker* mpac); +MSGPACK_DLLEXPORT msgpack_object msgpack_unpacker_data(msgpack_unpacker* mpac); +MSGPACK_DLLEXPORT msgpack_zone* msgpack_unpacker_release_zone(msgpack_unpacker* mpac); +MSGPACK_DLLEXPORT void msgpack_unpacker_reset_zone(msgpack_unpacker* mpac); +MSGPACK_DLLEXPORT void msgpack_unpacker_reset(msgpack_unpacker* mpac); static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac); @@ -185,6 +196,7 @@ static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac) // obsolete +MSGPACK_DLLEXPORT msgpack_unpack_return msgpack_unpack(const char* data, size_t len, size_t* off, msgpack_zone* result_zone, msgpack_object* result); @@ -194,8 +206,10 @@ msgpack_unpack(const char* data, size_t len, size_t* off, static inline size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac); +MSGPACK_DLLEXPORT bool msgpack_unpacker_flush_zone(msgpack_unpacker* mpac); +MSGPACK_DLLEXPORT bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size); static inline bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size) diff --git a/include/msgpack/version.h b/include/msgpack/version.h index 233fa818..85471ba8 100644 --- a/include/msgpack/version.h +++ b/include/msgpack/version.h @@ -22,9 +22,11 @@ extern "C" { #endif - +MSGPACK_DLLEXPORT const char* msgpack_version(void); +MSGPACK_DLLEXPORT int msgpack_version_major(void); +MSGPACK_DLLEXPORT int msgpack_version_minor(void); #include "version_master.h" diff --git a/include/msgpack/vrefbuffer.h b/include/msgpack/vrefbuffer.h index e16e9051..4bc53b96 100644 --- a/include/msgpack/vrefbuffer.h +++ b/include/msgpack/vrefbuffer.h @@ -70,8 +70,10 @@ typedef struct msgpack_vrefbuffer { #define MSGPACK_VREFBUFFER_CHUNK_SIZE 8192 #endif +MSGPACK_DLLEXPORT bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf, size_t ref_size, size_t chunk_size); +MSGPACK_DLLEXPORT void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf); static inline msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size); @@ -82,14 +84,18 @@ static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t l static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref); static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref); +MSGPACK_DLLEXPORT int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf, const char* buf, size_t len); +MSGPACK_DLLEXPORT int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf, const char* buf, size_t len); +MSGPACK_DLLEXPORT int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to); +MSGPACK_DLLEXPORT void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vref); /** @} */ diff --git a/include/msgpack/zone.h b/include/msgpack/zone.h index 177750af..05e6bc8d 100644 --- a/include/msgpack/zone.h +++ b/include/msgpack/zone.h @@ -61,10 +61,14 @@ typedef struct msgpack_zone { #define MSGPACK_ZONE_CHUNK_SIZE 8192 #endif +MSGPACK_DLLEXPORT bool msgpack_zone_init(msgpack_zone* zone, size_t chunk_size); +MSGPACK_DLLEXPORT void msgpack_zone_destroy(msgpack_zone* zone); +MSGPACK_DLLEXPORT msgpack_zone* msgpack_zone_new(size_t chunk_size); +MSGPACK_DLLEXPORT void msgpack_zone_free(msgpack_zone* zone); static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size); @@ -75,8 +79,10 @@ static inline bool msgpack_zone_push_finalizer(msgpack_zone* zone, static inline void msgpack_zone_swap(msgpack_zone* a, msgpack_zone* b); +MSGPACK_DLLEXPORT bool msgpack_zone_is_empty(msgpack_zone* zone); +MSGPACK_DLLEXPORT void msgpack_zone_clear(msgpack_zone* zone); /** @} */ @@ -86,6 +92,7 @@ void msgpack_zone_clear(msgpack_zone* zone); #define MSGPACK_ZONE_ALIGN sizeof(int) #endif +MSGPACK_DLLEXPORT void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size); void* msgpack_zone_malloc_no_align(msgpack_zone* zone, size_t size) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 59bf41d8..028f8be8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -55,9 +55,9 @@ FOREACH (source_file ${check_PROGRAMS}) ENDIF () IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + STRING(REGEX REPLACE "/W[0-4]" "/W3 /wd4290 /wd4309" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") ELSE () - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /wd4290 /wd4309") ENDIF () ENDIF () ENDFOREACH () diff --git a/test/msgpack_basic.cpp b/test/msgpack_basic.cpp index 210a6c5a..56087de8 100644 --- a/test/msgpack_basic.cpp +++ b/test/msgpack_basic.cpp @@ -11,6 +11,12 @@ #include +#if defined(_MSC_VER) +#define msgpack_rand() ((double)rand() / RAND_MAX) +#else // _MSC_VER +#define msgpack_rand() drand48() +#endif // _MSC_VER + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -147,11 +153,20 @@ TEST(MSGPACK, simple_buffer_float) v.push_back(numeric_limits::min()); v.push_back(numeric_limits::max()); v.push_back(nanf("tag")); - v.push_back(1.0/0.0); // inf - v.push_back(-(1.0/0.0)); // -inf + if (numeric_limits::has_infinity) { + v.push_back(numeric_limits::infinity()); + v.push_back(-numeric_limits::infinity()); + } + if (numeric_limits::has_quiet_NaN) { + v.push_back(numeric_limits::quiet_NaN()); + } + if (numeric_limits::has_signaling_NaN) { + v.push_back(numeric_limits::signaling_NaN()); + } + for (unsigned int i = 0; i < kLoop; i++) { - v.push_back(drand48()); - v.push_back(-drand48()); + v.push_back(static_cast(msgpack_rand())); + v.push_back(static_cast(-msgpack_rand())); } for (unsigned int i = 0; i < v.size() ; i++) { msgpack::sbuffer sbuf; @@ -227,11 +242,24 @@ TEST(MSGPACK, simple_buffer_double) v.push_back(numeric_limits::min()); v.push_back(numeric_limits::max()); v.push_back(nanf("tag")); - v.push_back(1.0/0.0); // inf - v.push_back(-(1.0/0.0)); // -inf + if (numeric_limits::has_infinity) { + v.push_back(numeric_limits::infinity()); + v.push_back(-numeric_limits::infinity()); + } + if (numeric_limits::has_quiet_NaN) { + v.push_back(numeric_limits::quiet_NaN()); + } + if (numeric_limits::has_signaling_NaN) { + v.push_back(numeric_limits::signaling_NaN()); + } for (unsigned int i = 0; i < kLoop; i++) { - v.push_back(drand48()); - v.push_back(-drand48()); + v.push_back(msgpack_rand()); + v.push_back(-msgpack_rand()); + } + + for (unsigned int i = 0; i < kLoop; i++) { + v.push_back(msgpack_rand()); + v.push_back(-msgpack_rand()); } for (unsigned int i = 0; i < v.size() ; i++) { msgpack::sbuffer sbuf; diff --git a/test/msgpack_c.cpp b/test/msgpack_c.cpp index 7d832002..d710d185 100644 --- a/test/msgpack_c.cpp +++ b/test/msgpack_c.cpp @@ -6,6 +6,12 @@ #include +#if defined(_MSC_VER) +#define msgpack_rand() ((double)rand() / RAND_MAX) +#else // _MSC_VER +#define msgpack_rand() drand48() +#endif // _MSC_VER + using namespace std; const unsigned int kLoop = 10000; @@ -188,11 +194,20 @@ TEST(MSGPACKC, simple_buffer_float) v.push_back(numeric_limits::min()); v.push_back(numeric_limits::max()); v.push_back(nanf("tag")); - v.push_back(1.0/0.0); // inf - v.push_back(-(1.0/0.0)); // -inf + if (numeric_limits::has_infinity) { + v.push_back(numeric_limits::infinity()); + v.push_back(-numeric_limits::infinity()); + } + if (numeric_limits::has_quiet_NaN) { + v.push_back(numeric_limits::quiet_NaN()); + } + if (numeric_limits::has_signaling_NaN) { + v.push_back(numeric_limits::signaling_NaN()); + } + for (unsigned int i = 0; i < kLoop; i++) { - v.push_back(drand48()); - v.push_back(-drand48()); + v.push_back(static_cast(msgpack_rand())); + v.push_back(static_cast(-msgpack_rand())); } for (unsigned int i = 0; i < v.size() ; i++) { @@ -230,11 +245,19 @@ TEST(MSGPACKC, simple_buffer_double) v.push_back(numeric_limits::min()); v.push_back(numeric_limits::max()); v.push_back(nan("tag")); - v.push_back(1.0/0.0); // inf - v.push_back(-(1.0/0.0)); // -inf + if (numeric_limits::has_infinity) { + v.push_back(numeric_limits::infinity()); + v.push_back(-numeric_limits::infinity()); + } + if (numeric_limits::has_quiet_NaN) { + v.push_back(numeric_limits::quiet_NaN()); + } + if (numeric_limits::has_signaling_NaN) { + v.push_back(numeric_limits::signaling_NaN()); + } for (unsigned int i = 0; i < kLoop; i++) { - v.push_back(drand48()); - v.push_back(-drand48()); + v.push_back(msgpack_rand()); + v.push_back(-msgpack_rand()); } for (unsigned int i = 0; i < v.size() ; i++) {