Changeset: 9facda64986d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9facda64986d
Modified Files:
monetdb5/modules/mal/rapi.c
Branch: RIntegration
Log Message:
R API: Fixed compilation issues
diffs (164 lines):
diff --git a/monetdb5/modules/mal/rapi.c b/monetdb5/modules/mal/rapi.c
--- a/monetdb5/modules/mal/rapi.c
+++ b/monetdb5/modules/mal/rapi.c
@@ -24,27 +24,36 @@
#include "monetdb_config.h"
#include "rapi.h"
-char * R_HomeDir() {
- // this won't work in general
+// The R-environment should be single threaded, calling for some protective
measures.
+static MT_Lock rapiLock;
+
+char* R_HomeDir(void) {
+ // FIXME this won't work in general
return "/usr/lib64/R";
}
-// The R-environment should be single threaded, calling for some protective
measures.
-static MT_Lock rapiLock;
+// void writeConsole(const char * buf, int buflen) {
+// THRprintf(GDKout,buf);
+// }
+// void writeConsoleEx(const char * buf, int buflen, int foo) {
+// THRprintf(GDKout,buf);
+
+// }
str
RAPIprelude(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){
+ char *rargv[] = { "whatever", "--quiet", "--no-save", "--vanilla" };
+
(void) cntxt;
(void) mb;
(void) stk;
(void) pci;
- char *rargv[] = { "whatever", "--quiet", "--no-save", "--vanilla" };
MT_lock_init( &rapiLock,"rapi_lock");
Rf_initEmbeddedR(4, rargv);
// these globals are indicative for non-thread safe R settings.
- ptr_R_WriteConsole = GDKout;
- ptr_R_WriteConsoleEx = GDKerr;
+ // ptr_R_WriteConsole = writeConsole;
+ // ptr_R_WriteConsoleEx = writeConsoleEx;
R_Outputfile = NULL;
R_Consolefile = NULL;
return MAL_SUCCEED;
@@ -62,13 +71,13 @@ RAPIpostlude(Client cntxt, MalBlkPtr mb,
str
RAPIeval(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){
- str expr = *(str*) getArgReference(stk,pci,pci->retc+1);
+ str exprStr = *(str*) getArgReference(stk,pci,pci->retc+1);
SEXP x;
ParseStatus status;
int i;
char buf[256]={"rapi"};
- char *args, *msg = createException(MAL,"rapi.eval","NYI");
-
+ str *args;
+ char *msg = createException(MAL,"rapi.eval","NYI");
(void) mb;
@@ -84,43 +93,46 @@ RAPIeval(Client cntxt, MalBlkPtr mb, Mal
#else
(void) cntxt;
#endif
+
// install the MAL variables into the R environment
for( i = pci->retc+1; i< pci->argc; i++){
SEXP varname;
SEXP varvalue;
- snprintf(buf,"arg%d", i);
+ sprintf(buf,"arg%d", i);
args[i] = GDKstrdup(buf);
varname = Rf_install( GDKstrdup(buf));
// check for BAT or scalar first !!
- if ( isaBatType(getArgType(pci,i))){
+ if ( isaBatType(getArgType(mb,pci,i))){
// hand over a BAT into a vector
} else
- switch(ATOMstorage(getTailType(getArgType(pci,i)))){
+ switch(ATOMstorage(getTailType(getArgType(mb,pci,i)))){
case TYPE_int:
varvalue = NEW_INTEGER(*(int*)
getArgReference(stk,pci,i));
break;
case TYPE_flt:
- varvalue = NEW_FLOAT(*(flt*)
getArgReference(stk,pci,i));
- break;
+ //varvalue = NEW_FLOAT(*(flt*)
getArgReference(stk,pci,i));
+ //break;
case TYPE_dbl:
- varvalue = NEW_DOUBLE(*(dbl*)
getArgReference(stk,pci,i));
- break;
+ //varvalue = NEW_DOUBLE(*(dbl*)
getArgReference(stk,pci,i));
+ //break;
case TYPE_bte:
case TYPE_sht:
case TYPE_lng:
// no clue what type to consider
default:
- msg = createException(MAL,"mapi.eval","unknown argument
type");
+ msg = createException(MAL,"rapi.eval","unknown argument
type");
goto wrapup;
}
+ // TODO: it's probably a good idea to have a different, new
environment here
+ // TODO: also, let's use an anonymous function call to run the
user code
+ // install vector into R environment
Rf_defineVar(varname,varvalue, R_GlobalEnv);
}
-
- // install vector into R environment
+
x = R_ParseVector(mkString(exprStr), INT_MAX, &status, R_NilValue);
if (status != PARSE_OK){
- msg= createException(MAL,"RAPI %s\n", exprStr);
+ msg= createException(MAL,"rapi.eval","%s", exprStr);
goto wrapup;
}
@@ -131,14 +143,14 @@ RAPIeval(Client cntxt, MalBlkPtr mb, Mal
// collect the return values
for( i=0; i< pci->retc; i++){
SEXP othervar;
- snprintf(bug, "ret%d",i);
+ //sprintf(bug, "ret%d",i);
args[i] = GDKstrdup(buf);
othervar = Rf_findVar(Rf_install(buf), R_GlobalEnv);
//do something with it
- if ( isaBatType(getArgType(pci,i))){
+ if ( isaBatType(getArgType(mb,pci,i))){
// hand over the vector into a BAT
} else {
- switch(ATOMstorage(getTailType(getArgType(pci,i)))){
+ switch(ATOMstorage(getTailType(getArgType(mb,pci,i)))){
case TYPE_int:
*(int*) getArgReference(stk,pci,i) = *(int*) othervar;;
break;
@@ -151,18 +163,20 @@ RAPIeval(Client cntxt, MalBlkPtr mb, Mal
case TYPE_lng:
// no clue what type to consider
default:
- msg = createException(MAL,"mapi.eval","unknown argument
type");
+ msg = createException(MAL,"rapi.eval","unknown argument
type");
goto wrapup;
}
}
msg = MAL_SUCCEED;
+}
wrapup:
MT_lock_unset(&rapiLock,"rapi.evaluate");
// free all names variables introduced so far.
// Beware, they still live in the R global context
for(i=0; i<pci->argc; i++)
- if( args[i])
- GDKree(args[i]);
+ if(args[i])
+ GDKfree(args[i]);
GDKfree(args);
+
return msg;
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list