in src/ujdecode.c [808:896]
UJObject UJDecode(const char *input, size_t cbInput, UJHeapFuncs *hf, void **outState)
{
UJObject ret;
struct DecoderState *ds;
void *initialHeap;
size_t cbInitialHeap;
HeapSlab *slab;
JSONObjectDecoder decoder = {
newString,
objectAddKey,
arrayAddItem,
newTrue,
newFalse,
newNull,
newObject,
newArray,
newInt,
newLong,
newUnsignedLong,
newDouble,
releaseObject,
NULL,
NULL,
NULL,
NULL,
NULL,
0,
NULL
};
if (hf == NULL)
{
decoder.malloc = malloc;
decoder.free = free;
decoder.realloc = realloc;
cbInitialHeap = 16384;
initialHeap = malloc(cbInitialHeap);
if (initialHeap == NULL)
{
return NULL;
}
}
else
{
decoder.malloc = hf->malloc;
decoder.free = hf->free;
decoder.realloc = hf->realloc;
initialHeap = hf->initalHeap;
cbInitialHeap = hf->cbInitialHeap;
if (cbInitialHeap < sizeof(HeapSlab) + sizeof(struct DecoderState))
{
return NULL;
}
}
*outState = NULL;
slab = (HeapSlab * ) initialHeap;
slab->start = (unsigned char *) (slab + 1);
slab->offset = slab->start;
slab->end = (unsigned char *) initialHeap + cbInitialHeap;
slab->size = cbInitialHeap;
slab->owned = hf == NULL ? 1 : 0;
slab->next = NULL;
ds = (struct DecoderState *) slab->offset;
slab->offset += sizeof(struct DecoderState);
*outState = (void *) ds;
ds->heap = slab;
ds->malloc = decoder.malloc;
ds->free = decoder.free;
ds->error = NULL;
decoder.prv = (void *) ds;
ret = (UJObject) JSON_DecodeObject(&decoder, input, cbInput);
if (ret == NULL)
{
ds->error = decoder.errorStr;
}
return ret;
}