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.
This commit is contained in:
William S Fulton 2017-10-11 19:37:11 +01:00
commit fcd7ecd9e2
2 changed files with 7 additions and 9 deletions

View file

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

View file

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