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

Merged with default


diffs (275 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/batExtensions.c 
b/monetdb5/modules/mal/batExtensions.c
--- a/monetdb5/modules/mal/batExtensions.c
+++ b/monetdb5/modules/mal/batExtensions.c
@@ -240,11 +240,20 @@ CMDBATappend_bulk(Client cntxt, MalBlkPt
                                        BBPunfix(b->batCacheid);
                                        throw(MAL, "bat.append_bulk", 
SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
                                }
+                               if (mask_cand(d)) {
+                                       BAT *du = d;
+                                       d = BATunmask(d);
+                                       BBPunfix(du->batCacheid);
+                                       if (!d) {
+                                               BBPunfix(b->batCacheid);
+                                               throw(MAL, "bat.append_bulk", 
GDK_EXCEPTION);
+                                       }
+                               }
                                rt = BATappend(b, d, NULL, force);
                                BBPunfix(d->batCacheid);
                                if (rt != GDK_SUCCEED) {
                                        BBPunfix(b->batCacheid);
-                                       throw(MAL,"bat.append_bulk", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                                       throw(MAL,"bat.append_bulk", 
GDK_EXCEPTION);
                                }
                        }
                } else {
@@ -252,7 +261,7 @@ CMDBATappend_bulk(Client cntxt, MalBlkPt
                        total = number_existing + inputs;
                        if (BATextend(b, total) != GDK_SUCCEED) {
                                BBPunfix(b->batCacheid);
-                               throw(MAL,"bat.append_bulk", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+                               throw(MAL,"bat.append_bulk", GDK_EXCEPTION);
                        }
                        for (int i = 3, args = pci->argc; i < args; i++) {
                                ptr u = getArgReference(stk,pci,i);
@@ -260,7 +269,7 @@ CMDBATappend_bulk(Client cntxt, MalBlkPt
                                        u = (ptr) *(ptr *) u;
                                if (BUNappend(b, u, force) != GDK_SUCCEED) {
                                        BBPunfix(b->batCacheid);
-                                       throw(MAL,"bat.append_bulk", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                                       throw(MAL,"bat.append_bulk", 
GDK_EXCEPTION);
                                }
                        }
                }
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);
-                               throw(MAL, "mat.pack", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+                               BBPreclaim(bn);
+                               throw(MAL, "mat.pack", GDK_EXCEPTION);
                        }
                }
                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 ");
                }
@@ -234,7 +250,7 @@ MATpackValues(Client cntxt, MalBlkPtr mb
        return MAL_SUCCEED;
   bailout:
        BBPreclaim(bn);
-       throw(MAL, "mat.pack", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+       throw(MAL, "mat.pack", GDK_EXCEPTION);
 }
 
 #include "mel.h"
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
@@ -351,7 +351,7 @@ MKEYbulk_rotate_xor_hash(Client cntxt, M
 {
        bat *res = getArgReference_bat(stk, pci, 0), *hid = 
getArgReference_bat(stk, pci, 1), *bid = getArgReference_bat(stk, pci, 3),
                *sid1 = pci->argc == 6 ? getArgReference_bat(stk, pci, 4) : 
NULL, *sid2 = pci->argc == 6 ? getArgReference_bat(stk, pci, 5) : NULL;
-       BAT *hb = NULL, *ob = NULL, *b = NULL, *bn = NULL, *s1 = NULL, *s2 = 
NULL;
+       BAT *hb = NULL, *b = NULL, *bn = NULL, *s1 = NULL, *s2 = NULL;
        int lbit = *getArgReference_int(stk, pci, 2), rbit = (int) sizeof(lng) 
* 8 - lbit;
        str msg = MAL_SUCCEED;
        struct canditer ci1 = {0}, ci2 = {0};
@@ -370,10 +370,14 @@ MKEYbulk_rotate_xor_hash(Client cntxt, M
                msg = createException(MAL, "mkey.rotate_xor_hash", 
SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
                goto bailout;
        }
-       ob = b;
-       if ((b->ttype == TYPE_msk || mask_cand(b)) && !(b = BATunmask(b))) {
-               msg = createException(MAL, "mkey.rotate_xor_hash", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
-               goto bailout;
+       if (b->ttype == TYPE_msk || mask_cand(b)) {
+               BAT *ob = b;
+               b = BATunmask(b);
+               BBPunfix(ob->batCacheid);
+               if (!b) {
+                       BBPunfix(hb->batCacheid);
+                       throw(MAL, "mkey.rotate_xor_hash", GDK_EXCEPTION);
+               }
        }
        if ((sid1 && !is_bat_nil(*sid1) && !(s1 = BATdescriptor(*sid1))) || 
(sid2 && !is_bat_nil(*sid2) && !(s2 = BATdescriptor(*sid2)))) {
                msg = createException(MAL, "mkey.rotate_xor_hash", 
SQLSTATE(HY005) RUNTIME_OBJECT_MISSING);
@@ -466,8 +470,6 @@ bailout:
        }
        if (b)
                BBPunfix(b->batCacheid);
-       if (ob && b != ob)
-               BBPunfix(ob->batCacheid);
        if (hb)
                BBPunfix(hb->batCacheid);
        if (s1)
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to