Changeset: f9fa9e2cb894 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/f9fa9e2cb894
Modified Files:
monetdb5/mal/mal_builder.c
monetdb5/mal/mal_function.c
monetdb5/mal/mal_parser.c
monetdb5/mal/mal_stack.c
monetdb5/mal/mal_stack.h
monetdb5/modules/atoms/str.c
monetdb5/modules/kernel/alarm.c
monetdb5/modules/kernel/algebra.c
monetdb5/modules/kernel/bat5.c
Branch: resource_management
Log Message:
MALblk allocator in miscellaneous modules
diffs (251 lines):
diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c
--- a/monetdb5/mal/mal_builder.c
+++ b/monetdb5/mal/mal_builder.c
@@ -471,7 +471,7 @@ getStrConstant(MalBlkPtr mb, str val)
VALset(&cst, TYPE_str, val);
_t = fndConstant(mb, &cst, MAL_VAR_WINDOW);
if (_t < 0) {
- if ((cst.val.sval = /*GDKmalloc*/ma_alloc(mb->ma, cst.len)) ==
NULL)
+ if ((cst.val.sval = ma_alloc(mb->ma, cst.len)) == NULL)
return -1;
memcpy(cst.val.sval, val, cst.len); /* includes terminating
\0 */
_t = defConstant(mb, TYPE_str, &cst);
diff --git a/monetdb5/mal/mal_function.c b/monetdb5/mal/mal_function.c
--- a/monetdb5/mal/mal_function.c
+++ b/monetdb5/mal/mal_function.c
@@ -679,7 +679,7 @@ chkDeclarations(MalBlkPtr mb)
char name[IDLENGTH];
if (mb->errors)
- return GDKstrdup(mb->errors);
+ return MA_STRDUP(mb->ma, mb->errors);
blks[top] = blkId;
/* initialize the scope */
diff --git a/monetdb5/mal/mal_parser.c b/monetdb5/mal/mal_parser.c
--- a/monetdb5/mal/mal_parser.c
+++ b/monetdb5/mal/mal_parser.c
@@ -2275,7 +2275,7 @@ parseMAL(Client ctx, Symbol curPrg, int
(void) curPrg;
echoInput(ctx);
// can we use mal block allocator always?
- allocator *ma = ctx->backup ? ctx->alloc : curPrg->def->ma;
+ allocator *ma = ctx->backup? ctx->backup->def->ma:curPrg->def->ma;
/* here the work takes place */
while ((c = currChar(ctx)) && lines > 0) {
switch (c) {
diff --git a/monetdb5/mal/mal_stack.c b/monetdb5/mal/mal_stack.c
--- a/monetdb5/mal/mal_stack.c
+++ b/monetdb5/mal/mal_stack.c
@@ -52,14 +52,14 @@
/* #define DEBUG_MAL_STACK*/
MalStkPtr
-newGlobalStack(allocator *alloc, int size)
+newGlobalStack(allocator *ma, int size)
{
MalStkPtr s;
- s = (MalStkPtr) alloc? ma_alloc(alloc, stackSize(size)) :
GDKmalloc(stackSize(size));
+ s = (MalStkPtr) ma? ma_alloc(ma, stackSize(size)) :
GDKmalloc(stackSize(size));
if (!s)
return NULL;
- s->allocated = !alloc;
+ s->allocated = !ma;
s->stksize = size;
s->stktop = s->stkbot = s->stkdepth = s->calldepth = 0;
s->keepAlive = s->keepTmps = 0;
@@ -79,7 +79,7 @@ newGlobalStack(allocator *alloc, int siz
}
MalStkPtr
-reallocGlobalStack(allocator *alloc, MalStkPtr old, int cnt)
+reallocGlobalStack(allocator *ma, MalStkPtr old, int cnt)
{
int k;
MalStkPtr s;
@@ -87,7 +87,7 @@ reallocGlobalStack(allocator *alloc, Mal
if (old->stksize > cnt)
return old;
k = ((cnt / STACKINCR) + 1) * STACKINCR;
- s = newGlobalStack(alloc, k);
+ s = newGlobalStack(ma, k);
if (!s) {
return NULL;
}
diff --git a/monetdb5/mal/mal_stack.h b/monetdb5/mal/mal_stack.h
--- a/monetdb5/mal/mal_stack.h
+++ b/monetdb5/mal/mal_stack.h
@@ -16,7 +16,7 @@
#define stackSize(CNT) (sizeof(ValRecord)*(CNT) + offsetof(MalStack, stk))
-mal_export MalStkPtr newGlobalStack(allocator *alloc, int size);
+mal_export MalStkPtr newGlobalStack(allocator *ma, int size);
mal_export MalStkPtr reallocGlobalStack(allocator *alloc, MalStkPtr s, int
cnt);
mal_export void clearStack(MalStkPtr s);
mal_export void freeStack(MalStkPtr stk);
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
@@ -2073,8 +2073,9 @@ strbat_reverse(allocator *ma, BAT *b)
len = strlen(src);
if (len >= dstlen) {
char *ndst;
+ size_t osz = dstlen;
dstlen = len + 1024;
- ndst = GDKrealloc(dst, dstlen);
+ ndst = ma_realloc(ma, dst, dstlen, osz);
if (ndst == NULL) {
bat_iterator_end(&bi);
BBPreclaim(bn);
diff --git a/monetdb5/modules/kernel/alarm.c b/monetdb5/modules/kernel/alarm.c
--- a/monetdb5/modules/kernel/alarm.c
+++ b/monetdb5/modules/kernel/alarm.c
@@ -76,7 +76,7 @@ ALARMsleep(Client cntxt, MalBlkPtr mb, M
static str
ALARMctime(Client ctx, str *res)
{
- (void) ctx;
+ allocator *ma = ctx->curprg->def->ma;
time_t t = time(0);
char *base;
char buf[26];
@@ -91,7 +91,7 @@ ALARMctime(Client ctx, str *res)
throw(MAL, "alarm.ctime", "failed to format time");
base[24] = 0; /* squash final newline */
- *res = GDKstrdup(base);
+ *res = MA_STRDUP(ma, base);
if (*res == NULL)
throw(MAL, "alarm.ctime", SQLSTATE(HY013) MAL_MALLOC_FAIL);
return MAL_SUCCEED;
diff --git a/monetdb5/modules/kernel/algebra.c
b/monetdb5/modules/kernel/algebra.c
--- a/monetdb5/modules/kernel/algebra.c
+++ b/monetdb5/modules/kernel/algebra.c
@@ -1045,26 +1045,26 @@ ALGgroupedfirstn(Client cntxt, MalBlkPtr
if (nbats % 3 != 0)
throw(MAL, "algebra.groupedfirstn", ILLEGAL_ARGUMENT);
nbats /= 3;
- BAT **bats = GDKmalloc(nbats * sizeof(BAT *));
- bool *ascs = GDKmalloc(nbats * sizeof(bool));
- bool *nlss = GDKmalloc(nbats * sizeof(bool));
+ BAT **bats = ma_alloc(mb->ma, nbats * sizeof(BAT *));
+ bool *ascs = ma_alloc(mb->ma, nbats * sizeof(bool));
+ bool *nlss = ma_alloc(mb->ma, nbats * sizeof(bool));
if (bats == NULL || ascs == NULL || nlss == NULL) {
- GDKfree(bats);
- GDKfree(ascs);
- GDKfree(nlss);
+ //GDKfree(bats);
+ //GDKfree(ascs);
+ //GDKfree(nlss);
throw(MAL, "algebra.groupedfirstn", MAL_MALLOC_FAIL);
}
if (!is_bat_nil(sid) && (s = BATdescriptor(sid)) == NULL) {
- GDKfree(bats);
- GDKfree(ascs);
- GDKfree(nlss);
+ //GDKfree(bats);
+ //GDKfree(ascs);
+ //GDKfree(nlss);
throw(MAL, "algebra.groupedfirstn", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
}
if (!is_bat_nil(gid) && (g = BATdescriptor(gid)) == NULL) {
BBPreclaim(s);
- GDKfree(bats);
- GDKfree(ascs);
- GDKfree(nlss);
+ //GDKfree(bats);
+ //GDKfree(ascs);
+ //GDKfree(nlss);
throw(MAL, "algebra.groupedfirstn", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
}
for (int i = 0; i < nbats; i++) {
@@ -1074,9 +1074,9 @@ ALGgroupedfirstn(Client cntxt, MalBlkPtr
BBPreclaim(bats[--i]);
BBPreclaim(g);
BBPreclaim(s);
- GDKfree(bats);
- GDKfree(ascs);
- GDKfree(nlss);
+ //GDKfree(bats);
+ //GDKfree(ascs);
+ //GDKfree(nlss);
throw(MAL, "algebra.groupedfirstn", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
}
ascs[i] = *getArgReference_bit(stk, pci, i * 3 + 5);
@@ -1087,9 +1087,9 @@ ALGgroupedfirstn(Client cntxt, MalBlkPtr
BBPreclaim(g);
for (int i = 0; i < nbats; i++)
BBPreclaim(bats[i]);
- GDKfree(bats);
- GDKfree(ascs);
- GDKfree(nlss);
+ //GDKfree(bats);
+ //GDKfree(ascs);
+ //GDKfree(nlss);
if (bn == NULL)
throw(MAL, "algebra.groupedfirstn", GDK_EXCEPTION);
*ret = bn->batCacheid;
diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c
--- a/monetdb5/modules/kernel/bat5.c
+++ b/monetdb5/modules/kernel/bat5.c
@@ -374,14 +374,14 @@ BKCgetCapacity(Client ctx, lng *res, con
static str
BKCgetColumnType(Client ctx, str *res, const bat *bid)
{
- (void) ctx;
+ allocator *ma = ctx->curprg->def->ma;
const char *ret = str_nil;
BAT *b = BBPquickdesc(*bid);
if (b == NULL)
throw(MAL, "bat.getColumnType", ILLEGAL_ARGUMENT);
ret = *bid < 0 ? ATOMname(TYPE_void) : ATOMname(b->ttype);
- *res = GDKstrdup(ret);
+ *res = MA_STRDUP(ma, ret);
if (*res == NULL)
throw(MAL, "bat.getColumnType", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
return MAL_SUCCEED;
@@ -541,20 +541,20 @@ BKCsetAccess(Client ctx, bat *res, const
static str
BKCgetAccess(Client ctx, str *res, const bat *bid)
{
- (void) ctx;
+ allocator *ma = ctx->curprg->def->ma;
BAT *b;
if ((b = BATdescriptor(*bid)) == NULL)
throw(MAL, "bat.getAccess", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
switch (BATgetaccess(b)) {
case BAT_READ:
- *res = GDKstrdup("read");
+ *res = MA_STRDUP(ma, "read");
break;
case BAT_APPEND:
- *res = GDKstrdup("append");
+ *res = MA_STRDUP(ma, "append");
break;
case BAT_WRITE:
- *res = GDKstrdup("write");
+ *res = MA_STRDUP(ma, "write");
break;
default:
MT_UNREACHABLE();
@@ -949,13 +949,13 @@ BKCsetName(Client ctx, void *r, const ba
static str
BKCgetBBPname(Client ctx, str *ret, const bat *bid)
{
- (void) ctx;
+ allocator *ma = ctx->curprg->def->ma;
BAT *b;
if ((b = BATdescriptor(*bid)) == NULL) {
throw(MAL, "bat.getName", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
}
- *ret = GDKstrdup(BBP_logical(b->batCacheid));
+ *ret = MA_STRDUP(ma, BBP_logical(b->batCacheid));
BBPunfix(b->batCacheid);
return *ret ? MAL_SUCCEED : createException(MAL, "bat.getName",
SQLSTATE(HY013)
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]