Move confess_at() to utils.cpp

This commit is contained in:
Alessandro Ranellucci 2013-09-09 21:40:57 +02:00
parent 873762491b
commit 1fbf9c3952
2 changed files with 29 additions and 34 deletions

View File

@ -20,39 +20,8 @@ namespace Slic3r {}
using namespace Slic3r; using namespace Slic3r;
/* Implementation of CONFESS("foo"): */ /* Implementation of CONFESS("foo"): */
#define CONFESS(...) \ #define CONFESS(...) confess_at(__FILE__, __LINE__, __func__, __VA_ARGS__)
confess_at(__FILE__, __LINE__, __func__, __VA_ARGS__) void confess_at(const char *file, int line, const char *func, const char *pat, ...);
/* End implementation of CONFESS("foo"): */
void
do_confess(SV *error_sv)
{
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs( sv_2mortal(error_sv) );
PUTBACK;
call_pv("Carp::confess", G_DISCARD);
FREETMPS;
LEAVE;
}
void
confess_at(const char *file, int line, const char *func,
const char *pat, ...)
{
va_list args;
SV *error_sv = newSVpvf("Error in function %s at %s:%d: ", func,
file, line);
va_start(args, pat);
sv_vcatpvf(error_sv, pat, &args);
va_end(args);
sv_catpvn(error_sv, "\n\t", 2);
do_confess(error_sv);
}
/* End implementation of CONFESS("foo") */
#endif #endif

26
xs/src/utils.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <myinit.h>
void
confess_at(const char *file, int line, const char *func,
const char *pat, ...)
{
va_list args;
SV *error_sv = newSVpvf("Error in function %s at %s:%d: ", func,
file, line);
va_start(args, pat);
sv_vcatpvf(error_sv, pat, &args);
va_end(args);
sv_catpvn(error_sv, "\n\t", 2);
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs( sv_2mortal(error_sv) );
PUTBACK;
call_pv("Carp::confess", G_DISCARD);
FREETMPS;
LEAVE;
}