diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index 6af45cf40..007eaf140 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -12,6 +12,8 @@ %apply int {unsigned int} %apply int {short} %apply int {unsigned short} +%apply int {signed char} +%apply int {unsigned char} %typemap("rtype") long, long *, long & "integer"; %apply long {long long} @@ -36,10 +38,9 @@ %typemap("rtype") SWIGTYPE & "$R_class"; %typemap("rtype") SWIGTYPE "$&R_class"; -%typemap("rtypecheck") int, int &, long, long &, - unsigned char, unsigned char & +%typemap("rtypecheck") int, int &, long, long & %{ (is.integer($arg) || is.numeric($arg)) && length($arg) == 1 %} -%typemap("rtypecheck") int *, long *, unsigned char * +%typemap("rtypecheck") int *, long * %{ is.integer($arg) || is.numeric($arg) %} @@ -107,9 +108,8 @@ %typemap(scoercein) enum SWIGTYPE *const %{ $input = enumToInteger($input, "$R_class"); %} - %typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE *const, SWIGTYPE & - %{ %} + %{ if (.hasSlot($input, "ref")) $input = slot($input,"ref") %} /* %typemap(scoercein) SWIGTYPE *, SWIGTYPE *const @@ -141,7 +141,7 @@ long *, long &, long[ANY] - "$input = as.integer($input); "; + "$input = as.integer($input);"; %typemap(scoercein) char *, string, std::string, string &, std::string & @@ -159,18 +159,30 @@ string &, std::string & %typemap(scoerceout) enum SWIGTYPE *const %{ $result = enumToInteger($result, "$R_class"); %} +#%typemap(scoerceout) SWIGTYPE +# %{ class($result) <- "$&R_class"; %} -%typemap(scoerceout) SWIGTYPE - %{ class($result) <- "$&R_class"; %} +#%typemap(scoerceout) SWIGTYPE & +# %{ class($result) <- "$R_class"; %} -%typemap(scoerceout) SWIGTYPE & - %{ class($result) <- "$R_class"; %} +#%typemap(scoerceout) SWIGTYPE * +# %{ class($result) <- "$R_class"; %} -%typemap(scoerceout) SWIGTYPE * - %{ class($result) <- "$R_class"; %} +#%typemap(scoerceout) SWIGTYPE *const +# %{ class($result) <- "$R_class"; %} + + %typemap(scoerceout) SWIGTYPE + %{ $result <- new("$&R_class", ref=$result); %} + + %typemap(scoerceout) SWIGTYPE & + %{ $result <- new("$R_class", ref=$result) ; %} + + %typemap(scoerceout) SWIGTYPE * + %{ $result <- new("$R_class", ref=$result) ; %} + + %typemap(scoerceout) SWIGTYPE *const + %{ $result <- new("$R_class", ref=$result) ; %} -%typemap(scoerceout) SWIGTYPE *const - %{ class($result) <- "$R_class"; %} /* Override the SWIGTYPE * above. */ %typemap(scoerceout) char, @@ -208,8 +220,10 @@ string &, std::string & signed long &, unsigned long, unsigned long &, - unsigned char *, - unsigned char & + signed char, + signed char &, + unsigned char, + unsigned char & %{ %} #if 0 diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index f163c8b30..b589bfda7 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1891,6 +1891,9 @@ int R::functionWrapper(Node *n) { if(nargs == -1) nargs = getFunctionPointerNumArgs(p, tt); + Printv(sfun->code, "if (.hasSlot(", name, ", \"ref\")) {\n", + name, " = slot(", name, ", \"ref\");\n", + "}\n", NIL); String *snargs = NewStringf("%d", nargs); Printv(sfun->code, "if(is.function(", name, ")) {", "\n", "assert('...' %in% names(formals(", name, @@ -2112,7 +2115,8 @@ int R::functionWrapper(Node *n) { { String *finalizer = NewString(iname); Replace(finalizer, "new_", "", DOH_REPLACE_FIRST); - Printf(sfun->code, "reg.finalizer(ans, delete_%s)\n", finalizer); + Printf(sfun->code, "if (.hasSlot(ans, \"ref\")) {\n" + "reg.finalizer(ans@ref, delete_%s); }\n", finalizer); } Printf(sfun->code, "ans\n"); }