PyErr_SetString() != raise ?

D

David Eger

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@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..... 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
 
M

Modular Forms Boy

David Eger wrote:
:> My exception disappears!

to which Paul Simmonds <[email protected]> replied:
: This part should work fine. Try looking back through the function
: calls, layer by layer, making sure each function in turn tests for a
: NULL return, and propagates it back to the interpreter. Without a
: little more code it's tough to say exactly what's wrong.

I've found the place where my exception gets swallowed. Thanks for the
pointer! The problem is in the SWIG wrappers: I'm taking discussion
to that list: (e-mail address removed).

-Eger David
 

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

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top