Changeset 2160

Show
Ignore:
Timestamp:
09/20/08 01:05:24 (4 months ago)
Author:
karpet
Message:

ref_cnt checking

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/src/libswish3/tokenizer.c

    r2155 r2160  
    343343        tl->n--; 
    344344        tl->tokens[tl->n]->ref_cnt--; 
    345         swish_free_token(tl->tokens[tl->n]); 
     345        if (tl->tokens[tl->n]->ref_cnt < 1) 
     346            swish_free_token(tl->tokens[tl->n]); 
    346347    } 
    347348 
     
    418419xmlChar * 
    419420swish_get_token_value( 
    420     swish_TokenList *tl, 
    421421    swish_Token *t 
    422422) 
    423423{ 
    424424/*     SWISH_DEBUG_MSG("get token value: '%s'  %d, %d", xmlBufferContent(tl->buf), t->start_byte, t->len); */ 
    425     return xmlStrsub(xmlBufferContent(tl->buf), t->start_byte, t->len); 
     425    return xmlStrsub(xmlBufferContent(t->list->buf), t->start_byte, t->len); 
    426426} 
    427427 
     
    439439    t->len = 0; 
    440440    t->ref_cnt = 0; 
     441    t->list = NULL; 
    441442    return t; 
    442443} 
     
    455456 
    456457    t->meta->ref_cnt--; 
     458    if (t->meta->ref_cnt == 0) 
     459        swish_free_metaname(t->meta); 
     460     
     461    if (t->list != NULL) { 
     462        t->list->ref_cnt--; 
     463    } 
    457464 
    458465    swish_xfree(t); 
     
    487494*/ 
    488495    while ((t = swish_next_token(it)) != NULL) { 
    489         t->value = swish_get_token_value(it->tl, t); 
     496        t->value = swish_get_token_value(t); 
    490497        swish_debug_token(t); 
    491498    } 
     
    518525    } 
    519526    it->config->ref_cnt--; 
     527    if (it->config->ref_cnt == 0) 
     528        swish_free_config(it->config); 
     529         
    520530    it->tl->ref_cnt--; 
     531    if (it->tl->ref_cnt == 0) 
     532        swish_free_token_list(it->tl); 
     533     
    521534    swish_xfree(it); 
    522535} 
     
    527540) 
    528541{ 
     542    swish_Token *t; 
     543    t = NULL; 
     544     
    529545/* SWISH_DEBUG_MSG("next_token: %d %d", it->pos, it->tl->n); */ 
    530546    if (it->pos >= it->tl->n) 
    531547        return NULL; 
    532548 
    533     return it->tl->tokens[it->pos++]; 
     549     
     550    t = it->tl->tokens[it->pos++]; 
     551    t->list = it->tl; 
     552    t->list->ref_cnt++; 
     553    return t; 
    534554} 
    535555 
     
    539559    swish_3 *s3, 
    540560    xmlChar *buf, 
    541     ... 
    542 
    543 
    544     swish_TokenList *tl; 
    545     swish_MetaName *meta; 
    546     xmlChar *context; 
    547  
    548     va_list args; 
    549  
    550     va_start(args, buf); 
    551     tl = va_arg(args, swish_TokenList * 
    552     ); 
    553     meta = va_arg(args, swish_MetaName * 
    554     ); 
    555     context = va_arg(args, xmlChar * 
    556     ); 
    557  
    558     va_end(args); 
    559  
     561    swish_TokenList *tl, 
     562    swish_MetaName *meta, 
     563    xmlChar *context 
     564
     565
    560566    if (swish_is_ascii(buf)) { 
    561567        return swish_tokenize3_ascii(s3, buf, tl, meta, context);