change R components so that pointers are visible through ref

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13601 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Joseph Wang 2012-08-12 15:21:39 +00:00
commit fad95da7f5
2 changed files with 35 additions and 17 deletions

View file

@ -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

View file

@ -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");
}