Re: Undocumented Python 2.6 change: Py_None vs NULL when Cimplementation raises exception

Discussion in 'Python' started by Fredrik Lundh, Jul 23, 2008.

  1. Heikki Toivonen wrote:

    > I was debugging M2Crypto function written in C which changed behavior
    > between Python 2.6 and earlier Python versions. In an error condition
    > the function was supposed to raise exception type A, but with 2.6 it
    > raised type B, and further, there was no string value for the exception.
    >
    > I tracked this down to the C code incorrectly returning Py_None when it
    > should have returned NULL. Changing the C code to return NULL made it
    > behave correctly in 2.6.
    >
    > I don't know how common a mistake it is to return Py_None when NULL
    > should have been returned, but it might be worth a note in the list of
    > changes for 2.6 that this behavior changed, don't you think?


    the behaviour when setting the exception status without returning NULL
    has never been well-defined; it pretty much depends on what kind of
    error checking the code that runs later happens to use.

    (this has been an entertaining source of obscure errors over the years;
    code that uses PyErr_Clear may mask errors, and code that uses
    PyErr_Occurred to check if something went wrong might raise the wrong
    error, often at an unexpected location).

    </F>
     
    Fredrik Lundh, Jul 23, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    331
  2. Noah
    Replies:
    3
    Views:
    488
  3. Trond Valen
    Replies:
    20
    Views:
    1,146
    Jacek Dziedzic
    Dec 7, 2005
  4. Martin v. Löwis
    Replies:
    1
    Views:
    755
    Martin v. Löwis
    Jul 24, 2008
  5. John Wallace

    1.0 -> 1.1 Undocumented (?) change in behaviour!

    John Wallace, Sep 7, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    103
    John Wallace
    Sep 7, 2003
Loading...

Share This Page