Changeset 2030

Show
Ignore:
Timestamp:
02/25/08 21:58:22 (3 months ago)
Author:
karpet
Message:

expand ref counting and clean up some unused code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/bindings/perl/XS/Analyzer.xs

    r2029 r2030  
    135135                        context 
    136136                        ); 
    137          
    138         RETVAL->ref_cnt++; 
    139          
     137                 
    140138        /* TODO do we need to worry about free()ing metaname and context ?? */ 
    141139                         
  • libswish3/trunk/bindings/perl/XS/Config.xs

    r2029 r2030  
    88     
    99    CODE: 
    10         RETVAL = sp_new_config(); 
     10        RETVAL = swish_init_config(); 
     11        RETVAL->ref_cnt++; 
     12        RETVAL->stash = sp_Stash_new(); 
    1113         
    1214    OUTPUT: 
  • libswish3/trunk/bindings/perl/XS/Data.xs

    r2029 r2030  
    1414    CODE: 
    1515        self->s3->ref_cnt++; 
    16         class  = sp_hvref_fetch_as_char((SV*)self->s3->stash, SELF_CLASS_KEY); 
     16        class  = sp_Stash_get_char((SV*)self->s3->stash, SELF_CLASS_KEY); 
    1717        warn("s3 class = %s\n", class); 
    1818        RETVAL = sp_bless_ptr( class, (IV)self->s3 ); 
     
    3333 
    3434    CODE: 
    35         CLASS  = sp_hvref_fetch_as_char(self->s3->stash, CONFIG_CLASS_KEY); 
     35        CLASS  = sp_Stash_get_char(self->s3->stash, CONFIG_CLASS_KEY); 
    3636        self->s3->config->ref_cnt++; 
    3737        RETVAL = self->s3->config; 
     
    122122# MUST increment refcnt 2x so that SWISH::3::WordList::DESTROY 
    123123# does not free it. 
    124         self->wordlist->ref_cnt += 2; 
     124        //self->wordlist->ref_cnt += 2; 
     125        self->wordlist->ref_cnt++; 
    125126        RETVAL = self->wordlist; 
    126127         
  • libswish3/trunk/bindings/perl/lib/SWISH/3.pm

    r2029 r2030  
    131131 
    132132    print "WordList\n"; 
    133     while ( my $swishword = $data->wordlist->next ) { 
     133    my $wordlist = $data->wordlist; 
     134    while ( my $swishword = $wordlist->next ) { 
    134135        print '-' x 50, "\n"; 
    135136        for my $w (SWISH_WORD_FIELDS) { 
  • libswish3/trunk/bindings/perl/t/07-refcnt.t

    r2029 r2030  
    2121# avoid spurious mem error from libswish3 
    2222# just because of order of Perl ref cleanup 
    23 #undef $analyzer; 
     23undef $analyzer; 
    2424 
  • libswish3/trunk/bindings/perl/t/11get_set_parser.t

    r2029 r2030  
    4444#undef $conf1; 
    4545#undef $config; 
    46 #undef $s3; 
     46undef $s3; 
    4747 
  • libswish3/trunk/bindings/perl/t/12-stash.t

    r2029 r2030  
    1212ok(my $s3 = SWISH::3->new( config_class => 'MyConfig' ), "new s3"); 
    1313ok(my $conf = $s3->config, "get config"); 
     14undef $conf; 
    1415undef $s3; 
    1516diag("s3 == undef"); 
  • libswish3/trunk/bindings/perl/xs_helpers.c

    r2029 r2030  
    2626static void     sp_describe_object( SV* object ); 
    2727static IV       sp_extract_ptr( SV* object ); 
    28 static SV*      sp_accessor( SV* object, char* name ); 
    2928static void     sp_store_xml2_pair_in_perl_hash( xmlChar* val, HV* perl_hash, xmlChar* key ); 
    3029static HV*      sp_xml2_hash_to_perl_hash( xmlHashTablePtr xml2_hash ); 
     
    4039static void     sp_debug_token( swish_Token *token ); 
    4140static HV*      sp_get_config_subconfig( swish_Config* config, const char* key ); 
    42 static swish_Config*    sp_new_config(); 
    43 static swish_Analyzer*  sp_new_analyzer(); 
    44  
    45 /* implements nearly all methods for SWISH::3::Stash, a private class */ 
     41 
     42/* implement nearly all methods for SWISH::3::Stash, a private class */ 
    4643 
    4744static SV*      sp_Stash_new(); 
     
    385382} 
    386383 
    387  
    388 /* fetch a hash value from an object (i.e. a generic accessor) */ 
    389 static SV*  
    390 sp_accessor( SV* object, char* name ) 
    391 { 
    392     dTHX; 
    393     char* class = sp_get_objects_class( object ); 
    394     //warn("looking for %s in %s\n", name, class); 
    395     HV* hash = sp_extract_hash( object ); 
    396     SV* sv   = sp_hv_fetch( hash, (const char*)name ); 
    397      
    398     if (!sv) 
    399         croak("no %s in %s object!", name, class); 
    400          
    401     return sv; 
    402 } 
    403  
    404384static void 
    405385sp_hv_replace( HV *hash, char *key, SV *value ) 
     
    541521    //sp_describe_object(s3->stash); 
    542522     
    543     handler     = sp_hvref_fetch((SV*)s3->stash, HANDLER_KEY); 
     523    handler     = sp_Stash_get(s3->stash, HANDLER_KEY); 
    544524     
    545525    //warn("got handler and s3"); 
    546526     
    547     data_class  = sp_hvref_fetch_as_char((SV*)s3->stash, DATA_CLASS_KEY); 
     527    data_class  = sp_Stash_get_char(s3->stash, DATA_CLASS_KEY); 
    548528     
    549529    //warn("data_class = %s", data_class); 
     
    640620 
    641621    list = swish_init_wordlist(); 
     622    list->ref_cnt++; 
    642623    num_code_points = 0; 
    643624     
     
    758739} 
    759740 
    760 static swish_Config* 
    761 sp_new_config() 
    762 { 
    763     HV* stash; 
    764     swish_Config* config; 
    765      
    766     stash  = newHV(); 
    767     config = swish_init_config(); 
    768     config->ref_cnt++; 
    769     config->stash = sp_Stash_new(); 
    770      
    771     return config; 
    772 } 
  • libswish3/trunk/src/libswish3/docinfo.c

    r2027 r2030  
    4343     
    4444    swish_DocInfo *docinfo = swish_xmalloc( sizeof(swish_DocInfo) ); 
     45    docinfo->ref_cnt        = 0; 
    4546    docinfo->nwords         = 0; 
    4647    docinfo->mtime          = 0; 
     
    7273        swish_debug_docinfo( ptr ); 
    7374 
     75 
     76    if (ptr->ref_cnt != 0) { 
     77        SWISH_WARN("docinfo ref_cnt != 0: %d", ptr->ref_cnt); 
     78    } 
    7479 
    7580    ptr->nwords = 0; /* why is this required? */ 
  • libswish3/trunk/src/libswish3/libswish3.h

    r2027 r2030  
    243243    xmlChar *           parser; 
    244244    xmlChar *           update; 
     245    int                 ref_cnt; 
    245246}; 
    246247 
  • libswish3/trunk/src/libswish3/parser.c

    r2028 r2030  
    749749    ptr->tag = NULL; 
    750750    ptr->wordlist   = swish_init_wordlist(); 
     751    ptr->wordlist->ref_cnt++; 
    751752    ptr->properties = swish_init_nb(s3->config, (xmlChar*)SWISH_PROP); 
     753    ptr->properties->ref_cnt++; 
    752754    ptr->metanames  = swish_init_nb(s3->config, (xmlChar*)SWISH_META); 
     755    ptr->metanames->ref_cnt++; 
    753756 
    754757    /* prime the stacks */ 
     
    842845        SWISH_DEBUG_MSG("freeing swish_ParserData properties"); 
    843846 
     847    ptr->properties->ref_cnt--; 
    844848    swish_free_nb(ptr->properties); 
    845849 
     
    847851        SWISH_DEBUG_MSG("freeing swish_ParserData metanames"); 
    848852 
     853    ptr->metanames->ref_cnt--; 
    849854    swish_free_nb(ptr->metanames); 
    850855 
     
    894899            SWISH_DEBUG_MSG("free swish_ParserData wordList"); 
    895900 
     901        ptr->wordlist->ref_cnt--; 
    896902        swish_free_wordlist(ptr->wordlist); 
    897903    } 
     
    903909            SWISH_DEBUG_MSG("free swish_ParserData docinfo"); 
    904910 
     911        ptr->docinfo->ref_cnt--; 
    905912        swish_free_docinfo(ptr->docinfo); 
    906913 
     
    983990 
    984991    swish_DocInfo *info = swish_init_docinfo(); 
     992    info->ref_cnt++; 
    985993 
    986994    if (SWISH_DEBUG > 5) 
     
    12511259        /* blank line indicates body */ 
    12521260            curTime      = swish_time_elapsed(); 
    1253             parser_data  = init_parser_data(s3); 
     1261            parser_data  = init_parser_data(s3); 
    12541262            head         = buf_to_head( (xmlChar*)xmlBufferContent(head_buf) ); 
    12551263            parser_data->docinfo = head_to_docinfo(head); 
     
    14351443    swish_ParserData *parser_data = init_parser_data(s3); 
    14361444    parser_data->docinfo         = swish_init_docinfo(); 
     1445    parser_data->docinfo->ref_cnt++; 
    14371446 
    14381447    if (!swish_docinfo_from_filesystem(filename, parser_data->docinfo, parser_data)) 
     
    17801789    if (tmplist->nwords == 0) 
    17811790    { 
     1791        tmplist->ref_cnt--; 
    17821792        swish_free_wordlist(tmplist); 
    17831793        return; 
  • libswish3/trunk/src/libswish3/words.c

    r2028 r2030  
    146146 
    147147    swish_WordList *list = swish_init_wordlist(); 
    148  
     148    list->ref_cnt++; 
    149149 
    150150    return list; 
     
    283283    int byte_count = 0; 
    284284    swish_WordList *list = swish_init_wordlist(); 
     285    list->ref_cnt++; 
    285286    xmlChar * utf8_str; 
    286287 
     
    504505    char            c, nextc, in_word; 
    505506    int             i, w, wl, byte_count; 
    506     swish_WordList * list = swish_init_wordlist(); 
    507     xmlChar        * word = swish_xmalloc(sizeof(xmlChar*) * analyzer->maxwordlen); 
     507    swish_WordList * list; 
     508    xmlChar        * word; 
     509    list = swish_init_wordlist(); 
     510    list->ref_cnt++; 
     511    word = swish_xmalloc(sizeof(xmlChar*) * analyzer->maxwordlen); 
    508512 
    509513    if (!initialized)