Changeset: b50dadf65e4d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b50dadf65e4d
Added Files:
        
sql/test/BugTracker-2017/Tests/aggr_udf_with_more_than_2params.Bug-6385.sql
        
sql/test/BugTracker-2017/Tests/aggr_udf_with_more_than_2params.Bug-6385.stable.err
        
sql/test/BugTracker-2017/Tests/aggr_udf_with_more_than_2params.Bug-6385.stable.out
Modified Files:
        clients/mapilib/mapi.c
        clients/odbc/driver/ODBCDesc.c
        common/stream/stream.c
        sql/benchmarks/tpch/load.sh
        sql/server/rel_select.c
        sql/test/BugTracker-2017/Tests/All
Branch: default
Log Message:

Merge with Jul2017 branch.


diffs (truncated from 577 to 300 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -989,7 +989,16 @@ static int mapi_initialized = 0;
                        return (e);                                     \
                }                                                       \
        } while (0)
-#define REALLOC(p,c)   ((p) = ((p) ? realloc((p),(c)*sizeof(*(p))) : 
malloc((c)*sizeof(*(p)))))
+#define REALLOC(p, c)                                          \
+       do {                                                    \
+               if (p) {                                        \
+                       void *tmp = (p);                        \
+                       (p) = realloc((p), (c) * sizeof(*(p))); \
+                       if ((p) == NULL)                        \
+                               free(tmp);                      \
+               } else                                          \
+                       (p) = malloc((c) * sizeof(*(p)));       \
+       } while (0)
 
 /*
  * Blocking
@@ -1010,11 +1019,13 @@ static int mapi_initialized = 0;
  * errors, and mapi_explain or mapi_explain_query to print a formatted error
  * report.
  */
+static char nomem[] = "Memory allocation failed";
+
 static void
 mapi_clrError(Mapi mid)
 {
        assert(mid);
-       if (mid->errorstr)
+       if (mid->errorstr && mid->errorstr != nomem)
                free(mid->errorstr);
        mid->action = 0;        /* contains references to constants */
        mid->error = 0;
@@ -1026,7 +1037,10 @@ mapi_setError(Mapi mid, const char *msg,
 {
        assert(msg);
        REALLOC(mid->errorstr, strlen(msg) + 1);
-       strcpy(mid->errorstr, msg);
+       if (mid->errorstr == NULL)
+               mid->errorstr = nomem;
+       else
+               strcpy(mid->errorstr, msg);
        mid->error = error;
        mid->action = action;
        return mid->error;
@@ -1574,7 +1588,7 @@ close_result(MapiHdl hdl)
                result->cache.line = NULL;
                result->cache.tuplecount = 0;
        }
-       if (result->errorstr)
+       if (result->errorstr && result->errorstr != nomem)
                free(result->errorstr);
        result->errorstr = NULL;
        memset(result->sqlstate, 0, sizeof(result->sqlstate));
@@ -1613,8 +1627,12 @@ add_error(struct MapiResultSet *result, 
                error += 6;
        }
        REALLOC(result->errorstr, size + strlen(error) + 2);
-       strcpy(result->errorstr + size, error);
-       strcat(result->errorstr + size, "\n");
+       if (result->errorstr == NULL)
+               result->errorstr = nomem;
+       else {
+               strcpy(result->errorstr + size, error);
+               strcat(result->errorstr + size, "\n");
+       }
 }
 
 const char *
@@ -2134,7 +2152,7 @@ mapi_destroy(Mapi mid)
                (void) mapi_disconnect(mid);
        if (mid->blk.buf)
                free(mid->blk.buf);
-       if (mid->errorstr)
+       if (mid->errorstr && mid->errorstr != nomem)
                free(mid->errorstr);
        if (mid->hostname)
                free(mid->hostname);
@@ -2774,7 +2792,8 @@ mapi_reconnect(Mapi mid)
                mid->errorstr = NULL;
                mapi_close_handle(hdl);
                mapi_setError(mid, errorstr, "mapi_reconnect", error);
-               free(errorstr); /* now free it after a copy has been made */
+               if (errorstr != nomem)
+                       free(errorstr); /* now free it after a copy has been 
made */
                close_connection(mid);
                return mid->error;
        }
@@ -3216,9 +3235,14 @@ mapi_prepare(Mapi mid, const char *cmd)
        do {                                                    \
                /* note: k==strlen(hdl->query) */               \
                if (k+len >= lim) {                             \
+                       char *q = hdl->query;                   \
                        lim = k + len + MAPIBLKSIZE;            \
                        hdl->query = realloc(hdl->query, lim);  \
-                       assert(hdl->query);                     \
+                       if (hdl->query == NULL) {               \
+                               free(q);                        \
+                               return;                         \
+                       }                                       \
+                       hdl->query = q;                         \
                }                                               \
        } while (0)
 
@@ -3236,7 +3260,8 @@ mapi_param_store(MapiHdl hdl)
 
        lim = strlen(hdl->template) + MAPIBLKSIZE;
        REALLOC(hdl->query, lim);
-       assert(hdl->query);
+       if (hdl->query == NULL)
+               return;
        hdl->query[0] = 0;
        k = 0;
 
@@ -3252,7 +3277,8 @@ mapi_param_store(MapiHdl hdl)
                if (k + (q - p) >= lim) {
                        lim += MAPIBLKSIZE;
                        REALLOC(hdl->query, lim);
-                       assert(hdl->query);
+                       if (hdl->query == NULL)
+                               return;
                }
                strncpy(hdl->query + k, p, q - p);
                k += q - p;
diff --git a/clients/odbc/driver/ODBCDesc.c b/clients/odbc/driver/ODBCDesc.c
--- a/clients/odbc/driver/ODBCDesc.c
+++ b/clients/odbc/driver/ODBCDesc.c
@@ -163,10 +163,14 @@ setODBCDescRecCount(ODBCDesc *desc, int 
                desc->descRec = NULL;
        } else if (desc->descRec == NULL) {
                assert(desc->sql_desc_count == 0);
-               desc->descRec = (ODBCDescRec *) malloc((count + 1) * 
sizeof(*desc->descRec));
+               desc->descRec = malloc((count + 1) * sizeof(*desc->descRec));
        } else {
+               ODBCDescRec *p;
                assert(desc->sql_desc_count > 0);
-               desc->descRec = (ODBCDescRec *) realloc(desc->descRec, (count + 
1) * sizeof(*desc->descRec));
+               p = realloc(desc->descRec, (count + 1) * 
sizeof(*desc->descRec));
+               if (p == NULL)
+                       return; /* TODO: error handling */
+               desc->descRec = p;
        }
        if (count > desc->sql_desc_count) {
                int i;
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -3448,8 +3448,13 @@ buffer_get_buf(buffer *b)
 
        if (b == NULL)
                return NULL;
-       if (b->pos == b->len && (b->buf = realloc(b->buf, b->len + 1)) == NULL)
-               return NULL;
+       if (b->pos == b->len) {
+               if ((r = realloc(b->buf, b->len + 1)) == NULL) {
+                       /* keep b->buf in tact */
+                       return NULL;
+               }
+               b->buf = r;
+       }
        r = b->buf;
        r[b->pos] = '\0';
        b->buf = malloc(b->len);
@@ -3505,14 +3510,14 @@ buffer_write(stream *s, const void *buf,
                return -1;
        }
        if (b->pos + size > b->len) {
-               size_t ns = b->len;
-
-               while (b->pos + size > ns)
-                       ns *= 2;
-               if ((b->buf = realloc(b->buf, ns)) == NULL) {
+               char *p;
+               size_t ns = b->pos + size + 8192;
+
+               if ((p = realloc(b->buf, ns)) == NULL) {
                        s->errnr = MNSTR_WRITE_ERROR;
                        return -1;
                }
+               b->buf = p;
                b->len = ns;
        }
        memcpy(b->buf + b->pos, buf, size);
@@ -5076,12 +5081,14 @@ bstream_read(bstream *s, size_t size)
        }
 
        assert(s->buf != NULL);
-       if (s->len == s->size &&
-           (s->buf = realloc(s->buf, (s->size <<= 1) + 1)) == NULL) {
-               s->size = 0;
-               s->len = 0;
-               s->pos = 0;
-               return -1;
+       if (s->len == s->size) {
+               char *p;
+               size_t ns = s->size + size + 8192;
+               if ((p = realloc(s->buf, ns + 1)) == NULL) {
+                       return -1;
+               }
+               s->size = ns;
+               s->buf = p;
        }
 
        if (size > s->size - s->len)
@@ -5127,12 +5134,14 @@ bstream_readline(bstream *s)
        }
 
        assert(s->buf != NULL);
-       if (s->len == s->size &&
-           (s->buf = realloc(s->buf, (s->size <<= 1) + 1)) == NULL) {
-               s->size = 0;
-               s->len = 0;
-               s->pos = 0;
-               return -1;
+       if (s->len == s->size) {
+               char *p;
+               size_t ns = s->size + size + 8192;
+               if ((p = realloc(s->buf, ns + 1)) == NULL) {
+                       return -1;
+               }
+               s->size = ns;
+               s->buf = p;
        }
 
        if (size > s->size - s->len)
diff --git a/sql/benchmarks/tpch/load.sh b/sql/benchmarks/tpch/load.sh
--- a/sql/benchmarks/tpch/load.sh
+++ b/sql/benchmarks/tpch/load.sh
@@ -24,8 +24,8 @@ SF='sf-0.01'
 #SF='sf-5'
 
 dir=`echo $SF | tr '[a-z]' '[A-Z]'`
-$SQL < c.sql
-#$SQL < c.sql-primary-foreign
-cat load-$SF-LOCKED.sql$T | sed -e s+PWD+$PWD/$dir+ | $SQL 
-#cat load-$SF.sql$T | sed -e s+PWD+$PWD/$dir+ | $SQL
+#$SQL < c.sql
+$SQL < c.sql-primary-foreign
+#cat load-$SF-LOCKED.sql$T | sed -e s+PWD+$PWD/$dir+ | $SQL 
+cat load-$SF.sql$T | sed -e s+PWD+$PWD/$dir+ | $SQL
 #$SQL < alter.sql
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -1545,8 +1545,20 @@ rel_filter(mvc *sql, sql_rel *rel, list 
                        return rel_select(sql->sa, rel, e);
 
                if (/*is_semi(rel->op) ||*/ is_outerjoin(rel->op)) {
-                       rel_join_add_exp(sql->sa, rel, e);
-                       return rel;
+                       if ((is_left(rel->op) || is_full(rel->op)) && 
rel_find_exp(rel->l, l->h->data)) {
+                               rel_join_add_exp(sql->sa, rel, e);
+                               return rel;
+                       } else if ((is_right(rel->op) || is_full(rel->op)) && 
rel_find_exp(rel->r, l->h->data)) {
+                               rel_join_add_exp(sql->sa, rel, e);
+                               return rel;
+                       }
+                       if (is_left(rel->op) && rel_find_exp(rel->r, 
l->h->data)) {
+                               rel->r = rel_push_select(sql, rel->r, L, e);
+                               return rel;
+                       } else if (is_right(rel->op) && rel_find_exp(rel->l, 
l->h->data)) {
+                               rel->l = rel_push_select(sql, rel->l, L, e);
+                               return rel;
+                       }
                }
                /* push select into the given relation */
                return rel_push_select(sql, rel, L, e);
@@ -2935,8 +2947,15 @@ rel_unop(mvc *sql, sql_rel **rel, symbol
        sql->session->status = 0;
        sql->errstr[0] = '\0';
                e = rel_value_exp(sql, rel, l->next->data.sym, fs, iek);
-       if (!e)
+       if (!e) {
+               if (!f && *rel && (*rel)->card == CARD_AGGR) {
+                       /* reset error */
+                       sql->session->status = 0;
+                       sql->errstr[0] = '\0';
+                       return sql_error(sql, 02, "SELECT: no such aggregate 
'%s'", fname);
+               }
                return NULL;
+       }
 
        t = exp_subtype(e);
        if (!t) {
@@ -3220,8 +3239,14 @@ rel_binop(mvc *sql, sql_rel **rel, symbo
 
        l = rel_value_exp(sql, rel, dl->next->data.sym, f, iek);
        r = rel_value_exp(sql, rel, dl->next->next->data.sym, f, iek);
-       if (!l && !r)
+       if (!l || !r)
                sf = find_func(sql, s, fname, 2, F_AGGR, NULL);
+       if (!sf && (!l || !r) && *rel && (*rel)->card == CARD_AGGR) {
+               /* reset error */
+               sql->session->status = 0;
+               sql->errstr[0] = '\0';
+               return sql_error(sql, 02, "SELECT: no such aggregate '%s'", 
fname);
+       }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to