[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [aspell-devel] clear_session, store_replacement, and support

From: Kevin Atkinson
Subject: Re: [aspell-devel] clear_session, store_replacement, and support
Date: Sun, 14 Aug 2005 00:51:22 -0600 (MDT)

On Thu, 28 Jul 2005, Bill Moseley wrote:

> The questions I referred to above are about store_replacement failing
> to return a true value.  aspell.h has only this:
>     int aspell_speller_store_replacement(struct AspellSpeller * ths, const 
> char * mis, int mis_size, const char * cor, int cor_size);
> And from my *brief* look at the code it seems as if it should return a
> value indicating an error, although I didn't dig that deep:
> extern "C" int aspell_speller_store_replacement(Speller * ths, const char * 
> mis, int mis_size, const char * cor, int cor_size)
> {
>   ths->temp_str_0.clear();
>   ths->to_internal_->convert(mis, mis_size, ths->temp_str_0);
>   unsigned int s0 = ths->temp_str_0.size();
>   ths->temp_str_1.clear();
>   ths->to_internal_->convert(cor, cor_size, ths->temp_str_1);
>   unsigned int s1 = ths->temp_str_1.size();
>   PosibErr<bool> ret = 
> ths->store_replacement(MutableString(ths->temp_str_0.mstr(), s0), 
> MutableString(ths->temp_str_1.mstr(), s1));
>   ths->err_.reset(ret.release_err());
>   if (ths->err_ != 0) return -1;
>   return;
> }

OK.  After close examination this function is incorrect.  The internal 
API function returns a PosibErr<void> which means that it doesn't actually 
return a value except an error condition.   Thus I am casing a void to a 
bool somewhere.  The resulting bool is actually uninitialized.  Thus the 
function return value is also uninitialized.

I will fix this in Aspell 0.60.4.  This function will now return true on 
success and false on an error condition to be consistent with the other 
functions which don't return value.

> Actually, I'm not clear what is expected as a return.  My Perl xs code
> does this:
>         RETVAL = aspell_speller_store_replacement(self->speller, word, -1, 
> replacement, -1);
>         if ( !RETVAL )
>         {
>             self->errnum = aspell_speller_error_number( (const AspellSpeller 
> *)self->speller );
>             strncpy(self->lastError, (char*) 
> aspell_speller_error_message(self->speller), MAX_ERRSTR_LEN);
>             XSRETURN_UNDEF;
>         }

I suggest you change this code to:
  if (aspell_speller_error(self->speller)) 

This will always work as any function which can create an error condition 
will also reset the error object.

Also, error numbers are no longer used.  aspell_speller_error_number will 
simply return 0 if there is no error or 1 otherwise.  There is no point in 
storing it.

> Then today someone else emailed saying another test was failing.  When
> running "make test" on the Perl module I add a new word to the
> session, and then make sure that word is returned in the session.
> Then I call clear_session() and then check if the word is then removed
> from the session.  It's this last test that is failing -- the word is
> still being returned from suggest().  The failure report is from
> someone using OS X, and I've not been able to reproduce the problem in
> other OS X machines.  And the word is not normally in their dictionary.
> Am I not understanding clear_session()?  Or is there another reason the
> word is not removed from the session?

File a bug report.

> Is there more than apsell.h and the page
> to use as the API reference?

There is the example programs in the "examples/" directory if the source 

However, I admit that the API documentation is poor.  I have not had the 
time to write something better.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]