Changeset: bd544588b265 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/bd544588b265
Modified Files:
gdk/gdk.h
gdk/gdk_aggr.c
gdk/gdk_calc.h
gdk/gdk_calc_convert.c
gdk/gdk_value.c
monetdb5/mal/mal_builder.c
monetdb5/mal/mal_instruction.c
monetdb5/mal/mal_instruction.h
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_profiler.c
monetdb5/mal/mal_stack.c
monetdb5/modules/mal/calc.c
monetdb5/optimizer/opt_remap.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_cast_impl_int.h
sql/backends/monet5/sql_rank.c
sql/backends/monet5/sql_scenario.c
sql/server/rel_exp.c
sql/server/sql_atom.c
sql/server/sql_atom.h
sql/server/sql_mvc.h
sql/server/sql_var.c
sql/storage/store.c
Branch: resource_management
Log Message:
pass allocator explicitly where possible
diffs (truncated from 886 to 300 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -640,7 +640,7 @@ typedef struct {
} *ValPtr, ValRecord;
/* interface definitions */
-gdk_export void *VALconvert(int typ, ValPtr t);
+gdk_export void *VALconvert(allocator *ma, int typ, ValPtr t);
gdk_export char *VALformat(const ValRecord *res)
__attribute__((__warn_unused_result__));
gdk_export void VALempty(ValPtr v)
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -2029,7 +2029,7 @@ BATgroupavg3(BAT **avgp, BAT **remp, BAT
}
ValRecord zero;
(void) VALinit(NULL, &zero, TYPE_bte, &(bte){0});
- bn = BATconstant(min, b->ttype, VALconvert(b->ttype, &zero),
+ bn = BATconstant(min, b->ttype, VALconvert(NULL, b->ttype, &zero),
ngrp, TRANSIENT);
rn = BATconstant(min, TYPE_lng, &(lng){0}, ngrp, TRANSIENT);
cn = BATconstant(min, TYPE_lng, &(lng){0}, ngrp, TRANSIENT);
@@ -2657,7 +2657,8 @@ BATgroupavg3combine(BAT *avg, BAT *rem,
}
ValRecord zero;
(void) VALinit(NULL, &zero, TYPE_bte, &(bte){0});
- bn = BATconstant(min, avg->ttype, VALconvert(avg->ttype, &zero),
+ bn = BATconstant(min, avg->ttype,
+ VALconvert(NULL, avg->ttype, &zero),
ngrp, TRANSIENT);
/* rn and cn are temporary storage of intermediates */
rn = BATconstant(min, TYPE_lng, &(lng){0}, ngrp, TRANSIENT);
diff --git a/gdk/gdk_calc.h b/gdk/gdk_calc.h
--- a/gdk/gdk_calc.h
+++ b/gdk/gdk_calc.h
@@ -121,7 +121,7 @@ gdk_export gdk_return VARcalceq(ValPtr r
gdk_export gdk_return VARcalcne(ValPtr ret, const ValRecord *lft, const
ValRecord *rgt, bool nil_matches);
gdk_export gdk_return VARcalccmp(ValPtr ret, const ValRecord *lft, const
ValRecord *rgt);
gdk_export BAT *BATconvert(BAT *b, BAT *s, int tp, uint8_t scale1, uint8_t
scale2, uint8_t precision);
-gdk_export gdk_return VARconvert(ValPtr ret, const ValRecord *v, uint8_t
scale1, uint8_t scale2, uint8_t precision);
+gdk_export gdk_return VARconvert(allocator *ma, ValPtr ret, const ValRecord
*v, uint8_t scale1, uint8_t scale2, uint8_t precision);
gdk_export gdk_return BATcalcavg(BAT *b, BAT *s, dbl *avg, BUN *vals, int
scale);
gdk_export BAT *BATgroupsum(BAT *b, BAT *g, BAT *e, BAT *s, int tp, bool
skip_nils);
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
@@ -1548,7 +1548,7 @@ BATconvert(BAT *b, BAT *s, int tp,
}
gdk_return
-VARconvert(ValPtr ret, const ValRecord *v,
+VARconvert(allocator *ma, ValPtr ret, const ValRecord *v,
uint8_t scale1, uint8_t scale2, uint8_t precision)
{
ptr p;
@@ -1558,7 +1558,7 @@ VARconvert(ValPtr ret, const ValRecord *
assert(!v->bat);
if (ret->vtype == TYPE_msk) {
ValRecord tmp = { .vtype = TYPE_bit };
- if (VARconvert(&tmp, v, scale1, scale2, precision) !=
GDK_SUCCEED)
+ if (VARconvert(ma, &tmp, v, scale1, scale2, precision) !=
GDK_SUCCEED)
return GDK_FAIL;
if (is_bte_nil(tmp.val.btval)) {
GDKerror("22003!cannot convert nil to msk.\n");
@@ -1568,16 +1568,16 @@ VARconvert(ValPtr ret, const ValRecord *
ret->len = ATOMsize(TYPE_msk);
} else if (v->vtype == TYPE_msk) {
ValRecord tmp = { .vtype = TYPE_bit, .val.btval = v->val.mval };
- if (VARconvert(ret, &tmp, scale1, scale2, precision) !=
GDK_SUCCEED)
+ if (VARconvert(ma, ret, &tmp, scale1, scale2, precision) !=
GDK_SUCCEED)
return GDK_FAIL;
} else if (ret->vtype == TYPE_str) {
if (v->vtype == TYPE_void ||
(*ATOMcompare(v->vtype))(VALptr(v),
ATOMnilptr(v->vtype)) == 0) {
- if (VALinit(NULL, ret, TYPE_str, str_nil) == NULL)
+ if (VALinit(ma, ret, TYPE_str, str_nil) == NULL)
return GDK_FAIL;
} else if (BATatoms[v->vtype].atomToStr ==
BATatoms[TYPE_str].atomToStr) {
- if (VALinit(NULL, ret, TYPE_str, v->val.sval) == NULL)
+ if (VALinit(ma, ret, TYPE_str, v->val.sval) == NULL)
return GDK_FAIL;
} else {
ret->len = 0;
@@ -1586,7 +1586,7 @@ VARconvert(ValPtr ret, const ValRecord *
&ret->len,
VALptr(v),
false) < 0) {
- GDKfree(ret->val.sval);
+ //GDKfree(ret->val.sval);
ret->val.sval = NULL;
ret->len = 0;
return GDK_FAIL;
@@ -1600,11 +1600,11 @@ VARconvert(ValPtr ret, const ValRecord *
ret->val.oval = oid_nil;
ret->len = ATOMsize(TYPE_void);
} else if (v->vtype == TYPE_void) {
- if (VALinit(NULL, ret, ret->vtype, ATOMnilptr(ret->vtype)) ==
NULL)
+ if (VALinit(ma, ret, ret->vtype, ATOMnilptr(ret->vtype)) ==
NULL)
return GDK_FAIL;
} else if (v->vtype == TYPE_str) {
if (strNil(v->val.sval)) {
- if (VALinit(NULL, ret, ret->vtype,
ATOMnilptr(ret->vtype)) == NULL)
+ if (VALinit(ma, ret, ret->vtype,
ATOMnilptr(ret->vtype)) == NULL)
return GDK_FAIL;
} else if (ATOMstorage(ret->vtype) == TYPE_ptr) {
nils = BUN_NONE + 1;
@@ -1625,8 +1625,8 @@ VARconvert(ValPtr ret, const ValRecord *
if ((l = (*BATatoms[ret->vtype].atomFromStr)(
v->val.sval, &len, &p, false)) < 0 ||
l < (ssize_t) strlen(v->val.sval)) {
- if (ATOMextern(ret->vtype))
- GDKfree(p);
+ //if (ATOMextern(ret->vtype))
+ // GDKfree(p);
GDKclrerr();
size_t sz = escapedStrlen(v->val.sval, NULL,
NULL, '\'');
char *bf = GDKmalloc(sz + 1);
@@ -1647,8 +1647,10 @@ VARconvert(ValPtr ret, const ValRecord *
assert(ATOMextern(ret->vtype) ||
p == VALget(ret));
ret->len = (int) len;
- if (ATOMextern(ret->vtype))
+ if (ATOMextern(ret->vtype)) {
VALset(ret, ret->vtype, p);
+ ret->allocated = false;
+ }
}
}
} else {
@@ -1666,6 +1668,6 @@ VARconvert(ValPtr ret, const ValRecord *
ATOMname(v->vtype), ATOMname(ret->vtype));
return GDK_FAIL;
}
- ret->allocated = true;
+ //ret->allocated = !ma;
return nils == BUN_NONE ? GDK_FAIL : GDK_SUCCEED;
}
diff --git a/gdk/gdk_value.c b/gdk/gdk_value.c
--- a/gdk/gdk_value.c
+++ b/gdk/gdk_value.c
@@ -130,11 +130,18 @@ VALget(ValPtr v)
void
VALclear(ValPtr v)
{
- //if (v->allocated && !v->bat && ATOMextern(v->vtype)) {
- // if (v->val.pval && v->val.pval != ATOMnilptr(v->vtype))
- // GDKfree(v->val.pval);
- //}
- VALempty(v);
+ if (v->allocated && !v->bat && ATOMextern(v->vtype)) {
+ if (v->vtype == TYPE_str) {
+ if (v->val.sval && v->val.sval != ATOMnilptr(v->vtype)) {
+ GDKfree(v->val.sval);
+ }
+ } else {
+ if (v->val.pval && v->val.pval != ATOMnilptr(v->vtype)) {
+ GDKfree(v->val.pval);
+ }
+ }
+ }
+ VALempty(v);
}
/* Initialize V to an empty value (type void, value nil). See
@@ -156,35 +163,35 @@ VALempty(ValPtr v)
*
* Returns NULL In case of (malloc) failure. */
ValPtr
-VALcopy(allocator *va, ValPtr d, const ValRecord *s)
+VALcopy(allocator *ma, ValPtr d, const ValRecord *s)
{
if (d == s) {
return d;
}
- allocator *ma = va? va : MT_thread_getallocator();
- assert(ma);
*d = *s;
- d->allocated = false;
if (s->bat || !ATOMextern(s->vtype)) {
//*d = *s;
+ d->allocated = false;
} else if (s->val.pval == NULL) {
return VALinit(ma, d, s->vtype, ATOMnilptr(s->vtype));
} else if (s->vtype == TYPE_str) {
const char *p = s->val.sval;
d->vtype = TYPE_str;
d->len = strLen(p);
- d->val.sval = ma_alloc(ma, d->len);
+ d->val.sval = ma? ma_alloc(ma, d->len) : GDKmalloc(d->len);
if (d->val.sval == NULL)
return NULL;
memcpy(d->val.sval, p, d->len);
+ d->allocated = !ma;
} else {
const void *p = s->val.pval;
d->vtype = s->vtype;
d->len = ATOMlen(d->vtype, p);
- d->val.pval = ma_alloc(ma, d->len);
+ d->val.pval = ma? ma_alloc(ma, d->len) : GDKmalloc(d->len);
if (d->val.pval == NULL)
return NULL;
memcpy(d->val.pval, p, d->len);
+ d->allocated = !ma;
}
return d;
}
@@ -196,10 +203,8 @@ VALcopy(allocator *va, ValPtr d, const V
*
* Returns NULL in case of (malloc) failure. */
ValPtr
-VALinit(allocator *va, ValPtr d, int tpe, const void *s)
+VALinit(allocator *ma, ValPtr d, int tpe, const void *s)
{
- allocator *ma = va? va : MT_thread_getallocator();
- assert(ma);
d->bat = false;
d->allocated = false;
switch (ATOMstorage(d->vtype = tpe)) {
@@ -237,10 +242,12 @@ VALinit(allocator *va, ValPtr d, int tpe
break;
case TYPE_str:
d->len = strLen(s);
- d->val.sval = ma_alloc(ma, d->len);
+ d->val.sval = ma? ma_alloc(ma, d->len) :
+ GDKmalloc(d->len);
if (d->val.sval == NULL)
return NULL;
memcpy(d->val.sval, s, d->len);
+ d->allocated = !ma;
return d;
case TYPE_ptr:
d->val.pval = *(const ptr *) s;
@@ -249,10 +256,12 @@ VALinit(allocator *va, ValPtr d, int tpe
default:
assert(ATOMextern(ATOMstorage(tpe)));
d->len = ATOMlen(tpe, s);
- d->val.pval = ma_alloc(ma, d->len);
+ d->val.pval = ma? ma_alloc(ma, d->len) :
+ GDKmalloc(d->len);
if (d->val.pval == NULL)
return NULL;
memcpy(d->val.pval, s, d->len);
+ d->allocated = !ma;
return d;
}
d->len = ATOMsize(d->vtype);
@@ -281,13 +290,13 @@ VALformat(const ValRecord *res)
* didn't succeed. If the conversion didn't succeed, the original
* value is not modified. Also see VARconvert. */
ptr
-VALconvert(int typ, ValPtr t)
+VALconvert(allocator *ma, int typ, ValPtr t)
{
int src_tpe = t->vtype;
ValRecord dst = { .vtype = typ };
/* first convert into a new location */
- if (VARconvert(&dst, t, 0, 0, 0) != GDK_SUCCEED)
+ if (VARconvert(ma, &dst, t, 0, 0, 0) != GDK_SUCCEED)
return NULL;
/* then maybe free the old */
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
@@ -593,7 +593,7 @@ pushNilType(MalBlkPtr mb, InstrPtr q, ch
} else {
ValRecord cst = { .vtype = TYPE_void, .val.oval = oid_nil };
- msg = convertConstant(idx, &cst);
+ msg = convertConstant(mb->ma, idx, &cst);
if (msg == MAL_SUCCEED) {
_t = defConstant(mb, idx, &cst);
if (_t >= 0) {
@@ -617,7 +617,7 @@ pushType(MalBlkPtr mb, InstrPtr q, int t
if (q == NULL || mb->errors)
return q;
ValRecord cst = { .vtype = TYPE_void, .val.oval = oid_nil };
- msg = convertConstant(tpe, &cst);
+ msg = convertConstant(mb->ma, tpe, &cst);
if (msg != MAL_SUCCEED) {
addMalException(mb, msg);
freeException(msg);
@@ -639,7 +639,7 @@ pushZero(MalBlkPtr mb, InstrPtr q, int t
if (q == NULL || mb->errors)
return q;
ValRecord cst = { .vtype = TYPE_int, .val.ival = 0 };
- msg = convertConstant(tpe, &cst);
+ msg = convertConstant(mb->ma, tpe, &cst);
if (msg != MAL_SUCCEED) {
addMalException(mb, msg);
freeException(msg);
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
@@ -840,7 +840,7 @@ trimMalVariables(MalBlkPtr mb, MalStkPtr
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]