Changeset 2172
- Timestamp:
- 09/22/08 00:19:34 (4 months ago)
- Files:
-
- libswish3/trunk/bindings/perl/3.xs (modified) (10 diffs)
- libswish3/trunk/bindings/perl/XS/MetaName.xs (modified) (1 diff)
- libswish3/trunk/bindings/perl/XS/Token.xs (modified) (2 diffs)
- libswish3/trunk/bindings/perl/XS/TokenIterator.xs (modified) (1 diff)
- libswish3/trunk/bindings/perl/lib/SWISH/3.pm (modified) (2 diffs)
- libswish3/trunk/bindings/perl/t/07-refcnt.t (modified) (1 diff)
- libswish3/trunk/bindings/perl/t/09-mem.t (added)
- libswish3/trunk/bindings/perl/t/10tokenize.t (modified) (3 diffs)
- libswish3/trunk/bindings/perl/t/11get_set_parser.t (modified) (3 diffs)
- libswish3/trunk/bindings/perl/t/12-stash.t (modified) (2 diffs)
- libswish3/trunk/bindings/perl/t/13-chained.t (modified) (1 diff)
- libswish3/trunk/bindings/perl/t/20metanames.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/bindings/perl/3.xs
r2164 r2172 16 16 PROTOTYPES: enable 17 17 18 INCLUDE: XS/Constants.xs 18 19 void 20 init(CLASS) 21 char* CLASS; 22 23 CODE: 24 swish_init(); 25 26 19 27 20 28 swish_3* 21 init(CLASS)29 _setup(CLASS) 22 30 char* CLASS; 23 31 … … 349 357 350 358 351 # utility methods352 353 359 void 354 360 describe(self, obj) … … 360 366 361 367 362 368 369 void 370 mem_debug(CLASS) 371 char* CLASS; 372 373 CODE: 374 swish_mem_debug(); 375 376 377 378 int 379 get_memcount(CLASS) 380 char* CLASS; 381 382 CODE: 383 RETVAL = swish_get_memcount(); 384 385 OUTPUT: 386 RETVAL 387 388 363 389 364 390 # tokenize() from Perl space uses same C func as tokenizer callback … … 372 398 swish_TokenIterator* ti; 373 399 swish_MetaName* metaname; 374 xmlChar* meta;375 400 xmlChar* context; 376 401 xmlChar* buf; 377 402 378 403 CODE: 379 404 CLASS = TOKENITERATOR_CLASS; 380 405 ti = swish_init_token_iterator(self); 381 406 ti->ref_cnt++; 382 meta = (xmlChar*)SWISH_DEFAULT_METANAME;383 407 context = (xmlChar*)SWISH_DEFAULT_METANAME; 384 408 buf = (xmlChar*)SvPV(str, PL_na); … … 397 421 if ( items > 2 ) 398 422 { 399 meta = (xmlChar*)SvPV(ST(2), PL_na);423 metaname = (swish_MetaName*)sp_extract_ptr(ST(2)); 400 424 401 425 if ( items > 3 ) … … 405 429 406 430 } 407 408 metaname = swish_init_metaname(meta); 409 metaname->ref_cnt++; 410 431 else { 432 metaname = swish_init_metaname((xmlChar*)SWISH_DEFAULT_METANAME); 433 metaname->ref_cnt++; 434 } 435 411 436 sp_tokenize3( ti, buf, metaname, context ); 412 413 437 RETVAL = ti; 414 415 438 416 439 OUTPUT: 417 440 RETVAL … … 429 452 swish_TokenIterator* ti; 430 453 swish_MetaName* metaname; 431 xmlChar* meta;432 454 xmlChar* context; 433 455 xmlChar* buf; 434 456 435 457 CODE: 436 458 CLASS = TOKENITERATOR_CLASS; 437 459 ti = swish_init_token_iterator(self); 438 460 ti->ref_cnt++; 439 meta = (xmlChar*)SWISH_DEFAULT_METANAME;440 461 context = (xmlChar*)SWISH_DEFAULT_METANAME; 441 462 buf = (xmlChar*)SvPV(str, PL_na); 442 463 443 464 // TODO reimplement as hashref arg 444 465 466 // TODO why this check?? 445 467 if (!SvUTF8(str)) 446 468 { … … 453 475 if ( items > 2 ) 454 476 { 455 meta = (xmlChar*)SvPV(ST(2), PL_na);477 metaname = (swish_MetaName*)sp_extract_ptr(ST(2)); 456 478 457 479 if ( items > 3 ) … … 461 483 462 484 } 463 464 metaname = swish_init_metaname(meta); 465 metaname->ref_cnt++; 466 485 else { 486 metaname = swish_init_metaname((xmlChar*)SWISH_DEFAULT_METANAME); 487 metaname->ref_cnt++; 488 } 489 467 490 swish_tokenize3( ti, buf, metaname, context ); 468 469 491 RETVAL = ti; 470 471 492 472 493 OUTPUT: 473 494 RETVAL … … 476 497 477 498 # include the other .xs files 499 INCLUDE: XS/Constants.xs 478 500 INCLUDE: XS/Config.xs 479 501 INCLUDE: XS/Analyzer.xs libswish3/trunk/bindings/perl/XS/MetaName.xs
r2045 r2172 2 2 3 3 PROTOTYPES: enable 4 5 swish_MetaName * 6 new(CLASS, name) 7 char * CLASS; 8 xmlChar * name; 9 10 CODE: 11 RETVAL = swish_init_metaname(name); 12 RETVAL->ref_cnt++; 13 14 OUTPUT: 15 RETVAL 16 17 4 18 5 19 SV* libswish3/trunk/bindings/perl/XS/Token.xs
r2168 r2172 24 24 CLASS = METANAME_CLASS; 25 25 RETVAL = self->meta; 26 RETVAL->ref_cnt++; 26 27 27 28 OUTPUT: … … 63 64 64 65 CODE: 65 //self->ref_cnt--;66 self->ref_cnt--; 66 67 67 68 if (SWISH_DEBUG) { 68 69 warn("DESTROYing swish_Token object %s [%d] [ref_cnt = %d]", 69 70 SvPV(ST(0), PL_na), self, self->ref_cnt); 71 warn("Token has swish_MetaName object ref_cnt = %d", 72 self->meta->ref_cnt); 73 } 74 75 if (self->ref_cnt > 0 && self->meta->ref_cnt == 0) { 76 SWISH_WARN("Token's MetaName ref_cnt should not be less than Token"); 70 77 } 71 78 libswish3/trunk/bindings/perl/XS/TokenIterator.xs
r2168 r2172 27 27 28 28 CODE: 29 //self->ref_cnt--;29 self->ref_cnt--; 30 30 31 31 if (SWISH_DEBUG) { libswish3/trunk/bindings/perl/lib/SWISH/3.pm
r2168 r2172 26 26 XSLoader::load( __PACKAGE__, $VERSION ); 27 27 28 # our symbol table is populated with newCONSTSUB in 3.xs 28 # init the memory counter as class method at start up 29 # and call debug in END block 30 SWISH::3->init; 31 32 END { 33 my $memcount = SWISH::3->get_memcount; 34 if ($memcount) { 35 warn "suspicious memory count in global cleanup"; 36 SWISH::3->mem_debug(); 37 } 38 } 39 40 # our symbol table is populated with newCONSTSUB in Constants.xs 29 41 # directly from libswish3.h, so we just grep the symbol table. 30 42 my @constants = ( grep {m/^SWISH_/} keys %SWISH::3:: ); … … 50 62 my $class = shift; 51 63 my %arg = @_; 52 my $self = $class-> init;64 my $self = $class->_setup; 53 65 54 66 if ( $arg{config} ) { libswish3/trunk/bindings/perl/t/07-refcnt.t
r2030 r2172 19 19 is( $s3->config->refcount, 1, "config refcount == 1" ); 20 20 21 # avoid spurious mem error from libswish322 # just because of order of Perl ref cleanup23 undef $analyzer;24 libswish3/trunk/bindings/perl/t/10tokenize.t
r2168 r2172 6 6 ok( my $tokens = $s3->tokenize( 7 7 "now is the time, ain't it? or when else might it be!", 8 'foo', 'bar'8 SWISH::3::MetaName->new('foo'), 'bar' 9 9 ), 10 10 "wordlist" … … 30 30 } 31 31 32 #diag( '=' x 60 );32 diag( '=' x 60 ); 33 33 for my $w (SWISH_TOKEN_FIELDS) { 34 34 … … 37 37 $val = $val->name; 38 38 } 39 #diag( sprintf( "%15s: %s\n", $w, $val ) ); 39 40 diag( sprintf( "%15s: %s\n", $w, $val ) ); 40 41 41 42 } 42 43 } 43 44 44 #undef $wlist;45 #undef $s3;libswish3/trunk/bindings/perl/t/11get_set_parser.t
r2030 r2172 17 17 ok( my $s3 = SWISH::3->new( handler => sub { } ), "new parser" ); 18 18 19 ok( my $conf1 = $s3->get_config,"get initial config" );19 ok( my $conf1 = $s3->get_config, "get initial config" ); 20 20 ok( my $config = SWISH::3::Config->new, "new config" ); 21 21 ok( !$s3->set_config($config), "set config" ); … … 24 24 ); 25 25 ok( my $conf2 = $s3->get_config, "get conf2" ); 26 diag("config = $config"); 27 diag("conf1 = $conf1"); 28 diag("conf2 = $conf2"); 26 27 #diag("config = $config"); 28 #diag("conf1 = $conf1"); 29 #diag("conf2 = $conf2"); 29 30 30 31 ok( my $ana1 = $s3->get_analyzer, "get initial analyzer" ); … … 36 37 ok( my $ana2 = $s3->get_analyzer, "get ana2" ); 37 38 38 # avoid spurious libswish3 mem error due to "random" order of Perl39 # SV cleanup40 #undef $analyzer;41 #undef $ana2;42 #undef $ana1;43 #undef $conf2;44 #undef $conf1;45 #undef $config;46 undef $s3;47 libswish3/trunk/bindings/perl/t/12-stash.t
r2030 r2172 2 2 3 3 { 4 4 5 package MyConfig; 5 6 our @ISA = ('SWISH::3::Config'); 7 6 8 sub DESTROY { 7 9 $_[0]->SUPER::DESTROY; … … 10 12 11 13 use_ok('SWISH::3'); 12 ok(my $s3 = SWISH::3->new( config_class => 'MyConfig' ), "new s3"); 13 ok(my $conf = $s3->config, "get config"); 14 undef $conf; 15 undef $s3; 16 diag("s3 == undef"); 14 ok( my $s3 = SWISH::3->new( config_class => 'MyConfig' ), "new s3" ); 15 ok( my $conf = $s3->config, "get config" ); libswish3/trunk/bindings/perl/t/13-chained.t
r2031 r2172 4 4 ok(my $a = SWISH::3->new->analyzer, 'new analyzer'); 5 5 is($a->refcount, 1, 'refcount'); 6 libswish3/trunk/bindings/perl/t/20metanames.t
r2151 r2172 68 68 69 69 } 70 71 # TODO this ends with -177 mem err
