Logo Search packages:      
Sourcecode: yajl version File versions

yajl_handle YAJL_API yajl_alloc ( const yajl_callbacks callbacks,
const yajl_parser_config config,
const yajl_alloc_funcs allocFuncs,
void *  ctx 

allocate a parser handle

callbacks a yajl callbacks structure specifying the functions to call when different JSON entities are encountered in the input text. May be NULL, which is only useful for validation.
config configuration parameters for the parse.
ctx a context pointer that will be passed to callbacks.

Definition at line 64 of file yajl.c.

References yajl_parser_config::allowComments, yajl_parser_config::checkUTF8, yajl_alloc_funcs::free, yajl_alloc_funcs::malloc, yajl_alloc_funcs::realloc, and yajl_alloc().

Referenced by yajl_alloc().

    unsigned int allowComments = 0;
    unsigned int validateUTF8 = 0;
    yajl_handle hand = 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;

    hand = (yajl_handle) YA_MALLOC(afs, sizeof(struct yajl_handle_t));

    /* copy in pointers to allocation routines */
    memcpy((void *) &(hand->alloc), (void *) afs, sizeof(yajl_alloc_funcs));

    if (config != NULL) {
        allowComments = config->allowComments;
        validateUTF8 = config->checkUTF8;

    hand->callbacks = callbacks;
    hand->ctx = ctx;
    hand->lexer = yajl_lex_alloc(&(hand->alloc), allowComments, validateUTF8);
    hand->errorOffset = 0;
    hand->decodeBuf = yajl_buf_alloc(&(hand->alloc));
    yajl_bs_init(hand->stateStack, &(hand->alloc));

    yajl_bs_push(hand->stateStack, yajl_state_start);    

    return hand;

Generated by  Doxygen 1.6.0   Back to index