From ff0c05b8f13f4f8a1da82ef1337d594916ef9df9 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Sun, 29 Apr 2012 22:09:29 +0300 Subject: [PATCH] Support building on Windows Jansson now builds correctly with Visual C++ Express 2010. --- src/dump.c | 4 +- src/error.c | 1 + src/hashtable.c | 2 +- src/jansson.def | 65 +++++++++++++++++++++++++++ src/jansson.h | 2 +- src/jansson_config.h.win32 | 2 +- src/jansson_private.h | 6 +++ src/load.c | 9 +++- src/memory.c | 2 +- src/pack_unpack.c | 4 +- src/value.c | 4 +- test/suites/api/check-exports | 100 ++++-------------------------------------- 12 files changed, 99 insertions(+), 102 deletions(-) create mode 100644 src/jansson.def diff --git a/src/dump.c b/src/dump.c index e39197a..4251104 100644 --- a/src/dump.c +++ b/src/dump.c @@ -11,7 +11,7 @@ #include #include -#include +#include "jansson.h" #include "jansson_private.h" #include "strbuffer.h" #include "utf.h" @@ -186,7 +186,7 @@ static int do_dump(const json_t *json, size_t flags, int depth, size = snprintf(buffer, MAX_INTEGER_STR_LENGTH, "%" JSON_INTEGER_FORMAT, json_integer_value(json)); - if(size >= MAX_INTEGER_STR_LENGTH) + if(size < 0 || size >= MAX_INTEGER_STR_LENGTH) return -1; return dump(buffer, size, data); diff --git a/src/error.c b/src/error.c index a7c8cbb..a544a59 100644 --- a/src/error.c +++ b/src/error.c @@ -59,4 +59,5 @@ void jsonp_error_vset(json_error_t *error, int line, int column, error->position = position; vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap); + error->text[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; } diff --git a/src/hashtable.c b/src/hashtable.c index 76cf69b..fce7550 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -7,7 +7,7 @@ #include #include -#include /* for JSON_INLINE */ +#include "jansson_config.h" /* for JSON_INLINE */ #include "jansson_private.h" /* for container_of() */ #include "hashtable.h" diff --git a/src/jansson.def b/src/jansson.def new file mode 100644 index 0000000..6b2c8a7 --- /dev/null +++ b/src/jansson.def @@ -0,0 +1,65 @@ +LIBRARY "jansson" + +EXPORTS + json_delete + json_true + json_false + json_null + json_string + json_string_nocheck + json_string_value + json_string_set + json_string_set_nocheck + json_integer + json_integer_value + json_integer_set + json_real + json_real_value + json_real_set + json_number_value + json_array + json_array_size + json_array_get + json_array_set_new + json_array_append_new + json_array_insert_new + json_array_remove + json_array_clear + json_array_extend + json_object + json_object_size + json_object_get + json_object_set_new + json_object_set_new_nocheck + json_object_del + json_object_clear + json_object_update + json_object_update_existing + json_object_update_missing + json_object_iter + json_object_iter_at + json_object_iter_next + json_object_iter_key + json_object_iter_value + json_object_iter_set_new + json_object_key_to_iter + json_dumps + json_dumpf + json_dump_file + json_dump_callback + json_loads + json_loadb + json_loadf + json_load_file + json_load_callback + json_equal + json_copy + json_deep_copy + json_pack + json_pack_ex + json_vpack_ex + json_unpack + json_unpack_ex + json_vunpack_ex + json_set_alloc_funcs + diff --git a/src/jansson.h b/src/jansson.h index e22b68f..25f8746 100644 --- a/src/jansson.h +++ b/src/jansson.h @@ -12,7 +12,7 @@ #include /* for size_t */ #include -#include +#include "jansson_config.h" #ifdef __cplusplus extern "C" { diff --git a/src/jansson_config.h.win32 b/src/jansson_config.h.win32 index da5d0e9..fc8e5ea 100644 --- a/src/jansson_config.h.win32 +++ b/src/jansson_config.h.win32 @@ -24,7 +24,7 @@ #ifdef __cplusplus #define JSON_INLINE inline #else -#define JSON_INLINE +#define JSON_INLINE __inline #endif /* If your compiler supports the `long long` type and the strtoll() diff --git a/src/jansson_private.h b/src/jansson_private.h index bd11e87..7d6d09d 100644 --- a/src/jansson_private.h +++ b/src/jansson_private.h @@ -83,4 +83,10 @@ void* jsonp_malloc(size_t size); void jsonp_free(void *ptr); char *jsonp_strdup(const char *str); +/* Windows compatibility */ +#ifdef _WIN32 +#define snprintf _snprintf +#define vsnprintf _vsnprintf +#endif + #endif diff --git a/src/load.c b/src/load.c index 245244e..7acd3e7 100644 --- a/src/load.c +++ b/src/load.c @@ -13,7 +13,7 @@ #include #include -#include +#include "jansson.h" #include "jansson_private.h" #include "strbuffer.h" #include "utf.h" @@ -87,6 +87,7 @@ static void error_set(json_error_t *error, const lex_t *lex, va_start(ap, msg); vsnprintf(msg_text, JSON_ERROR_TEXT_LENGTH, msg, ap); + msg_text[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; va_end(ap); if(lex) @@ -102,6 +103,7 @@ static void error_set(json_error_t *error, const lex_t *lex, if(lex->saved_text.length <= 20) { snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near '%s'", msg_text, saved_text); + msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; result = msg_with_context; } } @@ -114,6 +116,7 @@ static void error_set(json_error_t *error, const lex_t *lex, else { snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near end of file", msg_text); + msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; result = msg_with_context; } } @@ -444,7 +447,11 @@ out: } #if JSON_INTEGER_IS_LONG_LONG +#ifdef _WIN32 +#define json_strtoint _strtoi64 +#else #define json_strtoint strtoll +#endif #else #define json_strtoint strtol #endif diff --git a/src/memory.c b/src/memory.c index b2f529d..543ecc4 100644 --- a/src/memory.c +++ b/src/memory.c @@ -9,7 +9,7 @@ #include #include -#include +#include "jansson.h" #include "jansson_private.h" /* memory function pointers */ diff --git a/src/pack_unpack.c b/src/pack_unpack.c index 7a6d81d..39db9b8 100644 --- a/src/pack_unpack.c +++ b/src/pack_unpack.c @@ -7,7 +7,7 @@ */ #include -#include +#include "jansson.h" #include "jansson_private.h" #include "utf.h" @@ -431,7 +431,7 @@ static int unpack(scanner_t *s, json_t *root, va_list *ap) if(!(s->flags & JSON_VALIDATE_ONLY)) { int *target = va_arg(*ap, int*); if(root) - *target = json_integer_value(root); + *target = (int)json_integer_value(root); } return 0; diff --git a/src/value.c b/src/value.c index 70d03ca..8d05d91 100644 --- a/src/value.c +++ b/src/value.c @@ -11,7 +11,7 @@ #include #include -#include +#include "jansson.h" #include "hashtable.h" #include "jansson_private.h" #include "utf.h" @@ -779,7 +779,7 @@ static json_t *json_real_copy(json_t *real) double json_number_value(const json_t *json) { if(json_is_integer(json)) - return json_integer_value(json); + return (double)json_integer_value(json); else if(json_is_real(json)) return json_real_value(json); else diff --git a/test/suites/api/check-exports b/test/suites/api/check-exports index f5f86bf..eb2d83e 100755 --- a/test/suites/api/check-exports +++ b/test/suites/api/check-exports @@ -1,99 +1,17 @@ #!/bin/sh - +# # This test checks that libjansson.so exports the correct symbols. - -# The list of symbols that the shared object should export -sort >$test_log/exports <$test_log/macros_or_inline <$test_log/exports + nm -D $SOFILE >/dev/null >$test_log/symbols 2>/dev/null \ || exit 77 # Skip if "nm -D" doesn't seem to work -- 2.1.4