]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Some updates to make the code compatible with VC 9 (2008) 12/head
authorJohn Arbash Meinel <john@arbash-meinel.com>
Wed, 1 Feb 2012 08:27:49 +0000 (09:27 +0100)
committerJohn Arbash Meinel <john@arbash-meinel.com>
Wed, 1 Feb 2012 08:27:49 +0000 (09:27 +0100)
VC 9 doesn't support late variable declarations, and doesn't have inttypes
so we need some direct definitions of a couple of more types.

.gitignore
json_inttypes.h
json_object.c
json_util.c
printbuf.c

index a4cab254b2ebf95f3f14e5f8c39e87bcda0608c5..6acd8193eb070963efa5ed4662bccc1aeba82f29 100644 (file)
@@ -21,4 +21,6 @@ test1
 test2
 test4
 testSubDir
-test_parse_int64
\ No newline at end of file
+test_parse_int64
+Debug
+Release
index 1cbafc21f4f269f413618c094088e39bb4db6499..1f3e4d2992848285a18aff058df04460c3726b8b 100644 (file)
@@ -5,6 +5,9 @@
 #if defined(_MSC_VER) && _MSC_VER < 1600
 
 /* Anything less than Visual Studio C++ 10 is missing stdint.h and inttypes.h */
+typedef __int32 int32_t;
+#define INT32_MIN    ((int32_t)_I32_MIN)
+#define INT32_MAX    ((int32_t)_I32_MAX)
 typedef __int64 int64_t;
 #define PRId64 "I64d"
 #define SCNd64 "I64d"
index bc09d658ee20d760481783571c7eabc5bd666e2d..65c1f6c08a2322b5e02bdd1056d2a69d7e674ba4 100644 (file)
@@ -321,10 +321,13 @@ struct json_object* json_object_new_int(int32_t i)
 
 int32_t json_object_get_int(struct json_object *jso)
 {
+  int64_t cint64;
+  enum json_type o_type;
+
   if(!jso) return 0;
 
-  enum json_type o_type = jso->o_type;
-  int64_t cint64 = jso->o.c_int64;
+  o_type = jso->o_type;
+  cint64 = jso->o.c_int64;
 
   if (o_type == json_type_string)
   {
index dab3d8c9579f8f3c7e6e48fb1277eb1a73398091..c6db882ee9ed83ef940eb0faa532d4f28b421807 100644 (file)
@@ -130,13 +130,15 @@ int json_object_to_file(char *filename, struct json_object *obj)
 int json_parse_int64(const char *buf, int64_t *retval)
 {
        int64_t num64;
+       const char *buf_skip_space;
+       int orig_has_neg;
        if (sscanf(buf, "%" SCNd64, &num64) != 1)
        {
                MC_DEBUG("Failed to parse, sscanf != 1\n");
                return 1;
        }
-       const char *buf_skip_space = buf;
-       int orig_has_neg = 0;
+       buf_skip_space = buf;
+       orig_has_neg = 0;
        // Skip leading spaces
        while (isspace((int)*buf_skip_space) && *buf_skip_space)
                buf_skip_space++;
@@ -156,6 +158,7 @@ int json_parse_int64(const char *buf, int64_t *retval)
                char buf_cmp[100];
                char *buf_cmp_start = buf_cmp;
                int recheck_has_neg = 0;
+               int buf_cmp_len;
                snprintf(buf_cmp_start, sizeof(buf_cmp), "%" PRId64, num64);
                if (*buf_cmp_start == '-')
                {
@@ -164,7 +167,7 @@ int json_parse_int64(const char *buf, int64_t *retval)
                }
                // No need to skip leading spaces or zeros here.
 
-               int buf_cmp_len = strlen(buf_cmp_start);
+               buf_cmp_len = strlen(buf_cmp_start);
                /**
                 * If the sign is different, or
                 * some of the digits are different, or
index 6ed1e94481041b6f7eb86ba4e2aac08404561bc8..e8902c844b092ba8157d08f93dc2fd0a5f0ebe7a 100644 (file)
@@ -65,7 +65,7 @@ int printbuf_memappend(struct printbuf *p, const char *buf, int size)
   return size;
 }
 
-#if !HAVE_VSNPRINTF && defined(WIN32)
+#if !HAVE_VSNPRINTF && defined(_MSC_VER)
 # define vsnprintf _vsnprintf
 #elif !HAVE_VSNPRINTF /* !HAVE_VSNPRINTF */
 # error Need vsnprintf!