Changeset: fa9db9aff095 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/fa9db9aff095
Modified Files:
        clients/Tests/exports.stable.out
        gdk/gdk_system.c
        gdk/gdk_system.h
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_client.h
        monetdb5/mal/mal_dataflow.c
        monetdb5/modules/mal/tablet.c
Branch: Dec2025
Log Message:

Clean up GDK error buffer handling.
Each thread automatically gets its own, private GDK error buffer (aka
GDKerrbuf).  We no longer need errbuf fields in the client context or
the tablet task structure.


diffs (203 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -320,7 +320,6 @@ void GDKqsort(void *restrict h, void *re
 void *GDKrealloc(void *pold, size_t size) __attribute__((__alloc_size__(2))) 
__attribute__((__warn_unused_result__));
 gdk_return GDKrebuild_segment_tree(oid ncount, oid data_size, BAT *st, void 
**segment_tree, oid **levels_offset, oid *nlevels);
 void GDKreset(int status);
-void GDKsetbuf(char *);
 void GDKsetdebug(unsigned debug);
 gdk_return GDKsetenv(const char *name, const char *value);
 stream *GDKstdin;
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -228,7 +228,7 @@ struct mtthread {
 #endif
        MT_Id tid;
        uintptr_t sp;
-       char *errbuf;
+       char gdkerrbuf[GDKMAXERRLEN];
        struct freebats freebats;
 };
 static struct mtthread mainthread = {
@@ -552,20 +552,6 @@ MT_thread_getname(void)
        return self ? self->threadname : UNKNOWN_THREAD;
 }
 
-void
-GDKsetbuf(char *errbuf)
-{
-       struct mtthread *self;
-
-       self = thread_self();
-       if (self == NULL)
-               self = &mainthread;
-       assert(errbuf == NULL || self->errbuf == NULL);
-       self->errbuf = errbuf;
-       if (errbuf)
-               *errbuf = 0;            /* start clean */
-}
-
 char *
 GDKgetbuf(void)
 {
@@ -574,7 +560,7 @@ GDKgetbuf(void)
        self = thread_self();
        if (self == NULL)
                self = &mainthread;
-       return self->errbuf;
+       return self->gdkerrbuf;
 }
 
 struct freebats *
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -189,7 +189,6 @@ gdk_export MT_Id MT_getpid(void);
 gdk_export int MT_join_thread(MT_Id t);
 gdk_export QryCtx *MT_thread_get_qry_ctx(void);
 gdk_export void MT_thread_set_qry_ctx(QryCtx *ctx);
-gdk_export void GDKsetbuf(char *);
 gdk_export char *GDKgetbuf(void);
 
 #if SIZEOF_VOID_P == 4
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -254,7 +254,6 @@ MCinitClientRecord(Client c, oid user, b
        ATOMIC_SET(&c->qryctx.datasize, 0);
        c->qryctx.maxmem = 0;
        c->maxmem = 0;
-       c->errbuf = 0;
 
        c->prompt = PROMPT1;
        c->promptlength = strlen(c->prompt);
@@ -306,16 +305,7 @@ MCinitClientThread(Client c)
         * the proper IO descriptors.
         */
        c->mythread = MT_thread_getname();
-       c->errbuf = GDKerrbuf;
-       if (c->errbuf == NULL) {
-               char *n = ma_zalloc(c->ma, GDKMAXERRLEN);
-               if (n == NULL) {
-                       return -1;
-               }
-               GDKsetbuf(n);
-               c->errbuf = GDKerrbuf;
-       } else
-               c->errbuf[0] = 0;
+       GDKclrerr();
        return 0;
 }
 
@@ -361,13 +351,6 @@ MCcloseClient(Client c)
        c->scenario = NULL;
        c->prompt = NULL;
        c->promptlength = -1;
-       if (c->errbuf) {
-               /* no client threads in embedded mode */
-               GDKsetbuf(NULL);
-               //if (c->father == NULL)
-               //      GDKfree(c->errbuf);
-               c->errbuf = NULL;
-       }
        if (c->usermodule)
                freeModule(c->usermodule);
        c->usermodule = c->curmodule = 0;
diff --git a/monetdb5/mal/mal_client.h b/monetdb5/mal/mal_client.h
--- a/monetdb5/mal/mal_client.h
+++ b/monetdb5/mal/mal_client.h
@@ -148,7 +148,6 @@ typedef struct CLIENT {
         */
        MT_Sema s;                                      /* sema to (de)activate 
thread */
        const char *mythread;
-       char *errbuf;                                   /* location of GDK 
exceptions */
        struct CLIENT *father;
        /*
         * Each client has a private entry point into the namespace and
diff --git a/monetdb5/mal/mal_dataflow.c b/monetdb5/mal/mal_dataflow.c
--- a/monetdb5/mal/mal_dataflow.c
+++ b/monetdb5/mal/mal_dataflow.c
@@ -88,7 +88,6 @@ struct worker {
        ATOMIC_PTR_TYPE cntxt;          /* client we do work for (NULL -> any) 
*/
        MT_Sema s;
        struct worker *next;
-       char errbuf[GDKMAXERRLEN];      /* GDKerrbuf so that we can allocate 
before fork */
 };
 /* heads of three mutually exclusive linked lists, all using the .next
  * field in the worker struct */
@@ -251,7 +250,6 @@ DFLOWworker(void *T)
 #ifdef _MSC_VER
        srand((unsigned int) GDKusec());
 #endif
-       GDKsetbuf(t->errbuf);           /* where to leave errors */
        snprintf(t->s.name, sizeof(t->s.name), "DFLOWsema%04zu", MT_getpid());
        allocator *ma = MT_thread_getallocator();
 
@@ -450,7 +448,6 @@ DFLOWworker(void *T)
                exited_workers = t;
        }
        MT_lock_unset(&dataflowLock);
-       GDKsetbuf(NULL);
 }
 
 /*
diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -572,7 +572,6 @@ typedef struct {
        MT_Sema sema;                           /* threads wait for work , 
negative next implies exit */
        MT_Sema reply;                          /* let reader continue */
        Tablet *as;
-       char *errbuf;
        const char *csep, *rsep;
        size_t seplen, rseplen;
 
@@ -1100,9 +1099,7 @@ SQLworker(void *arg)
        int j, piece;
        lng t0;
 
-       GDKsetbuf(GDKmalloc(GDKMAXERRLEN));     /* where to leave errors */
        GDKclrerr();
-       task->errbuf = GDKerrbuf;
        MT_thread_set_qry_ctx(task->set_qry_ctx ? &task->cntxt->qryctx : NULL);
        allocator *ma = task->cntxt->curprg->def->ma;
        assert(ma);
@@ -1157,8 +1154,6 @@ SQLworker(void *arg)
        MT_sema_up(&task->reply);
 
   do_return:
-       GDKfree(GDKerrbuf);
-       GDKsetbuf(NULL);
        MT_thread_set_qry_ctx(NULL);
 }
 
@@ -1322,14 +1317,12 @@ SQLproducer(void *p)
                        goto reportlackofinput;
                }
 
-               if (task->errbuf && task->errbuf[0]) {
-                       if (unlikely(GDKerrbuf && GDKerrbuf[0])) {
-                               tablet_error(task, rowno, lineno, int_nil, 
GDKerrbuf,
-                                                        "SQLload_file");
+               if (GDKerrbuf[0]) {
+                       tablet_error(task, rowno, lineno, int_nil, GDKerrbuf,
+                                                "SQLload_file");
 /*                             TRC_DEBUG(MAL_SERVER, "Bailout on SQLload\n");*/
-                               ateof[cur] = true;
-                               break;
-                       }
+                       ateof[cur] = true;
+                       break;
                }
 
   parseSTDIN:
@@ -1663,7 +1656,6 @@ SQLload_file(Client cntxt, Tablet *as, b
        task.seplen = strlen(csep);
        task.rsep = rsep;
        task.rseplen = strlen(rsep);
-       task.errbuf = cntxt->errbuf;
 
        MT_sema_init(&task.producer, 0, "task.producer");
        MT_sema_init(&task.consumer, 0, "task.consumer");
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to