Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1190 Builtin constructor failure ignored

pending-fixed
szager
python (259)
5
2011-08-30
2011-08-30
Anonymous
No

I have a %extend-created constructor that, on failure, throws a Python exception and returns NULL. But the wrapper code (SWIG_NewPointerObj in _wrap_new_X) converts NULL to Py_None and then returns a nonnegative value, indicating success, and the object is created. The generated code _is_ checking for this case and acting differently:

return resultobj == Py_None ? 1 : 0;

However, Python only checks for < 0 as an error case, so 1 means the same as 0 or any other nonnegative value here (return value from tp_init initproc), and -1 should be returned in this case instead. If I change the 1 return to -1, the exception is propagated as expected. The above code is generated by an "if (builtin_ctor)" case in PYTHON::functionWrapper.

Discussion

  • szager
    szager
    2011-08-30

    Fixed with revision 12792; will be in swig 2.0.5.

    Thanks for the catch,

    Stefan

     
  • szager
    szager
    2011-08-30

    • assigned_to: nobody --> szager
    • status: open --> pending-fixed