Changeset 2171

Show
Ignore:
Timestamp:
09/22/08 00:08:00 (4 months ago)
Author:
karpet
Message:

get rid of the circular reference in TokenList/Token?; make swish_init() a separate call from swish_init_swish3() so it can be called as class method rather than once-per-object; clean up some ref_cnt logic and mem debugging

Files:

Legend:

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

    r2169 r2171  
    287287    unsigned int        len; 
    288288    int                 ref_cnt; 
    289     swish_TokenList    *list;           // the parent list 
    290289}; 
    291290 
     
    421420void        swish_xfree( void *ptr ); 
    422421void        swish_mem_debug(); 
     422long int    swish_get_memcount(); 
    423423xmlChar *   swish_xstrdup( const xmlChar * ptr ); 
    424424xmlChar *   swish_xstrndup( const xmlChar * ptr, int len ); 
  • libswish3/trunk/src/libswish3/mem.c

    r2133 r2171  
    3838{ 
    3939    memcount = 0; 
     40} 
    4041 
     42long int 
     43swish_get_memcount( 
     44) 
     45{ 
     46    return memcount; 
    4147} 
    4248 
     
    136142    if (memcount > 0) 
    137143        SWISH_WARN 
    138             ("memory error: %ld more swish_xmalloc()s or swish_xstrdup()s than swish_xfree()s", 
     144            ("%ld more swish_xmalloc()s or swish_xstrdup()s than swish_xfree()s", 
    139145             memcount); 
    140146 
    141147    if (memcount < 0) 
    142         SWISH_WARN("memory error: too many swish_xfree()s %d", memcount); 
     148        SWISH_WARN("too many swish_xfree()s %d", memcount); 
    143149} 
  • libswish3/trunk/src/libswish3/swish.c

    r2170 r2171  
    3131{ 
    3232    swish_3 *s3; 
    33     swish_init(); 
    3433    s3 = swish_xmalloc(sizeof(swish_3)); 
    3534    s3->ref_cnt = 0; 
     
    5453    swish_3 *s3 
    5554) 
    56 
    57     boolean children_are_freed; 
    58      
    59     children_are_freed = 0; 
     55{     
    6056    s3->parser->ref_cnt--; 
    6157    if (s3->parser->ref_cnt < 1) { 
    6258        swish_free_parser(s3->parser); 
    63         children_are_freed++; 
    6459    } 
    6560 
     
    6762    if (s3->analyzer->ref_cnt < 1) { 
    6863        swish_free_analyzer(s3->analyzer); 
    69         children_are_freed++; 
    7064    } 
    7165 
     
    7367    if (s3->config->ref_cnt < 1) { 
    7468        swish_free_config(s3->config); 
    75         children_are_freed++; 
    7669    } 
    7770 
     
    8073    } 
    8174    swish_xfree(s3); 
    82      
    83     if (children_are_freed == 3) { 
    84         swish_mem_debug(); 
    85     } 
    8675} 
    8776 
     77/* MUST call this before instantiating any swish_3 objects */ 
    8878void 
    8979swish_init( 
  • libswish3/trunk/src/libswish3/tokenizer.c

    r2169 r2171  
    441441    t->len = 0; 
    442442    t->ref_cnt = 0; 
    443     t->list = NULL; 
    444443    return t; 
    445444} 
     
    453452        SWISH_WARN("freeing Token with ref_cnt != 0 (%d)", t->ref_cnt); 
    454453    } 
    455  
     454     
     455    if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 
     456        SWISH_DEBUG_MSG("freeing Token %d with MetaName ref_cnt %d",  
     457            t, t->meta->ref_cnt); 
     458    } 
     459     
    456460    t->meta->ref_cnt--; 
    457     if (t->meta->ref_cnt == 0) 
     461    if (t->meta->ref_cnt == 0) { 
     462        if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 
     463            SWISH_DEBUG_MSG("Token's MetaName ref_cnt == 0 ... freeing MetaName"); 
     464        } 
    458465        swish_free_metaname(t->meta); 
    459      
    460     if (t->list != NULL) { 
    461         t->list->ref_cnt--; 
    462     } 
    463  
     466    } 
     467     
    464468    swish_xfree(t); 
    465469} 
     
    521525    } 
    522526     
     527    if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 
     528        SWISH_DEBUG_MSG( 
     529        "freeing TokenIterator %d with TokenList ref_cnt %d and s3 ref_cnt %d",  
     530        it, it->tl->ref_cnt, it->s3->ref_cnt); 
     531    } 
     532     
    523533    it->s3->ref_cnt--; 
    524534         
     
    544554     
    545555    t = it->tl->tokens[it->pos++]; 
    546     t->list = it->tl; 
    547     t->list->ref_cnt++; 
    548556    return t; 
    549557} 
  • libswish3/trunk/src/swish_lint.c

    r2167 r2171  
    156156    swish_3 *s3; 
    157157 
     158    swish_init();   // always call first 
    158159    option_index = 0; 
    159160    files = 0; 
     
    249250 
    250251    swish_free_swish3(s3); 
     252    swish_mem_debug(); 
    251253 
    252254    return (0); 
  • libswish3/trunk/src/swish_tokenize.c

    r2162 r2171  
    7575    swish_3 *s3; 
    7676 
     77    swish_init();   // always call first 
    7778    meta = (xmlChar *)SWISH_DEFAULT_METANAME; 
    7879    option_index = 0; 
  • libswish3/trunk/src/utf8test.c

    r2140 r2171  
    7171    loop = 1; 
    7272 
    73     swish_verify_utf8_locale(); 
     73    swish_init();   // always call first 
    7474 
    7575    while ((ch = getopt_long(argc, argv, "d:f:h", longopts, &option_index)) != -1) {