Changeset: bc5c5f2e48f4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/bc5c5f2e48f4
Modified Files:
        monetdb5/modules/mal/calc.c
        monetdb5/modules/mal/pcre.c
        monetdb5/modules/mal/txtsim.c
Branch: resource_management
Log Message:

MALblk allocator in txtsim


diffs (truncated from 524 to 300 lines):

diff --git a/monetdb5/modules/mal/calc.c b/monetdb5/modules/mal/calc.c
--- a/monetdb5/modules/mal/calc.c
+++ b/monetdb5/modules/mal/calc.c
@@ -92,18 +92,18 @@ CMDvarADDstr(Client ctx, str *ret, const
 static str
 CMDvarADDstrint(Client ctx, str *ret, const char *const *s1, const int *i)
 {
-       (void) ctx;
+       allocator *ma = ctx->curprg->def->ma;
        str s;
        size_t len;
 
        if (strNil(*s1) || is_int_nil(*i)) {
-               *ret = GDKstrdup(str_nil);
+               *ret = MA_STRDUP(ma, str_nil);
                if (*ret == NULL)
                        return mythrow(MAL, "calc.+", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                return MAL_SUCCEED;
        }
        len = strlen(*s1) + 16;         /* maxint = 2147483647 which fits 
easily */
-       s = GDKmalloc(len);
+       s = ma_alloc(ma, len);
        if (s == NULL)
                return mythrow(MAL, "calc.+", SQLSTATE(HY013) MAL_MALLOC_FAIL);
        snprintf(s, len, "%s%d", *s1, *i);
diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c
--- a/monetdb5/modules/mal/pcre.c
+++ b/monetdb5/modules/mal/pcre.c
@@ -743,10 +743,10 @@ sql2pcre(allocator *ma, str *r, const ch
 #ifdef HAVE_LIBPCRE
 /* change SQL PATINDEX pattern into PCRE pattern */
 static str
-pat2pcre(str *r, const char *pat)
+pat2pcre(allocator *ma, str *r, const char *pat)
 {
        size_t len = strlen(pat);
-       char *ppat = GDKmalloc(len * 2 + 3 /* 3 = "^'the translated regexp'$0" 
*/ );
+       char *ppat = ma_alloc(ma, len * 2 + 3 /* 3 = "^'the translated 
regexp'$0" */ );
        int start = 0;
 
        if (ppat == NULL)
@@ -850,7 +850,8 @@ PCREimatch(Client ctx, bit *ret, const c
 static str
 PCREpatindex(Client ctx, int *ret, const char *const *pat, const char *const 
*val)
 {
-       (void) ctx;
+       allocator *ma = ctx->curprg->def->ma;
+       (void) ma;
 #ifdef HAVE_LIBPCRE
        pcre2_code *re;
        pcre2_match_data *match_data;
diff --git a/monetdb5/modules/mal/txtsim.c b/monetdb5/modules/mal/txtsim.c
--- a/monetdb5/modules/mal/txtsim.c
+++ b/monetdb5/modules/mal/txtsim.c
@@ -60,7 +60,7 @@ damerau_putat(int *pOrigin, int col, int
 }
 
 static str
-dameraulevenshtein(int *res, const char *s, const char *t, int insdel_cost,
+dameraulevenshtein(allocator *ma, int *res, const char *s, const char *t, int 
insdel_cost,
                                   int replace_cost, int transpose_cost)
 {
        int *d;                                         /* pointer to matrix */
@@ -97,7 +97,7 @@ dameraulevenshtein(int *res, const char 
        sz = (((lng)n) + 1) * (((lng)m) + 1) * sizeof(int);
        if (sz > (LL_CONSTANT(1)<<28))
                throw(MAL, "dameraulevenshtein", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-       d = (int *) GDKmalloc((size_t)sz);
+       d = (int *) ma_alloc(ma, (size_t)sz);
        if (d == NULL)
                throw(MAL, "dameraulevenshtein", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
 
@@ -143,29 +143,29 @@ dameraulevenshtein(int *res, const char 
        }
        /* Step 7 */
        *res = damerau_getat(d, n, m, n);
-       GDKfree(d);
+       //GDKfree(d);
        return MAL_SUCCEED;
 }
 
 static str
 TXTSIMdameraulevenshtein1(Client ctx, int *result, const char *const *s, const 
char *const *t)
 {
-       (void) ctx;
-       return dameraulevenshtein(result, *s, *t, 1, 1, 2);
+       allocator *ma = ctx->curprg->def->ma;
+       return dameraulevenshtein(ma, result, *s, *t, 1, 1, 2);
 }
 
 static str
 TXTSIMdameraulevenshtein2(Client ctx, int *result, const char *const *s, const 
char *const *t)
 {
-       (void) ctx;
-       return dameraulevenshtein(result, *s, *t, 1, 1, 1);
+       allocator *ma = ctx->curprg->def->ma;
+       return dameraulevenshtein(ma, result, *s, *t, 1, 1, 1);
 }
 
 static str
-TXTSIMdameraulevenshtein(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
+TXTSIMdameraulevenshtein(Client ctx, MalBlkPtr mb, MalStkPtr stk,
                                                 InstrPtr pci)
 {
-       (void) cntxt;
+       (void) ctx;
        (void) mb;
        int *res = getArgReference_int(stk, pci, 0);
        const char *x = *getArgReference_str(stk, pci, 1),
@@ -184,12 +184,12 @@ TXTSIMdameraulevenshtein(Client cntxt, M
                transpose_cost = *getArgReference_int(stk, pci, 5);
        }
 
-       return dameraulevenshtein(res, x, y, insdel_cost, replace_cost,
+       return dameraulevenshtein(mb->ma, res, x, y, insdel_cost, replace_cost,
                                                          transpose_cost);
 }
 
 static inline str
-levenshtein(int *res, const char *x, const char *y, int insdel_cost,
+levenshtein(allocator *ma, int *res, const char *x, const char *y, int 
insdel_cost,
                        int replace_cost, int max)
 {
        unsigned int xlen, ylen, i = 0, j = 0;
@@ -210,7 +210,7 @@ levenshtein(int *res, const char *x, con
                return MAL_SUCCEED;
        }
 
-       column = GDKmalloc((xlen + 1) * sizeof(unsigned int));
+       column = ma_alloc(ma, (xlen + 1) * sizeof(unsigned int));
        if (column == NULL)
                throw(MAL, "levenshtein", MAL_MALLOC_FAIL);
 
@@ -238,16 +238,16 @@ levenshtein(int *res, const char *x, con
                }
                if (max != -1 && min > (unsigned int) max) {
                        *res = INT_MAX;
-                       GDKfree(column);
+                       //GDKfree(column);
                        return MAL_SUCCEED;
                }
        }
 
        *res = column[xlen];
-       GDKfree(column);
+       //GDKfree(column);
        return MAL_SUCCEED;
   illegal:
-       GDKfree(column);
+       //GDKfree(column);
        throw(MAL, "txtsim.levenshtein", "Illegal unicode code point");
 }
 
@@ -298,9 +298,9 @@ levenshtein2(const char *x, const char *
 }
 
 static str
-TXTSIMlevenshtein(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+TXTSIMlevenshtein(Client ctx, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       (void) cntxt;
+       (void) ctx;
        (void) mb;
        int *res = getArgReference_int(stk, pci, 0);
        const char *x = *getArgReference_str(stk, pci, 1),
@@ -316,20 +316,20 @@ TXTSIMlevenshtein(Client cntxt, MalBlkPt
                /* Backwards compatibility purposes */
                if (pci->argc == 6) {
                        int transposition_cost = *getArgReference_int(stk, pci, 
5);
-                       return dameraulevenshtein(res, x, y, insdel_cost, 
replace_cost,
+                       return dameraulevenshtein(mb->ma, res, x, y, 
insdel_cost, replace_cost,
                                                                          
transposition_cost);
                }
        } else {
                throw(MAL, "txtsim.levenshtein", RUNTIME_SIGNATURE_MISSING);
        }
 
-       return levenshtein(res, x, y, insdel_cost, replace_cost, -1);;
+       return levenshtein(mb->ma, res, x, y, insdel_cost, replace_cost, -1);;
 }
 
 static str
-TXTSIMmaxlevenshtein(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+TXTSIMmaxlevenshtein(Client ctx, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       (void) cntxt;
+       (void) ctx;
        (void) mb;
        int *res = getArgReference_int(stk, pci, 0);
        const char *x = *getArgReference_str(stk, pci, 1),
@@ -347,13 +347,13 @@ TXTSIMmaxlevenshtein(Client cntxt, MalBl
                throw(MAL, "txtsim.maxlevenshtein", RUNTIME_SIGNATURE_MISSING);
        }
 
-       return levenshtein(res, x, y, insdel_cost, replace_cost, *k);
+       return levenshtein(mb->ma, res, x, y, insdel_cost, replace_cost, *k);
 }
 
 static str
-BATTXTSIMmaxlevenshtein(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
+BATTXTSIMmaxlevenshtein(Client ctx, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       (void) cntxt;
+       (void) ctx;
        (void) mb;
        bat *res = getArgReference_bat(stk, pci, 0);
        bat *lid = getArgReference_bat(stk, pci, 1);
@@ -403,8 +403,9 @@ BATTXTSIMmaxlevenshtein(Client cntxt, Ma
                        v = false;
                else {
                        if (llen > maxlen) {
+                               size_t osz = maxlen * sizeof(unsigned int);
                                maxlen = llen;
-                               unsigned int *tmp = GDKrealloc(buffer, (maxlen 
+ 1) * sizeof(unsigned int));
+                               unsigned int *tmp = ma_realloc(mb->ma, buffer, 
(maxlen + 1) * sizeof(unsigned int), osz);
                                if (tmp == NULL) {
                                        bat_iterator_end(&li);
                                        bat_iterator_end(&ri);
@@ -432,7 +433,7 @@ BATTXTSIMmaxlevenshtein(Client cntxt, Ma
        *res = bn->batCacheid;
        BBPkeepref(bn);
   exit:
-       GDKfree(buffer);
+       //GDKfree(buffer);
        BBPreclaim(left);
        BBPreclaim(right);
        if (msg != MAL_SUCCEED)
@@ -488,7 +489,7 @@ str_item_lenrev_cmp(const void *a, const
 }
 
 static str
-str_2_codepointseq(str_item *s)
+str_2_codepointseq(allocator *ma, str_item *s)
 {
        const uint8_t *p = (const uint8_t *) s->val;
 
@@ -496,7 +497,7 @@ str_2_codepointseq(str_item *s)
                s->cp_sequence = NULL;
                return MAL_SUCCEED;
        }
-       s->cp_sequence = GDKmalloc(s->len * sizeof(int));
+       s->cp_sequence = ma_alloc(ma, s->len * sizeof(int));
        if (s->cp_sequence == NULL)
                throw(MAL, "str_2_byteseq", SQLSTATE(HY013) MAL_MALLOC_FAIL);
 
@@ -603,7 +604,7 @@ jarowinkler(const str_item *x, const str
 static str
 TXTSIMjarowinkler(Client ctx, dbl *res, const char *const *x, const char 
*const *y)
 {
-       (void) ctx;
+       allocator *ma = ctx->curprg->def->ma;
        int *x_flags = NULL, *y_flags = NULL;
        str_item xi, yi;
        str msg = MAL_SUCCEED;
@@ -625,14 +626,14 @@ TXTSIMjarowinkler(Client ctx, dbl *res, 
                return MAL_SUCCEED;
        }
 
-       if ((msg = str_2_codepointseq(&xi)) != MAL_SUCCEED)
+       if ((msg = str_2_codepointseq(ma, &xi)) != MAL_SUCCEED)
                goto bailout;
 
-       if ((msg = str_2_codepointseq(&yi)) != MAL_SUCCEED)
+       if ((msg = str_2_codepointseq(ma, &yi)) != MAL_SUCCEED)
                goto bailout;
 
-       x_flags = GDKmalloc(xi.len * sizeof(int));
-       y_flags = GDKmalloc(yi.len * sizeof(int));
+       x_flags = ma_alloc(ma, xi.len * sizeof(int));
+       y_flags = ma_alloc(ma, yi.len * sizeof(int));
 
        if (x_flags == NULL || y_flags == NULL)
                goto bailout;
@@ -640,10 +641,10 @@ TXTSIMjarowinkler(Client ctx, dbl *res, 
        *res = jarowinkler(&xi, &yi, -1, x_flags, y_flags);
 
   bailout:
-       GDKfree(x_flags);
-       GDKfree(y_flags);
-       GDKfree(xi.cp_sequence);
-       GDKfree(yi.cp_sequence);
+       //GDKfree(x_flags);
+       //GDKfree(y_flags);
+       //GDKfree(xi.cp_sequence);
+       //GDKfree(yi.cp_sequence);
        return msg;
 }
 
@@ -676,7 +677,7 @@ TXTSIMminjarowinkler(Client ctx, bit *re
                                SI[n].cp_sequence = NULL;                       
                                        \
                                SI[n].len = UTF8_strlen(SI[n].val);             
                                \
                                SI[n].cp_seq_len = str_strlen(SI[n].val);       
                        \
-                               if ((msg = str_2_codepointseq(&SI[n])) != 
MAL_SUCCEED)  \
+                               if ((msg = str_2_codepointseq(ma, &SI[n])) != 
MAL_SUCCEED)      \
                                        goto exit;                              
                                                        \
                                str_alphabet_bitmap(&SI[n]);                    
                                \
                        }                                                       
                                                                \
@@ -749,7 +750,7 @@ maxlevenshtein_extcol_stritem(const str_
 }
 
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to