C Extension Seg Faults

Daryl rts.cts at gmail.com
Tue Jul 10 14:03:20 EDT 2007


I'm having trouble tracking down some segmentation faults with a C
extension.  I can see where it's failing but don't know how to fix
it.  Basically, my python programme builds a pair of large tuples of
tuples.  I want to unpack these tuples and process them.  The code in
question looks something like:

... snip ...

SizeN = PyTuple_Size(PlacementN);
SizeP = PyTuple_Size(PlacementP);
for(ixN = 0; ixN < SizeN; ixN++) {
    LenN = (int) PyTuple_Size(PyList_GetItem(PlacementN, ixN));
    for(Count = 0; Count < LenN; Count++)
        *(GatesN+Count) = (int)
PyInt_AsLong(PyTuple_GetItem(PyTuple_GetItem(PyList_GetItem(PlacementN,
ixN), Count), GATE));
        for(ixP = 0; ixP < SizeP; ixP++) {
            printf("I feel lucky (%d)...", ixP); fflush(stdout);
            LenP = (int) PyTuple_Size(PyList_GetItem(PlacementP,
ixP));
            printf("Ta-Da!\n"); fflush(stdout);
            for(Count = 0; Count < LenP; Count++)
                *(GatesP+Count) = (int)
PyInt_AsLong(PyTuple_GetItem(PyTuple_GetItem(PyList_GetItem(PlacementP,
ixP), Count), GATE));
            [ MUCH PROCESSING ]
... snip ...

The inner loop runs a few hundred times (263) then fails with a
segmentation fault.  I've trolled through the documentation online and
in the various .h files but can't seem to find anything.

Anybody have an idea what really obvious foolish thing I'm doing?

Thanks,
-Daryl




More information about the Python-list mailing list