From 68b14c06f04fc2fb85eac0b7861816ffdb7da9cb Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 16 Mar 2009 18:14:06 -0700 Subject: [PATCH] Refactor callthis(), twiddle the Perl stack correctly and add more error checking --- Changes | 1 + swig/gsl_typemaps.i | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index bcec036..aa98e81 100644 --- a/Changes +++ b/Changes @@ -18,6 +18,7 @@ - Overload '==' and '!=' for MatrixComplex and Matrix objects - Fix amd64 -fPIC compile failure - Add tests to Monte and refactor Sort tests + - Refactor and add error checking to callbacks =head1 v0.16 - December 14 2008 (Happy Snowpocalypse PDX!) diff --git a/swig/gsl_typemaps.i b/swig/gsl_typemaps.i index 4773d00..999a66d 100644 --- a/swig/gsl_typemaps.i +++ b/swig/gsl_typemaps.i @@ -46,6 +46,7 @@ */ double callthis(double x , int func, void *params){ SV ** sv; + unsigned int count; double y; dSP; @@ -58,8 +59,16 @@ PUSHMARK(SP); XPUSHs(sv_2mortal(newSVnv((double)x))); - PUTBACK; - call_sv(*sv, G_SCALAR); + PUTBACK; /* make local stack pointer global */ + + count = call_sv(*sv, G_SCALAR); + SPAGAIN; + + if (count != 1) + croak("Expected to call subroutine in scalar context!"); + + PUTBACK; /* make local stack pointer global */ + y = POPn; return y; } -- 2.11.4.GIT