You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some memory pool API (like Apache APR) don't implement a realloc function, so it's not possible to use these API with yajl. And it's totally impossible to develop a genric one.
A (quite simple) possibility is to allow to not specify a realloc function and, in this case, use an internal function. We can do that because in all calls to realloc, we know the old size (which we don't know in an external function).
Concretely:
Remove existing tests "afs->yajl_realloc == NULL"
Create the internal "extended" realloc:
void* yajl_realloc2(yajl_alloc_funcs* afs, void* previous, size_t sz, size_t oldsz)
{
void* new = afs->yajl_malloc(afs->ctx, sz);
if (!new) return NULL;
if (!previous) return new;
if (oldsz) memcpy(new, previous, oldsz);
afs->yajl_free(afs->ctx, previous);
return new;
}
Extend the definition of YA_REALLOC:
#define YA_REALLOC(afs, ptr, sz, oldsz) ((afs)->yajl_realloc ? (afs)->yajl_realloc((afs)->ctx, (ptr), (sz)) : yajl_realloc2((afs), (ptr), (sz), (oldsz)))
I attached a complete diff, tested with mod_security2 (APR).
For info, this speeds up the parsing by 250% on big JSON.
I do like this idea. I have to think a bit harder still about whether or not it changes the API in any significant way. I don't think it does, but I haven't convinced myself 100% yet.
If we can conclude it is entirely backward compatible API and ABI wise then I think it could be included in the imminent next release.
Some memory pool API (like Apache APR) don't implement a realloc function, so it's not possible to use these API with yajl. And it's totally impossible to develop a genric one.
A (quite simple) possibility is to allow to not specify a realloc function and, in this case, use an internal function. We can do that because in all calls to realloc, we know the old size (which we don't know in an external function).
Concretely:
Remove existing tests "afs->yajl_realloc == NULL"
Create the internal "extended" realloc:
void* yajl_realloc2(yajl_alloc_funcs* afs, void* previous, size_t sz, size_t oldsz)
{
void* new = afs->yajl_malloc(afs->ctx, sz);
if (!new) return NULL;
if (!previous) return new;
if (oldsz) memcpy(new, previous, oldsz);
afs->yajl_free(afs->ctx, previous);
return new;
}
Extend the definition of YA_REALLOC:
#define YA_REALLOC(afs, ptr, sz, oldsz) ((afs)->yajl_realloc ? (afs)->yajl_realloc((afs)->ctx, (ptr), (sz)) : yajl_realloc2((afs), (ptr), (sz), (oldsz)))
I attached a complete diff, tested with mod_security2 (APR).
For info, this speeds up the parsing by 250% on big JSON.
yajl_realloc2.zip
The text was updated successfully, but these errors were encountered: