Skip to content

Commit

Permalink
cJSON: Add cJSON_malloc and cJSON_free
Browse files Browse the repository at this point in the history
  • Loading branch information
FSMaxB committed Apr 12, 2017
1 parent d67b008 commit 02a05ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 4 additions & 0 deletions cJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 02a05ee

Please sign in to comment.