Logo Search packages:      
Sourcecode: yajl version File versions

yajl_gen YAJL_API yajl_gen_alloc ( const yajl_gen_config config,
const yajl_alloc_funcs allocFuncs 

allocate a generator handle

config a pointer to a structure containing parameters which configure the behavior of the json generator
allocFuncs an optional pointer to a structure which allows the client to overide the memory allocation used by yajl. May be NULL, in which case malloc/free/realloc will be used.
an allocated handle on success, NULL on failure (bad params)

Definition at line 64 of file yajl_gen.c.

References yajl_gen_config::beautify, yajl_alloc_funcs::free, yajl_gen_config::indentString, yajl_alloc_funcs::malloc, yajl_alloc_funcs::realloc, and yajl_gen_alloc().

Referenced by yajl_gen_alloc().

    yajl_gen g = NULL;
    yajl_alloc_funcs afsBuffer;

    /* first order of business is to set up memory allocation routines */
    if (afs != NULL) {
        if (afs->malloc == NULL || afs->realloc == NULL || afs->free == NULL)
            return NULL;
    } else {
        afs = &afsBuffer;

    g = (yajl_gen) YA_MALLOC(afs, sizeof(struct yajl_gen_t));
    memset((void *) g, 0, sizeof(struct yajl_gen_t));
    /* copy in pointers to allocation routines */
    memcpy((void *) &(g->alloc), (void *) afs, sizeof(yajl_alloc_funcs));

    if (config) {
        g->pretty = config->beautify;
        g->indentString = config->indentString ? config->indentString : "  ";
    g->buf = yajl_buf_alloc(&(g->alloc));

    return g;

Generated by  Doxygen 1.6.0   Back to index