PyErr_SetString() != raise ?

David Eger eger at cc.gatech.edu
Mon Jul 14 21:10:59 EDT 2003


When I use PyErr_SetString() in an extension, python just keeps on
chugging instead of acting as though a Python exception had been
'raise'd.  Why is this, and do I really have to write the Python code
to raise an exception manually after I've used PyErr_SetString()?

Most recently, writing an iterator -- I write:

    if (nextEl == NULL) {
      PyErr_SetString(PyExc_StopIteration, "Array index out of bounds");
      return NULL;
      }

in my iterator extension, but when I use my extension, I get an infinite loop:

eger at rosencrantz:/usr/src/CIM-stuff/wbemcli/bugs$ python2.2 
Python 2.2.2 (#1, Mar 21 2003, 23:40:29) 
[GCC 3.2.3 20030316 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import StopIterTest
>>> a = StopIterTest.dupstring("Amanda's")
>>> b = StopIterTest.dupstring("got")
>>> l = StopIterTest.stringArray()
>>> l.add(a)
>>> l.add(b)
>>> for i in l:
...    print i
... 
_10180840_p_string
_10181b38_p_string
None
None
None
None
None
None
None
None
None
None

(and so on, and so on...)  The thing is, even though I *set* the
exception with PyErr_SetString, to the interpreter, it doesn't get
raised.  Am I just misinterpretting how PyErr_SetString is supposed 
to work?

-David




More information about the Python-list mailing list