Changeset: c73b23452967 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c73b23452967
Modified Files:
        gdk/gdk_utils.c
        monetdb5/modules/atoms/str.c
Branch: resource_management
Log Message:

temp buf use tls allocator


diffs (truncated from 490 to 300 lines):

diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -2562,6 +2562,7 @@ static void *
 void *
 sa_alloc(allocator *sa, size_t sz)
 {
+       assert(sa);
        size_t nsize = sz + SA_HEADER_SIZE;
        char* r = (char*) _sa_alloc_internal(sa, nsize);
        return sa_fill_in_header(r, sz);
@@ -2730,6 +2731,7 @@ sa_get_eb(allocator *sa)
 allocator_state *
 sa_open(allocator *sa)
 {
+       assert(sa);
        if (sa) {
                allocator_state *res = sa_alloc(sa,
                                sizeof(allocator_state));
@@ -2770,6 +2772,7 @@ sa_close(allocator *sa)
 void
 sa_close_to(allocator *sa, allocator_state *state)
 {
+       assert(sa);
        if (sa) {
                COND_LOCK_ALLOCATOR(sa);
                assert(sa_tmp_active(sa));
diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -332,15 +332,18 @@ STRTail(Client ctx, str *res, const char
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH;
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.tail", SQLSTATE(HY013) MAL_MALLOC_FAIL);
                if ((msg = str_tail(&buf, &buflen, s, off)) != MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -389,15 +392,18 @@ STRSubString(Client ctx, str *res, const
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH;
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.substring", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                if ((msg = str_Sub_String(&buf, &buflen, s, off, len)) != 
MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -430,15 +436,18 @@ STRFromWChr(Client ctx, str *res, const 
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = MAX(strlen(str_nil) + 1, 8);
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.unicode", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                if ((msg = str_from_wchr(&buf, &buflen, cc)) != MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -496,15 +505,18 @@ doStrConvert(allocator *ma, str *res, co
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH;
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.lower", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                if ((*func)(&buf, &buflen, arg1) != GDK_SUCCEED) {
                        //GDKfree(buf);
                        throw(MAL, "str.lower", GDK_EXCEPTION);
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -808,15 +820,18 @@ STRsplitpart(Client ctx, str *res, const
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH;
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.splitpart", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                if ((msg = str_splitpart(&buf, &buflen, s, s2, f)) != 
MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -932,15 +947,18 @@ STRStrip(Client ctx, str *res, const cha
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH;
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.strip", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                if ((msg = str_strip(&buf, &buflen, s)) != MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -974,15 +992,18 @@ STRLtrim(Client ctx, str *res, const cha
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH;
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.ltrim", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                if ((msg = str_ltrim(&buf, &buflen, s)) != MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -1016,15 +1037,18 @@ STRRtrim(Client ctx, str *res, const cha
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH;
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.rtrim", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                if ((msg = str_rtrim(&buf, &buflen, s)) != MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -1100,15 +1124,18 @@ STRStrip2(Client ctx, str *res, const ch
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH * sizeof(int);
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.strip2", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                if ((msg = str_strip2(&buf, &buflen, s, s2)) != MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -1155,15 +1182,18 @@ STRLtrim2(Client ctx, str *res, const ch
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH * sizeof(int);
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.ltrim2", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                if ((msg = str_ltrim2(&buf, &buflen, s, s2)) != MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -1210,15 +1240,18 @@ STRRtrim2(Client ctx, str *res, const ch
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH * sizeof(int);
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.rtrim2", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                if ((msg = str_rtrim2(&buf, &buflen, s, s2)) != MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -1312,15 +1345,18 @@ STRLpad(Client ctx, str *res, const char
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH;
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.lpad", SQLSTATE(HY013) MAL_MALLOC_FAIL);
                if ((msg = str_lpad(&buf, &buflen, s, l)) != MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -1354,15 +1390,18 @@ STRRpad(Client ctx, str *res, const char
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH;
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
                        throw(MAL, "str.rpad", SQLSTATE(HY013) MAL_MALLOC_FAIL);
                if ((msg = str_rpad(&buf, &buflen, s, l)) != MAL_SUCCEED) {
                        //GDKfree(buf);
                        return msg;
                }
                *res = MA_STRDUP(ma, buf);
+               ma_close_to(ta, ta_state);
        }
 
        //GDKfree(buf);
@@ -1396,15 +1435,18 @@ STRLpad3(Client ctx, str *res, const cha
                *res = MA_STRDUP(ma, str_nil);
        } else {
                size_t buflen = INITIAL_STR_BUFFER_LENGTH;
+               allocator *ta = MT_thread_getallocator();
+               allocator_state *ta_state = ma_open(ta);
 
                *res = NULL;
-               if (!(buf = ma_alloc(ma, buflen)))
+               if (!(buf = ma_alloc(ta, buflen)))
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to