Changeset: 59a417367725 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=59a417367725
Modified Files:
gdk/gdk_atoms.mx
gdk/gdk_bat.mx
gdk/gdk_relop.mx
gdk/gdk_ssort.mx
Branch: Aug2011
Log Message:
Do not use alloca.
This changeset removes all occurrences of alloca in GDK.
diffs (186 lines):
diff --git a/gdk/gdk_atoms.mx b/gdk/gdk_atoms.mx
--- a/gdk/gdk_atoms.mx
+++ b/gdk/gdk_atoms.mx
@@ -1358,11 +1358,12 @@
t = r;
while ((c = *t) && (c == '_' || GDKisalnum(c)))
t++;
- s = (char *) alloca((unsigned) (1 + t - r));
+ s = GDKmalloc((unsigned) (1 + t - r));
if (s != NULL) {
strncpy(s, r, t - r);
s[t - r] = 0;
bid = BBPindex(s);
+ GDKfree(s);
}
**dst = bid == 0 ? bat_nil : bid;
return (int) (t + (c == '>') - src);
diff --git a/gdk/gdk_bat.mx b/gdk/gdk_bat.mx
--- a/gdk/gdk_bat.mx
+++ b/gdk/gdk_bat.mx
@@ -1070,9 +1070,11 @@
}
@= acc_move
{
- char *htmp = alloca(hs);
- char *ttmp = alloca(ts);
-
+ char htmp[16];
+ char ttmp[16];
+
+ assert(hs <= 16);
+ assert(ts <= 16);
if (b->H->hash) {
HASHmove(b->H->hash, @3, @4, BUNhead(bi, @1), @1 < last);
}
@@ -1089,7 +1091,6 @@
/* move first to deleted */
@:un_move(htmp,Hloc(b,@2),hs)@
@:un_move(ttmp,Tloc(b,@2),ts)@
-
}
@- BUN Insertion
diff --git a/gdk/gdk_relop.mx b/gdk/gdk_relop.mx
--- a/gdk/gdk_relop.mx
+++ b/gdk/gdk_relop.mx
@@ -84,19 +84,24 @@
_slices++;
}
if (_slices > SAMPLE_TRESHOLD_LOG) {
- /* use cheapo sampling by taking a number of slices and
joining those with the algo */
+ /* use cheapo sampling by taking a number of
+ * slices and joining those with the algo */
BUN _idx = 0, _tot = 0, _step, _lo, _avg, _sample,
*_cnt;
BAT *_tmp1 = l, *_tmp2, *_tmp3 = NULL;
_step = _lcount / (_slices -= SAMPLE_TRESHOLD_LOG);
_sample = _slices * SAMPLE_SLICE_SIZE;
- _cnt = (BUN *) alloca(_slices * sizeof(BUN));
+ _cnt = GDKmalloc(_slices * sizeof(BUN));
+ if (_cnt == NULL)
+ return NULL;
for (_lo = 0; _idx < _slices; _lo += _step) {
BUN _size = 0, _hi = _lo + SAMPLE_SLICE_SIZE;
l = BATslice(_tmp1, _lo, _hi); /* slice keeps
all parent properties */
- if (l == NULL)
+ if (l == NULL) {
+ GDKfree(_cnt);
return NULL;
+ }
_tmp2 = @2; /* @2 = e.g. BATXjoin(l,r) */
if (_tmp2) {
_size = BATcount(_tmp2);
@@ -105,7 +110,8 @@
_tot += (_cnt[_idx++] = _size);
BBPreclaim(l);
}
- /* do outlier detection on sampling results; this
guards against skew */
+ /* do outlier detection on sampling results;
+ * this guards against skew */
if (@1 == JOIN_EQ) {
for (_avg = _tot / _slices, _idx = 0; _idx <
_slices; _idx++) {
BUN _diff = _cnt[_idx] - _avg;
@@ -116,7 +122,9 @@
break;
}
if (_idx < _slices) {
- /* outliers detected, compute a real
sample on at most 1% of the data */
+ /* outliers detected, compute
+ * a real sample on at most 1%
+ * of the data */
_sample = MIN(_lcount / 100, (1 <<
SAMPLE_TRESHOLD_LOG) / 3);
_tmp2 = BATsample(_tmp1, _sample);
if (_tmp2) {
@@ -127,10 +135,13 @@
}
BBPreclaim(_tmp2);
}
- if (_tmp3 == NULL)
+ if (_tmp3 == NULL) {
+ GDKfree(_cnt);
return NULL;
+ }
}
}
+ GDKfree(_cnt);
/* overestimate always by 5% */
{
double _d = (double) (((lng) _tot) * ((lng)
_lcount)) / (0.95 * (double) _sample);
@@ -2997,8 +3008,8 @@
int
BATmultijoin(int argc, BAT *argv[], RowFcn tuple_fcn, ptr tuple_data, ColFcn
value_fcn[], ptr value_data[], int orderby)
{
- column_t *lead_col, *c = (column_t *) alloca(argc * (int)
sizeof(column_t));
- column_t **reorder = (column_t **) alloca(argc * (int) sizeof(column_t
*));
+ column_t *lead_col, *c = (column_t *) GDKmalloc(argc * (int)
sizeof(column_t));
+ column_t **reorder = (column_t **) GDKmalloc(argc * (int)
sizeof(column_t *));
int status = 0, algo = LEAD_TRAVERSE_SEQ;
int i, k;
BUN p, q;
@@ -3007,6 +3018,11 @@
@-
Init the table descriptor.
@c
+ if (c == NULL || reorder == NULL) {
+ GDKfree(c);
+ GDKfree(reorder);
+ return 0;
+ }
memset(c, 0, argc * sizeof(column_t));
t.tuple_data = tuple_data;
t.value_data = value_data;
@@ -3137,11 +3153,15 @@
} else if (!BAThkey(n->b) && n->sync == NULL) {
if (BATprepareHash(n->b)) {
GDKerror("BATmultijoin: could not hash '%s'\n",
BATgetId(n->b));
+ GDKfree(c);
+ GDKfree(reorder);
return 0;
}
n->hitsize = 20;
n->hit = (BUN *) GDKmalloc(n->hitsize * sizeof(BUN));
if (n->hit == NULL) {
+ GDKfree(c);
+ GDKfree(reorder);
return 0;
}
}
@@ -3172,6 +3192,8 @@
if (c[i].hitsize)
GDKfree(c[i].hit);
}
+ GDKfree(c);
+ GDKfree(reorder);
return status;
}
diff --git a/gdk/gdk_ssort.mx b/gdk/gdk_ssort.mx
--- a/gdk/gdk_ssort.mx
+++ b/gdk/gdk_ssort.mx
@@ -62,8 +62,8 @@
most 2 lng's, we don't need to allocate anything. */
void *th;
void *tt;
- char tempstorageh[sizeof(lng)];
- char tempstoraget[sizeof(lng)];
+ char tempstorageh[16]; /* 16 bytes should be wide enough ... */
+ char tempstoraget[16]; /* ... for all our fixed-sized data */
/* This controls when we get *into* galloping mode. It's
initialized to MIN_GALLOP. merge_lo and merge_hi tend to
@@ -1003,9 +1003,10 @@
if (!t)
t = &temp;
ms.bt = t;
- ms.th = (size_t) hs <= sizeof(ms.tempstorageh) ? ms.tempstorageh :
alloca(hs);
- ms.tt = (size_t) ts <= sizeof(ms.tempstoraget) ? ms.tempstoraget :
alloca(ts);
-
+ ms.th = ms.tempstorageh;
+ ms.tt = ms.tempstoraget;
+ assert((size_t) hs <= sizeof(ms.tempstorageh));
+ assert((size_t) ts <= sizeof(ms.tempstoraget));
nremaining = (ssize_t) nitems;
if (nremaining < 2)
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list