%header %{ #undef SWIG_Error // if placed in %wrapper it will be at the end, too late for the wrapper code #define SWIG_Error(code, msg) call_perl_carp((char *) SWIG_ErrorType(code), (char *) msg) __BEGIN_DECLS static void call_perl_carp(char *a, char *b); __END_DECLS %} %wrapper %{ static void call_perl_carp(char *a, char *b) { std::string *errstr = new std::string; errstr->append(a); errstr->append(" "); errstr->append(b); dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVpv(errstr->c_str(), 0))); PUTBACK; call_pv("Carp::croak", G_VOID | G_DISCARD); FREETMPS; LEAVE; } %} %perlcode %{ use Carp; # ensure Carp.pm is available for wrapper argument validation %}