Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixes to support multiple speller objects, RT #84054

  • Loading branch information...
commit 08c0bbfeec077e99798d6091b190daf7cf6c9dc7 1 parent e2030c8
Paul Flo Williams hisdeedsaredust authored
9 Hunspell.pm
@@ -98,9 +98,6 @@ Text::Hunspell - Perl interface to the GNU Hunspell library
98 98 print "Morphological modification generator...\n";
99 99 print Data::Dumper::Dumper(\@suggestions);
100 100
101   - # Deletes the underlying Hunspell C/C++ object
102   - $speller->delete($speller);
103   -
104 101
105 102 =head1 DESCRIPTION
106 103
@@ -187,12 +184,6 @@ Returns morphologically modified stem like $word.
187 184 TODO WHY IS THIS DIFFERENT FROM generate2() ???
188 185 EXPLAIN.
189 186
190   -=head2 C<< $speller->delete($speller) >>
191   -
192   -Deletes the speller class.
193   -
194   -TODO WHY IS THIS NEEDED?? Called on C<$speller> and needs C<$speller> ???
195   -
196 187 =head1 BUGS
197 188
198 189 Probably. Yes, definitely.
50 Hunspell.xs
@@ -19,16 +19,6 @@ using namespace std;
19 19
20 20 /* $Id: Hunspell.xs,v 1.5 2002/08/29 20:28:00 moseley Exp $ */
21 21
22   -static Hunspell *handle;
23   -
24   -/* Needed for static initialization inside XS functions.
25   - A hack, yes, since 'THIS' is always empty it seems.
26   -*/
27   -static Hunspell * get_hunspell_handle () {
28   - assert(handle != NULL);
29   - return handle;
30   -}
31   -
32 22 static void * get_mortalspace ( size_t nbytes ) {
33 23 SV * mortal;
34 24 mortal = sv_2mortal( NEWSV(0, nbytes ) );
@@ -47,34 +37,28 @@ Hunspell::new(aff,dic )
47 37 char *aff;
48 38 char *dic;
49 39 CODE:
50   - /* Store the new object as static shared handle.
51   - Every new will overwrite it. Ugly, but reasonable. */
52   - handle = new Hunspell(aff, dic);
53   - RETVAL = handle;
  40 + RETVAL = new Hunspell(aff, dic);
54 41
55 42 OUTPUT:
56 43 RETVAL
57 44
58   -
59 45 int
60 46 Hunspell::delete(h)
61 47 Hunspell *h;
62 48 CODE:
63   - delete h;
64   - /* If we deleted our shared static object (most likely)
65   - then remove the reference to it, so it doesn't get used */
66   - if (h == handle)
67   - handle = NULL;
68   -
69   - /* And return something to the caller too. */
  49 + warn("Text::Hunspell::delete() is deprecated and no replacement is needed");
70 50 RETVAL = 1;
  51 + OUTPUT:
  52 + RETVAL
  53 +
  54 +void
  55 +Hunspell::DESTROY()
71 56
72 57 int
73 58 Hunspell::add_dic(dic)
74 59 char *dic;
75 60 CODE:
76   - handle = get_hunspell_handle();
77   - RETVAL = handle->add_dic(dic);
  61 + RETVAL = THIS->add_dic(dic);
78 62
79 63 OUTPUT:
80 64 RETVAL
@@ -83,8 +67,7 @@ int
83 67 Hunspell::check(buf)
84 68 char *buf;
85 69 CODE:
86   - handle = get_hunspell_handle();
87   - RETVAL = handle->spell(buf);
  70 + RETVAL = THIS->spell(buf);
88 71
89 72 OUTPUT:
90 73 RETVAL
@@ -96,8 +79,7 @@ Hunspell::suggest(buf)
96 79 char **wlsti;
97 80 int i, val;
98 81 PPCODE:
99   - handle = get_hunspell_handle();
100   - val = handle->suggest(&wlsti, buf);
  82 + val = THIS->suggest(&wlsti, buf);
101 83 for (int i = 0; i < val; i++) {
102 84 PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
103 85 free(wlsti[i]);
@@ -110,8 +92,7 @@ Hunspell::analyze(buf)
110 92 char **wlsti;
111 93 int i, val;
112 94 PPCODE:
113   - handle = get_hunspell_handle();
114   - val = handle->analyze(&wlsti, buf);
  95 + val = THIS->analyze(&wlsti, buf);
115 96 for (i = 0; i < val; i++) {
116 97 PUSHs(sv_2mortal(newSVpv(wlsti[i], 0)));
117 98 free(wlsti[i]);
@@ -125,8 +106,7 @@ Hunspell::stem( buf)
125 106 char **wlsti;
126 107 int i, val;
127 108 PPCODE:
128   - handle = get_hunspell_handle();
129   - val = handle->stem(&wlsti, buf);
  109 + val = THIS->stem(&wlsti, buf);
130 110 for (int i = 0; i < val; i++) {
131 111 PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
132 112 free(wlsti[i]);
@@ -141,8 +121,7 @@ Hunspell::generate( buf, sample)
141 121 char **wlsti;
142 122 int i, val;
143 123 PPCODE:
144   - handle = get_hunspell_handle();
145   - val = handle->generate(&wlsti, buf, sample);
  124 + val = THIS->generate(&wlsti, buf, sample);
146 125 for (int i = 0; i < val; i++) {
147 126 PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
148 127 free(wlsti[i]);
@@ -171,8 +150,7 @@ Hunspell::generate2( buf, avref)
171 150 array[i] = SvPV( *elem, PL_na );
172 151 }
173 152
174   - handle = get_hunspell_handle();
175   - val = handle->generate(&wlsti, buf, array, len);
  153 + val = THIS->generate(&wlsti, buf, array, len);
176 154
177 155 for (int i = 0; i < val; i++) {
178 156 PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
6 t/05-core.t
@@ -2,7 +2,7 @@ use strict;
2 2 use warnings;
3 3
4 4 use Data::Dumper;
5   -use Test::More tests => 6;
  5 +use Test::More tests => 5;
6 6 use Text::Hunspell;
7 7
8 8 my $speller = Text::Hunspell->new(qw(./t/test.aff ./t/test.dic));
@@ -30,7 +30,3 @@ is_deeply(
30 30 \@suggestions => [ qw(lói ló lót) ],
31 31 q(List of suggestions should be correct)
32 32 );
33   -
34   -# Curtains down
35   -ok($speller->delete($speller), q(delete method presumably worked));
36   -
5 t/07-add-dictionary.t
@@ -2,7 +2,7 @@ use strict;
2 2 use warnings;
3 3
4 4 use Data::Dumper;
5   -use Test::More tests => 5;
  5 +use Test::More tests => 4;
6 6 use Text::Hunspell;
7 7
8 8 my $speller = Text::Hunspell->new(qw(./t/test.aff ./t/test.dic));
@@ -24,6 +24,3 @@ ok(
24 24 $speller->check($word),
25 25 qq(Word '$word' is in the supplemental dictionary)
26 26 );
27   -
28   -# Curtains down
29   -ok($speller->delete($speller), q(delete method presumably worked));
40 t/08-two-dics.t
... ... @@ -0,0 +1,40 @@
  1 +use strict;
  2 +use warnings;
  3 +
  4 +use Test::More tests => 7;
  5 +use Text::Hunspell;
  6 +
  7 +my $speller = Text::Hunspell->new(qw(./t/test.aff ./t/test.dic));
  8 +die unless $speller;
  9 +ok($speller, qq(Created a Text::Hunspell object [$speller]));
  10 +
  11 +my $word = q(lótól);
  12 +ok(
  13 + $speller->check($word),
  14 + qq(Word '$word' found in first dictionary)
  15 +);
  16 +
  17 +my $speller2 = Text::Hunspell->new(qw(./t/supp.aff ./t/supp.dic));
  18 +die unless $speller2;
  19 +ok($speller2, qq(Created another Text::Hunspell object [$speller2]));
  20 +
  21 +ok(
  22 + $speller->check($word),
  23 + qq(Word '$word' found in first dictionary)
  24 +);
  25 +
  26 +ok(
  27 + !$speller2->check($word),
  28 + qq(Word '$word' not found in second dictionary)
  29 +);
  30 +
  31 +$word = q(munkey);
  32 +ok(
  33 + !$speller->check($word),
  34 + qq(Word '$word' not found in first dictionary)
  35 +);
  36 +
  37 +ok(
  38 + $speller2->check($word),
  39 + qq(Word '$word' found in second dictionary)
  40 +);
1  t/supp.aff
... ... @@ -0,0 +1 @@
  1 +SET UTF-8
5 typemap
@@ -2,7 +2,6 @@
2 2
3 3 TYPEMAP
4 4 Hunspell * O_OBJECT
5   -Hunspell O_OBJECT
6 5
7 6 # From: "perlobject.map" Dean Roehrich, version 19960302
8 7 # O_OBJECT -> link an opaque C or C++ object to a blessed Perl object.
@@ -15,10 +14,8 @@ O_OBJECT
15 14
16 15 INPUT
17 16 O_OBJECT
18   -# warn(\" sv_isobject($arg) $arg SvTYPE(SvRV($arg)) SVt_PVMG $type\");
19 17 if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) )
20   -# $var = ($type)SvIV((SV*)SvRV( $arg ));
21   - $var = INT2PTR ($type, SvIV (SvRV ($arg)));
  18 + $var = ($type)SvIV((SV*)SvRV( $arg ));
22 19 else{
23 20 warn( \"${Package}::$func_name() -- $var is not a blessed SV reference\" );
24 21 XSRETURN_UNDEF;

0 comments on commit 08c0bbf

Please sign in to comment.
Something went wrong with that request. Please try again.