Changeset: 7e640bd395a6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7e640bd395a6
Modified Files:
        
Branch: Aug2011
Log Message:

Merge with Aug2011


diffs (truncated from 408 to 300 lines):

diff --git a/gdk/gdk.mx b/gdk/gdk.mx
--- a/gdk/gdk.mx
+++ b/gdk/gdk.mx
@@ -401,10 +401,6 @@
 #endif
 #endif
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #include "gdk_system.h"
 #include "gdk_posix.h"
 #include <stream.h>
@@ -2621,9 +2617,6 @@
 #define THRset_errbuf(t,b)     (t->data[2] = b)
 
 #ifndef GDK_NOLINK
-#ifdef __cplusplus
-extern "C" {
-#endif
 
 static inline bat
 BBPcheck(register bat x, register const char *y)
@@ -2680,9 +2673,6 @@
        return BBP_cache(-b->batCacheid);
 }
 
-#ifdef __cplusplus
-}
-#endif
 #endif
 
 /*
@@ -3422,10 +3412,6 @@
 
 typedef void (*ColFcn) (ptr, ptr);
 typedef void (*RowFcn) (ptr, ptr *);
-
-#ifdef __cplusplus
-}
-#endif
 @
 
 @h
diff --git a/gdk/gdk_atoms.mx b/gdk/gdk_atoms.mx
--- a/gdk/gdk_atoms.mx
+++ b/gdk/gdk_atoms.mx
@@ -89,9 +89,6 @@
 This leads to the following type descriptor table.
 @h
 
-#ifdef __cplusplus
-extern "C" {
-#endif
 gdk_export int lngFromStr(str src, int *len, lng **dst);
 gdk_export int lngToStr(str *dst, int *len, lng *src);
 gdk_export int intFromStr(str src, int *len, int **dst);
@@ -122,9 +119,6 @@
 gdk_export int strNil(const char *s);
 gdk_export int escapedStrlen(const char *src);
 gdk_export int escapedStr(char *dst, const char *src, int dstlen);
-#ifdef __cplusplus
-}
-#endif
 @- inline comparison routines
 Return 0 on l==r, < 0 iff l < r, >0 iff l > r  
 @c
@@ -1358,11 +1352,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,13 @@
 }
 @= acc_move
 {
-       char *htmp = alloca(hs);
-       char *ttmp = alloca(ts);
-
+       char tmp[16];
+       /* avoid compiler warning: dereferencing type-punned pointer
+        * will break strict-aliasing rules */
+       char *tmpp = tmp;
+
+       assert(hs <= 16);
+       assert(ts <= 16);
        if (b->H->hash) {
                HASHmove(b->H->hash, @3, @4, BUNhead(bi, @1), @1 < last); 
        }
@@ -1081,15 +1085,18 @@
        }
 
        /* move first to tmp */
-       @:un_move(Hloc(b,@1),htmp,hs)@
-       @:un_move(Tloc(b,@1),ttmp,ts)@
+       @:un_move(Hloc(b,@1),tmpp,hs)@
        /* move delete to first */
        @:un_move(Hloc(b,@2),Hloc(b,@1),hs)@
+       /* move first to deleted */
+       @:un_move(tmpp,Hloc(b,@2),hs)@
+
+       /* move first to tmp */
+       @:un_move(Tloc(b,@1),tmpp,ts)@
+       /* move delete to first */
        @:un_move(Tloc(b,@2),Tloc(b,@1),ts)@
        /* move first to deleted */
-       @:un_move(htmp,Hloc(b,@2),hs)@
-       @:un_move(ttmp,Tloc(b,@2),ts)@
-
+       @:un_move(tmpp,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)
diff --git a/monetdb5/modules/mal/remote.mx b/monetdb5/modules/mal/remote.mx
--- a/monetdb5/modules/mal/remote.mx
+++ b/monetdb5/modules/mal/remote.mx
@@ -1498,6 +1498,6 @@
        return(MAL_SUCCEED);
 }
 
-@h /* _REMOTE_DEF */
-#endif
+@h
+#endif /* _REMOTE_DEF */
 @}
diff --git a/sql/test/BugTracker-2011/Tests/All 
b/sql/test/BugTracker-2011/Tests/All
--- a/sql/test/BugTracker-2011/Tests/All
+++ b/sql/test/BugTracker-2011/Tests/All
@@ -28,3 +28,4 @@
 blob-update-crash.Bug-2832
 select_value_insert_into.Bug-2845
 recursive_case.Bug-2838
+str_cast_exception.Bug-2847
diff --git a/sql/test/BugTracker-2011/Tests/str_cast_exception.Bug-2847.sql 
b/sql/test/BugTracker-2011/Tests/str_cast_exception.Bug-2847.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2011/Tests/str_cast_exception.Bug-2847.sql
@@ -0,0 +1,14 @@
+START TRANSACTION;
+
+CREATE SCHEMA "testschema";
+CREATE TABLE "testschema"."test" (
+        "type"                        CHARACTER LARGE OBJECT NOT NULL,
+        "output"                      CHARACTER LARGE OBJECT NOT NULL,
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to