Changeset: 6e534d939e36 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6e534d939e36
Modified Files:
        monetdb5/mal/mal_interpreter.mx
        monetdb5/modules/mal/tablet_sql.c
Branch: default
Log Message:

Merge with Dec2011 branch.


diffs (245 lines):

diff --git a/monetdb5/mal/mal_interpreter.mx b/monetdb5/mal/mal_interpreter.mx
--- a/monetdb5/mal/mal_interpreter.mx
+++ b/monetdb5/mal/mal_interpreter.mx
@@ -89,7 +89,7 @@ mal_export int DFLOWadmission(lng argcla
 #define heapinfo(X) if ((X) && (X)->base) vol = (X)->free; else vol = 0;
 #define hashinfo(X) if ((X) && (X)->mask) vol = ((X)->mask + (X)->lim + 1) * 
sizeof(int) + sizeof(*(X)); else vol = 0;
 
-#define FREE_EXCEPTION(p) { if (p && p != M5OutOfMemory) GDKfree(p); }
+#define FREE_EXCEPTION(p) do { if (p && p != M5OutOfMemory) GDKfree(p); } 
while (0)
 
 /*
  * @-
@@ -134,12 +134,13 @@ ptr getArgReference(MalStkPtr stk, Instr
 void showErrors(Client cntxt)
 {
        int i;
-       if (cntxt->errbuf && *cntxt->errbuf) {
-               i = (int)strlen(cntxt->errbuf);
-               mnstr_printf(cntxt->fdout, "%s", cntxt->errbuf);
-               if (cntxt->errbuf[i - 1] != '\n')
+       char *errbuf = GDKerrbuf;
+       if (errbuf && *errbuf) {
+               i = (int)strlen(errbuf);
+               mnstr_printf(cntxt->fdout, "%s", errbuf);
+               if (errbuf[i - 1] != '\n')
                        mnstr_printf(cntxt->fdout, "\n");
-               cntxt->errbuf[0] = '\0';
+               errbuf[0] = '\0';
        }
 }
 /*
@@ -972,7 +973,6 @@ DFLOWstep(FlowTask *t, FlowStatus fs)
        printf("#EXECUTE THREAD %d \n", tid);
        printInstruction(GDKstdout, flow->mb, 0, pci, LIST_MAL_STMT | 
LIST_MAPI);
 #endif
-       THRset_errbuf(THRget(THRgettid()), cntxt->errbuf);  /* where to leave 
errors */
        if (stk->cmd || mb->trap) {
                lng tm = 0;
                if (oldtimer)
@@ -1079,6 +1079,8 @@ runDFLOWworker(void *t)
        int i, local = 0, last = 0;
 
        thr = THRnew(MT_getpid(), "DFLOWworker");
+       GDKsetbuf(GDKmalloc(GDKMAXERRLEN));     /* where to leave errors */
+       GDKerrbuf[0] = 0;
        while (task) {
                local = nxtfs != 0;
                if (nxtfs == 0)
@@ -1137,6 +1139,8 @@ runDFLOWworker(void *t)
                else
                        q_enqueue(task->flow->done, fs);
        }
+       GDKfree(GDKerrbuf);
+       GDKsetbuf(0);
        THRdel(thr);
 }
 
@@ -2308,32 +2312,35 @@ mal_export str catchKernelException(Clie
 str catchKernelException(Client cntxt, str ret)
 {
        str z;
-       if (cntxt->errbuf && cntxt->errbuf[0]) {
+       char *errbuf = GDKerrbuf;
+       (void) cntxt;
+       if (errbuf && errbuf[0]) {
                if (ret != MAL_SUCCEED) {
-                       z = (char*)GDKmalloc(strlen(ret) + 
strlen(cntxt->errbuf) + 2);
+                       z = (char*)GDKmalloc(strlen(ret) + strlen(errbuf) + 2);
                        if (z) {
                                strcpy(z, ret);
                                if (z[strlen(z) - 1] != '\n') strcat(z, "\n");
-                               strcat(z, cntxt->errbuf);
+                               strcat(z, errbuf);
                        }
                } else {
                        /* trap hidden (GDK) exception */
-                       z = (char*)GDKmalloc(strlen("GDKerror:") + 
strlen(cntxt->errbuf) + 2);
+                       z = (char*)GDKmalloc(strlen("GDKerror:") + 
strlen(errbuf) + 2);
                        if (z)
-                               sprintf(z, "GDKerror:%s\n", cntxt->errbuf);
+                               sprintf(z, "GDKerror:%s\n", errbuf);
                }
                /* did we eat the error away of not */
                if (z)
-                       cntxt->errbuf[0] = '\0';
+                       errbuf[0] = '\0';
        } else
                z = ret;
        return z;
 }
 @= exceptionHndlr
-if (cntxt->errbuf && cntxt->errbuf[0]) {
+if (GDKerrbuf && GDKerrbuf[0]) {
        str oldret = ret;
        ret = catchKernelException(cntxt, ret);
-       FREE_EXCEPTION(oldret);
+       if (ret != oldret)
+               FREE_EXCEPTION(oldret);
 }
 
 if (ret != MAL_SUCCEED) {
diff --git a/monetdb5/modules/atoms/str.mx b/monetdb5/modules/atoms/str.mx
--- a/monetdb5/modules/atoms/str.mx
+++ b/monetdb5/modules/atoms/str.mx
@@ -2457,7 +2457,7 @@ STRrepeat(str *ret, str *s, int *c)
                        throw(MAL, "str.repeat", "Allocation failed");
                *t = 0;
                for(i = *c; i>0; i--, t += l) 
-                       strcat(t, *s);
+                       strcpy(t, *s);
        }
        return MAL_SUCCEED;
 }
diff --git a/monetdb5/modules/mal/tablet_sql.c 
b/monetdb5/modules/mal/tablet_sql.c
--- a/monetdb5/modules/mal/tablet_sql.c
+++ b/monetdb5/modules/mal/tablet_sql.c
@@ -332,9 +332,12 @@ SQLworker(void *arg)
        unsigned int i;
        int j, piece;
        lng t0;
+       Thread thr;
 
-       /* where to leave errors */
-       THRset_errbuf(THRget(THRgettid()), task->errbuf);
+       thr = THRnew(MT_getpid(), "SQLworker");
+       GDKsetbuf(GDKmalloc(GDKMAXERRLEN));     /* where to leave errors */
+       GDKerrbuf[0] = 0;
+       task->errbuf = GDKerrbuf;
 #ifdef _DEBUG_TABLET_
        mnstr_printf(GDKout, "SQLworker %d started\n", task->id);
 #endif
@@ -350,7 +353,7 @@ SQLworker(void *arg)
 #ifdef _DEBUG_TABLET_
                        mnstr_printf(GDKout, "SQLworker terminated\n");
 #endif
-                       return;
+                       goto do_return;
                }
 
                /* stage one, break the lines spread the worker over the 
workers */
@@ -386,6 +389,11 @@ SQLworker(void *arg)
 #ifdef _DEBUG_TABLET_
        mnstr_printf(GDKout, "SQLworker exits\n");
 #endif
+
+  do_return:
+       GDKfree(GDKerrbuf);
+       GDKsetbuf(0);
+       THRdel(thr);
 }
 
 static void
@@ -446,8 +454,6 @@ SQLworkdivider(READERtask *task, READERt
  * Reading is handled by a separate task as a preparation for
  * mode parallelism
  */
-static void SQLloader(void *p)
-       __attribute__ ((__noreturn__));
 static void
 SQLloader(void *p)
 {
@@ -466,7 +472,6 @@ SQLloader(void *p)
                task->ateof = tablet_read_more(task->b, task->out, 
task->b->size - (task->b->len - task->b->pos)) == EOF;
                MT_sema_up(&task->consumer, "tablet loader");
        }
-       MT_exit_thread(0);
 }
 
 BUN
diff --git a/sql/backends/monet5/UDF/README b/sql/backends/monet5/UDF/README
--- a/sql/backends/monet5/UDF/README
+++ b/sql/backends/monet5/UDF/README
@@ -1,2 +1,3 @@
 This directory is a template for extending SQL with a new scalar type.
-See the website for further documentation.
+For further documentation, see the MonetDB website at
+http://www.monetdb.org/Documentation/Cookbooks/SQLrecipies/Extensions
diff --git a/sql/backends/monet5/UDF/udf.c b/sql/backends/monet5/UDF/udf.c
--- a/sql/backends/monet5/UDF/udf.c
+++ b/sql/backends/monet5/UDF/udf.c
@@ -22,15 +22,18 @@
 #include "udf.h"
 
 static str
-reverse(str src)
+reverse(const char *src)
 {
-       int len;
+       size_t len;
        str ret, new;
 
        /* The scalar function returns the new space */
-       len = (int) strlen(src);
-       ret = new = GDKzalloc(len + 1);
-       for (len--; len >= 0; len--)
+       len = strlen(src);
+       ret = new = GDKmalloc(len + 1);
+       if (new == NULL)
+               return NULL;
+       new[len] = 0;
+       while (--len != 0)
                *new++ = src[len];
        return ret;
 }
@@ -62,13 +65,14 @@ str UDFBATreverse(int *ret, int *bid)
 
        /* create the result container */
        bn = BATnew(left->htype, TYPE_str, BATcount(left));
-       if (left->htype == TYPE_void)
-               BATseqbase(bn, left->hseqbase);
        if (bn == NULL) {
                BBPreleaseref(left->batCacheid);
                throw(MAL, "mal.reverse", MAL_MALLOC_FAIL);
        }
 
+       if (left->htype == TYPE_void)
+               BATseqbase(bn, left->hseqbase);
+
        /* manage the properties of the result */
        bn->hsorted = left->hsorted;
        bn->tsorted = 0;  /* assume not sorted afterwards */
@@ -78,18 +82,19 @@ str UDFBATreverse(int *ret, int *bid)
        BATaccessBegin(left, USE_HEAD | USE_TAIL, MMAP_SEQUENTIAL);
 
        /* the core of the algorithm, expensive due to malloc/frees */
-       BATloop(left, p, q)
-       {
+       BATloop(left, p, q) {
                ptr h = BUNhead(li, p);
                str tl = (str) BUNtail(li, p);
                v = reverse(tl);
+               if (v == NULL)
+                       goto bunins_failed;
                bunfastins(bn, h, v);
                GDKfree(v);
        }
        BATaccessEnd(left, USE_HEAD | USE_TAIL, MMAP_SEQUENTIAL);
        if (!(bn->batDirty & 2))
-               (bn) = BATsetaccess(bn, BAT_READ);
-       *ret = (bn)->batCacheid;
+               bn = BATsetaccess(bn, BAT_READ);
+       *ret = bn->batCacheid;
        BBPkeepref(*ret);
        BBPreleaseref(left->batCacheid);
        return MAL_SUCCEED;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to