Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support building on Windows

Jansson now builds correctly with Visual C++ Express 2010.
  • Loading branch information...
commit ff0c05b8f13f4f8a1da82ef1337d594916ef9df9 1 parent 4601bf7
@akheron authored
View
4 src/dump.c
@@ -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);
View
1  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';
}
View
2  src/hashtable.c
@@ -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"
View
65 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
+
View
2  src/jansson.h
@@ -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" {
View
2  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()
View
6 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
View
9 src/load.c
@@ -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 @@ static void lex_scan_string(lex_t *lex, json_error_t *error)
}
#if JSON_INTEGER_IS_LONG_LONG
+#ifdef _WIN32
+#define json_strtoint _strtoi64
+#else
#define json_strtoint strtoll
+#endif
#else
#define json_strtoint strtol
#endif
View
2  src/memory.c
@@ -9,7 +9,7 @@
#include <stdlib.h>
#include <string.h>
-#include <jansson.h>
+#include "jansson.h"
#include "jansson_private.h"
/* memory function pointers */
View
4 src/pack_unpack.c
@@ -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;
View
4 src/value.c
@@ -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
View
100 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 <<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
Please sign in to comment.
Something went wrong with that request. Please try again.