Changeset: 1c98a592b0e1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1c98a592b0e1
Modified Files:
        monetdb5/mal/mal_parser.c
        tools/monetdbe/monetdbe.c
Branch: Sep2022
Log Message:

Allocate the right number of arguments right away.


diffs (93 lines):

diff --git a/monetdb5/mal/mal_parser.c b/monetdb5/mal/mal_parser.c
--- a/monetdb5/mal/mal_parser.c
+++ b/monetdb5/mal/mal_parser.c
@@ -1063,6 +1063,55 @@ parseInclude(Client cntxt)
        return 0;
 }
 
+/* return the combined count of the number of arguments and the number
+ * of return values so that we can allocate enough space in the
+ * instruction; returns -1 on error (missing closing parenthesis) */
+static int
+cntArgsReturns(Client cntxt)
+{
+       size_t yycur = cntxt->yycur;
+       int cnt = 0;
+       char ch;
+
+       ch = currChar(cntxt);
+       if (ch != ')') {
+               cnt++;
+               while (ch != ')' && ch && !NL(ch)) {
+                       if (ch == ',')
+                               cnt++;
+                       nextChar(cntxt);
+                       ch = currChar(cntxt);
+               }
+       }
+       if (ch != ')') {
+               parseError(cntxt, "')' expected\n");
+               cntxt->yycur = yycur;
+               return -1;
+       }
+       advance(cntxt, 1);
+       ch = currChar(cntxt);
+       if (ch == '(') {
+               advance(cntxt, 1);
+               ch = currChar(cntxt);
+               cnt++;
+               while (ch != ')' && ch && !NL(ch)) {
+                       if (ch == ',')
+                               cnt++;
+                       nextChar(cntxt);
+                       ch = currChar(cntxt);
+               }
+               if (ch != ')') {
+                       parseError(cntxt, "')' expected\n");
+                       cntxt->yycur = yycur;
+                       return -1;
+               }
+       } else {
+               cnt++;
+       }
+       cntxt->yycur = yycur;
+       return cnt;
+}
+
 /*
  * Definition
  * The definition statements share a lot in common, which calls for factoring
@@ -1135,7 +1184,11 @@ fcnHeader(Client cntxt, int kind)
 
        assert(!cntxt->backup);
        cntxt->backup = cntxt->curprg;
-       cntxt->curprg = newFunction( modnme, fnme, kind);
+       int nargs = cntArgsReturns(cntxt);
+       if (nargs < 0)
+               return 0;
+       /* one extra for argument/return manipulation */
+       cntxt->curprg = newFunctionArgs( modnme, fnme, kind, nargs + 1);
        if(cntxt->curprg == NULL) {
                /* reinstate curprg to have a place for the error */
                cntxt->curprg = cntxt->backup;
diff --git a/tools/monetdbe/monetdbe.c b/tools/monetdbe/monetdbe.c
--- a/tools/monetdbe/monetdbe.c
+++ b/tools/monetdbe/monetdbe.c
@@ -1236,7 +1236,7 @@ monetdbe_prepare_cb(void* context, char*
                assert (((backend*)  mdbe->c->sqlcontext)->remote < INT_MAX);
                char nme[16]            = {0};
                const char* name        = number2name(nme, sizeof(nme), 
++((backend*)  mdbe->c->sqlcontext)->remote);
-               prg                                     = newFunction(userRef, 
putName(name), FUNCTIONsymbol);
+               prg                                     = 
newFunctionArgs(userRef, putName(name), FUNCTIONsymbol, (int) nparams + 1);
        }
 
        resizeMalBlk(prg->def, (int) nparams + 3 /*function declaration + 
remote.exec + return statement*/);
@@ -2005,7 +2005,7 @@ append_create_remote_append_mal_program(
        assert(prg);
 
        *prg    = NULL;
-       _prg    = newFunction(userRef, putName(remote_program_name), 
FUNCTIONsymbol); // remote program
+       _prg    = newFunctionArgs(userRef, putName(remote_program_name), 
FUNCTIONsymbol, (int) ccount + 1); // remote program
        mb              = _prg->def;
 
        { // START OF HACK
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to