Changeset: f1763da7a24d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/f1763da7a24d
Modified Files:
clients/Tests/exports.stable.out
monetdb5/extras/mal_optimizer_template/opt_sql_append.c
monetdb5/mal/mal_builder.c
monetdb5/mal/mal_import.c
monetdb5/mal/mal_instruction.c
monetdb5/mal/mal_instruction.h
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_prelude.c
monetdb5/modules/mal/manifold.c
monetdb5/modules/mal/orderidx.c
monetdb5/optimizer/opt_commonTerms.c
monetdb5/optimizer/opt_dataflow.c
monetdb5/optimizer/opt_dict.c
monetdb5/optimizer/opt_for.c
monetdb5/optimizer/opt_generator.c
monetdb5/optimizer/opt_jit.c
monetdb5/optimizer/opt_json.c
monetdb5/optimizer/opt_mask.c
monetdb5/optimizer/opt_matpack.c
monetdb5/optimizer/opt_mergetable.c
monetdb5/optimizer/opt_mitosis.c
monetdb5/optimizer/opt_multiplex.c
monetdb5/optimizer/opt_projectionpath.c
monetdb5/optimizer/opt_pushselect.c
monetdb5/optimizer/opt_querylog.c
monetdb5/optimizer/opt_remap.c
monetdb5/optimizer/opt_remoteQueries.c
monetdb5/optimizer/opt_strimps.c
monetdb5/optimizer/opt_support.c
monetdb5/optimizer/opt_volcano.c
monetdb5/tools/Tests/mserver5-ipv6.py
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_execute.c
sql/backends/monet5/sql_gencode.c
sql/backends/monet5/sql_gencode.h
sql/backends/monet5/sql_statement.c
testing/process.py
tools/monetdbe/monetdbe.c
Branch: default
Log Message:
Significant change in producing MAL code blocks.
The newStmt family of functions (newStmt newStmtArgs newAssignment
newAssignmentArgs newComment newCatchStmt newRaiseStmt newExitStmt
newReturnStmt newFcnCall newFcnCallArgs) no longer call pushInstruction
to add the new instruction to the MalBlk. This now needs to be done by
the caller of these functsion *after* all pushArgument and pushReturn
functions and their variants have been called.
The functions newInstruction and newInstructionArgs now no longer abort
if GDKmalloc fails. Instead they return NULL like any normal allocating
function should. This gets propagated by the above mentioned
functions. I went through the code and added error checking.
The reason for these changes is that pushArgument may have to extend the
instruction, and when it does, it now no longer has to search the MalBlk
in order to replace the instruction. Also, we don't want the server to
exit (or worse, crash) if GDKmalloc fails. We want the server to abort
the query instead (and give an understandable error message).
The function addArgument has been removed since it now would be
identical to pushArgument (i.e. just use the latter).
The functions newFunction and newFunctionArgs still do push the newly
created instruction onto the MalBlk because they don't return an
instruction pointer. This means that if more than 8 (MAXARG) arguments
+ return values are needed, newFunctionArgs must be called, and it must
be called with a large enough argument count. Hence the split of
relational_func_create_result into two functions
relational_func_create_result_part1 and
relational_func_create_result_part2.
diffs (truncated from 5687 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
@@ -794,7 +794,6 @@ void TABLETdestroy_format(Tablet *as);
int TABLEToutput_file(Tablet *as, BAT *order, stream *s);
int TRACEtable(Client cntxt, BAT **r);
int TYPE_xml;
-InstrPtr addArgument(MalBlkPtr mb, InstrPtr p, int varid);
void addMalException(MalBlkPtr mb, str msg);
str addOptimizerPipe(Client cntxt, MalBlkPtr mb, const char *name);
str addPipeDefinition(Client cntxt, const char *name, const char *pipe);
diff --git a/monetdb5/extras/mal_optimizer_template/opt_sql_append.c
b/monetdb5/extras/mal_optimizer_template/opt_sql_append.c
--- a/monetdb5/extras/mal_optimizer_template/opt_sql_append.c
+++ b/monetdb5/extras/mal_optimizer_template/opt_sql_append.c
@@ -182,19 +182,27 @@ OPTsql_appendImplementation(Client cntxt
/* it will be added to the block and
even my
* re-use MAL instructions */
q1 =
newInstruction(mb,aggrRef,countRef);
- getArg(q1,0) = newTmpVariable(mb,
TYPE_lng);
- q1 = pushArgument(mb, q1, getArg(p, 5));
- pushInstruction(mb, q1);
+ if (q1) {
+ getArg(q1,0) =
newTmpVariable(mb, TYPE_lng);
+ q1 = pushArgument(mb, q1,
getArg(p, 5));
+ }
}
/* push new v2 := algebra.slice( v0, 0, v1 ); */
/* use mal_builder.h primitives
* q1 = newStmt(mb, algebraRef,sliceRef); */
q2 = newInstruction(mb,algebraRef, sliceRef);
+ if (q1 == NULL || q2 == NULL) {
+ freeInstruction(q1);
+ freeInstruction(q2);
+ i--;
+ break;
+ }
getArg(q2,0) = newTmpVariable(mb, TYPE_any);
q2 = pushArgument(mb, q2, getArg(p, 5));
q2 = pushLng(mb, q2, 0);
q2 = pushArgument(mb, q2, getArg(q1, 0));
+ pushInstruction(mb, q1);
pushInstruction(mb, q2);
/* push modified v3 := sql.append( ..., ...,
..., ..., v2 ); */
diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c
--- a/monetdb5/mal/mal_builder.c
+++ b/monetdb5/mal/mal_builder.c
@@ -36,9 +36,10 @@ newAssignmentArgs(MalBlkPtr mb, int args
str msg = createException(MAL, "newAssignment", "Can not
allocate variable");
addMalException(mb, msg);
freeException(msg);
+ GDKfree(q);
+ return NULL;
} else
getArg(q,0) = k;
- pushInstruction(mb, q);
return q;
}
@@ -69,8 +70,9 @@ newStmtArgs(MalBlkPtr mb, const char *mo
str msg = createException(MAL, "newStmtArgs", "Can not allocate
variable");
addMalException(mb, msg);
freeException(msg);
+ GDKfree(q);
+ return NULL;
}
- pushInstruction(mb, q);
return q;
}
@@ -87,10 +89,11 @@ newReturnStmt(MalBlkPtr mb)
str msg = createException(MAL, "newReturnStmt", "Can not
allocate return variable");
addMalException(mb, msg);
freeException(msg);
+ GDKfree(q);
+ return NULL;
} else
getArg(q,0) = k;
q->barrier= RETURNsymbol;
- pushInstruction(mb, q);
return q;
}
@@ -100,10 +103,12 @@ newFcnCallArgs(MalBlkPtr mb, const char
InstrPtr q = newAssignmentArgs(mb, args);
const char *fcnName, *modName;
- modName = putName(mod);
- fcnName = putName(fcn);
- setModuleId(q, modName);
- setFunctionId(q, fcnName);
+ if (q != NULL) {
+ modName = putName(mod);
+ fcnName = putName(fcn);
+ setModuleId(q, modName);
+ setFunctionId(q, fcnName);
+ }
return q;
}
@@ -128,15 +133,18 @@ newComment(MalBlkPtr mb, const char *val
str msg = createException(MAL, "newComment", "Can not allocate
comment");
addMalException(mb, msg);
freeException(msg);
+ GDKfree(q);
+ return NULL;
} else {
k = defConstant(mb, TYPE_str, &cst);
- if( k >= 0){
- getArg(q,0) = k;
- clrVarConstant(mb,getArg(q,0));
- setVarDisabled(mb,getArg(q,0));
+ if (k < 0) {
+ GDKfree(q);
+ return NULL;
}
+ getArg(q,0) = k;
+ clrVarConstant(mb,getArg(q,0));
+ setVarDisabled(mb,getArg(q,0));
}
- pushInstruction(mb, q);
return q;
}
@@ -156,6 +164,8 @@ newCatchStmt(MalBlkPtr mb, const char *n
str msg = createException(MAL, "newCatchStmt", "Can not
allocate variable");
addMalException(mb, msg);
freeException(msg);
+ GDKfree(q);
+ return NULL;
}else{
getArg(q,0) = k;
}
@@ -179,6 +189,8 @@ newRaiseStmt(MalBlkPtr mb, const char *n
str msg = createException(MAL, "newRaiseStmt", "Can not
allocate variable");
addMalException(mb, msg);
freeException(msg);
+ GDKfree(q);
+ return NULL;
} else
getArg(q,0) = k;
} else
@@ -202,6 +214,8 @@ newExitStmt(MalBlkPtr mb, const char *nm
str msg = createException(MAL, "newExitStmt", "Can not
allocate variable");
addMalException(mb, msg);
freeException(msg);
+ GDKfree(q);
+ return NULL;
}else
getArg(q,0) = k;
} else
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -105,7 +105,7 @@ malLoadScript(str name, bstream **fdin)
*fdin = bstream_create(fd, sz == 0 ? (size_t) (2 * 128 * BLOCK) : sz);
if(*fdin == NULL) {
close_stream(fd);
- throw(MAL, "malInclude", MAL_MALLOC_FAIL);
+ throw(MAL, "malInclude", SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
if (bstream_next(*fdin) < 0) {
bstream_destroy(*fdin);
@@ -175,10 +175,10 @@ malIncludeString(Client c, const char *n
stream* mal_stream;
if ((mal_buf = GDKmalloc(sizeof(buffer))) == NULL)
- throw(MAL, "malIncludeString", MAL_MALLOC_FAIL);
+ throw(MAL, "malIncludeString", SQLSTATE(HY013) MAL_MALLOC_FAIL);
if ((mal_stream = buffer_rastream(mal_buf, name)) == NULL) {
GDKfree(mal_buf);
- throw(MAL, "malIncludeString", MAL_MALLOC_FAIL);
+ throw(MAL, "malIncludeString", SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
buffer_init(mal_buf, mal, mal_len);
c->srcFile = name;
@@ -187,7 +187,7 @@ malIncludeString(Client c, const char *n
if ((c->fdin = bstream_create(mal_stream, mal_len)) == NULL) {
mnstr_destroy(mal_stream);
GDKfree(mal_buf);
- throw(MAL, "malIncludeString", MAL_MALLOC_FAIL);
+ throw(MAL, "malIncludeString", SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
bstream_next(c->fdin);
parseMAL(c, c->curprg, 1, INT_MAX, address);
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
@@ -457,6 +457,7 @@ newInstructionArgs(MalBlkPtr mb, const c
p = GDKzalloc(args * sizeof(p->argv[0]) + offsetof(InstrRecord, argv));
if (p == NULL) {
+#if 0
/* We are facing an hard problem.
* The upper layers of the code base assume that this routine
will always produce a structure.
* Furthermore, failure to allocate such a small data structure
indicates we are in serious trouble.
@@ -464,6 +465,9 @@ newInstructionArgs(MalBlkPtr mb, const c
*/
GDKfatal(SQLSTATE(HY013) MAL_MALLOC_FAIL);
exit(1);
+#else
+ return NULL;
+#endif
}
p->maxarg = args;
p->typechk = TYPE_UNKNOWN;
@@ -1191,51 +1195,6 @@ extendInstruction(MalBlkPtr mb, InstrPtr
InstrPtr
pushArgument(MalBlkPtr mb, InstrPtr p, int varid)
{
- InstrPtr pn;
-
- if (p == NULL)
- return NULL;
- if (varid < 0) {
- /* leave everything as is in this exceptional programming error
*/
- mb->errors = createMalException(mb, 0, TYPE,"improper variable
id");
- return p;
- }
- if (p->argc == p->maxarg) {
- pn = extendInstruction(mb, p);
-
- /* if the instruction is already stored in the MAL block
- * it should be replaced by an extended version.
- */
- if (p != pn) {
- for (int i = mb->stop - 1; i >= 0; i--) {
- if (mb->stmt[i] == p) {
- mb->stmt[i] = pn;
- break;
- }
- }
- }
- p = pn;
- if (mb->errors)
- return p;
- }
- /* protect against the case that the instruction is malloced
- * in isolation */
- if( mb->maxarg < p->maxarg)
- mb->maxarg= p->maxarg;
- p->argv[p->argc++] = varid;
- return p;
-}
-
-
-/* the next version assumes that we have allocated an isolated instruction
- * using newInstruction. As long as it is not stored in the MAL block
- * we can simpy extend it with arguments
- */
-InstrPtr
-addArgument(MalBlkPtr mb, InstrPtr p, int varid)
-{
- InstrPtr pn = p;
-
if (p == NULL)
return NULL;
if (varid < 0) {
@@ -1245,14 +1204,11 @@ addArgument(MalBlkPtr mb, InstrPtr p, in
}
if (p->argc == p->maxarg) {
- pn = extendInstruction(mb, p);
#ifndef NDEBUG
- if (p != pn) {
- for (int i = mb->stop - 1; i >= 0; i--)
- assert(mb->stmt[i] != p);
- }
+ for (int i = 0; i < mb->stop; i++)
+ assert(mb->stmt[i] != p);
#endif
- p = pn;
+ p = extendInstruction(mb, p);
if (mb->errors)
return p;
}
@@ -1283,6 +1239,8 @@ setArgument(MalBlkPtr mb, InstrPtr p, in
InstrPtr
pushReturn(MalBlkPtr mb, InstrPtr p, int varid)
{
+ if (p == NULL)
+ return NULL;
if (p->retc == 1 && p->argv[0] == -1) {
p->argv[0] = varid;
return p;
diff --git a/monetdb5/mal/mal_instruction.h b/monetdb5/mal/mal_instruction.h
--- a/monetdb5/mal/mal_instruction.h
+++ b/monetdb5/mal/mal_instruction.h
@@ -189,7 +189,6 @@ mal_export str convertConstant(malType t
mal_export void pushInstruction(MalBlkPtr mb, InstrPtr p);
mal_export InstrPtr pushArgument(MalBlkPtr mb, InstrPtr p, int varid);
-mal_export InstrPtr addArgument(MalBlkPtr mb, InstrPtr p, int varid);
mal_export InstrPtr setArgument(MalBlkPtr mb, InstrPtr p, int idx, int varid);
mal_export InstrPtr pushReturn(MalBlkPtr mb, InstrPtr p, int varid);
mal_export InstrPtr pushArgumentId(MalBlkPtr mb, InstrPtr p, const char *name);
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]