Changeset 2015
- Timestamp:
- 02/12/08 00:36:10 (3 months ago)
- Files:
-
- libswish3/trunk/bindings/perl/3.xs (modified) (18 diffs)
- libswish3/trunk/bindings/perl/lib/SWISH/3.pm (modified) (4 diffs)
- libswish3/trunk/bindings/perl/lib/SWISH/3/Config.pm (added)
- libswish3/trunk/bindings/perl/macros.h (modified) (1 diff)
- libswish3/trunk/bindings/perl/t/01slurp.t (modified) (1 diff)
- libswish3/trunk/bindings/perl/t/07-refcnt.t (added)
- libswish3/trunk/bindings/perl/t/08-handler.t (added)
- libswish3/trunk/bindings/perl/t/10tokenize.t (modified) (2 diffs)
- libswish3/trunk/bindings/perl/xs_helpers.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/bindings/perl/3.xs
r2014 r2015 27 27 stash = newHV(); 28 28 RETVAL = swish_init_swish3( &sp_handler, newRV_inc((SV*)stash) ); 29 RETVAL->ref_cnt ++;29 RETVAL->ref_cnt = 1; 30 30 31 31 sp_hv_store(stash, DATA_CLASS_KEY, newSVpv(DATA_CLASS, 0)); … … 37 37 //sp_describe_object(newRV_noinc((SV*)RETVAL->stash)); 38 38 39 RETVAL->analyzer->ref_cnt ++;39 RETVAL->analyzer->ref_cnt = 1; 40 40 RETVAL->analyzer->tokenizer = &sp_tokenize; 41 41 analyzer_stash = newHV(); 42 42 RETVAL->analyzer->stash = newRV_inc((SV*)analyzer_stash); 43 43 44 RETVAL->config->ref_cnt = 1; 45 RETVAL->parser->ref_cnt = 1; 46 44 47 //SvREFCNT_inc(RETVAL); 45 48 … … 72 75 SV* 73 76 slurp(self, filename) 74 SV*self;75 char* filename;77 swish_3* self; 78 char* filename; 76 79 77 80 PREINIT: … … 265 268 void 266 269 DESTROY(self) 267 swish_3 *self; 268 269 CODE: 270 271 //if (SWISH_DEBUG) { 270 SV *self; 271 272 PREINIT: 273 swish_3 *s3; 274 275 CODE: 276 s3 = (swish_3*)sp_ptr_from_object(self); 277 278 if (SWISH_DEBUG) { 272 279 warn("DESTROYing swish_3 object %s [%d] [ref_cnt = %d]", 273 SvPV(ST(0), PL_na), self, s elf->ref_cnt);274 //}280 SvPV(ST(0), PL_na), self, s3->ref_cnt); 281 } 275 282 276 283 // TODO free pointers when we figure out ref cnt 277 //swish_free_swish3( (swish_3*)sp_ptr_from_object( (SV*)self ) ); 278 279 284 swish_free_swish3( s3 ); 285 286 287 int 288 refcount(obj) 289 SV* obj; 290 291 CODE: 292 RETVAL = SvREFCNT((SV*)SvRV(obj)); 293 294 OUTPUT: 295 RETVAL 296 280 297 281 298 ########################################################################################## … … 345 362 346 363 CODE: 347 sc = swish_subconfig_hash(self, (xmlChar*)key);348 RETVAL = sp_xml2_hash_to_perl_hash(sc);349 350 OUTPUT: 351 RETVAL 352 353 364 sc = swish_subconfig_hash(self, (xmlChar*)key); 365 RETVAL = sp_xml2_hash_to_perl_hash(sc); 366 367 OUTPUT: 368 RETVAL 369 370 354 371 355 372 int … … 418 435 } 419 436 437 int 438 refcount(obj) 439 SV* obj; 440 441 CODE: 442 RETVAL = SvREFCNT((SV*)SvRV(obj)); 443 444 OUTPUT: 445 RETVAL 446 420 447 421 448 # ******************************************************************************* … … 435 462 436 463 CODE: 464 //RETVAL = swish_init_analyzer((swish_Config*)sp_ptr_from_object( (SV*)config )); 437 465 RETVAL = swish_init_analyzer(config); 438 RETVAL->ref_cnt ++;466 RETVAL->ref_cnt = 1; 439 467 stash = newHV(); 440 468 RETVAL->stash = newRV_inc((SV*)stash); … … 506 534 507 535 CODE: 508 CLASS = "SWISH::3::WordList"; 536 CLASS = WORDLIST_CLASS; 537 538 // TODO reimplement as hashref arg 509 539 510 540 if (!SvUTF8(str)) … … 528 558 if ( items > 5 ) 529 559 context = (xmlChar*)SvPV(ST(5), PL_na); 560 561 //warn ("word_pos %d offset %d metaname %s context %s\n", word_pos, offset, metaname, context ); 530 562 531 563 } … … 564 596 565 597 CODE: 566 CLASS = "SWISH::3::WordList";598 CLASS = WORDLIST_CLASS; 567 599 568 600 if (!SvUTF8(str)) … … 605 637 OUTPUT: 606 638 RETVAL 639 640 int 641 refcount(obj) 642 SV* obj; 643 644 CODE: 645 RETVAL = SvREFCNT((SV*)SvRV(obj)); 646 647 OUTPUT: 648 RETVAL 649 607 650 608 651 # ******************************************************************************* … … 620 663 621 664 CODE: 622 CLASS = "SWISH::3::Word";665 CLASS = WORD_CLASS; 623 666 624 667 if (self->current == NULL) { … … 664 707 } 665 708 709 int 710 refcount(obj) 711 SV* obj; 712 713 CODE: 714 RETVAL = SvREFCNT((SV*)SvRV(obj)); 715 716 OUTPUT: 717 RETVAL 718 666 719 667 720 # ******************************************************************************* … … 728 781 729 782 783 int 784 refcount(obj) 785 SV* obj; 786 787 CODE: 788 RETVAL = SvREFCNT((SV*)SvRV(obj)); 789 790 OUTPUT: 791 RETVAL 792 730 793 731 794 # ******************************************************************************* … … 812 875 RETVAL 813 876 877 int 878 refcount(obj) 879 SV* obj; 880 881 CODE: 882 RETVAL = SvREFCNT((SV*)SvRV(obj)); 883 884 OUTPUT: 885 RETVAL 886 814 887 815 888 # ******************************************************************************* 816 889 817 MODULE = SWISH::3 PACKAGE = SWISH::3:: Parser::Data890 MODULE = SWISH::3 PACKAGE = SWISH::3::Data 818 891 819 892 PROTOTYPES: enable … … 905 978 OUTPUT: 906 979 RETVAL 907 980 981 908 982 swish_WordList * 909 983 wordlist(self) … … 914 988 915 989 CODE: 916 CLASS = "SWISH::3::WordList";990 CLASS = WORDLIST_CLASS; 917 991 918 992 # MUST increment refcnt 2x so that SWISH::3::Parser::WordList::DESTROY … … 938 1012 # SvREFCNT_dec( self->user_data ); 939 1013 940 1014 int 1015 refcount(obj) 1016 SV* obj; 1017 1018 CODE: 1019 RETVAL = SvREFCNT((SV*)SvRV(obj)); 1020 1021 OUTPUT: 1022 RETVAL 1023 1024 libswish3/trunk/bindings/perl/lib/SWISH/3.pm
r2014 r2015 7 7 our $VERSION = '0.01'; 8 8 9 $ENV{SWISH3} = 1; # should be set by libswish3 in swish.c but doesn't seem to.9 #$ENV{SWISH3} = 1; # should be set by libswish3 in swish.c but doesn't seem to. 10 10 11 11 use Carp; … … 13 13 use Devel::Peek; 14 14 15 require XSLoader;15 use XSLoader; 16 16 XSLoader::load( __PACKAGE__, $VERSION ); 17 use SWISH::3::Config; 18 use SWISH::3::Constants; 19 20 # convenience accessors 21 *config = \&get_config; 22 *analyzer = \&get_analyzer; 17 23 18 24 sub new { … … 34 40 } 35 41 36 if ( !$arg{handler} ) { 37 no strict 'refs'; 38 no warnings 'redefine'; 39 my $data_class = $self->get_data_class; 40 eval "use $data_class"; 41 if ($@) { 42 croak "can't load data_class $data_class:\n$@"; 43 } 44 $arg{handler} = \&{ $data_class . '::handler' }; 45 } 42 $arg{handler} ||= \&default_handler; 46 43 47 44 $self->set_handler( $arg{handler} ); … … 78 75 Dump($self); 79 76 Data::Dump::dump($self); 77 } 78 } 79 80 sub default_handler { 81 my $data = shift; 82 83 select(STDERR); 84 85 print '~' x 80, "\n"; 86 87 my $props = $data->config->properties; 88 89 print "Properties\n"; 90 for my $p ( keys %$props ) { 91 my $v = $data->property($p); 92 my $type = $props->{$p}; 93 94 print " <$p type='$type'>$v</$p>\n"; 95 } 96 97 print "Doc\n"; 98 for my $d ( SWISH_DOC_FIELDS() ) { 99 100 #printf("%15s: %s\n", $d, $data->doc->$d); 101 } 102 103 print "WordList\n"; 104 while ( my $swishword = $data->wordlist->next ) { 105 for my $w ( SWISH_WORD_FIELDS() ) { 106 107 printf( "%15s: %s\n", $w, $swishword->$w ); 108 } 80 109 } 81 110 } libswish3/trunk/bindings/perl/macros.h
r2014 r2015 8 8 #define PARSER_CLASS "SWISH::3::Parser" 9 9 #define PARSER_CLASS_KEY "sp_parser_class" 10 #define DATA_CLASS "SWISH::3:: Parser::Data"10 #define DATA_CLASS "SWISH::3::Data" 11 11 #define DATA_CLASS_KEY "sp_data_class" 12 12 #define TOKEN_CLASS "SWISH::3::Token" 13 13 #define WORDLIST_CLASS "SWISH::3::WordList" 14 #define WORD_CLASS "SWISH::3::Word" 15 #define SELF_KEY "sp_self" 14 16 #define CONFIG_KEY "sp_config" 15 17 #define ANALYZER_KEY "sp_analyzer" libswish3/trunk/bindings/perl/t/01slurp.t
r2014 r2015 7 7 ok( my $buf = $s3->slurp("t/test.html"), "slurp file" ); 8 8 9 diag($buf); 9 #diag( $s3->dump ); 10 #diag( $s3->refcount ); 10 11 12 #diag($buf); 13 libswish3/trunk/bindings/perl/t/10tokenize.t
r2014 r2015 1 use Test::More tests => 8;1 use Test::More tests => 9; 2 2 3 3 use_ok('SWISH::3'); 4 4 use_ok('SWISH::3::Constants'); 5 5 6 ok( my $analyzer = SWISH::3->new()->get_analyzer, "new tokenizer" ); 6 ok( my $s3 = SWISH::3->new, "new s3" ); 7 ok( my $analyzer = $s3->analyzer, "new tokenizer" ); 7 8 8 9 ok( my $wlist = $analyzer->tokenize( 9 10 "now is the time, ain't it? or when else might it be!", 10 13, 14, 'foo', 'bar'11 5, 14, 'foo', 'bar' 11 12 ), 12 13 "wordlist" … … 19 20 my $word = $swishword->word; 20 21 if ( $word eq 'now' ) { 21 is( $swishword->position, 14, "now position" );22 is( $swishword->position, 6, "now position" ); 22 23 } 23 24 if ( $word eq 'time' ) { 24 is( $swishword->position, 17, "time position" );25 is( $swishword->position, 9, "time position" ); 25 26 } 26 27 if ( $word eq 'be' ) { 27 is( $swishword->position, 25, "be position" );28 is( $swishword->position, 17, "be position" ); 28 29 } 29 30 libswish3/trunk/bindings/perl/xs_helpers.c
r2014 r2015 442 442 443 443 SV* obj; 444 obj = sp_ptr_to_object( TOKEN_CLASS, (IV)token );444 obj = sp_ptr_to_object( TOKEN_CLASS, (IV)token ); 445 445 446 446 PUSHMARK(SP); … … 456 456 { 457 457 dTHX; 458 458 459 unsigned int wpos, offset, num_code_points; 459 460 swish_Token *s3_token; … … 477 478 va_end(args); 478 479 480 //warn("wpos %d offset %d meta %s ctxt %s\n", wpos, offset, meta, ctxt); 481 479 482 s3_token = swish_xmalloc(sizeof(swish_Token)); 480 483 mg = NULL; … … 519 522 s3_token->analyzer = analyzer; 520 523 s3_token->list = list; 524 s3_token->offset = offset; // gets incremented 521 525 522 526 … … 549 553 550 554 tok_pts = end - start; // TODO what is this for?? 555 tok_bytes = end_ptr - start_ptr; 551 556 552 557 s3_token->start_ptr = start_ptr; 553 s3_token->tok_bytes = end_ptr - start_ptr;558 s3_token->tok_bytes = tok_bytes; 554 559 s3_token->start = start; 555 560 s3_token->end = end; 556 561 s3_token->wpos = ++wpos; 557 s3_token->offset = (tok_bytes + offset - 1);562 558 563 559 564 if (token_handler) { … … 563 568 } 564 569 570 /* increment for next iteration */ 571 s3_token->offset += tok_bytes; 565 572 } 566 573
