Changeset: d97e52eae5a3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d97e52eae5a3
Modified Files:
        clients/Tests/exports.stable.out
        clients/mapilib/mapi.c
        monetdb5/mal/mal.c
        monetdb5/mal/mal.h
        monetdb5/mal/mal_function.c
        monetdb5/mal/mal_function.h
        monetdb5/mal/mal_instruction.c
        monetdb5/mal/mal_instruction.h
        monetdb5/mal/mal_interpreter.c
        monetdb5/mal/mal_listing.c
        monetdb5/mal/mal_parser.c
        monetdb5/mal/mal_prelude.c
        monetdb5/mal/mal_profiler.c
        monetdb5/mal/mal_session.c
        monetdb5/mal/mel.h
        monetdb5/modules/mal/inspect.c
        monetdb5/modules/mal/mal_mapi.c
        monetdb5/modules/mal/mdb.c
        monetdb5/modules/mal/profiler.c
        monetdb5/modules/mal/remote.c
        monetdb5/optimizer/opt_macro.c
        monetdb5/optimizer/opt_remoteQueries.c
        sql/backends/monet5/mal_backend.h
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql.h
        sql/backends/monet5/sql_execute.c
        sql/backends/monet5/sql_scenario.c
        tools/monetdbe/monetdbe.c
Branch: no_type_bat
Log Message:

changed variable names into allocated strings (only when needed)


diffs (truncated from 1324 to 300 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -994,7 +994,7 @@ int getStrConstant(MalBlkPtr mb, str val
 const char *getTraceRef;
 str getTypeIdentifier(malType tpe);
 str getTypeName(malType tpe);
-char *getVarName(MalBlkPtr mb, int idx);
+char *getVarNameIntoBuffer(MalBlkPtr mb, int idx, const char *buf);
 const char *getVariableRef;
 Module globalModule(const char *nme);
 const char *grantRef;
@@ -1204,7 +1204,6 @@ const char *remapRef;
 const char *remoteRef;
 void removeInstruction(MalBlkPtr mb, InstrPtr p);
 void removeInstructionBlock(MalBlkPtr mb, int pc, int cnt);
-void renameVariables(MalBlkPtr mb);
 const char *rename_columnRef;
 const char *rename_schemaRef;
 const char *rename_tableRef;
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -2010,6 +2010,8 @@ mapi_destroy(Mapi mid)
        free(mid->tracebuffer);
        if (mid->errorstr && mid->errorstr != mapi_nomem)
                free(mid->errorstr);
+       if (mid->noexplain)
+               free(mid->noexplain);
 
        msettings_destroy(mid->settings);
 
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -100,7 +100,7 @@ mal_init(char *modules[], bool embedded,
        GDKprintinforegister(MALprintinfo);
 
        err = malBootstrap(modules, embedded, initpasswd);
-       if (err !=MAL_SUCCEED) {
+       if (err != MAL_SUCCEED) {
                mal_client_reset();
                TRC_CRITICAL(MAL_SERVER, "%s\n", err);
                freeException(err);
diff --git a/monetdb5/mal/mal.h b/monetdb5/mal/mal.h
--- a/monetdb5/mal/mal.h
+++ b/monetdb5/mal/mal.h
@@ -109,15 +109,16 @@ typedef struct SYMDEF {
        struct SYMDEF *skip;            /* skip to next different symbol */
        const char *name;
        int kind;                                       /* what kind of symbol 
*/
+       bool allocated;                         /* allocated using mallocs or 
compiled inside the binary */
        struct MALBLK *def;                     /* the details of the MAL fcn */
        mel_func *func;
 } *Symbol, SymRecord;
 
 
 typedef struct VARRECORD {
-       char name[IDLENGTH];            /* use the space for the full name */
+       char *name;//[IDLENGTH];                /* use the space for the full 
name */
+       malType type;                           /* internal type signature */
        char kind;                                      /* Could be either _, X 
or C to stamp the variable type */
-       malType type;                           /* internal type signature */
        bool constant:1,
                typevar:1,
                fixedtype:1,
@@ -169,7 +170,6 @@ typedef struct MALBLK {
        struct MALBLK *alternative;
        int vtop;                                       /* next free slot */
        int vsize;                                      /* size of variable 
arena */
-       int vid;                                        /* generate local 
variable counter */
        VarRecord *var;                         /* Variable table */
        int stop;                                       /* next free slot */
        int ssize;                                      /* byte size of arena */
diff --git a/monetdb5/mal/mal_function.c b/monetdb5/mal/mal_function.c
--- a/monetdb5/mal/mal_function.c
+++ b/monetdb5/mal/mal_function.c
@@ -94,6 +94,7 @@ chkFlow(MalBlkPtr mb)
        int endseen = 0, retseen = 0;
        InstrPtr p, sig;
        str msg = MAL_SUCCEED;
+       char name[IDLENGTH] = { 0 };
 
        if (mb->errors != MAL_SUCCEED)
                return mb->errors;
@@ -117,8 +118,7 @@ chkFlow(MalBlkPtr mb)
                                if (v == var[j])
                                        throw(MAL, "chkFlow",
                                                  "%s.%s recursive %s[%d] 
shields %s[%d]",
-                                                 getModuleId(sig), 
getFunctionId(sig), getVarName(mb,
-                                                                               
                                                                   v),
+                                                 getModuleId(sig), 
getFunctionId(sig), getVarNameIntoBuffer(mb, v, name),
                                                  pc[j], getFcnName(mb), pc[i]);
 
                        btop++;
@@ -128,12 +128,12 @@ chkFlow(MalBlkPtr mb)
                        if (btop > 0 && var[btop - 1] != v)
                                throw(MAL, "chkFlow",
                                          "%s.%s exit-label '%s' doesnot match 
'%s'",
-                                         getModuleId(sig), getFunctionId(sig), 
getVarName(mb, v),
-                                         getVarName(mb, var[btop - 1]));
+                                         getModuleId(sig), getFunctionId(sig), 
getVarNameIntoBuffer(mb, v, name),
+                                         getVarNameIntoBuffer(mb, var[btop - 
1], name));
                        if (btop == 0)
                                throw(MAL, "chkFlow",
                                          "%s.%s exit-label '%s' without 
begin-label",
-                                         getModuleId(sig), getFunctionId(sig), 
getVarName(mb, v));
+                                         getModuleId(sig), getFunctionId(sig), 
getVarNameIntoBuffer(mb, v, name));
                        /* search the matching block */
                        for (j = btop - 1; j >= 0; j--)
                                if (var[j] == v)
@@ -163,7 +163,7 @@ chkFlow(MalBlkPtr mb)
                                if (var[j] == v)
                                        break;
                        if (j < 0) {
-                               str nme = getVarName(mb, v);
+                               str nme = getVarNameIntoBuffer(mb, v, name);
                                throw(MAL, "chkFlow", "%s.%s label '%s' not in 
guarded block",
                                          getModuleId(sig), getFunctionId(sig), 
nme);
                        }
@@ -219,7 +219,7 @@ chkFlow(MalBlkPtr mb)
 
        if (endseen && btop > 0)
                throw(MAL, "chkFlow", "barrier '%s' without exit in %s[%d]",
-                         getVarName(mb, var[btop - 1]), getFcnName(mb), i);
+                         getVarNameIntoBuffer(mb, var[btop - 1], name), 
getFcnName(mb), i);
        p = getInstrPtr(mb, 0);
        if (!isaSignature(p))
                throw(MAL, "chkFlow", "%s.%s signature missing", 
getModuleId(sig),
@@ -445,7 +445,6 @@ listFunction(stream *fd, MalBlkPtr mb, M
 
        assert(size >= 0);
        assert(first >= 0 && first < mb->stop);
-       renameVariables(mb);
        if (flg & LIST_MAL_MAPI) {
                size_t len = 0;
                str ps;
@@ -472,25 +471,6 @@ listFunction(stream *fd, MalBlkPtr mb, M
 
 
 void
-renameVariables(MalBlkPtr mb)
-{
-       int i;
-       char *s;
-
-       /* Temporary variables get their name from the position in the symbol 
table */
-       /* However, also MAL input may contain temporary names. At some point 
you need to clean it up to avoid clashes */
-       /* Certainly when you are about to print the MAL function */
-       /* During optimization they may be copied around, which means there 
name should be re-establised */
-       /* rename all temporaries for ease of variable table interpretation */
-       /* this code should not be necessary is variables always keep their 
position */
-       for (i = 0; i < mb->vtop; i++) {
-               s = getVarName(mb, i);
-               if (s[1] == '_' && (*s == 'C' || *s == 'X'))
-                       snprintf(s + 2, IDLENGTH - 2, "%d", i);
-       }
-}
-
-void
 printFunction(stream *fd, MalBlkPtr mb, MalStkPtr stk, int flg)
 {
        int i, j;
@@ -712,6 +692,7 @@ chkDeclarations(MalBlkPtr mb)
        short blks[MAXDEPTH], top = 0, blkId = 1;
        int dflow = -1;
        str msg = MAL_SUCCEED;
+       char name[IDLENGTH] = { 0 };
 
        if (mb->errors)
                return GDKstrdup(mb->errors);
@@ -754,8 +735,7 @@ chkDeclarations(MalBlkPtr mb)
                                                   && !isVarInit(mb, l)) {
                                        throw(MAL, "chkFlow",
                                                  "%s.%s '%s' may not be used 
before being initialized",
-                                                 getModuleId(sig), 
getFunctionId(sig), getVarName(mb,
-                                                                               
                                                                   l));
+                                                 getModuleId(sig), 
getFunctionId(sig), getVarNameIntoBuffer(mb, l, name));
                                }
                        } else if (!isVarInit(mb, l)) {
                                /* is the block still active ? */
@@ -764,8 +744,7 @@ chkDeclarations(MalBlkPtr mb)
                                                break;
                                if (i > top || blks[i] != getVarScope(mb, l))
                                        throw(MAL, "chkFlow", "%s.%s '%s' used 
outside scope",
-                                                 getModuleId(sig), 
getFunctionId(sig), getVarName(mb,
-                                                                               
                                                                   l));
+                                                 getModuleId(sig), 
getFunctionId(sig), getVarNameIntoBuffer(mb, l, name));
                        }
                        if (blockCntrl(p) || blockStart(p))
                                setVarInit(mb, l);
diff --git a/monetdb5/mal/mal_function.h b/monetdb5/mal/mal_function.h
--- a/monetdb5/mal/mal_function.h
+++ b/monetdb5/mal/mal_function.h
@@ -31,7 +31,6 @@ mal_export int isLoopBarrier(MalBlkPtr m
 mal_export int getBlockExit(MalBlkPtr mb, int pc);
 mal_export int getBlockBegin(MalBlkPtr mb, int pc);
 mal_export void setVariableScope(MalBlkPtr mb);
-mal_export void renameVariables(MalBlkPtr mb);
 
 mal_export void printFunction(stream *fd, MalBlkPtr mb, MalStkPtr stk, int 
flg);
 mal_export void traceFunction(component_t comp, MalBlkPtr mb, MalStkPtr stk,
diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c
--- a/monetdb5/mal/mal_instruction.c
+++ b/monetdb5/mal/mal_instruction.c
@@ -73,8 +73,12 @@ freeSymbol(Symbol s)
        if (s->def) {
                freeMalBlk(s->def);
                s->def = NULL;
+       } else if (s->allocated && s->func) {
+               GDKfree(s->func->comment);
+               GDKfree((char*)s->func->cname);
+               GDKfree(s->func->args);
+               GDKfree(s->func);
        }
-       /* TODO free s->func */
        GDKfree(s);
 }
 
@@ -225,6 +229,9 @@ resetMalBlk(MalBlkPtr mb)
        mb->stop = 0;
 
        for (i = 0; i < mb->vtop; i++) {
+               if (mb->var[i].name)
+                       GDKfree(mb->var[i].name);
+               mb->var[i].name = NULL;
                if (isVarConstant(mb, i))
                        VALclear(&getVarConstant(mb, i));
        }
@@ -242,7 +249,6 @@ resetMalBlk(MalBlkPtr mb)
                mb->vsize = MALCHUNK;
        }
        mb->vtop = 0;
-       mb->vid = 0;
 }
 
 
@@ -259,11 +265,14 @@ freeMalBlk(MalBlkPtr mb)
                        mb->stmt[i] = NULL;
                }
        mb->stop = 0;
-       for (i = 0; i < mb->vtop; i++)
+       for (i = 0; i < mb->vtop; i++) {
+               if (mb->var[i].name)
+                       GDKfree(mb->var[i].name);
+               mb->var[i].name = NULL;
                if (isVarConstant(mb, i))
                        VALclear(&getVarConstant(mb, i));
+       }
        mb->vtop = 0;
-       mb->vid = 0;
        GDKfree(mb->stmt);
        mb->stmt = 0;
        GDKfree(mb->var);
@@ -302,11 +311,15 @@ copyMalBlk(MalBlkPtr old)
        }
 
        mb->vsize = old->vsize;
-       mb->vid = old->vid;
 
        /* copy all variable records */
        for (i = 0; i < old->vtop; i++) {
                mb->var[i] = old->var[i];
+               if (mb->var[i].name) {
+                       mb->var[i].name = GDKstrdup(mb->var[i].name);
+                       if (!mb->var[i].name)
+                               goto bailout;
+               }
                if (VALcopy(&(mb->var[i].value), &(old->var[i].value)) == NULL) 
{
                        mb->vtop = i;
                        goto bailout;
@@ -347,8 +360,11 @@ copyMalBlk(MalBlkPtr old)
   bailout:
        for (i = 0; i < old->stop; i++)
                freeInstruction(mb->stmt[i]);
-       for (i = 0; i < old->vtop; i++)
+       for (i = 0; i < old->vtop; i++) {
+               if (mb->var[i].name)
+                       GDKfree(mb->var[i].name);
                VALclear(&mb->var[i].value);
+       }
        GDKfree(mb->var);
        GDKfree(mb->stmt);
        GDKfree(mb);
@@ -515,7 +531,7 @@ findVariable(MalBlkPtr mb, const char *n
        if (name == NULL)
                return -1;
        for (i = mb->vtop - 1; i >= 0; i--)
-               if (idcmp(name, mb->var[i].name) == 0)
+               if (mb->var[i].name && idcmp(name, mb->var[i].name) == 0)
                        return i;
        return -1;
 }
@@ -545,85 +561,6 @@ getArgDefault(MalBlkPtr mb, InstrPtr p, 
        return NULL;
 }
 
-/* All variables are implicitly declared upon their first assignment.
- *
- * Lexical constants require some care. They typically appear as
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to