Changeset: ea00a7dce65d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ea00a7dce65d
Modified Files:
        sql/storage/bat/bat_storage.c
Branch: default
Log Message:

Merged with Jan2022


diffs (truncated from 2163 to 300 lines):

diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -1746,10 +1746,8 @@ BATprod(void *res, int tp, BAT *b, BAT *
        do {                                                            \
                const TYPE *restrict vals = (const TYPE *) bi.base;     \
                TYPE *restrict avgs = GDKzalloc(ngrp * sizeof(TYPE));   \
-               if (avgs == NULL) {                                     \
-                       bat_iterator_end(&bi);                          \
-                       goto alloc_fail;                                \
-               }                                                       \
+               if (avgs == NULL)                       \
+                       goto bailout;                           \
                TIMEOUT_LOOP(ncand, timeoffset) {                       \
                        i = canditer_next(&ci) - b->hseqbase;           \
                        if (gids == NULL ||                             \
@@ -1770,7 +1768,7 @@ BATprod(void *res, int tp, BAT *b, BAT *
                        }                                               \
                }                                                       \
                TIMEOUT_CHECK(timeoffset,                               \
-                             GOTO_LABEL_TIMEOUT_HANDLER(alloc_fail));  \
+                             GOTO_LABEL_TIMEOUT_HANDLER(bailout));     \
                for (i = 0; i < ngrp; i++) {                            \
                        if (cnts[i] == 0 || is_lng_nil(cnts[i])) {      \
                                dbls[i] = dbl_nil;                      \
@@ -1807,7 +1805,7 @@ BATprod(void *res, int tp, BAT *b, BAT *
                        }                                               \
                }                                                       \
                TIMEOUT_CHECK(timeoffset,                               \
-                             GOTO_LABEL_TIMEOUT_HANDLER(alloc_fail));  \
+                             GOTO_LABEL_TIMEOUT_HANDLER(bailout));     \
                for (i = 0; i < ngrp; i++) {                            \
                        if (cnts[i] == 0 || is_lng_nil(cnts[i])) {      \
                                dbls[i] = dbl_nil;                      \
@@ -1834,6 +1832,7 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
        BUN ncand;
        const char *err;
        lng t0 = 0;
+       BATiter bi = {0};
 
        lng timeoffset = 0;
        QryCtx *qry_ctx = MT_thread_get_qry_ctx();
@@ -1906,25 +1905,25 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
 #endif
                rems = GDKzalloc(ngrp * sizeof(lng));
                if (rems == NULL)
-                       goto alloc_fail;
+                       goto bailout;
                break;
        default:
                break;
        }
        if (cntsp) {
                if ((cn = COLnew(min, TYPE_lng, ngrp, TRANSIENT)) == NULL)
-                       goto alloc_fail;
+                       goto bailout;
                cnts = (lng *) Tloc(cn, 0);
                memset(cnts, 0, ngrp * sizeof(lng));
        } else {
                cnts = GDKzalloc(ngrp * sizeof(lng));
                if (cnts == NULL)
-                       goto alloc_fail;
+                       goto bailout;
        }
 
        bn = COLnew(min, TYPE_dbl, ngrp, TRANSIENT);
        if (bn == NULL)
-               goto alloc_fail;
+               goto bailout;
        dbls = (dbl *) Tloc(bn, 0);
 
        if (BATtdense(g))
@@ -1932,7 +1931,6 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
        else
                gids = (const oid *) Tloc(g, 0);
 
-       BATiter bi;
        bi = bat_iterator(b);
        switch (b->ttype) {
        case TYPE_bte:
@@ -1959,15 +1957,8 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
                AGGR_AVG_FLOAT(dbl);
                break;
        default:
-               bat_iterator_end(&bi);
-               GDKfree(rems);
-               if (cn)
-                       BBPreclaim(cn);
-               else
-                       GDKfree(cnts);
-               BBPunfix(bn->batCacheid);
                GDKerror("type (%s) not supported.\n", ATOMname(b->ttype));
-               return GDK_FAIL;
+               goto bailout;
        }
        bat_iterator_end(&bi);
        GDKfree(rems);
@@ -2003,8 +1994,8 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
                  ALGOOPTBATPAR(s), ALGOOPTBATPAR(bn),
                  ci.seq, ncand, GDKusec() - t0);
        return GDK_SUCCEED;
-
-  alloc_fail:
+  bailout:
+       bat_iterator_end(&bi);
        if (bn)
                BBPunfix(bn->batCacheid);
        GDKfree(rems);
@@ -2938,7 +2929,7 @@ BATgroupavg3combine(BAT *avg, BAT *rem, 
                        n++;                                            \
                }                                                       \
                TIMEOUT_CHECK(timeoffset,                               \
-                             TIMEOUT_HANDLER(GDK_FAIL));               \
+                             GOTO_LABEL_TIMEOUT_HANDLER(bailout));             
\
                /* the sum fit, so now we can calculate the average */  \
                *avg = n > 0 ? (dbl) sum / n : dbl_nil;                 \
                if (0) {                                                \
@@ -2997,7 +2988,7 @@ BATgroupavg3combine(BAT *avg, BAT *rem, 
                        AVERAGE_ITER_FLOAT(TYPE, x, a, n);      \
                }                                               \
                TIMEOUT_CHECK(timeoffset,                       \
-                             TIMEOUT_HANDLER(GDK_FAIL));       \
+                             GOTO_LABEL_TIMEOUT_HANDLER(bailout));     \
                *avg = n > 0 ? a : dbl_nil;                     \
        } while (0)
 
@@ -3054,10 +3045,9 @@ BATcalcavg(BAT *b, BAT *s, dbl *avg, BUN
                AVERAGE_FLOATTYPE(dbl);
                break;
        default:
-               bat_iterator_end(&bi);
                GDKerror("average of type %s unsupported.\n",
                         ATOMname(b->ttype));
-               return GDK_FAIL;
+               goto bailout;
        }
        bat_iterator_end(&bi);
        if (scale != 0 && !is_dbl_nil(*avg))
@@ -3065,6 +3055,9 @@ BATcalcavg(BAT *b, BAT *s, dbl *avg, BUN
        if (vals)
                *vals = (BUN) n;
        return GDK_SUCCEED;
+bailout:
+       bat_iterator_end(&bi);
+       return GDK_FAIL;
 }
 
 /* ---------------------------------------------------------------------- */
@@ -3107,6 +3100,7 @@ BATgroupcount(BAT *b, BAT *g, BAT *e, BA
        BUN ncand;
        const char *err;
        lng t0 = 0;
+       BATiter bi = {0};
 
        lng timeoffset = 0;
        QryCtx *qry_ctx = MT_thread_get_qry_ctx();
@@ -3170,7 +3164,7 @@ BATgroupcount(BAT *b, BAT *g, BAT *e, BA
                atomcmp = ATOMcompare(t);
                t = ATOMbasetype(t);
 
-               BATiter bi = bat_iterator(b);
+               bi = bat_iterator(b);
 
                switch (t) {
                case TYPE_bte:
@@ -3230,6 +3224,7 @@ BATgroupcount(BAT *b, BAT *g, BAT *e, BA
        return bn;
 
   bailout:
+       bat_iterator_end(&bi);
        BBPreclaim(bn);
        return NULL;
 }
@@ -4051,7 +4046,7 @@ doBATgroupquantile(BAT *b, BAT *g, BAT *
        struct canditer ci;
        BUN ncand;
        BAT *t1, *t2;
-       BATiter bi;
+       BATiter bi = {0};
        const void *v;
        const void *nil = ATOMnilptr(tp);
        const void *dnil = nil;
@@ -4232,10 +4227,8 @@ doBATgroupquantile(BAT *b, BAT *g, BAT *
                                if (!skip_nils && !b->tnonil)
                                        nils += (*atomcmp)(v, dnil) == 0;
                        }
-                       if (bunfastapp_nocheck(bn, v) != GDK_SUCCEED) {
-                               bat_iterator_end(&bi);
+                       if (bunfastapp_nocheck(bn, v) != GDK_SUCCEED)
                                goto bunins_failed;
-                       }
                }
                bat_iterator_end(&bi);
                nils += ngrp - BATcount(bn);
@@ -4378,6 +4371,7 @@ doBATgroupquantile(BAT *b, BAT *g, BAT *
        return bn;
 
   bunins_failed:
+       bat_iterator_end(&bi);
        if (b && b != origb)
                BBPunfix(b->batCacheid);
        if (g && g != origg)
@@ -4672,7 +4666,7 @@ BATcalccovariance_sample(BAT *b1, BAT *b
                                goto overflow;                          \
                }                                                       \
                TIMEOUT_CHECK(timeoffset,                               \
-                             TIMEOUT_HANDLER(dbl_nil));                \
+                             GOTO_LABEL_TIMEOUT_HANDLER(bailout));             
\
        } while (0)
 
 dbl
@@ -4718,10 +4712,8 @@ BATcalccorrelation(BAT *b1, BAT *b2)
                AGGR_CORRELATION_SINGLE(dbl);
                break;
        default:
-               bat_iterator_end(&b1i);
-               bat_iterator_end(&b2i);
                GDKerror("type (%s) not supported.\n", ATOMname(tp));
-               return dbl_nil;
+               goto bailout;
        }
        bat_iterator_end(&b1i);
        bat_iterator_end(&b2i);
@@ -4733,9 +4725,10 @@ BATcalccorrelation(BAT *b1, BAT *b2)
                  ALGOBATPAR(b1), ALGOBATPAR(b2), GDKusec() - t0);
        return aux;
   overflow:
+       GDKerror("22003!overflow in calculation.\n");
+  bailout:
        bat_iterator_end(&b1i);
        bat_iterator_end(&b2i);
-       GDKerror("22003!overflow in calculation.\n");
        return dbl_nil;
 }
 
@@ -4805,6 +4798,7 @@ dogroupstdev(BAT **avgb, BAT *b, BAT *g,
        BUN ncand;
        const char *err;
        lng t0 = 0;
+       BATiter bi = {0};
 
        lng timeoffset = 0;
        QryCtx *qry_ctx = MT_thread_get_qry_ctx();
@@ -4873,7 +4867,6 @@ dogroupstdev(BAT **avgb, BAT *b, BAT *g,
                m2[i] = 0;
        }
 
-       BATiter bi;
        bi = bat_iterator(b);
        if (BATtdense(g))
                gids = NULL;
@@ -4905,18 +4898,9 @@ dogroupstdev(BAT **avgb, BAT *b, BAT *g,
                AGGR_STDEV(dbl);
                break;
        default:
-               bat_iterator_end(&bi);
-               if (an)
-                       BBPreclaim(an);
-               else
-                       GDKfree(mean);
-               GDKfree(delta);
-               GDKfree(m2);
-               GDKfree(cnts);
-               BBPunfix(bn->batCacheid);
                GDKerror("%s: type (%s) not supported.\n",
                         func, ATOMname(b->ttype));
-               return NULL;
+               goto alloc_fail;
        }
        bat_iterator_end(&bi);
        if (an) {
@@ -4954,9 +4938,9 @@ dogroupstdev(BAT **avgb, BAT *b, BAT *g,
                  func, GDKusec() - t0);
        return bn;
   overflow:
-       bat_iterator_end(&bi);
        GDKerror("22003!overflow in calculation.\n");
   alloc_fail:
+       bat_iterator_end(&bi);
        if (an)
                BBPreclaim(an);
        else
@@ -5059,6 +5043,7 @@ dogroupcovariance(BAT *b1, BAT *b2, BAT 
        struct canditer ci;
        const char *err;
        lng t0 = 0;
+       BATiter b1i = {0}, b2i = {0};
 
        lng timeoffset = 0;
        QryCtx *qry_ctx = MT_thread_get_qry_ctx();
@@ -5123,7 +5108,6 @@ dogroupcovariance(BAT *b1, BAT *b2, BAT 
        else
                gids = (const oid *) Tloc(g, 0);
 
-       BATiter b1i, b2i;
        b1i = bat_iterator(b1);
        b2i = bat_iterator(b2);
        switch (b1->ttype) {
@@ -5151,8 +5135,6 @@ dogroupcovariance(BAT *b1, BAT *b2, BAT 
                AGGR_COVARIANCE(dbl);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to