Selaa lähdekoodia

cJSON: Add cJSON_malloc and cJSON_free

Max Bruckner 8 vuotta sitten
vanhempi
commit
02a05eea4e
2 muutettua tiedostoa jossa 14 lisäystä ja 0 poistoa
  1. 10 0
      cJSON.c
  2. 4 0
      cJSON.h

+ 10 - 0
cJSON.c

@@ -2585,3 +2585,13 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons
             return false;
     }
 }
+
+CJSON_PUBLIC(void *) cJSON_malloc(size_t size)
+{
+    return global_hooks.allocate(size);
+}
+
+CJSON_PUBLIC(void) cJSON_free(void *object)
+{
+    global_hooks.deallocate(object);
+}

+ 4 - 0
cJSON.h

@@ -241,6 +241,10 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
 /* Macro for iterating over an array */
 #define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
 
+/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
+CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
+CJSON_PUBLIC(void) cJSON_free(void *object);
+
 #ifdef __cplusplus
 }
 #endif