%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
%}
####
#define SWIG_croak(x) { SWIG_Error(SWIG_RuntimeError, x); SWIG_fail; }
#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else
#define SWIG_SetError(str) SWIG_Error(SWIG_RuntimeError, str)
####
if (!argp2) {
SWIG_exception_fail(SWIG_ValueError, "invalid null reference "
"in method '" "new_Foo" "', argument " "2"" of type '" "Bar &""'");
}
####
#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0)
#define SWIG_Error(code, msg) sv_setpvf(GvSV(PL_errgv),"%s %s\n", SWIG_ErrorType(code), msg)
#define SWIG_ErrorType(code) SWIG_Perl_ErrorType(code)
SWIG_Perl_ErrorType(int code) { C code that returns a string describing the error code }
#define SWIG_fail goto fail
#define SWIG_croak_null() croak(Nullch)