Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes to support multiple speller objects, RT #84054

  • Loading branch information...
commit 08c0bbfeec077e99798d6091b190daf7cf6c9dc7 1 parent e2030c8
@hisdeedsaredust hisdeedsaredust authored
View
9 Hunspell.pm
@@ -98,9 +98,6 @@ Text::Hunspell - Perl interface to the GNU Hunspell library
print "Morphological modification generator...\n";
print Data::Dumper::Dumper(\@suggestions);
- # Deletes the underlying Hunspell C/C++ object
- $speller->delete($speller);
-
=head1 DESCRIPTION
@@ -187,12 +184,6 @@ Returns morphologically modified stem like $word.
TODO WHY IS THIS DIFFERENT FROM generate2() ???
EXPLAIN.
-=head2 C<< $speller->delete($speller) >>
-
-Deletes the speller class.
-
-TODO WHY IS THIS NEEDED?? Called on C<$speller> and needs C<$speller> ???
-
=head1 BUGS
Probably. Yes, definitely.
View
50 Hunspell.xs
@@ -19,16 +19,6 @@ using namespace std;
/* $Id: Hunspell.xs,v 1.5 2002/08/29 20:28:00 moseley Exp $ */
-static Hunspell *handle;
-
-/* Needed for static initialization inside XS functions.
- A hack, yes, since 'THIS' is always empty it seems.
-*/
-static Hunspell * get_hunspell_handle () {
- assert(handle != NULL);
- return handle;
-}
-
static void * get_mortalspace ( size_t nbytes ) {
SV * mortal;
mortal = sv_2mortal( NEWSV(0, nbytes ) );
@@ -47,34 +37,28 @@ Hunspell::new(aff,dic )
char *aff;
char *dic;
CODE:
- /* Store the new object as static shared handle.
- Every new will overwrite it. Ugly, but reasonable. */
- handle = new Hunspell(aff, dic);
- RETVAL = handle;
+ RETVAL = new Hunspell(aff, dic);
OUTPUT:
RETVAL
-
int
Hunspell::delete(h)
Hunspell *h;
CODE:
- delete h;
- /* If we deleted our shared static object (most likely)
- then remove the reference to it, so it doesn't get used */
- if (h == handle)
- handle = NULL;
-
- /* And return something to the caller too. */
+ warn("Text::Hunspell::delete() is deprecated and no replacement is needed");
RETVAL = 1;
+ OUTPUT:
+ RETVAL
+
+void
+Hunspell::DESTROY()
int
Hunspell::add_dic(dic)
char *dic;
CODE:
- handle = get_hunspell_handle();
- RETVAL = handle->add_dic(dic);
+ RETVAL = THIS->add_dic(dic);
OUTPUT:
RETVAL
@@ -83,8 +67,7 @@ int
Hunspell::check(buf)
char *buf;
CODE:
- handle = get_hunspell_handle();
- RETVAL = handle->spell(buf);
+ RETVAL = THIS->spell(buf);
OUTPUT:
RETVAL
@@ -96,8 +79,7 @@ Hunspell::suggest(buf)
char **wlsti;
int i, val;
PPCODE:
- handle = get_hunspell_handle();
- val = handle->suggest(&wlsti, buf);
+ val = THIS->suggest(&wlsti, buf);
for (int i = 0; i < val; i++) {
PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
free(wlsti[i]);
@@ -110,8 +92,7 @@ Hunspell::analyze(buf)
char **wlsti;
int i, val;
PPCODE:
- handle = get_hunspell_handle();
- val = handle->analyze(&wlsti, buf);
+ val = THIS->analyze(&wlsti, buf);
for (i = 0; i < val; i++) {
PUSHs(sv_2mortal(newSVpv(wlsti[i], 0)));
free(wlsti[i]);
@@ -125,8 +106,7 @@ Hunspell::stem( buf)
char **wlsti;
int i, val;
PPCODE:
- handle = get_hunspell_handle();
- val = handle->stem(&wlsti, buf);
+ val = THIS->stem(&wlsti, buf);
for (int i = 0; i < val; i++) {
PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
free(wlsti[i]);
@@ -141,8 +121,7 @@ Hunspell::generate( buf, sample)
char **wlsti;
int i, val;
PPCODE:
- handle = get_hunspell_handle();
- val = handle->generate(&wlsti, buf, sample);
+ val = THIS->generate(&wlsti, buf, sample);
for (int i = 0; i < val; i++) {
PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
free(wlsti[i]);
@@ -171,8 +150,7 @@ Hunspell::generate2( buf, avref)
array[i] = SvPV( *elem, PL_na );
}
- handle = get_hunspell_handle();
- val = handle->generate(&wlsti, buf, array, len);
+ val = THIS->generate(&wlsti, buf, array, len);
for (int i = 0; i < val; i++) {
PUSHs(sv_2mortal(newSVpv( wlsti[i] ,0 )));
View
6 t/05-core.t
@@ -2,7 +2,7 @@ use strict;
use warnings;
use Data::Dumper;
-use Test::More tests => 6;
+use Test::More tests => 5;
use Text::Hunspell;
my $speller = Text::Hunspell->new(qw(./t/test.aff ./t/test.dic));
@@ -30,7 +30,3 @@ is_deeply(
\@suggestions => [ qw(lói ló lót) ],
q(List of suggestions should be correct)
);
-
-# Curtains down
-ok($speller->delete($speller), q(delete method presumably worked));
-
View
5 t/07-add-dictionary.t
@@ -2,7 +2,7 @@ use strict;
use warnings;
use Data::Dumper;
-use Test::More tests => 5;
+use Test::More tests => 4;
use Text::Hunspell;
my $speller = Text::Hunspell->new(qw(./t/test.aff ./t/test.dic));
@@ -24,6 +24,3 @@ ok(
$speller->check($word),
qq(Word '$word' is in the supplemental dictionary)
);
-
-# Curtains down
-ok($speller->delete($speller), q(delete method presumably worked));
View
40 t/08-two-dics.t
@@ -0,0 +1,40 @@
+use strict;
+use warnings;
+
+use Test::More tests => 7;
+use Text::Hunspell;
+
+my $speller = Text::Hunspell->new(qw(./t/test.aff ./t/test.dic));
+die unless $speller;
+ok($speller, qq(Created a Text::Hunspell object [$speller]));
+
+my $word = q(lótól);
+ok(
+ $speller->check($word),
+ qq(Word '$word' found in first dictionary)
+);
+
+my $speller2 = Text::Hunspell->new(qw(./t/supp.aff ./t/supp.dic));
+die unless $speller2;
+ok($speller2, qq(Created another Text::Hunspell object [$speller2]));
+
+ok(
+ $speller->check($word),
+ qq(Word '$word' found in first dictionary)
+);
+
+ok(
+ !$speller2->check($word),
+ qq(Word '$word' not found in second dictionary)
+);
+
+$word = q(munkey);
+ok(
+ !$speller->check($word),
+ qq(Word '$word' not found in first dictionary)
+);
+
+ok(
+ $speller2->check($word),
+ qq(Word '$word' found in second dictionary)
+);
View
1  t/supp.aff
@@ -0,0 +1 @@
+SET UTF-8
View
5 typemap
@@ -2,7 +2,6 @@
TYPEMAP
Hunspell * O_OBJECT
-Hunspell O_OBJECT
# From: "perlobject.map" Dean Roehrich, version 19960302
# O_OBJECT -> link an opaque C or C++ object to a blessed Perl object.
@@ -15,10 +14,8 @@ O_OBJECT
INPUT
O_OBJECT
-# warn(\" sv_isobject($arg) $arg SvTYPE(SvRV($arg)) SVt_PVMG $type\");
if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) )
-# $var = ($type)SvIV((SV*)SvRV( $arg ));
- $var = INT2PTR ($type, SvIV (SvRV ($arg)));
+ $var = ($type)SvIV((SV*)SvRV( $arg ));
else{
warn( \"${Package}::$func_name() -- $var is not a blessed SV reference\" );
XSRETURN_UNDEF;
Please sign in to comment.
Something went wrong with that request. Please try again.