#1308 SWIG_exception / SWIG_fail compile failure

open
nobody
None
5
2014-07-25
2013-03-06
dstndstn
No

Hi,

With the SWIG below, I get a compile failure: it looks like SWIG_fail is expanding to "goto fail", but the "fail:" label is in the wrong function (the calling function).

This is with swig 2.0.9, and my target is python, though I think the problem is language-independent.

%module test

%include <exception.i>

%inline %{

    typedef struct {
    } s;

    %}

%extend s {

    s(int x) {
        // option A
        SWIG_exception(SWIG_RuntimeError, "Msg");

        // option B
        PyErr_SetString(PyExc_RuntimeError, "Msg");
        SWIG_fail;

        return NULL;
    }

 }

Produces:

#define SWIG_fail       goto fail                      
// [snip]
SWIGINTERN s *new_s(int x){
        SWIG_exception(SWIG_RuntimeError, "Msg");
        PyErr_SetString(PyExc_RuntimeError, "Msg");
        SWIG_fail;
        return NULL;
    }

SWIGINTERN PyObject *_wrap_new_s(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
/// [snip]
  result = (s *)new_s(arg1);
  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_s, SWIG_POINTER_NEW |  0 );
  return resultobj;
fail:
  return NULL;
}

Notice that 'SWIG_fail', ie, 'goto fail' is in 'new_s()', but the 'fail:' label is in '_wrap_new_s'.

Thanks,
dustin

Discussion


Log in to post a comment.