Changeset: 7ef3a9500bb0 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7ef3a9500bb0
Modified Files:
        monetdb5/modules/mal/rapi.c
Branch: RIntegration
Log Message:

Handling the return


diffs (128 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
@@ -81,6 +81,7 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
        int evalErr;
        char *msg = createException(MAL, "rapi.eval", "NYI");
        BAT *b;
+       BUN cnt;
        char *rargv[] = { "whatever", "--quiet", "--no-save", "--vanilla" };
        Rf_initEmbeddedR(4, rargv);
        (void) mb;
@@ -152,32 +153,7 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
                                goto wrapup;
                        }
                        BBPreleaseref(b->batCacheid);
-               } else
-                       switch (ATOMstorage(getTailType(getArgType(mb,pci,i)))) 
{
-                       case TYPE_bte:
-                               varvalue = NEW_LOGICAL(1);
-                               LOGICAL_POINTER(varvalue)[0] = *(int*) 
getArgReference(stk, pci,
-                                               i);
-                               break;
-                       case TYPE_int:
-                               varvalue = NEW_INTEGER(1);
-                               INTEGER_POINTER(varvalue)[0] = *(int*) 
getArgReference(stk, pci,
-                                               i);
-                               break;
-                       case TYPE_dbl:
-                               varvalue = NEW_NUMERIC(1);
-                               NUMERIC_POINTER(varvalue)[0] = *(flt*) 
getArgReference(stk, pci,
-                                               i);
-                               break;
-                       case TYPE_str:
-                               //varvalue = NEW_CHARACTER( strlen(*(str*) 
getArgReference(stk,pci,i)));
-                               break;
-                       default:
-                               // no clue what type to consider
-                               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
@@ -223,20 +199,53 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
                sprintf(buf, "ret%d", i);
                args[i] = GDKstrdup(buf);
 
+               cnt = (BUN)LENGTH(retval);
+
                //do something with it
                if (isaBatType(getArgType(mb,pci,i))) {
                        // hand over the vector into a BAT
                        switch (ATOMstorage(getTailType(getArgType(mb,pci,i)))) 
{
                        case TYPE_bte:
-                               b = BATnew(TYPE_oid, TYPE_bte, 0);
-                               // mem copy the R vector into the BAT
+                               b = BATnew(TYPE_oid, TYPE_int, cnt);
                                break;
                        case TYPE_int:
-                               b = BATnew(TYPE_oid, TYPE_int, 0);
-                               // mem copy the R vector into the BAT
+                       {       int *p, prev;
+                               b = BATnew(TYPE_oid, TYPE_int, cnt);
+                           BATseqbase(b, 0);
+                               b->T->nil = 0;
+                               b->T->nonil = 1;
+                               b->tkey = 1;
+                               b->tsorted = 1;
+                               b->trevsorted = 1;
+                               b->tdense = 1;
+                               BATsetcount(b,cnt);
+
+                               p = (int*) Tloc(b, BUNfirst(b));
+                               for( i =0; i< (int) cnt; i++, p++){
+                                       *p = INTEGER_POINTER(retval)[i];
+                                       if ( Rf_isNull(((SEXP*)retval)[i])){
+                                               b->T->nil = 1;
+                                               b->T->nonil = 0;
+                                               *p= int_nil;
+                                       } 
+                                       // also update the sortedness properties
+                                       if (prev){
+                                               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;
+                               }
                                break;
+                       }
                        case TYPE_dbl:
-                               b = BATnew(TYPE_oid, TYPE_dbl, 0);
+                               b = BATnew(TYPE_oid, TYPE_dbl, cnt);
                                // mem copy the R vector into the BAT
                                break;
                        default:
@@ -246,23 +255,6 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
                                goto wrapup;
                        }
                        BBPkeepref(b->batCacheid);
-               } else {
-                       switch (ATOMstorage(getTailType(getArgType(mb,pci,i)))) 
{
-                       case TYPE_bte:
-                               *(bte*) getArgReference(stk, pci, i) = 
*LOGICAL(retval);
-                               break;
-                       case TYPE_int:
-                               *(int*) getArgReference(stk, pci, i) = 
*INTEGER(retval);
-                               break;
-                       case TYPE_dbl:
-                               *(dbl*) getArgReference(stk, pci, i) = 
*REAL(retval);
-                               break;
-                       default:
-                               // no clue what type to consider
-                               msg = createException(MAL, "rapi.eval",
-                                               "unknown argument type");
-                               goto wrapup;
-                       }
                }
                msg = MAL_SUCCEED;
        }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to