Changeset: d320ddec4159 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/d320ddec4159 Modified Files: sql/backends/monet5/sql_cat.c sql/backends/monet5/sql_gencode.c sql/server/rel_semantic.c sql/server/rel_updates.c Branch: default Log Message:
Don't leave new compilation properties on errors, so set them at a reversible state. Cleaned my mal function find implementation address code diffs (210 lines): diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c --- a/sql/backends/monet5/sql_cat.c +++ b/sql/backends/monet5/sql_cat.c @@ -988,7 +988,7 @@ create_func(mvc *sql, char *sname, char if (!sff->s || sff->system) throw(SQL,"sql.create_func", SQLSTATE(42000) "%s %s: not allowed to replace system %s %s;", base, F, fn, sff->base.name); - if (sff->lang == FUNC_LANG_MAL && !mal_function_find_implementation_address(&fimp, sql, sff)) { + if (sff->lang == FUNC_LANG_MAL && mal_function_find_implementation_address(&fimp, sql, sff) < 0) { backend_ok = false; sql->session->status = 0; /* clean the error */ sql->errstr[0] = '\0'; 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 @@ -1106,81 +1106,77 @@ backend_create_c_func(backend *be, sql_f int mal_function_find_implementation_address(str *res, mvc *m, sql_func *f) { - mvc *o = m; + mvc o = *m; buffer *b = NULL; bstream *bs = NULL; stream *buf = NULL; char *n = NULL; int len = _strlen(f->query); - sql_schema *s = cur_schema(m); dlist *l, *ext_name; - if (!(m = ZNEW(mvc))) { - (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); - goto bailout; - } - m->type = Q_PARSE; - m->user_id = m->role_id = USER_MONETDB; - m->store = o->store; - if (!(m->pa = sa_create(NULL))) { - (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); - goto bailout; + if (!(b = (buffer*)malloc(sizeof(buffer)))) { + (void) sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); + return -1; } - if (!(m->session = sql_session_create(m->store, m->pa, 0))) { - (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); - goto bailout; - } - if (s) - m->session->schema = s; - if (!(m->sa = sa_create(NULL))) { - (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); - goto bailout; - } - if (!(b = (buffer*)GDKmalloc(sizeof(buffer)))) { - (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); - goto bailout; - } - if (!(n = GDKmalloc(len + 2))) { - (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); - goto bailout; + if (!(n = malloc(len + 2))) { + free(b); + (void) sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); + return -1; } snprintf(n, len + 2, "%s\n", f->query); len++; buffer_init(b, n, len); if (!(buf = buffer_rastream(b, "sqlstatement"))) { - (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); - goto bailout; + buffer_destroy(b); + (void) sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); + return -1; } if (!(bs = bstream_create(buf, b->len))) { - (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); - goto bailout; + buffer_destroy(b); + (void) sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); + return -1; } scanner_init(&m->scanner, bs, NULL); m->scanner.mode = LINE_1; bstream_next(m->scanner.rs); - (void) sqlparse(m); /* blindly ignore errors */ - assert(m->sym->token == SQL_CREATE_FUNC); - l = m->sym->data.lval; - ext_name = l->h->next->next->next->data.lval; - if (!(*res = _STRDUP(qname_schema_object(ext_name)))) /* found the implementation, set it */ - (void) sql_error(o, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); -bailout: - if (m) { - bstream_destroy(m->scanner.rs); - if (m->session) { - sql_session_destroy(m->session); - } - if (m->sa) - sa_destroy(m->sa); - _DELETE(m); + m->type = Q_PARSE; + m->user_id = m->role_id = USER_MONETDB; + m->params = NULL; + m->sym = NULL; + m->errstr[0] = '\0'; + (void) sqlparse(m); + if (m->session->status || m->errstr[0] || !m->sym || m->sym->token != SQL_CREATE_FUNC) { + if (m->errstr[0] == '\0') + (void) sql_error(m, 02, SQLSTATE(42000) "Could not parse CREATE SQL MAL function statement"); + } else { + l = m->sym->data.lval; + ext_name = l->h->next->next->next->data.lval; + if (!(*res = _STRDUP(qname_schema_object(ext_name)))) /* found the implementation, set it */ + (void) sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL); } - m = o; - if (n) - GDKfree(n); - if (b) - GDKfree(b); - return m->errstr[0] == '\0'; /* m was set back to o */ + + buffer_destroy(b); + bstream_destroy(m->scanner.rs); + + m->sym = NULL; + o.frames = m->frames; /* may have been realloc'ed */ + o.sizeframes = m->sizeframes; + if (m->session->status || m->errstr[0]) { + int status = m->session->status; + + strcpy(o.errstr, m->errstr); + *m = o; + m->session->status = status; + } else { + unsigned int label = m->label; + + while (m->topframes > o.topframes) + clear_frame(m, m->frames[--m->topframes]); + *m = o; + m->label = label; + } + return m->errstr[0] == '\0' ? 0 : -1; /* m was set back to o */ } static int @@ -1204,7 +1200,7 @@ backend_create_sql_func(backend *be, sql if (!f->sql && (f->lang == FUNC_LANG_INT || f->lang == FUNC_LANG_MAL)) { if (f->lang == FUNC_LANG_MAL && !f->imp) { char *imp = NULL; - if (!mal_function_find_implementation_address(&imp, m, f)) + if (mal_function_find_implementation_address(&imp, m, f) < 0) return -1; f->imp = sa_strdup(f->sa, imp); _DELETE(imp); diff --git a/sql/server/rel_semantic.c b/sql/server/rel_semantic.c --- a/sql/server/rel_semantic.c +++ b/sql/server/rel_semantic.c @@ -36,12 +36,6 @@ rel_parse(mvc *m, sql_schema *s, const c sql_schema *c = cur_schema(m); sql_query *qc = NULL; - m->qc = NULL; - - m->emode = emode; - if (s) - m->session->schema = s; - if ((b = malloc(sizeof(buffer))) == NULL) return NULL; if ((n = malloc(len + 1 + 1)) == NULL) { @@ -65,6 +59,10 @@ rel_parse(mvc *m, sql_schema *s, const c m->scanner.mode = LINE_1; bstream_next(m->scanner.rs); + m->qc = NULL; + m->emode = emode; + if (s) + m->session->schema = s; m->params = NULL; m->sym = NULL; m->errstr[0] = '\0'; diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c --- a/sql/server/rel_updates.c +++ b/sql/server/rel_updates.c @@ -1891,12 +1891,6 @@ rel_parse_val(mvc *m, sql_schema *sch, c stream *s; bstream *bs; - m->qc = NULL; - - if (sch) - m->session->schema = sch; - - m->emode = emode; b = malloc(sizeof(buffer)); len += 8; /* add 'select ;' */ n = malloc(len + 1 + 1); @@ -1922,6 +1916,10 @@ rel_parse_val(mvc *m, sql_schema *sch, c m->scanner.mode = LINE_1; bstream_next(m->scanner.rs); + m->qc = NULL; + if (sch) + m->session->schema = sch; + m->emode = emode; m->params = NULL; m->sym = NULL; m->errstr[0] = '\0'; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list