I'm writting a python and perl binding for a c program.

2 ways are documented :
http://www.swig.org/Doc2.0/SWIGDocumentation.html#Customization_nn3
http://www.swig.org/Doc2.0/SWIGDocumentation.html#Customization_nn4

but both uses global variables and are not thread safe.

I'm trying to find a safe way to do it, but i don't manage to do it.

%exception myfunc1 {
    char *err;
    clear_exception();
    $action
    if ((err = check_exception())) {
       croak(err);
    }
}

void myfunc1() {

 // do something

}


// from python :

myfunc()


the only way i find it would be possible :
%exception myfunc1 {
    char *err;

    eobj e;

    clear_exception(e);
    myfunc1(e)
    if ((err = check_exception(e))) {
       croak(err);
    }
}

void myfunc1(e) {
 // do something
}
// from python :
myfunc()

unfortunallty,
it requires to be able to say to swig that :
- swig must ignore on the binding the parameter e
- $action must be replace with that extra arguments e

>>python_wrap.c

from

result = myfunc1(arg1, arg2)

should become

result = myfunc1(arg1, arg2, e)

(the last example give some arguments to be more complete.)


I found nothing to do that properly with swig.
Any idea ?