Discussion:
[Swig-devel] Python builtin and exception object problem
Yoann Vandoorselaere
2015-04-24 16:32:26 UTC
Permalink
Hi,

I am using the following code sequence in order to trigger custom Python
exception object, which used to work before enabling the builtin option:

SWIG_Python_Raise(SWIG_NewPointerObj(new PreludeError(e),
SWIGTYPE_p_Prelude__PreludeError, SWIG_POINTER_OWN), "PreludeError",
SWIGTYPE_p_Prelude__PreludeError);

Since we enabled builtin mode however, the code does not work anymore and
the triggered exception are always of type SWIG_RuntimeError.

The source of the problem seems to come from
the SWIG_Python_ExceptionType() function, because the clientdata->klass
member is never initialized in case builtin mode is used.

Returning clientdata->pytype seems to fix the problem for me, but I am not
sure whether that would be a correct, generic solution.

Any though ?

Regards,
William S Fulton
2015-04-25 00:13:05 UTC
Permalink
Post by Yoann Vandoorselaere
Hi,
I am using the following code sequence in order to trigger custom Python
SWIG_Python_Raise(SWIG_NewPointerObj(new PreludeError(e),
SWIGTYPE_p_Prelude__PreludeError, SWIG_POINTER_OWN), "PreludeError",
SWIGTYPE_p_Prelude__PreludeError);
Since we enabled builtin mode however, the code does not work anymore and
the triggered exception are always of type SWIG_RuntimeError.
The source of the problem seems to come from the SWIG_Python_ExceptionType()
function, because the clientdata->klass member is never initialized in case
builtin mode is used.
Returning clientdata->pytype seems to fix the problem for me, but I am not
sure whether that would be a correct, generic solution.
That all seems reasonable to me. Put the code within a #ifdef
SWIGPYTHON_BUILTIN in SWIG_Python_ExceptionType.

Can you put together a github patch and include a little testcase in
the test-suite too please?

William
Yoann Vandoorselaere
2015-04-25 06:03:31 UTC
Permalink
Hi William,

Here is the pull request : https://github.com/swig/swig/pull/397

Additionally, I noticed that the Prelude bindings won't compile when
generated using SWIG latest update, with plenty of error like this one. Any
idea where that might come from ?

_prelude.cxx: In function ‘int _wrap_new_IDMEF(PyObject*, PyObject*)’:
_prelude.cxx:15852:52: erreur: invalid conversion from ‘int’ to ‘PyObject*
{aka _object*}’ [-fpermissive]
return _wrap_new_IDMEF__SWIG_0(self, argc, argv);
^
_prelude.cxx:15852:52: erreur: too many arguments to function ‘int
_wrap_new_IDMEF__SWIG_0(PyObject*, PyObject*)’
_prelude.cxx:15760:16: note: declared here
SWIGINTERN int _wrap_new_IDMEF__SWIG_0(PyObject *self, PyObject *args) {

Regards,
Post by Yoann Vandoorselaere
Post by Yoann Vandoorselaere
Hi,
I am using the following code sequence in order to trigger custom Python
SWIG_Python_Raise(SWIG_NewPointerObj(new PreludeError(e),
SWIGTYPE_p_Prelude__PreludeError, SWIG_POINTER_OWN), "PreludeError",
SWIGTYPE_p_Prelude__PreludeError);
Since we enabled builtin mode however, the code does not work anymore and
the triggered exception are always of type SWIG_RuntimeError.
The source of the problem seems to come from the
SWIG_Python_ExceptionType()
Post by Yoann Vandoorselaere
function, because the clientdata->klass member is never initialized in
case
Post by Yoann Vandoorselaere
builtin mode is used.
Returning clientdata->pytype seems to fix the problem for me, but I am
not
Post by Yoann Vandoorselaere
sure whether that would be a correct, generic solution.
That all seems reasonable to me. Put the code within a #ifdef
SWIGPYTHON_BUILTIN in SWIG_Python_ExceptionType.
Can you put together a github patch and include a little testcase in
the test-suite too please?
William
Loading...