From fcd7ecd9e23bf32fd4cc5d75abebda25cac5d501 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 11 Oct 2017 19:37:11 +0100 Subject: [PATCH] R memory handling standardisation Replace R_SWIG_EXTERNAL and R_SWIG_OWNER with the standard equivalent macros. I can't see where these were actually used, but in case they are, equivalent backwards compatibility can be obtained using: #define R_SWIG_EXTERNAL 0 #define R_SWIG_OWNER SWIG_POINTER_OWN SWIG_MakePtr does not seem to be used within the R SWIG code base so I havn't added the above as backwards compatibility macros. There seems to be no memory management in R. I've made this change to fit in with the rest of SWIG though in preparation for an upcoming commit to use the same shared_ptr macros as is used elsewhere. --- Lib/r/rrun.swg | 6 ++---- Source/Modules/r.cxx | 10 +++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Lib/r/rrun.swg b/Lib/r/rrun.swg index 63b7ecc70..bec981546 100644 --- a/Lib/r/rrun.swg +++ b/Lib/r/rrun.swg @@ -213,17 +213,15 @@ R_SWIG_ReferenceFinalizer(SEXP el) return; } -typedef enum {R_SWIG_EXTERNAL, R_SWIG_OWNER } R_SWIG_Owner; - SWIGRUNTIME SEXP -SWIG_MakePtr(void *ptr, const char *typeName, R_SWIG_Owner owner) +SWIG_MakePtr(void *ptr, const char *typeName, int flags) { SEXP external, r_obj; Rf_protect(external = R_MakeExternalPtr(ptr, Rf_install(typeName), R_NilValue)); Rf_protect(r_obj = NEW_OBJECT(MAKE_CLASS((char *) typeName))); - if(owner) + if (flags & SWIG_POINTER_OWN) R_RegisterCFinalizer(external, R_SWIG_ReferenceFinalizer); r_obj = SET_SLOT(r_obj, Rf_mkString((char *) "ref"), external); diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index bd3395a73..0fe730c83 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -637,7 +637,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) { Replaceall(tm, "$1", name); Replaceall(tm, "$result", "r_tmp"); replaceRClass(tm, Getattr(p,"type")); - Replaceall(tm,"$owner", "R_SWIG_EXTERNAL"); + Replaceall(tm,"$owner", "0"); Delete(lstr); } @@ -697,7 +697,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) { Replaceall(tm,"$input", "r_swig_cb_data->retValue"); Replaceall(tm,"$target", Swig_cresult_name()); replaceRClass(tm, rettype); - Replaceall(tm,"$owner", "R_SWIG_EXTERNAL"); + Replaceall(tm,"$owner", "0"); Replaceall(tm,"$disown","0"); Printf(f->code, "%s\n", tm); } @@ -2062,7 +2062,7 @@ int R::functionWrapper(Node *n) { Replaceall(tm,"$n", pos); // The position into which to store the answer. Replaceall(tm,"$arg", Getattr(p, "emit:input")); Replaceall(tm,"$input", Getattr(p, "emit:input")); - Replaceall(tm,"$owner", "R_SWIG_EXTERNAL"); + Replaceall(tm,"$owner", "0"); Printf(outargs, "%s\n", tm); @@ -2087,9 +2087,9 @@ int R::functionWrapper(Node *n) { replaceRClass(tm, retType); if (GetFlag(n,"feature:new")) { - Replaceall(tm, "$owner", "R_SWIG_OWNER"); + Replaceall(tm, "$owner", "SWIG_POINTER_OWN"); } else { - Replaceall(tm,"$owner", "R_SWIG_EXTERNAL"); + Replaceall(tm,"$owner", "0"); } #if 0