[Xapian-devel] PHP Latest
Olly Betts
olly at survex.com
Thu Apr 20 13:42:43 BST 2006
On Thu, Apr 20, 2006 at 08:53:09AM +0100, Sam Liddicott wrote:
> The generated .cc had this in:
>
> #define SWIG_PHP_Error(code,msg) ErrorCode() = code; ErrorMsg() = msg;
> SWIG_fail;
>
> which looks dangerous if SWIG_PHP_ERROR is part of an if/else block.
>
> Surely it should be in { } or even the:
> do { } while (0)
> trick
>
> I don't know if that is ever used, it just stood out as looking highly
> dodgy.
Well spotted.
It is used in xapian_wrap.cc, but only explicitly in { } by itself so it's not
causing any problems for us currently.
But it would make more sense to make it safe to use anywhere, otherwise
it's a bug waiting to happen when someone perfectly reasonably uses it
in another context (perhaps even in a user typemap if it's permitted
there).
Actually, looking where it can be used by SWIG this has already happened - the
input typemap for "void *" uses it like this:
%typemap(in) void *
{
if(SWIG_ConvertPtr(*$input, (void **) &$1, 0, 0) < 0) {
/* Allow NULL from php for void* */
if ((*$input)->type==IS_NULL) $1=0;
else
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
}
}
So that will always SWIG_fail, but without setting the error code in the case
where it should have worked. A couple of "throws" typemaps might also be
problematic, but it depends where they actually get inserted.
I'll send a patch to the SWIG people.
Cheers,
Olly
More information about the Xapian-devel
mailing list