spurious IndexError [interfacing with swig generated code]

Thomas Wouters thomas at xs4all.net
Tue Jun 5 14:56:37 CEST 2001


On Tue, Jun 05, 2001 at 10:47:39AM +0000, jonathan at webtop.com wrote:

> We've been using swig to generate a python binding to a company 
> C++ class library.

> I've spotted a bug/problem which occurs in the following code :

> [call to unrelated SWIG generated constructor]
> w ="article";
> v ="articl";
> print w==v; # fails here with a spurious IndexError (list index out of range)

What is probably happening is that an earlier operation causes an IndexError
exception, and the error isn't being cleared. The assignment operation only
checks for errors if one of the functions called returns a value that
indicates an error, so it won't get detected until either something raises
an error (and overwrites the old error) or a function *might* have set an
exception -- which is what the compare operation does.

You can test whether an exception occured using PyErr_Occurred() from C.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list