"tuple index out of range" side effect of C extension??

A

Andrew MacIntyre

I'm seeing a bizarre situation where IndexErrors are being thrown with
"tuple index out of range" error strings.

The scenario is something like:

l = [(v1a, v1b), (v2a, v2b), ..., (vna, vnb)]

for a, b in l:
...



with the IndexError being thrown on the "for..." line after the last
element of l has been through the for loop.

I've also seen the same exception thrown on first access to an attribute
of a simple class.

The exception being thrown is not consistent, and reducing the number of
tuples and lists in the code seems to reduce the likelihood of the
exception being thrown.

The only thing unusual is the presence of a C extension which I am testing
- an Ingres DB interface module, most of whose functionality seems to work
when the IndexErrors don't get thrown.

Perusal of the source, while not exhaustive, hasn't turned up anything
obvious; other than the embedded SQL stuff it seems to be in tune with the
module layout in the Python docs.

The complications are:-
- I don't have MSVC, so can't build a standard Windows Python debug setup
to really look at the internals;
- I built the module with MinGW32 1.1 (gcc 2.95.3, it compiles with only
1 warning which surprised me a bit) and Python can't yet be built by
MinGW (so that I could use gdb) AFAIK.

Platform is Windows2000.

Other than the obvious sources of this exception (attempting to explicitly
access a non-existent tuple element), googling turned up a reference to
this exception being encountered with Boost.Python based extensions which
doesn't seem to help as this module is pure C.

Has anyone ever encountered this sort of bizarreness while working with a
C extension?

Replies cc'ed to the reply-to address in addition to the list appreciated.

Thanks,
Andrew.
 
M

Michael Hudson

Andrew MacIntyre said:
I'm seeing a bizarre situation where IndexErrors are being thrown with
"tuple index out of range" error strings.
[snippety]

Has anyone ever encountered this sort of bizarreness while working with a
C extension?

Usually, this is the infamous "non-NULL return with exception set",
i.e. the extension module sets an exception but then fails to return
NULL to let the interpreter know about it.

It's a shame you can't build a debug build, as that would help find
out if this really was the problem...

Cheers,
mwh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top