From efa5edbe5b5a86b788f4f9aa518be34e7f49fabc Mon Sep 17 00:00:00 2001 From: Joseph Wang Date: Sun, 18 Mar 2012 10:48:48 +0000 Subject: [PATCH] use type checks to order r outputs add noreturn exception handler git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12935 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/r/rrun.swg | 5 +++++ Lib/r/rtype.swg | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Lib/r/rrun.swg b/Lib/r/rrun.swg index 332cd1d39..9bb6fc276 100644 --- a/Lib/r/rrun.swg +++ b/Lib/r/rrun.swg @@ -361,6 +361,11 @@ SWIG_R_ConvertPacked(SEXP obj, void *ptr, size_t sz, swig_type_info *ty) { return SWIG_OK; } +#ifdef __cplusplus +#include +#define SWIG_exception_noreturn(code, msg) do { throw std::runtime_error(msg); } while(0); +#endif + #ifdef __cplusplus } #endif diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index 5103e43db..ef65b8210 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -36,7 +36,37 @@ %typemap("rtype") SWIGTYPE & "$R_class"; %typemap("rtype") SWIGTYPE "$&R_class"; +%typemap("rtypecheck") int, int &, long, long &, + unsigned char, unsigned char & + %{ is.integer($arg) || is.numeric($arg) %} +%typemap("rtypecheck") int *, long *, unsigned char * + %{ (is.integer($arg) || is.numeric($arg)) && length($arg) == 1 %} +%typemap("rtypecheck") double, double &, float, float & + %{ is.numeric($arg) && length($arg) == 1 %} +%typemap("rtypecheck") double*, float * + %{ is.numeric($arg) %} + +%typemap("rtypecheck") bool, bool & + %{ is.logical($arg) && length($arg) == 1 %} +%typemap("rtypecheck") bool * + %{ is.logical($arg) % } + +/* + Set up type checks to insure overloading precedence. + We would like non pointer items to shadow pointer items, so that + they get called if length = 1 +*/ + +%typecheck(SWIG_TYPECHECK_BOOL_PTR) bool * {} +%typecheck(SWIG_TYPECHECK_INT32_PTR) int * {} +%typecheck(SWIG_TYPECHECK_FLOAT_PTR) float * {} +%typecheck(SWIG_TYPECHECK_DOUBLE_PTR) double * {} +%typecheck(SWIG_TYPECHECK_CHAR_PTR) char * {} + +%typecheck(SWIG_TYPECHECK_INT32_ARRAY) int[ANY] {} +%typecheck(SWIG_TYPECHECK_FLOAT_ARRAY) float[ANY] {} +%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY) double [ANY] {} /* Have to be careful that as(x, "numeric") is different from as.numeric(x). The latter makes a REALSXP, whereas the former leaves an INTSXP as an @@ -170,10 +200,11 @@ string &, std::string & signed long, signed long &, unsigned long, - unsigned long & + unsigned long &, + unsigned char *, + unsigned char & %{ %} - #if 0 Just examining the values for a SWIGTYPE.