Changeset: e5adba1aea41 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e5adba1aea41
Modified Files:
sql/backends/monet5/sql_gencode.c
sql/backends/monet5/sql_scenario.c
Branch: Jun2023
Log Message:
More contortions to make setjmp/longjmp work.
diffs (truncated from 1133 to 300 lines):
diff --git a/sql/backends/monet5/sql_gencode.c
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -137,51 +137,15 @@ relational_func_create_result_part2(MalB
}
static int
-_create_relational_function(mvc *m, const char *mod, const char *name, sql_rel
*r, stmt *call, list *rel_ops, int inline_func)
+_create_relational_function_body(mvc *m, sql_rel *r, stmt *call, list
*rel_ops, int inline_func)
{
Client c = MCgetClient(m->clientid);
backend *be = (backend *) c->sqlcontext;
MalBlkPtr curBlk = 0;
InstrPtr curInstr = 0;
- Symbol symbackup = NULL;
- int res = 0, added_to_cache;
+ int res = 0, added_to_cache = 0;
str msg = MAL_SUCCEED;
- backend bebackup;
- exception_buffer ebsave = m->sa->eb;
-
- if (strlen(mod) >= IDLENGTH) {
- (void) sql_error(m, 10, SQLSTATE(42000) "Module name '%s' too
large for the backend", mod);
- res = -1;
- goto bailout;
- }
- if (strlen(name) >= IDLENGTH) {
- (void) sql_error(m, 10, SQLSTATE(42000) "Function name '%s' too
large for the backend", name);
- res = -1;
- goto bailout;
- }
- symbackup = c->curprg;
- bebackup = *be; /* backup current backend */
- backend_reset(be);
- int nargs;
- relational_func_create_result_part1(m, &r, &nargs);
- nargs += (call && call->type == st_list) ? list_length(call->op4.lval)
: rel_ops ? list_length(rel_ops) : 0;
-
- c->curprg = newFunctionArgs(putName(mod), putName(name),
FUNCTIONsymbol, nargs);
- if(c->curprg == NULL) {
- added_to_cache = 0;
- sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
- goto cleanup;
- }
- if (eb_savepoint(&m->sa->eb)) {
- added_to_cache = 0;
- sql_error(m, 10, "%s", m->sa->eb.msg);
- res = -1;
- goto cleanup;
- }
-
- added_to_cache = 0;
curBlk = c->curprg->def;
curInstr = getInstrPtr(curBlk, 0);
@@ -300,13 +264,55 @@ cleanup:
else
SQLremoveQueryFromCache(c);
}
+ return res;
+}
+
+static int
+_create_relational_function(mvc *m, const char *mod, const char *name, sql_rel
*r, stmt *call, list *rel_ops, int inline_func)
+{
+ Client c = MCgetClient(m->clientid);
+ backend *be = (backend *) c->sqlcontext;
+ Symbol symbackup = c->curprg;
+ backend bebackup = *be; /* backup current backend */
+ exception_buffer ebsave = m->sa->eb;
+
+ if (strlen(mod) >= IDLENGTH) {
+ (void) sql_error(m, 10, SQLSTATE(42000) "Module name '%s' too
large for the backend", mod);
+ goto bailout;
+ }
+ if (strlen(name) >= IDLENGTH) {
+ (void) sql_error(m, 10, SQLSTATE(42000) "Function name '%s' too
large for the backend", name);
+ goto bailout;
+ }
+
+ backend_reset(be);
+
+ int nargs;
+ relational_func_create_result_part1(m, &r, &nargs);
+ nargs += (call && call->type == st_list) ? list_length(call->op4.lval)
: rel_ops ? list_length(rel_ops) : 0;
+
+ c->curprg = newFunctionArgs(putName(mod), putName(name),
FUNCTIONsymbol, nargs);
+ if (c->curprg == NULL) {
+ sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ goto bailout;
+ } else if (eb_savepoint(&m->sa->eb)) {
+ sql_error(m, 10, "%s", m->sa->eb.msg);
+ freeSymbol(c->curprg);
+ goto bailout;
+ } else if (_create_relational_function_body(m, r, call, rel_ops,
inline_func) < 0) {
+ goto bailout;
+ }
*be = bebackup;
c->curprg = symbackup;
m->sa->eb = ebsave;
+ return 0;
bailout:
- if (res < 0 && m->sa->eb.enabled)
+ *be = bebackup;
+ c->curprg = symbackup;
+ m->sa->eb = ebsave;
+ if (m->sa->eb.enabled)
eb_error(&m->sa->eb, m->errstr[0] ? m->errstr : be->mb->errors
? be->mb->errors : *GDKerrbuf ? GDKerrbuf : "out of memory", 1000);
- return res;
+ return -1;
}
static str
@@ -342,42 +348,23 @@ cleanup:
/* stub and remote function */
static int
-_create_relational_remote(mvc *m, const char *mod, const char *name, sql_rel
*rel, stmt *call, prop *prp)
+_create_relational_remote_body(mvc *m, const char *mod, const char *name,
sql_rel *rel, sql_rel *rel2, stmt *call, prop *prp)
{
Client c = MCgetClient(m->clientid);
MalBlkPtr curBlk = 0;
InstrPtr curInstr = 0, p, o;
- Symbol backup = NULL;
sqlid table_id = prp->id;
node *n;
- int i, q, v, res = 0, added_to_cache, *lret, *rret;
+ int i, q, v, res = -1, added_to_cache = 0, *lret, *rret;
size_t len = 1024, nr, pwlen = 0;
char *lname = NULL, *buf = NULL, *mal_session_uuid, *err = NULL,
*pwhash = NULL;
str username = NULL, password = NULL, msg = NULL;
sql_rel *r = rel;
- exception_buffer ebsave = m->sa->eb;
-
- if (table_id == 0) {
- sql_error(m, 003, SQLSTATE(42000) "Missing property on the
input relation");
- res = -1;
- goto bailout;
- }
- if (strlen(mod) >= IDLENGTH) {
- sql_error(m, 10, SQLSTATE(42000) "Module name '%s' too large
for the backend", mod);
- res = -1;
- goto bailout;
- }
- if (strlen(name) >= IDLENGTH) {
- sql_error(m, 10, SQLSTATE(42000) "Function name '%s' too large
for the backend", name);
- res = -1;
- goto bailout;
- }
lname = sa_strdup(m->ta, name);
if (lname == NULL) {
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
- goto bailout;
+ goto cleanup;
}
if (is_topn(r->op) || is_sample(r->op))
@@ -387,37 +374,14 @@ static int
lret = SA_NEW_ARRAY(m->sa, int, list_length(r->exps));
if (lret == NULL) {
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
- goto bailout;
+ goto cleanup;
}
rret = SA_NEW_ARRAY(m->sa, int, list_length(r->exps));
if (rret == NULL) {
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
- goto bailout;
+ goto cleanup;
}
- /* create stub */
- backup = c->curprg;
- int nargs;
- sql_rel *rel2 = rel;
- relational_func_create_result_part1(m, &rel2, &nargs);
- if (call && call->type == st_list)
- nargs += list_length(call->op4.lval);
- c->curprg = newFunctionArgs(putName(mod), putName(name),
FUNCTIONsymbol, nargs);
- if( c->curprg == NULL) {
- sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- c->curprg = backup;
- res = -1;
- goto bailout;
- }
- if (eb_savepoint(&m->sa->eb)) {
- added_to_cache = 0;
- sql_error(m, 10, "%s", m->sa->eb.msg);
- res = -1;
- goto cleanup;
- }
- added_to_cache = 0;
lname[0] = 'l';
curBlk = c->curprg->def;
curInstr = getInstrPtr(curBlk, 0);
@@ -426,13 +390,11 @@ static int
const char *uri = mapiuri_uri(rt->query, m->sa);
if (!rt) {
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
goto cleanup;
}
curInstr = relational_func_create_result_part2(curBlk, curInstr, rel2);
if( curInstr == NULL) {
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
goto cleanup;
}
@@ -449,7 +411,6 @@ static int
sprintf(nbuf, "A%d", i++);
if ((varid = newVariable(curBlk, nbuf, strlen(nbuf),
type)) < 0) {
sql_error(m, 10, SQLSTATE(42000) "Internal
error while compiling statement: variable id too long");
- res = -1;
goto cleanup;
}
curInstr = pushArgument(curBlk, curInstr, varid);
@@ -467,7 +428,6 @@ static int
p = newFcnCall(curBlk, batRef, newRef);
if (p == NULL) {
sql_error(m, 10, SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- res = -1;
goto cleanup;
}
p = pushType(curBlk, p, getBatType(type));
@@ -483,7 +443,6 @@ static int
sql_error(m, 10, "%s", msg);
freeException(msg);
msg = NULL;
- res = -1;
goto cleanup;
}
/* q := remote.connect("uri", "username", "password", "msql"); */
@@ -492,7 +451,6 @@ static int
GDKfree(username);
GDKfree(password);
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
goto cleanup;
}
p = pushStr(curBlk, p, uri);
@@ -502,7 +460,6 @@ static int
pwhash = (char*)GDKmalloc(pwlen + 2);
if (pwhash == NULL) {
GDKfree(password);
- res = -1;
goto cleanup;
}
strconcat_len(pwhash, pwlen + 2, "\1", password, NULL);
@@ -517,7 +474,6 @@ static int
p = newInstructionArgs(curBlk, remoteRef, execRef, 10);
if (p == NULL) {
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
goto cleanup;
}
p = pushArgument(curBlk, p, q);
@@ -528,7 +484,6 @@ static int
if (o == NULL) {
freeInstruction(p);
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
goto cleanup;
}
o = pushArgument(curBlk, o, q);
@@ -540,7 +495,6 @@ static int
if (o == NULL) {
freeInstruction(p);
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
goto cleanup;
}
o = pushArgument(curBlk, o, q);
@@ -552,7 +506,6 @@ static int
if (o == NULL) {
freeInstruction(p);
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
goto cleanup;
}
o = pushArgument(curBlk, o, q);
@@ -563,7 +516,6 @@ static int
if (!(buf = rel2str(m, rel))) {
freeInstruction(p);
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
goto cleanup;
}
o = newFcnCall(curBlk, remoteRef, putRef);
@@ -571,7 +523,6 @@ static int
free(buf);
freeInstruction(p);
sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- res = -1;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]