| 207 | } |
| 208 | |
| 209 | CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) |
| 210 | { |
| 211 | if (hooks == NULL) |
| 212 | { |
| 213 | /* Reset hooks */ |
| 214 | global_hooks.allocate = malloc; |
| 215 | global_hooks.deallocate = free; |
| 216 | global_hooks.reallocate = realloc; |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | global_hooks.allocate = malloc; |
| 221 | if (hooks->malloc_fn != NULL) |
| 222 | { |
| 223 | global_hooks.allocate = hooks->malloc_fn; |
| 224 | } |
| 225 | |
| 226 | global_hooks.deallocate = free; |
| 227 | if (hooks->free_fn != NULL) |
| 228 | { |
| 229 | global_hooks.deallocate = hooks->free_fn; |
| 230 | } |
| 231 | |
| 232 | /* use realloc only if both free and malloc are used */ |
| 233 | global_hooks.reallocate = NULL; |
| 234 | if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) |
| 235 | { |
| 236 | global_hooks.reallocate = realloc; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /* Internal constructor. */ |
| 241 | static cJSON *cJSON_New_Item(const internal_hooks * const hooks) |
no outgoing calls
searching dependent graphs…