Update of /cvsroot/monetdb/MonetDB5/src/mal
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv3941

Modified Files:
        mal_instruction.mx mal_parser.mx 
Log Message:
Instruction records are either created in isolation or
are allocated on the program instruction stack directly.
In the latter case, we may have to adjust their reference
if we exceed the space reserved for arguments.

It does not make sense to search the complete stack,
because this would jeopardise long MAL program
build from newly allocated structures.

The alternative to this hack is to change the code in many places
and educate the programmer to not forget updating the stmtblock
after pushing the arguments. In sql_gencode this alone would be
>100 places and in the optimizers > 30. In almost all cases
the instructions have few parameters and are constructed with
the mal_builder functions.

In the end [throwing away 16hr of patching] the simple hack
with education has become the preference.


Index: mal_parser.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_parser.mx,v
retrieving revision 1.203
retrieving revision 1.204
diff -u -d -r1.203 -r1.204
--- mal_parser.mx       31 Aug 2007 08:59:41 -0000      1.203
+++ mal_parser.mx       3 Sep 2007 07:40:07 -0000       1.204
@@ -1048,8 +1048,8 @@
        } else 
        if( keyphrase1(cntxt,"(")){ /* deal with compound return */
                int retc= curInstr->argc, i1,i2=0;
-               int maxarg;
-               int *newarg;
+               int max;
+               short *newarg;
                /* parse multi-target result */
                /* skipSpace(cntxt);*/
                ch= currChar(cntxt);
@@ -1067,16 +1067,16 @@
                        ch = currChar(cntxt);
                }
                /* re-arrange the parameters, results first*/
-               maxarg= curInstr->maxarg;
-               newarg= (int*)GDKmalloc(maxarg*sizeof(int));
+               max= curInstr->maxarg;
+               newarg= (short*)GDKmalloc(max*sizeof(short));
                for(i1= retc; i1<curInstr->argc; i1++)
                        newarg[i2++]= curInstr->argv[i1];
                curInstr->retc= curInstr->argc-retc;
                for(i1= 1; i1<retc; i1++)
                        newarg[i2++]= curInstr->argv[i1];
                curInstr->argc= i2;
-               for(; i2<maxarg; i2++) newarg[i2]= 0;
-               for(i1=0; i1<maxarg; i1++) 
+               for(; i2<max; i2++) newarg[i2]= 0;
+               for(i1=0; i1<max; i1++) 
                        curInstr->argv[i1] = newarg[i1];
                GDKfree(newarg);
                if (currChar(cntxt) != ')') {

Index: mal_instruction.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_instruction.mx,v
retrieving revision 1.284
retrieving revision 1.285
diff -u -d -r1.284 -r1.285
--- mal_instruction.mx  20 Aug 2007 21:33:42 -0000      1.284
+++ mal_instruction.mx  3 Sep 2007 07:40:06 -0000       1.285
@@ -302,7 +302,7 @@
 #endif
 
 #define DEBUG_MAL_INSTR
-#define MAXARG 4
+#define MAXARG 4               /* BEWARE the code depends on this knowledge */
 #define STMT_INCREMENT 32
 #define STMT_MAXIMUM  1<<16
 #define MAXVARS 32
@@ -366,7 +366,7 @@
        str modname;            /* module context */
        str fcnname;            /* function name */
        short argc, retc, maxarg;       /* total and result argument count */
-       short argv[1];          /* at least one entry */
+       short argv[MAXARG];             /* at least a few entries */
 } *InstrPtr, InstrRecord;
 
 @-
@@ -897,7 +897,6 @@
 newInstruction(MalBlkPtr mb, int kind)
 {
        InstrPtr p = NULL;
-       int space;
 
        if (mb && mb->stop <mb->ssize) {
                p = mb->stmt[mb->stop];
@@ -907,8 +906,7 @@
                mb->stmt[mb->stop] = NULL;
        }
        if (p == NULL) {
-               space = (MAXARG - 1) * sizeof(int) + sizeof(InstrRecord);
-               p = GDKmalloc(space);
+               p = GDKmalloc(sizeof(InstrRecord));
                p->maxarg = MAXARG;
        }
        p->typechk = TYPE_UNKNOWN;
@@ -954,7 +952,7 @@
 copyInstruction(InstrPtr p)
 {
        InstrPtr new;
-       new = (InstrPtr) GDKmalloc(sizeof(InstrRecord) + sizeof(int) * 
p->maxarg - 1);
+       new = (InstrPtr) GDKmalloc(sizeof(InstrRecord) + sizeof(short) * 
(p->maxarg - MAXARG));
        oldmoveInstruction(new, p);
        return new;
 }
@@ -971,7 +969,7 @@
 clrInstruction(InstrPtr p)
 {
        clrFunction(p);
-       memset((char *) p, 0, sizeof(InstrRecord) + (p->argc - 1) * 
sizeof(int));
+       memset((char *) p, 0, sizeof(InstrRecord) + (p->maxarg - MAXARG) * 
sizeof(int));
 }
 
 void
@@ -990,7 +988,7 @@
 {
        int space;
 
-       space = sizeof(InstrRecord) + sizeof(int) * p->argc;
+       space = sizeof(InstrRecord) + sizeof(short) * (p->maxarg-MAXARG);
        memcpy((char *) new, (char *) p, space);
        setFunctionId(new, getFunctionId(p));
        setModuleId(new, getModuleId(p));
@@ -1830,13 +1828,26 @@
        p->argv[p->argc++] = varid;
        if (p->argc == p->maxarg) {
                InstrPtr pn;
-               int pc = 0;
-               int space = (p->maxarg - 1) * sizeof(int) + sizeof(InstrRecord);
-               pn = GDKmalloc(space + MAXARG * sizeof(int));
+               int pc = 0,pclimit;
+               int space = (p->maxarg - MAXARG) * sizeof(short) + 
sizeof(InstrRecord);
+               pn = GDKmalloc(space + MAXARG * sizeof(short));
                memcpy((char *) pn, (char *) p, space);
-               pn->maxarg = p->maxarg + MAXARG;
-               /* most likely the last instruction is affected */
-               for(pc= mb->stop-1; pc >= 0; pc--)
+               pn->maxarg += MAXARG;
+               /* instructions are either created in isolation or
+                  are stored on the program instruction stack already.
+                  In the latter case, we may have to adjust their reference.
+                  It does not make sense to locate it on the complete stack,
+                  because this would jeopardise long MAL program.
+
+                  The alternative to this hack is to change the code in many 
places
+                  and educate the programmer to not forget updating the 
stmtblock
+                  after pushing the arguments. In sql_gencode this alone would 
be
+                  >100 places and in the optimizers > 30. In almost all cases
+              the instructions have few parameters.
+                */
+               pclimit= mb->stop-8;
+               pclimit= pclimit<0? 0: pclimit;
+               for(pc= mb->stop-1; pc >= pclimit; pc--)
                if( mb->stmt[pc]== p){
                        mb->stmt[pc] = pn;
                        break;


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to