Changeset: 9f5fb7ce2b69 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9f5fb7ce2b69
Modified Files:
monetdb5/modules/atoms/json.c
monetdb5/modules/mal/tablet.c
Branch: resource_management
Log Message:
use context allocator in tablet.c, such that buffers can be alloced
independently
from temporary allocations.
In json.c only change length of the from string buffer when it is changed.
diffs (118 lines):
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
@@ -235,7 +235,7 @@ JSONtoStorageString(JSON *jt, int idx, j
return msg;
}
-static str JSONstr2json_intern(allocator *ma, json *ret, size_t len, const
char *const*j);
+static str JSONstr2json_intern(allocator *ma, json *ret, size_t *len, const
char *const*j);
static ssize_t
JSONfromString(allocator *ma, const char *src, size_t *len, void **J, bool
external)
@@ -250,15 +250,14 @@ JSONfromString(allocator *ma, const char
*len = 2;
return strNil(src) ? 1 : 3;
} else {
- str msg = JSONstr2json_intern(ma, buf, *len, &src);
+ str msg = JSONstr2json_intern(ma, buf, len, &src);
if (msg != MAL_SUCCEED) {
GDKerror("%s", getExceptionMessageAndState(msg));
freeException(msg);
return -1;
}
}
- *len = strlen(*buf) + 1;
- return (ssize_t) *len - 1;
+ return (ssize_t) strlen(*buf);
}
static ssize_t
@@ -513,7 +512,7 @@ JSON2json(Client ctx, json *ret, const j
}
static str
-JSONstr2json_intern(allocator *ma, json *ret, size_t len, const char *const*j)
+JSONstr2json_intern(allocator *ma, json *ret, size_t *len, const char *const*j)
{
assert(ma);
str msg = MAL_SUCCEED;
@@ -528,8 +527,10 @@ JSONstr2json_intern(allocator *ma, json
JSON *jt = NULL;
if (strNil(*j)) {
- if (!buf || len < strLen(*j))
- buf = (json)ma_alloc(ma, strLen(*j));
+ if (!buf || *len < strLen(*j)) {
+ *len = strLen(*j);
+ buf = (json)ma_alloc(ma, *len);
+ }
buf = strcpy(buf, *j);
} else {
jt = JSONparse(ta, *j);
@@ -543,8 +544,10 @@ JSONstr2json_intern(allocator *ma, json
goto bailout;
}
- if (!buf || len < ln)
+ if (!buf || *len < ln) {
+ *len = ln;
buf = (json)ma_alloc(ma, ln);
+ }
}
if (buf == NULL) {
msg = createException(MAL, "json.new", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
@@ -570,7 +573,7 @@ static str
JSONstr2json(Client ctx, json *ret, const char *const*j)
{
allocator *ma = ctx ? ctx->curprg->def->ma : MT_thread_getallocator();
- return JSONstr2json_intern(ma, ret, 0, j);
+ return JSONstr2json_intern(ma, ret, &(size_t){0}, j);
}
static str
@@ -630,7 +633,7 @@ upgradeJSONStorage(char **out, const cha
{
str msg;
allocator *ma = MT_thread_getallocator();
- if ((msg = JSONstr2json_intern(ma, out, 0, in)) != MAL_SUCCEED) {
+ if ((msg = JSONstr2json_intern(ma, out, &(size_t){0}, in)) !=
MAL_SUCCEED) {
freeException(msg);
return GDK_FAIL;
}
@@ -647,7 +650,7 @@ jsonRead(allocator *ma, str a, size_t *d
if ((a = BATatoms[TYPE_str].atomRead(ma, a, dstlen, s, cnt)) == NULL)
return NULL;
- msg = JSONstr2json_intern(ma, &out, 0, &(const char *){a});
+ msg = JSONstr2json_intern(ma, &out, &(size_t){0}, &(const char *){a});
if (ma == NULL)
GDKfree(a);
if (msg != MAL_SUCCEED) {
diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -1106,14 +1106,11 @@ SQLworker(void *arg)
GDKclrerr();
task->errbuf = GDKerrbuf;
MT_thread_set_qry_ctx(task->set_qry_ctx ? &task->cntxt->qryctx : NULL);
- //allocator *ma = task->cntxt ?
create_allocator(task->cntxt->curprg->def->ma, NULL, true) : NULL;
- //MT_thread_setallocator(ma);
- allocator *ma = MT_thread_getallocator();
+ allocator *ma = task->cntxt ? task->cntxt->curprg->def->ma : NULL;
assert(ma);
MT_sema_down(&task->sema);
while (task->top[task->cur] >= 0) {
- allocator_state *ma_state = ma_open(ma);
/* stage one, break the rows spread the work over the workers */
switch (task->state) {
case BREAKROW:
@@ -1158,7 +1155,6 @@ SQLworker(void *arg)
}
MT_sema_up(&task->reply);
MT_sema_down(&task->sema);
- ma_close_to(ma, ma_state);
}
MT_sema_up(&task->reply);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]