PyErr_SetString() != raise ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Eger

    PyErr_SetString() != raise ?

    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_StopIter ation, "Array index out of bounds");
    return NULL;
    }

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

    eger@rosencrant z:/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.[color=blue][color=green][color=darkred]
    >>> import StopIterTest
    >>> a = StopIterTest.du pstring("Amanda 's")
    >>> b = StopIterTest.du pstring("got")
    >>> l = StopIterTest.st ringArray()
    >>> l.add(a)
    >>> l.add(b)
    >>> for i in l:[/color][/color][/color]
    .... print i
    ....
    _10180840_p_str ing
    _10181b38_p_str ing
    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 misinterprettin g how PyErr_SetString is supposed
    to work?

    -David
  • Modular Forms Boy

    #2
    Re: PyErr_SetString () != raise ?

    David Eger wrote:
    :> My exception disappears!

    to which Paul Simmonds <psimmo60@hotma il.com> 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: swig@cs.uchicag o.edu.

    -Eger David

    Comment

    Working...