Changeset: a48dd66eeb1c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a48dd66eeb1c
Modified Files:
monetdb5/extras/rapi/rapi.c
Branch: Oct2014
Log Message:
Layout.
diffs (truncated from 424 to 300 lines):
diff --git a/monetdb5/extras/rapi/rapi.c b/monetdb5/extras/rapi/rapi.c
--- a/monetdb5/extras/rapi/rapi.c
+++ b/monetdb5/extras/rapi/rapi.c
@@ -45,73 +45,79 @@
//#define _RAPI_DEBUG_
-#define BAT_TO_INTSXP(bat,tpe,retsxp) { \
- tpe v; size_t j; \
- retsxp = PROTECT(NEW_INTEGER(BATcount(bat))); \
- for (j = 0; j < BATcount(bat); j++) { \
- v = ((tpe*) Tloc(bat, BUNfirst(bat)))[j]; \
- if ( v == tpe##_nil) \
- INTEGER_POINTER(retsxp)[j] = NA_INTEGER; \
- else \
- INTEGER_POINTER(retsxp)[j] = (int)v; \
- }\
-}
+#define BAT_TO_INTSXP(bat,tpe,retsxp)
\
+ do {
\
+ tpe v; size_t j;
\
+ retsxp = PROTECT(NEW_INTEGER(BATcount(bat))); \
+ for (j = 0; j < BATcount(bat); j++) {
\
+ v = ((tpe*) Tloc(bat, BUNfirst(bat)))[j];
\
+ if ( v == tpe##_nil)
\
+ INTEGER_POINTER(retsxp)[j] = NA_INTEGER; \
+ else
\
+ INTEGER_POINTER(retsxp)[j] = (int)v;
\
+ }
\
+ } while (0)
-#define BAT_TO_REALSXP(bat,tpe,retsxp) { \
- tpe v; size_t j; \
- retsxp = PROTECT(NEW_NUMERIC(BATcount(bat))); \
- for (j = 0; j < BATcount(bat); j++) { \
- v = ((tpe*) Tloc(bat, BUNfirst(bat)))[j]; \
- if ( v == tpe##_nil) \
- NUMERIC_POINTER(retsxp)[j] = NA_REAL; \
- else \
- NUMERIC_POINTER(retsxp)[j] = (double)v; \
- }\
-}
+#define BAT_TO_REALSXP(bat,tpe,retsxp)
\
+ do {
\
+ tpe v; size_t j;
\
+ retsxp = PROTECT(NEW_NUMERIC(BATcount(bat))); \
+ for (j = 0; j < BATcount(bat); j++) {
\
+ v = ((tpe*) Tloc(bat, BUNfirst(bat)))[j];
\
+ if ( v == tpe##_nil)
\
+ NUMERIC_POINTER(retsxp)[j] = NA_REAL;
\
+ else
\
+ NUMERIC_POINTER(retsxp)[j] = (double)v;
\
+ }
\
+ } while (0)
-#define SCALAR_TO_INTSXP(tpe,retsxp) { \
- tpe v; \
- retsxp = PROTECT(NEW_INTEGER(1)); \
- v = *(tpe*) getArgReference(stk,pci,i); \
- if ( v == tpe##_nil) \
- INTEGER_POINTER(retsxp)[0] = NA_INTEGER; \
- else \
- INTEGER_POINTER(retsxp)[0] = (int)v; \
-}
+#define SCALAR_TO_INTSXP(tpe,retsxp) \
+ do {
\
+ tpe v;
\
+ retsxp = PROTECT(NEW_INTEGER(1));
\
+ v = *(tpe*) getArgReference(stk,pci,i); \
+ if ( v == tpe##_nil)
\
+ INTEGER_POINTER(retsxp)[0] = NA_INTEGER; \
+ else
\
+ INTEGER_POINTER(retsxp)[0] = (int)v; \
+ } while (0)
-#define SCALAR_TO_REALSXP(tpe,retsxp) { \
- tpe v; \
- retsxp = PROTECT(NEW_NUMERIC(1)); \
- v = * (tpe*) getArgReference(stk,pci,i); \
- if ( v == tpe##_nil) \
- NUMERIC_POINTER(retsxp)[0] = NA_REAL; \
- else \
- NUMERIC_POINTER(retsxp)[0] = (double)v; \
-}
-#define SXP_TO_BAT(tpe,access_fun,na_check) { \
- tpe *p, prev = tpe##_nil; \
- b = BATnew(TYPE_void, TYPE_##tpe, cnt, TRANSIENT);\
- BATseqbase(b, 0); b->T->nil = 0; b->T->nonil = 1; b->tkey = 0;\
- b->tsorted = 1; b->trevsorted = 1; \
- p = (tpe*) Tloc(b, BUNfirst(b));\
- for( j =0; j< (int) cnt; j++, p++){\
- *p = (tpe) access_fun(ret_col)[j];\
- if (na_check){ b->T->nil = 1; b->T->nonil = 0; *p=
tpe##_nil;} \
- if (j > 0){ \
- if ( *p > prev && b->trevsorted){ \
- b->trevsorted = 0; \
- if (*p != prev +1) b->tdense = 0; \
- } else \
- if ( *p < prev && b->tsorted){ \
- b->tsorted = 0; \
- b->tdense = 0; \
- } \
- } \
- prev = *p; \
- } \
- BATsetcount(b,cnt);\
- BATsettrivprop(b);\
-}
+#define SCALAR_TO_REALSXP(tpe,retsxp) \
+ do {
\
+ tpe v;
\
+ retsxp = PROTECT(NEW_NUMERIC(1));
\
+ v = * (tpe*) getArgReference(stk,pci,i); \
+ if ( v == tpe##_nil)
\
+ NUMERIC_POINTER(retsxp)[0] = NA_REAL; \
+ else
\
+ NUMERIC_POINTER(retsxp)[0] = (double)v; \
+ } while (0)
+
+#define SXP_TO_BAT(tpe,access_fun,na_check)
\
+ do {
\
+ tpe *p, prev = tpe##_nil;
\
+ b = BATnew(TYPE_void, TYPE_##tpe, cnt, TRANSIENT);
\
+ BATseqbase(b, 0); b->T->nil = 0; b->T->nonil = 1; b->tkey = 0;
\
+ b->tsorted = 1; b->trevsorted = 1;
\
+ p = (tpe*) Tloc(b, BUNfirst(b));
\
+ for( j =0; j< (int) cnt; j++, p++){
\
+ *p = (tpe) access_fun(ret_col)[j];
\
+ if (na_check){ b->T->nil = 1; b->T->nonil = 0;
*p= tpe##_nil;} \
+ if (j > 0){
\
+ if ( *p > prev && b->trevsorted){
\
+ b->trevsorted = 0;
\
+ if (*p != prev +1) b->tdense = 0;
\
+ } else
\
+ if ( *p < prev && b->tsorted){
\
+ b->tsorted = 0;
\
+ b->tdense = 0;
\
+ }
\
+ }
\
+ prev = *p;
\
+ }
\
+ BATsetcount(b,cnt);
\
+ BATsettrivprop(b);
\
+ } while (0)
const char* rapi_enableflag = "embedded_r";
@@ -287,22 +293,22 @@ static void my_onintr(int sig)
//extern Rboolean R_LoadRconsole;
int RAPIinitialize(void) {
- structRstart rp;
+ structRstart rp;
Rstart Rp = &rp;
char Rversion[25], *RHome;
snprintf(Rversion, 25, "%s.%s", R_MAJOR, R_MINOR);
if(strncmp(getDLLVersion(), Rversion, 25) != 0) {
- fprintf(stderr, "Error: R.DLL version does not match\n");
- exit(1);
+ fprintf(stderr, "Error: R.DLL version does not match\n");
+ exit(1);
}
R_setStartTime();
R_DefParams(Rp);
if((RHome = get_R_HOME()) == NULL) {
- fprintf(stderr,
- "R_HOME must be set in the environment or Registry\n");
- exit(2);
+ fprintf(stderr,
+ "R_HOME must be set in the environment or
Registry\n");
+ exit(2);
}
Rp->rhome = RHome;
Rp->home = getRUser();
@@ -348,7 +354,7 @@ int RAPIinstalladdons(void) {
// r library folder, create if not exists
snprintf(rlibs, BUFSIZ, "%s%c%s", GDKgetenv("gdk_dbpath"), DIR_SEP,
- "rapi_packages");
+ "rapi_packages");
if (mkdir(rlibs, S_IRWXU) != 0 && errno != EEXIST) {
return 4;
@@ -364,11 +370,11 @@ int RAPIinstalladdons(void) {
// run rapi.R environment setup script
snprintf(rapiinclude, BUFSIZ, "source(\"%s\")",
- locate_file("rapi", ".R", 0));
+ locate_file("rapi", ".R", 0));
R_tryEvalSilent(
- VECTOR_ELT(
- R_ParseVector(mkString(rapiinclude), 1,
&status,
- R_NilValue), 0),
R_GlobalEnv, &evalErr);
+ VECTOR_ELT(
+ R_ParseVector(mkString(rapiinclude), 1, &status,
+ R_NilValue), 0), R_GlobalEnv,
&evalErr);
// of course the script may contain errors as well
if (evalErr != FALSE) {
@@ -378,11 +384,11 @@ int RAPIinstalladdons(void) {
}
rapi_export str RAPIevalStd(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
- InstrPtr pci) {
+ InstrPtr pci) {
return RAPIeval(cntxt, mb, stk, pci, 0);
}
rapi_export str RAPIevalAggr(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
- InstrPtr pci) {
+ InstrPtr pci) {
return RAPIeval(cntxt, mb, stk, pci, 1);
}
@@ -413,8 +419,8 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
if (!RAPIEnabled()) {
throw(MAL, "rapi.eval",
- "Embedded R has not been enabled. Start server
with --set %s=true",
- rapi_enableflag);
+ "Embedded R has not been enabled. Start server with
--set %s=true",
+ rapi_enableflag);
}
rcall = malloc(strlen(exprStr) + sizeof(argnames) + 100);
@@ -488,36 +494,30 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
// check the BAT count, if it is bigger than RAPI_MAX_TUPLES,
fail
if (BATcount(b) > RAPI_MAX_TUPLES) {
msg = createException(MAL, "rapi.eval",
- "Got "BUNFMT" rows, but can only handle
"LLFMT". Sorry.",
- BATcount(b), (lng) RAPI_MAX_TUPLES);
+ "Got "BUNFMT"
rows, but can only handle "LLFMT". Sorry.",
+ BATcount(b),
(lng) RAPI_MAX_TUPLES);
goto wrapup;
}
varname = PROTECT(Rf_install(args[i]));
switch (ATOMstorage(getColumnType(getArgType(mb,pci,i)))) {
case TYPE_bte:
- BAT_TO_INTSXP(b, bte, varvalue)
- ;
+ BAT_TO_INTSXP(b, bte, varvalue);
break;
case TYPE_sht:
- BAT_TO_INTSXP(b, sht, varvalue)
- ;
+ BAT_TO_INTSXP(b, sht, varvalue);
break;
case TYPE_int:
- BAT_TO_INTSXP(b, int, varvalue)
- ;
+ BAT_TO_INTSXP(b, int, varvalue);
break;
case TYPE_flt:
- BAT_TO_REALSXP(b, flt, varvalue)
- ;
+ BAT_TO_REALSXP(b, flt, varvalue);
break;
case TYPE_dbl:
- BAT_TO_REALSXP(b, dbl, varvalue)
- ;
+ BAT_TO_REALSXP(b, dbl, varvalue);
break;
case TYPE_lng: /* R's integers are stored as int, so we cannot
be sure long will fit */
- BAT_TO_REALSXP(b, lng, varvalue)
- ;
+ BAT_TO_REALSXP(b, lng, varvalue);
break;
case TYPE_str: { // there is only one string type, thus no
macro here
BUN p = 0, q = 0, j = 0;
@@ -525,15 +525,15 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
li = bat_iterator(b);
varvalue = PROTECT(NEW_STRING(BATcount(b)));
BATloop(b, p, q)
- {
- const char *t = (const char *) BUNtail(li, p);
- if (t == str_nil) {
- SET_STRING_ELT(varvalue, j, NA_STRING);
- } else {
- SET_STRING_ELT(varvalue, j, mkCharCE(t,
CE_UTF8));
+ {
+ const char *t = (const char *)
BUNtail(li, p);
+ if (t == str_nil) {
+ SET_STRING_ELT(varvalue, j,
NA_STRING);
+ } else {
+ SET_STRING_ELT(varvalue, j,
mkCharCE(t, CE_UTF8));
+ }
+ j++;
}
- j++;
- }
}
break;
default:
@@ -548,7 +548,7 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
UNPROTECT(2);
}
- /* we are going to evaluate the user function within a anonymous
function call:
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list