Permalink
Browse files

fix ST_DEBUG to make it a macro accessing var in Perl space rather th…

…an static int in C space
  • Loading branch information...
1 parent b89435b commit 998e37ad6c806558ba0b39729216dab97c7934e5 @karpet committed May 13, 2012
Showing with 48 additions and 9 deletions.
  1. +41 −5 Tools.xs
  2. +6 −4 search-tools.c
  3. +1 −0 search-tools.h
View
@@ -254,9 +254,18 @@ set_debug(self, val)
boolean val;
CODE:
- ST_DEBUG = val;
- //warn("ST_DEBUG set to %d", ST_DEBUG);
- RETVAL = self;
+ SV* st_debug_var;
+ st_debug_var = get_sv("Search::Tools::XS_DEBUG", GV_ADD);
+ //warn(" st_debug_var before = '%s'\n", SvPV_nolen(st_debug_var));
+ SvIV_set(st_debug_var, val);
+ SvIOK_on(st_debug_var);
+ //warn("ST_DEBUG set to %d", val);
+ //warn(" st_debug_var set = '%d'\n", ST_DEBUG);
+ if (SvREFCNT(st_debug_var) == 1) {
+ // IMPORTANT because we access var from Perl and C
+ SvREFCNT_inc(st_debug_var);
+ }
+ RETVAL = st_debug_var;
OUTPUT:
RETVAL
@@ -442,8 +451,21 @@ SV*
get_heat(self)
st_token_list *self;
+ PREINIT:
+ AV *heat;
+ IV len;
+ IV pos;
+ SV* h;
+
CODE:
- RETVAL = newRV_inc((SV*)self->heat);
+ heat = newAV();
+ pos = 0;
+ len = av_len(self->heat)+1;
+ while (pos < len) {
+ h = st_av_fetch(self->heat, pos++);
+ av_push(heat, h);
+ }
+ RETVAL = newRV((SV*)heat); /* no _inc -- this is a copy */
OUTPUT:
RETVAL
@@ -453,8 +475,22 @@ SV*
get_sentence_starts(self)
st_token_list *self;
+ PREINIT:
+ AV *starts;
+ IV len;
+ IV pos;
+ SV* sstart;
+
CODE:
- RETVAL = newRV_inc((SV*)self->sentence_starts);
+ starts = newAV();
+ pos = 0;
+ len = av_len(self->sentence_starts)+1;
+ while (pos < len) {
+ warn("fetch pos %d from len %d\n", pos, len);
+ sstart = st_av_fetch(self->sentence_starts, pos++);
+ av_push(starts, sstart);
+ }
+ RETVAL = newRV((SV*)starts); /* no _inc -- this is a copy */
OUTPUT:
RETVAL
View
@@ -11,8 +11,7 @@
#include <wctype.h>
#include "search-tools.h"
-/* global debug var */
-static boolean ST_DEBUG = 0;
+/* global vars */
static HV* ST_ABBREVS = NULL;
/* perl versions < 5.8.8 do not have this */
@@ -505,9 +504,11 @@ st_get_regex_from_sv( SV *regex_sv ) {
if (SvMAGICAL(sv))
mg = mg_find(sv, PERL_MAGIC_qr);
}
- if (!mg)
+ if (!mg) {
+ st_describe_object(regex_sv);
ST_CROAK("regex is not a qr// entity");
-
+ }
+
rx = (REGEXP*)mg->mg_obj;
#endif
@@ -717,6 +718,7 @@ st_tokenize( SV* str, SV* token_re, SV* heat_seeker, I32 match_num ) {
) {
token->is_sentence_start = 1;
inside_sentence = 1;
+ prev_sentence_start = token->pos;
}
}
else if (!prev_was_abbrev
View
@@ -10,6 +10,7 @@
#define ST_CROAK(args, ...) st_croak(__FILE__, __LINE__, FUNCTION__, args)
+#define ST_DEBUG SvIV(get_sv("Search::Tools::XS_DEBUG", GV_ADD))
#define ST_CLASS_TOKEN "Search::Tools::Token"
#define ST_CLASS_TOKENLIST "Search::Tools::TokenList"
#define ST_BAD_UTF8 "str must be UTF-8 encoded and flagged by Perl. \

0 comments on commit 998e37a

Please sign in to comment.