Changeset: a7e3d519e8fb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a7e3d519e8fb
Modified Files:
        monetdb5/modules/atoms/json.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_subquery.c
Branch: default
Log Message:

Hold bat iterator a little longer and small fixes


diffs (132 lines):

diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -1980,14 +1980,15 @@ JSONrenderRowObject(BAT **bl, MalBlkPtr 
        len = 1;
        for (i = pci->retc; i < pci->argc; i += 2) {
                name = stk->stk[getArg(pci, i)].val.sval;
+               tpe = getBatType(getArgType(mb, pci, i + 1));
                bi = bat_iterator(bl[i + 1]);
                p = BUNtail(bi, idx);
-               bat_iterator_end(&bi);
-               tpe = getBatType(getArgType(mb, pci, i + 1));
                if ((val = ATOMformat(tpe, p)) == NULL) {
+                       bat_iterator_end(&bi);
                        GDKfree(row);
                        return NULL;
                }
+               bat_iterator_end(&bi);
                if (strncmp(val, "nil", 3) == 0) {
                        GDKfree(val);
                        val = NULL;
@@ -2096,13 +2097,14 @@ JSONrenderRowArray(BAT **bl, MalBlkPtr m
        row[1] = 0;
        len = 1;
        for (i = pci->retc; i < pci->argc; i++) {
+               tpe = getBatType(getArgType(mb, pci, i));
                bi = bat_iterator(bl[i]);
                p = BUNtail(bi, idx);
-               bat_iterator_end(&bi);
-               tpe = getBatType(getArgType(mb, pci, i));
                if ((val = ATOMformat(tpe, p)) == NULL) {
+                       bat_iterator_end(&bi);
                        goto memfail;
                }
+               bat_iterator_end(&bi);
                if (strcmp(val, "nil") == 0) {
                        GDKfree(val);
                        val = NULL;
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3382,6 +3382,7 @@ SQLbat_alpha_cst(bat *res, const bat *de
                if (BUNappend(bn, &r, false) != GDK_SUCCEED) {
                        BBPreclaim(bn);
                        bat_iterator_end(&bi);
+                       BBPunfix(b->batCacheid);
                        throw(SQL, "sql.alpha", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                }
        }
@@ -3428,6 +3429,7 @@ SQLcst_alpha_bat(bat *res, const dbl *de
                if (BUNappend(bn, &r, false) != GDK_SUCCEED) {
                        BBPreclaim(bn);
                        bat_iterator_end(&bi);
+                       BBPunfix(b->batCacheid);
                        throw(SQL, "sql.alpha", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                }
        }
diff --git a/sql/backends/monet5/sql_subquery.c 
b/sql/backends/monet5/sql_subquery.c
--- a/sql/backends/monet5/sql_subquery.c
+++ b/sql/backends/monet5/sql_subquery.c
@@ -16,18 +16,17 @@ zero_or_one_error(ptr ret, const bat *bi
        BAT *b;
        BUN c;
        size_t _s;
+       BATiter bi = {0};
        const void *p = NULL;
 
-       if ((b = BATdescriptor(*bid)) == NULL) {
+       if ((b = BATdescriptor(*bid)) == NULL)
                throw(SQL, "sql.zero_or_one", SQLSTATE(HY005) "Cannot access 
column descriptor");
-       }
        c = BATcount(b);
        if (c == 0) {
                p = ATOMnilptr(b->ttype);
        } else if (c == 1 || (c > 1 && *err == false)) {
-               BATiter bi = bat_iterator(b);
+               bi = bat_iterator(b);
                p = BUNtail(bi, 0);
-               bat_iterator_end(&bi);
        } else {
                p = NULL;
                BBPunfix(b->batCacheid);
@@ -40,6 +39,8 @@ zero_or_one_error(ptr ret, const bat *bi
                _s = ATOMlen(ATOMtype(b->ttype), p);
                *(ptr *) ret = GDKmalloc(_s);
                if (*(ptr *) ret == NULL) {
+                       if (bi.b)
+                               bat_iterator_end(&bi);
                        BBPunfix(b->batCacheid);
                        throw(SQL, "sql.zero_or_one", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                }
@@ -47,6 +48,8 @@ zero_or_one_error(ptr ret, const bat *bi
        } else if (b->ttype == TYPE_bat) {
                bat bid = *(bat *) p;
                if ((*(BAT **) ret = BATdescriptor(bid)) == NULL){
+                       if (bi.b)
+                               bat_iterator_end(&bi);
                        BBPunfix(b->batCacheid);
                        throw(SQL, "sql.zero_or_one", SQLSTATE(HY005) "Cannot 
access column descriptor");
                }
@@ -65,6 +68,8 @@ zero_or_one_error(ptr ret, const bat *bi
        } else {
                memcpy(ret, p, _s);
        }
+       if (bi.b)
+               bat_iterator_end(&bi);
        BBPunfix(b->batCacheid);
        return MAL_SUCCEED;
 }
@@ -203,6 +208,7 @@ SQLall(ptr ret, const bat *bid)
                        if (ATOMextern(b->ttype)) {
                                *(ptr *) ret = GDKmalloc(s);
                                if (*(ptr *) ret == NULL) {
+                                       bat_iterator_end(&bi);
                                        BBPunfix(b->batCacheid);
                                        throw(SQL, "sql.all", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                                }
@@ -952,14 +958,11 @@ SQLallnotequal(Client cntxt, MalBlkPtr m
                default: {
                        int (*ocmp) (const void *, const void *) = 
ATOMcompare(l->ttype);
                        const void *nilp = ATOMnilptr(l->ttype);
-                       BATiter li = bat_iterator(l), ri = bat_iterator(r);
 
                        for (BUN q = 0; q < o; q++) {
                                const void *c = BUNtail(ri, q), *d = 
BUNtail(li, q);
                                res_l[q] = ocmp(nilp, c) == 0 || ocmp(nilp, d) 
== 0 ? bit_nil : ocmp(c, d) != 0;
                        }
-                       bat_iterator_end(&li);
-                       bat_iterator_end(&ri);
                }
                }
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to