Преглед изворни кода

同步官方至 https://github.com/DaveGamble/cJSON/commit/a6424b85dde200a87cac26451c6f0a6f3426681f
移除.c文件版本的判断

Meco Man пре 4 година
родитељ
комит
c9391fb10b
3 измењених фајлова са 12 додато и 10 уклоњено
  1. 4 5
      cJSON.c
  2. 7 0
      cJSON.h
  3. 1 5
      cJSON_port.c

+ 4 - 5
cJSON.c

@@ -116,11 +116,6 @@ CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
     return item->valuedouble;
 }
 
-/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
-#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 15)
-    #error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
-#endif
-
 CJSON_PUBLIC(const char*) cJSON_Version(void)
 {
     static char version[15];
@@ -562,6 +557,10 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
     {
         length = sprintf((char*)number_buffer, "null");
     }
+    else if(d == (double)item->valueint)
+    {
+        length = sprintf((char*)number_buffer, "%d", item->valueint);
+    }
     else
     {
         /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */

+ 7 - 0
cJSON.h

@@ -279,6 +279,13 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
 /* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
 CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
 
+/* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/
+#define cJSON_SetBoolValue(object, boolValue) ( \
+    (object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \
+    (object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
+    cJSON_Invalid\
+)
+
 /* Macro for iterating over an array or object */
 #define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
 

+ 1 - 5
cJSON_port.c

@@ -1,9 +1,5 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-
+#include <stddef.h>
 #include <rtthread.h>
-
 #include "cJSON.h"
 
 int cJSON_hook_init(void)