Changeset: 68fbb1481977 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/68fbb1481977
Modified Files:
        monetdb5/modules/kernel/bat5.c
        monetdb5/modules/mal/mat.c
        monetdb5/modules/mal/mkey.c
Branch: Jul2021
Log Message:

Cleaned matpack (missing checks). Added needed unmask call at bat.append


diffs (230 lines):

diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c
--- a/monetdb5/modules/kernel/bat5.c
+++ b/monetdb5/modules/kernel/bat5.c
@@ -194,6 +194,15 @@ BKCappend_cand_force_wrap(bat *r, const 
                BBPunfix(b->batCacheid);
                throw(MAL, "bat.append", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
        }
+       if (mask_cand(u)) {
+               BAT *ou = u;
+               u = BATunmask(u);
+               BBPunfix(ou->batCacheid);
+               if (!u) {
+                       BBPunfix(b->batCacheid);
+                       throw(MAL, "bat.append", GDK_EXCEPTION);
+               }
+       }
        if (sid && !is_bat_nil(*sid) && (s = BATdescriptor(*sid)) == NULL) {
                BBPunfix(b->batCacheid);
                BBPunfix(u->batCacheid);
diff --git a/monetdb5/modules/mal/mat.c b/monetdb5/modules/mal/mat.c
--- a/monetdb5/modules/mal/mat.c
+++ b/monetdb5/modules/mal/mat.c
@@ -77,25 +77,31 @@ MATpackInternal(Client cntxt, MalBlkPtr 
                throw(MAL, "mat.pack", SQLSTATE(HY013) MAL_MALLOC_FAIL);
 
        for (i = 1; i < p->argc; i++) {
-               BAT *ob = b = BATdescriptor(stk->stk[getArg(p,i)].val.ival);
-               if ((unmask && b && b->ttype == TYPE_msk) || mask_cand(b))
+               if (!(b = BATdescriptor(stk->stk[getArg(p,i)].val.ival))) {
+                       BBPreclaim(bn);
+                       throw(MAL, "mat.pack", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
+               }
+               if ((unmask && b->ttype == TYPE_msk) || mask_cand(b)) {
+                       BAT *ob = b;
                        b = BATunmask(b);
-               if( b ){
-                       if (BATcount(bn) == 0) {
-                               BAThseqbase(bn, b->hseqbase);
-                               BATtseqbase(bn, b->tseqbase);
-                       }
-                       if (BATappend(bn, b, NULL, false) != GDK_SUCCEED) {
-                               BBPunfix(bn->batCacheid);
-                               BBPunfix(b->batCacheid);
+                       BBPunfix(ob->batCacheid);
+                       if (!b) {
+                               BBPreclaim(bn);
                                throw(MAL, "mat.pack", GDK_EXCEPTION);
                        }
-                       BBPunfix(b->batCacheid);
+               }
+               if (BATcount(bn) == 0) {
+                       BAThseqbase(bn, b->hseqbase);
+                       BATtseqbase(bn, b->tseqbase);
                }
-               if (b != ob)
-                       BBPunfix(ob->batCacheid);
+               if (BATappend(bn, b, NULL, false) != GDK_SUCCEED) {
+                       BBPreclaim(bn);
+                       BBPunfix(b->batCacheid);
+                       throw(MAL, "mat.pack", GDK_EXCEPTION);
+               }
+               BBPunfix(b->batCacheid);
        }
-       if (!(!bn->tnil || !bn->tnonil)) {
+       if (bn->tnil && bn->tnonil) {
                BBPreclaim(bn);
                throw(MAL, "mat.pack", "INTERNAL ERROR" "bn->tnil or  
bn->tnonil fails ");
        }
@@ -112,7 +118,7 @@ MATpackIncrement(Client cntxt, MalBlkPtr
 {
        bat *ret = getArgReference_bat(stk,p,0);
        int     pieces;
-       BAT *b, *bb, *bn;
+       BAT *b, *bb, *bn, *nb;
        size_t newsize;
 
        (void) cntxt;
@@ -121,7 +127,6 @@ MATpackIncrement(Client cntxt, MalBlkPtr
                throw(MAL, "mat.pack", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
 
        if ( getArgType(mb,p,2) == TYPE_int){
-               BAT *ob = b;
                /* first step, estimate with some slack */
                pieces = stk->stk[getArg(p,2)].val.ival;
                int tt = ATOMtype(b->ttype);
@@ -138,58 +143,69 @@ MATpackIncrement(Client cntxt, MalBlkPtr
                        newsize =  b->tvheap->size * pieces;
                        if (HEAPextend(bn->tvheap, newsize, true) != 
GDK_SUCCEED) {
                                BBPunfix(b->batCacheid);
-                               BBPunfix(bn->batCacheid);
+                               BBPreclaim(bn);
                                throw(MAL, "mat.pack", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                        }
                }
                BATtseqbase(bn, b->tseqbase);
-               if (b->ttype == TYPE_msk || mask_cand(b))
+               if (b->ttype == TYPE_msk || mask_cand(b)) {
+                       BAT *ob = b;
                        b = BATunmask(b);
-               if (b && BATappend(bn, b, NULL, false) != GDK_SUCCEED) {
-                       BBPunfix(bn->batCacheid);
-                       if (b != ob)
-                               BBPunfix(ob->batCacheid);
+                       BBPunfix(ob->batCacheid);
+                       if (!b) {
+                               BBPreclaim(bn);
+                               throw(MAL, "mat.pack", GDK_EXCEPTION);
+                       }
+               }
+               if (BATappend(bn, b, NULL, false) != GDK_SUCCEED) {
+                       BBPreclaim(bn);
                        BBPunfix(b->batCacheid);
                        throw(MAL, "mat.pack", GDK_EXCEPTION);
                }
                bn->unused = (pieces-1); /* misuse "unused" field */
                BATsettrivprop(bn);
-               if (b != ob)
-                       BBPunfix(ob->batCacheid);
-               if (b)
-                       BBPunfix(b->batCacheid);
-               if (!(!bn->tnil || !bn->tnonil)) {
+               BBPunfix(b->batCacheid);
+               if (bn->tnil && bn->tnonil) {
                        BBPreclaim(bn);
-                       throw(MAL, "mat.packIncrement", "INTERNAL ERROR" " 
bn->tnil %d bn->tnonil %d", bn->tnil, bn->tnonil);
+                       throw(MAL, "mat.pack", "INTERNAL ERROR" " bn->tnil %d 
bn->tnonil %d", bn->tnil, bn->tnonil);
                }
                *ret = bn->batCacheid;
                BBPretain(bn->batCacheid);
                BBPunfix(bn->batCacheid);
        } else {
                /* remaining steps */
-               BAT *obb = bb = BATdescriptor(stk->stk[getArg(p,2)].val.ival);
-               if (bb && (bb->ttype == TYPE_msk || mask_cand(bb)))
+               if (!(bb = BATdescriptor(stk->stk[getArg(p,2)].val.ival))) {
+                       BBPunfix(b->batCacheid);
+                       throw(MAL, "mat.pack", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
+               }
+               if (bb->ttype == TYPE_msk || mask_cand(bb)) {
+                       BAT *obb = bb;
                        bb = BATunmask(bb);
-               if ( bb ){
-                       if (BATcount(b) == 0) {
-                               BAThseqbase(b, bb->hseqbase);
-                               BATtseqbase(b, bb->tseqbase);
-                       }
-                       if (BATappend(b, bb, NULL, false) != GDK_SUCCEED) {
-                               BBPunfix(bb->batCacheid);
+                       BBPunfix(obb->batCacheid);
+                       if (!bb) {
                                BBPunfix(b->batCacheid);
                                throw(MAL, "mat.pack", GDK_EXCEPTION);
                        }
-                       BBPunfix(bb->batCacheid);
                }
-               if (bb != obb)
-                       BBPunfix(obb->batCacheid);
-               b->unused--;
-               if (b->unused == 0 && (b = BATsetaccess(b, BAT_READ)) == NULL) {
+               if (BATcount(b) == 0) {
+                       BAThseqbase(b, bb->hseqbase);
+                       BATtseqbase(b, bb->tseqbase);
+               }
+               if (BATappend(b, bb, NULL, false) != GDK_SUCCEED) {
+                       BBPunfix(bb->batCacheid);
                        BBPunfix(b->batCacheid);
                        throw(MAL, "mat.pack", GDK_EXCEPTION);
                }
-               if (!(!b->tnil || !b->tnonil)) {
+               BBPunfix(bb->batCacheid);
+               b->unused--;
+               if (b->unused == 0) {
+                       if (!(nb = BATsetaccess(b, BAT_READ))) {
+                               BBPunfix(b->batCacheid);
+                               throw(MAL, "mat.pack", GDK_EXCEPTION);
+                       }
+                       b = nb;
+               }
+               if (b->tnil && b->tnonil) {
                        BBPunfix(b->batCacheid);
                        throw(MAL, "mat.pack", "INTERNAL ERROR" " b->tnil or  
b->tnonil fails ");
                }
diff --git a/monetdb5/modules/mal/mkey.c b/monetdb5/modules/mal/mkey.c
--- a/monetdb5/modules/mal/mkey.c
+++ b/monetdb5/modules/mal/mkey.c
@@ -325,7 +325,7 @@ MKEYrotate_xor_hash(Client cntxt, MalBlk
 static str
 MKEYbulk_rotate_xor_hash(bat *res, const bat *hid, const int *nbits, const bat 
*bid)
 {
-       BAT *hb, *b, *ob = NULL, *bn;
+       BAT *hb, *b, *bn;
        int lbit = *nbits;
        int rbit = (int) sizeof(lng) * 8 - lbit;
        ulng *restrict r;
@@ -346,13 +346,13 @@ MKEYbulk_rotate_xor_hash(bat *res, const
                throw(MAL, "mkey.rotate_xor_hash",
                          OPERATION_FAILED ": input bats are not aligned");
        }
-       ob = b;
-       if (b && (b->ttype == TYPE_msk || mask_cand(b))) {
+       if (b->ttype == TYPE_msk || mask_cand(b)) {
+               BAT *ob = b;
                b = BATunmask(b);
+               BBPunfix(ob->batCacheid);
                if (!b) {
                        BBPunfix(hb->batCacheid);
-                       BBPunfix(ob->batCacheid);
-                       throw(MAL, "mkey.rotate_xor_hash", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+                       throw(MAL, "mkey.rotate_xor_hash", GDK_EXCEPTION);
                }
        }
 
@@ -361,8 +361,6 @@ MKEYbulk_rotate_xor_hash(bat *res, const
        bn = COLnew(b->hseqbase, TYPE_lng, n, TRANSIENT);
        if (bn == NULL) {
                BBPunfix(hb->batCacheid);
-               if (b != ob)
-                       BBPunfix(ob->batCacheid);
                BBPunfix(b->batCacheid);
                throw(MAL, "mkey.rotate_xor_hash", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
        }
@@ -443,8 +441,6 @@ MKEYbulk_rotate_xor_hash(bat *res, const
        bn->tnil = false;
 
        BBPkeepref(*res = bn->batCacheid);
-       if (b != ob)
-               BBPunfix(ob->batCacheid);
        BBPunfix(b->batCacheid);
        BBPunfix(hb->batCacheid);
        return MAL_SUCCEED;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to