Changeset: 517de1f1bdb8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/517de1f1bdb8
Modified Files:
        clients/Tests/exports.stable.out
        gdk/gdk.h
        gdk/gdk_system.c
        gdk/gdk_system.h
        monetdb5/mal/mal_exception.c
        monetdb5/mal/mal_session.c
        sql/backends/monet5/UDF/pyapi3/conversion3.c
        sql/server/sql_privileges.c
Branch: Dec2025
Log Message:

Do not allocate exceptions on allocators, but use a per-thread buffer.


diffs (187 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
@@ -381,6 +381,7 @@ int MT_join_thread(MT_Id t);
 bool MT_path_absolute(const char *path);
 void MT_sleep_ms(unsigned int ms);
 void MT_thread_deregister(void);
+char *MT_thread_get_exceptbuf(void);
 QryCtx *MT_thread_get_qry_ctx(void);
 const char *MT_thread_getalgorithm(void);
 allocator *MT_thread_getallocator(void);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1023,7 +1023,7 @@ BATnegateprops(BAT *b)
        b->tmaxpos = b->tminpos = BUN_NONE;
 }
 
-#define GDKMAXERRLEN   10240
+#define GDKMAXERRLEN   5120
 #define GDKERROR       "!ERROR: "
 #define GDKFATAL       "!FATAL: "
 
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -229,6 +229,7 @@ struct mtthread {
        MT_Id tid;
        uintptr_t sp;
        char gdkerrbuf[GDKMAXERRLEN];
+       char malexcept[GDKMAXERRLEN];
        struct freebats freebats;
 };
 static struct mtthread mainthread = {
@@ -637,6 +638,16 @@ MT_thread_get_qry_ctx(void)
        return self ? self->qry_ctx : NULL;
 }
 
+char *
+MT_thread_get_exceptbuf(void)
+{
+       if (!thread_initialized)
+               return NULL;
+       struct mtthread *self = thread_self();
+
+       return self ? self->malexcept : NULL;
+}
+
 void
 MT_thread_setlockwait(MT_Lock *lock)
 {
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -190,6 +190,7 @@ 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 char *GDKgetbuf(void);
+gdk_export char *MT_thread_get_exceptbuf(void);
 
 #if SIZEOF_VOID_P == 4
 /* "limited" stack size on 32-bit systems */
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -74,33 +74,35 @@ static str
 createExceptionInternal(enum malexception type, const char *fcn,
                                                const char *format, va_list ap)
 {
-       size_t msglen;
        int len;
        char *msg;
        va_list ap2;
 
        va_copy(ap2, ap);                       /* we need to use it twice */
-       msglen = strlen(exceptionNames[type]) + strlen(fcn) + 2;
        len = vsnprintf(NULL, 0, format, ap);   /* count necessary length */
        if (len < 0) {
                TRC_CRITICAL(MAL_SERVER, "called with bad arguments");
                len = 0;
        }
-       allocator *ma = MT_thread_getallocator();
-       assert(ma);
-       msg = ma_alloc(ma, msglen + len + 2);
+       msg = MT_thread_get_exceptbuf();
        if (msg != NULL) {
                /* the calls below succeed: the arguments have already been 
checked */
-               (void) strconcat_len(msg, msglen + 1,
-                                                        exceptionNames[type], 
":", fcn, ":", NULL);
-               if (len > 0)
-                       (void) vsnprintf(msg + msglen, len + 1, format, ap2);
-               va_end(ap2);
+               size_t msglen = strconcat_len(msg, GDKMAXERRLEN, 
exceptionNames[type],
+                                                                         ":", 
fcn, ":", NULL);
+               if (len > 0 && msglen < GDKMAXERRLEN) {
+                       int prlen = vsnprintf(msg + msglen, GDKMAXERRLEN - 
msglen, format, ap2);
+                       if (msglen + prlen >= GDKMAXERRLEN)
+                               strcpy(msg + GDKMAXERRLEN - 5, "...\n");
+               }
                char *q = msg + strlen(msg);
                if (q[-1] != '\n') {
-                       /* make sure message ends with newline, we already have 
the space */
-                       *q++ = '\n';
-                       *q = '\0';
+                       /* make sure message ends with newline */
+                       if (q >= msg + GDKMAXERRLEN - 1) {
+                               strcpy(msg + GDKMAXERRLEN - 5, "...\n");
+                       } else {
+                               *q++ = '\n';
+                               *q = '\0';
+                       }
                }
                q = msg;
                for (char *p = strchr(msg, '\n'); p; q = p + 1, p = strchr(q, 
'\n'))
diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c
--- a/monetdb5/mal/mal_session.c
+++ b/monetdb5/mal/mal_session.c
@@ -553,13 +553,17 @@ optimizeMALBlock(Client cntxt, MalBlkPtr
                                mb->errors = NULL;
                        }
                        if (msg) {
-                               str place = getExceptionPlace(mb->ma, msg);
+                               allocator *ma = MT_thread_getallocator();
+                               allocator_state ma_state = ma_open(ma);
+                               str place = getExceptionPlace(ma, msg);
                                str nmsg = NULL;
                                if (place) {
+                                       nmsg = ma_strdup(ma, 
getExceptionMessageAndState(msg));
                                        nmsg = 
createException(getExceptionType(msg), place, "%s",
-                                                                               
   getExceptionMessageAndState(msg));
+                                                                               
   nmsg);
                                        //GDKfree(place);
                                }
+                               ma_close(ma, &ma_state);
                                if (nmsg) {
                                        freeException(msg);
                                        msg = nmsg;
diff --git a/sql/backends/monet5/UDF/pyapi3/conversion3.c 
b/sql/backends/monet5/UDF/pyapi3/conversion3.c
--- a/sql/backends/monet5/UDF/pyapi3/conversion3.c
+++ b/sql/backends/monet5/UDF/pyapi3/conversion3.c
@@ -596,11 +596,14 @@ PyDict_CheckForConversion(PyObject *pRes
                Py_INCREF(object);
                object = PyObject_CheckForConversion(object, 1, NULL, 
return_message);
                if (object == NULL) {
+                       allocator *ma = MT_thread_getallocator();
+                       allocator_state ma_state = ma_open(ma);
+                       msg = ma_strdup(ma, 
getExceptionMessage(*return_message));
                        msg = createException(
                                MAL, "pyapi3.eval",
                                SQLSTATE(PY000) "Error converting dict return 
value \"%s\": %s",
-                               retcol_names[i], 
getExceptionMessage(*return_message));
-                       freeException(*return_message);
+                               retcol_names[i], msg);
+                       ma_close(ma, &ma_state);
                        goto wrapup;
                }
                if (PyList_CheckExact(object)) {
diff --git a/sql/server/sql_privileges.c b/sql/server/sql_privileges.c
--- a/sql/server/sql_privileges.c
+++ b/sql/server/sql_privileges.c
@@ -871,20 +871,13 @@ sql_create_user(mvc *sql, char *user, ch
                throw(SQL, "sql.create_user", SQLSTATE(HY013) MAL_MALLOC_FAIL);
 
        if ((err = backend_create_user(sql, user, passwd, enc, fullname, 
schema_id, schema_path, sql->user_id, max_memory,
-                                       max_workers, optimizer, role_id)) != 
NULL)
-       {
+                                       max_workers, optimizer, role_id)) != 
NULL) {
                /* strip off MAL exception decorations */
-               char *r;
-               char *e = err;
-               if ((e = strchr(e, ':')) == NULL) {
-                       e = err;
-               } else if ((e = strchr(++e, ':')) == NULL) {
-                       e = err;
-               } else {
-                       e++;
-               }
-               r = createException(SQL,"sql.create_user", SQLSTATE(M0M27) 
"CREATE USER: %s", e);
-               //_DELETE(err);
+               allocator *ma = MT_thread_getallocator();
+               allocator_state ma_state = ma_open(ma);
+               char *r = ma_strdup(ma, getExceptionMessageAndState(err));
+               r = createException(SQL,"sql.create_user", SQLSTATE(M0M27) 
"CREATE USER: %s", r);
+               ma_close(ma, &ma_state);
                return r;
        }
 
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to