From 1fbf9c395293c49f3b375a13cfe4a6325599c2fb Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 9 Sep 2013 21:40:57 +0200 Subject: [PATCH 1/2] Move confess_at() to utils.cpp --- xs/src/myinit.h | 37 +++---------------------------------- xs/src/utils.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 34 deletions(-) create mode 100644 xs/src/utils.cpp diff --git a/xs/src/myinit.h b/xs/src/myinit.h index 5d1c17a177..84175da96a 100644 --- a/xs/src/myinit.h +++ b/xs/src/myinit.h @@ -20,39 +20,8 @@ namespace Slic3r {} using namespace Slic3r; /* Implementation of CONFESS("foo"): */ -#define CONFESS(...) \ - confess_at(__FILE__, __LINE__, __func__, __VA_ARGS__) - -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") */ +#define CONFESS(...) 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"): */ #endif diff --git a/xs/src/utils.cpp b/xs/src/utils.cpp new file mode 100644 index 0000000000..7a3b11adec --- /dev/null +++ b/xs/src/utils.cpp @@ -0,0 +1,26 @@ +#include + +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; +} From c592932cee7e43e8cb9f8827f79978f7846e4c41 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 9 Sep 2013 21:43:28 +0200 Subject: [PATCH 2/2] Use a general-purpose T_ARRAYREF_PTR typemap --- xs/xsp/my.map | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xs/xsp/my.map b/xs/xsp/my.map index 7b1cff8cf6..e7735f7d9a 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -23,7 +23,7 @@ Lines T_ARRAYREF Polygons T_ARRAYREF ExPolygons T_ARRAYREF -Polygons* T_ARRAYREF_POLYGONS_PTR +Polygons* T_ARRAYREF_PTR INPUT @@ -56,12 +56,12 @@ T_ARRAYREF } $var.clear(); -T_ARRAYREF_POLYGONS_PTR +T_ARRAYREF_PTR AV* av = newAV(); $arg = newRV_noinc((SV*)av); sv_2mortal($arg); av_extend(av, $var->size()-1); int i = 0; - for (Polygons::iterator it = $var->begin(); it != $var->end(); ++it) { + for (${ my $t = $type; $t =~ s/\*$//; \$t }::iterator it = $var->begin(); it != $var->end(); ++it) { av_store(av, i++, (*it).to_SV_ref()); }