Support building on Windows
authorPetri Lehtinen <petri@digip.org>
Sun, 29 Apr 2012 19:09:29 +0000 (22:09 +0300)
committerPetri Lehtinen <petri@digip.org>
Sun, 29 Apr 2012 19:09:29 +0000 (22:09 +0300)
Jansson now builds correctly with Visual C++ Express 2010.

12 files changed:
src/dump.c
src/error.c
src/hashtable.c
src/jansson.def [new file with mode: 0644]
src/jansson.h
src/jansson_config.h.win32
src/jansson_private.h
src/load.c
src/memory.c
src/pack_unpack.c
src/value.c
test/suites/api/check-exports

index e39197a..4251104 100644 (file)
@@ -11,7 +11,7 @@
 #include <string.h>
 #include <assert.h>
 
-#include <jansson.h>
+#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);
index a7c8cbb..a544a59 100644 (file)
@@ -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';
 }
index 76cf69b..fce7550 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include <jansson_config.h>   /* 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 (file)
index 0000000..6b2c8a7
--- /dev/null
@@ -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
+
index e22b68f..25f8746 100644 (file)
@@ -12,7 +12,7 @@
 #include <stdlib.h>  /* for size_t */
 #include <stdarg.h>
 
-#include <jansson_config.h>
+#include "jansson_config.h"
 
 #ifdef __cplusplus
 extern "C" {
index da5d0e9..fc8e5ea 100644 (file)
@@ -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()
index bd11e87..7d6d09d 100644 (file)
@@ -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
index 245244e..7acd3e7 100644 (file)
@@ -13,7 +13,7 @@
 #include <string.h>
 #include <assert.h>
 
-#include <jansson.h>
+#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
index b2f529d..543ecc4 100644 (file)
@@ -9,7 +9,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <jansson.h>
+#include "jansson.h"
 #include "jansson_private.h"
 
 /* memory function pointers */
index 7a6d81d..39db9b8 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #include <string.h>
-#include <jansson.h>
+#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;
index 70d03ca..8d05d91 100644 (file)
@@ -11,7 +11,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <jansson.h>
+#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
index f5f86bf..eb2d83e 100755 (executable)
@@ -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 <<EOF
-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
-EOF
-
-# The list of functions are not exported in the library because they
-# are macros or static inline functions. This is only the make the
-# list complete, there are not used by the test.
-sort >$test_log/macros_or_inline <<EOF
-json_typeof
-json_incref
-json_decref
-json_is_object
-json_is_object
-json_is_array
-json_is_string
-json_is_integer
-json_is_real
-json_is_true
-json_is_false
-json_is_null
-json_is_number
-json_is_boolean
-json_array_set
-json_array_append
-json_array_insert
-json_object_set
-json_object_set_nocheck
-EOF
+#
 
 SOFILE="../src/.libs/libjansson.so"
 
+# The list of symbols, which the shared object should export, is read
+# from the def file, which is used in Windows builds
+grep 'json_' $top_srcdir/src/jansson.def \
+    | sed -e 's/ //g' \
+    | sort \
+    >$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