Changeset: 246b88d35aa4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/246b88d35aa4
Modified Files:
gdk/gdk_atoms.c
gdk/gdk_calc_convert.c
gdk/gdk_storage.c
gdk/gdk_string.c
gdk/gdk_value.c
monetdb5/mal/mal_client.c
monetdb5/mal/mal_dataflow.c
monetdb5/mal/mal_instruction.c
monetdb5/mal/mal_listing.c
monetdb5/mal/mal_profiler.c
monetdb5/modules/atoms/json.c
monetdb5/modules/atoms/url.c
monetdb5/modules/mal/mal_mapi.c
monetdb5/modules/mal/mdb.c
monetdb5/modules/mal/remote.c
monetdb5/modules/mal/tablet.c
monetdb5/optimizer/opt_remoteQueries.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_bincopyconvert.c
sql/backends/monet5/sql_result.c
sql/backends/monet5/sql_statistics.c
sql/server/rel_dump.c
sql/server/rel_prop.c
sql/server/rel_updates.c
sql/server/sql_atom.c
Branch: resource_management
Log Message:
using allocator in tablet code, atom printing/formatting
diffs (truncated from 1082 to 300 lines):
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -342,7 +342,7 @@ ATOMprint(int t, const void *p, stream *
res = (*tostr) (&buf, &sz, p, true);
if (res > 0)
res = mnstr_write(s, buf, (size_t) res, 1);
- GDKfree(buf);
+ // GDKfree(buf);
}
} else {
res = mnstr_write(s, "nil", 1, 3);
@@ -357,18 +357,20 @@ char *
ATOMformat(int t, const void *p)
{
ssize_t (*tostr) (char **, size_t *, const void *, bool);
+ allocator *ma = MT_thread_getallocator();
+ assert(ma);
if (p && 0 <= t && t < GDKatomcnt && (tostr = BATatoms[t].atomToStr)) {
size_t sz = 0;
char *buf = NULL;
ssize_t res = (*tostr) (&buf, &sz, p, true);
if (res < 0 && buf) {
- GDKfree(buf);
+ // GDKfree(buf);
buf = NULL;
}
return buf;
}
- return GDKstrdup("nil");
+ return MA_STRDUP(ma, "nil");
}
ptr
@@ -1509,11 +1511,14 @@ BLOBfromstr(const char *instr, size_t *l
blob *result;
const char *s = instr;
+ allocator *ma = MT_thread_getallocator();
+ assert(ma);
+
if (strNil(instr) || (external && strncmp(instr, "nil", 3) == 0)) {
nbytes = blobsize(0);
if (*l < nbytes || *val == NULL) {
- GDKfree(*val);
- if ((*val = GDKmalloc(nbytes)) == NULL)
+ // GDKfree(*val);
+ if ((*val = ma_alloc(ma, nbytes)) == NULL)
return -1;
}
**val = blob_nil;
@@ -1537,8 +1542,8 @@ BLOBfromstr(const char *instr, size_t *l
nbytes = blobsize(nitems);
if (*l < nbytes || *val == NULL) {
- GDKfree(*val);
- *val = GDKmalloc(nbytes);
+ // GDKfree(*val);
+ *val = ma_alloc(ma, nbytes);
if( *val == NULL)
return -1;
*l = nbytes;
diff --git a/gdk/gdk_calc_convert.c b/gdk/gdk_calc_convert.c
--- a/gdk/gdk_calc_convert.c
+++ b/gdk/gdk_calc_convert.c
@@ -772,12 +772,12 @@ convert_str_var(BATiter *bi, BAT *bn, st
}
}
}
- GDKfree(dst);
+ // GDKfree(dst);
TIMEOUT_CHECK(qry_ctx, TIMEOUT_HANDLER(BUN_NONE, qry_ctx));
BATsetcount(bn, ci->ncand);
return nils;
bailout:
- GDKfree(dst);
+ // GDKfree(dst);
return BUN_NONE + 2;
}
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -947,7 +947,8 @@ BATprintcolumns(stream *s, int argc, BAT
for (i = 0; i < argc; i++) {
bat_iterator_end(&colinfo[i].i);
}
- GDKfree(buf);
+ // buf came from allocator
+ // GDKfree(buf);
GDKfree(colinfo);
return rc;
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -55,9 +55,9 @@
#define atommem(size) \
do { \
if (*dst == NULL || *len < (size)) { \
- GDKfree(*dst); \
+ /*GDKfree(*dst);*/ \
*len = (size); \
- *dst = GDKmalloc(*len); \
+ *dst = ma_alloc(ma, *len); \
if (*dst == NULL) { \
*len = 0; \
return -1; \
@@ -560,6 +560,8 @@ strFromStr(const char *restrict src, siz
const char *cur = src, *start = NULL;
size_t l = 1;
bool escaped = false;
+ allocator *ma = MT_thread_getallocator();
+ assert(ma);
if (!external) {
size_t sz = strLen(src);
@@ -708,6 +710,8 @@ ssize_t
strToStr(char **restrict dst, size_t *restrict len, const char *restrict src,
bool external)
{
size_t sz;
+ allocator *ma = MT_thread_getallocator();
+ assert(ma);
if (!external) {
sz = strLen(src);
diff --git a/gdk/gdk_value.c b/gdk/gdk_value.c
--- a/gdk/gdk_value.c
+++ b/gdk/gdk_value.c
@@ -261,8 +261,11 @@ char *
VALformat(const ValRecord *res)
{
if (res->bat) {
- if (is_bat_nil(res->val.bval))
- return GDKstrdup("nil");
+ if (is_bat_nil(res->val.bval)) {
+ allocator *ma = MT_thread_getallocator();
+ assert(ma);
+ return MA_STRDUP(ma, "nil");
+ }
else
return ATOMformat(TYPE_int, (const void *)
&res->val.ival);
} else
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -303,6 +303,7 @@ MCinitClient(oid user, bstream *fin, str
c = MCnewClient();
if (c) {
c = MCinitClientRecord(c, user, fin, fout);
+ MT_thread_setallocator(c->alloc);
MT_thread_set_qry_ctx(&c->qryctx);
}
MT_lock_unset(&mal_contextLock);
@@ -463,6 +464,7 @@ MCcloseClient(Client c)
}
c->ta = NULL;
ma_destroy(c->alloc);
+ MT_thread_setallocator(NULL);
MT_lock_unset(&mal_contextLock);
}
diff --git a/monetdb5/mal/mal_dataflow.c b/monetdb5/mal/mal_dataflow.c
--- a/monetdb5/mal/mal_dataflow.c
+++ b/monetdb5/mal/mal_dataflow.c
@@ -338,8 +338,10 @@ DFLOWworker(void *T)
allocator *pa = flow->mb->ma;
allocator *ta = ma_create(pa);
+ MT_thread_setallocator(ta);
error = runMALsequence(ta, flow->cntxt, flow->mb,
fe->pc, fe->pc + 1,
flow->stk,
0, 0);
+ MT_thread_setallocator(NULL);
ma_destroy(ta);
ATOMIC_DEC(&flow->cntxt->workers);
diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c
--- a/monetdb5/mal/mal_instruction.c
+++ b/monetdb5/mal/mal_instruction.c
@@ -257,7 +257,7 @@ resetMalBlk(MalBlkPtr mb)
void
freeMalBlk(MalBlkPtr mb)
{
- int i;
+ //int i;
/*
for (i = 0; i < mb->ssize; i++)
@@ -267,15 +267,15 @@ freeMalBlk(MalBlkPtr mb)
}
mb->stop = 0;
*/
- for (i = 0; i < mb->vtop; i++) {
- /*
- if (mb->var[i].name)
- GDKfree(mb->var[i].name);
- */
- //mb->var[i].name = NULL;
- if (isVarConstant(mb, i))
- VALclear(&getVarConstant(mb, i));
- }
+ //for (i = 0; i < mb->vtop; i++) {
+ // /*
+ // if (mb->var[i].name)
+ // GDKfree(mb->var[i].name);
+ // */
+ // //mb->var[i].name = NULL;
+ // if (isVarConstant(mb, i))
+ // VALclear(&getVarConstant(mb, i));
+ //}
freeException(mb->errors);
ma_destroy(mb->ma);
#if 0
diff --git a/monetdb5/mal/mal_listing.c b/monetdb5/mal/mal_listing.c
--- a/monetdb5/mal/mal_listing.c
+++ b/monetdb5/mal/mal_listing.c
@@ -135,7 +135,7 @@ renderTerm(MalBlkPtr mb, MalStkPtr stk,
bufend += snprintf(bufend, (buf +
max_len) - bufend, "[" BUNFMT "]", BATcount(d));
}
}
- GDKfree(cv);
+ // GDKfree(cv);
}
*bufend = 0;
// show the type when required or frozen by the user
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -453,7 +453,7 @@ prepareMalEvent(Client cntxt, MalBlkPtr
if (c) /* unlikely
that this isn't true */
*c = 0;
ok = logadd(&logbuf,
",\"file\":\"%s\"", cv + 1);
- GDKfree(cv);
+ // GDKfree(cv);
if (!ok) {
BBPunfix(d->batCacheid);
goto
cleanup_and_exit;
@@ -501,7 +501,7 @@ prepareMalEvent(Client cntxt, MalBlkPtr
cv = format_val2json(cntxt,
&stk->stk[getArg(pci, j)]);
if (cv)
ok = logadd(&logbuf,
",\"value\":%s", cv);
- GDKfree(cv);
+ // GDKfree(cv);
if (!ok)
goto cleanup_and_exit;
}
diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -84,17 +84,17 @@ int TYPE_json;
/* Internal constructors. */
static int jsonhint = 8;
-static JSON *JSONparse(Client ctx, const char *j);
+static JSON *JSONparse(allocator *ma, const char *j);
static JSON *
-JSONnewtree(allocator *alloc)
+JSONnewtree(allocator *ma)
{
JSON *js;
- js = ma_zalloc(alloc, sizeof(JSON));
+ js = ma_zalloc(ma, sizeof(JSON));
if (js == NULL)
return NULL;
- js->elm = ma_zalloc(alloc, sizeof(JSONterm) * jsonhint);
+ js->elm = ma_zalloc(ma, sizeof(JSONterm) * jsonhint);
if (js->elm == NULL) {
//GDKfree(js);
return NULL;
@@ -104,14 +104,14 @@ JSONnewtree(allocator *alloc)
}
static int
-JSONnew(Client ctx, JSON *js)
+JSONnew(allocator *ma, JSON *js)
{
JSONterm *term;
size_t osz = sizeof(JSONterm) * js->size;
if (js->free == js->size) {
size_t nsz = sizeof(JSONterm) * (js->size + 8);
- term = ma_realloc(ctx->alloc, js->elm, nsz, osz);
+ term = ma_realloc(ma, js->elm, nsz, osz);
if (term == NULL) {
js->error = createException(MAL, "json.new",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
@@ -242,9 +242,11 @@ JSONfromString(const char *src, size_t *
{
json *buf = (json *) J;
if(*buf) {
- //GDKfree(*buf);
+ // GDKfree(*buf);
*buf = NULL;
}
+ allocator *ma = MT_thread_getallocator();
+ assert(ma);
if (strNil(src) || (external && strncmp(src, "nil", 3) == 0)) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]