Here's code from KinoSearch::Util::Carp, which calls Carp::confess from C.
void Kino_confess (char* pat, ...) { va_list args; SV *error_sv; dSP; error_sv = newSV(0); va_start(args, pat); sv_vsetpvf(error_sv, pat, &args); va_end(args); ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs( sv_2mortal(error_sv) ); PUTBACK; call_pv("Carp::confess", G_DISCARD); FREETMPS; LEAVE; }
It assumes that somewhere, someone has invoked use Carp;.
If you know that either ISO or GNU variadic macros are available, you can transparently insert the filename and the line number of the C file from where the exception was thrown, plus the function if either __func__ (C99) or __FUNCTION__ (GNU) is defined. Take a look at KinoSearch::Util::Carp in my svn repository if you want to see how that can work.
The bonus contextual info is just plain ol' nasty C wrangling though -- the XS-specific stuff is the same. Check out perlcall for more info on how to call back to Perl from C.
In reply to Re: Output package and function name as well as linenum in a die in XS
by creamygoodness
in thread Output package and function name as well as linenum in a die in XS
by tbusch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |