Changeset: 41dd7a96f230 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/41dd7a96f230
Branch: ascii-flag
Log Message:

Merge with default branch.


diffs (truncated from 641 to 300 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
@@ -802,8 +802,8 @@ void TABLETdestroy_format(Tablet *as);
 int TABLEToutput_file(Tablet *as, BAT *order, stream *s, bstream *in);
 int TRACEtable(Client cntxt, BAT **r);
 int TYPE_xml;
-int UTF8_strlen(const char *restrict s);
-int UTF8_strwidth(const char *restrict s);
+int UTF8_strlen(const char *s);
+int UTF8_strwidth(const char *s);
 void addMalException(MalBlkPtr mb, str msg);
 str addOptimizerPipe(Client cntxt, MalBlkPtr mb, const char *name);
 str addPipeDefinition(Client cntxt, const char *name, const char *pipe);
@@ -1253,7 +1253,7 @@ const char *stoptraceRef;
 void strAfterCall(ValPtr v, ValPtr bak);
 void strBeforeCall(ValPtr v, ValPtr bak);
 const char *strRef;
-int str_strlen(const char *restrict s);
+int str_strlen(const char *s);
 const char *streamsRef;
 const char *strimpsRef;
 const char *subavgRef;
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -47,6 +47,10 @@
 
 #include <locale.h>
 
+#ifdef HAVE_WCWIDTH
+#include <wchar.h>
+#endif
+
 #ifdef HAVE_ICONV
 #include <iconv.h>
 #ifdef HAVE_NL_LANGINFO
@@ -413,6 +417,14 @@ utf8strlenmax(char *s, char *e, size_t m
                        c = (c << 6) | (*s & 0x3F);
                        if (--n == 0) {
                                /* last byte of a multi-byte character */
+#ifdef HAVE_WCWIDTH
+                               n = wcwidth(c);
+                               if (n >= 0)
+                                       len += n;
+                               else
+                                       len++;          /* assume width 1 if 
unprintable */
+                               n = 0;
+#else
                                len++;
                                /* this list was created by combining
                                 * the code points marked as
@@ -546,7 +558,7 @@ utf8strlenmax(char *s, char *e, size_t m
                                        len++;
                                else if (0x0080 <= c && c <= 0x009F)
                                        len += 5;
-
+#endif
                        }
                } else if ((*s & 0xE0) == 0xC0) {
                        assert(n == 0);
diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake
--- a/cmake/monetdb-defines.cmake
+++ b/cmake/monetdb-defines.cmake
@@ -118,6 +118,7 @@ function(monetdb_configure_defines)
   check_function_exists("task_info" HAVE_TASK_INFO)
   check_function_exists("times" HAVE_TIMES)
   check_function_exists("uname" HAVE_UNAME)
+  check_symbol_exists("wcwidth" "wchar.h" HAVE_WCWIDTH)
   # Some libc versions on Linux distributions don't have it
   check_symbol_exists("semtimedop" "sys/types.h;sys/ipc.h;sys/sem.h" 
HAVE_SEMTIMEDOP)
   cmake_push_check_state()
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -774,13 +774,14 @@ HEAPincref(Heap *h)
  *
  * If we find file X.new, we move it over X (if present) and open it.
  */
-static gdk_return
-HEAPload_intern(Heap *h, const char *nme, const char *ext, const char *suffix, 
bool trunc)
+gdk_return
+HEAPload(Heap *h, const char *nme, const char *ext, bool trunc)
 {
        size_t minsize;
        int ret = 0;
        char *srcpath, *dstpath;
        lng t0;
+       const char suffix[] = ".new";
 
        if (h->storage == STORE_INVALID || h->newstorage == STORE_INVALID) {
                size_t allocated;
@@ -889,12 +890,6 @@ HEAPload_intern(Heap *h, const char *nme
        return GDK_SUCCEED;
 }
 
-gdk_return
-HEAPload(Heap *h, const char *nme, const char *ext, bool trunc)
-{
-       return HEAPload_intern(h, nme, ext, ".new", trunc);
-}
-
 /*
  * @- HEAPsave
  *
@@ -910,12 +905,13 @@ HEAPload(Heap *h, const char *nme, const
  * After GDKsave returns successfully (>=0), we assume the heaps are
  * safe on stable storage.
  */
-static gdk_return
-HEAPsave_intern(Heap *h, const char *nme, const char *ext, const char *suffix, 
bool dosync, BUN free, MT_Lock *lock)
+gdk_return
+HEAPsave(Heap *h, const char *nme, const char *ext, bool dosync, BUN free, 
MT_Lock *lock)
 {
        storage_t store = h->newstorage;
        long_str extension;
        gdk_return rc;
+       const char suffix[] = ".new";
 
        if (h->base == NULL) {
                GDKerror("no heap to save\n");
@@ -965,12 +961,6 @@ HEAPsave_intern(Heap *h, const char *nme
        return rc;
 }
 
-gdk_return
-HEAPsave(Heap *h, const char *nme, const char *ext, bool dosync, BUN free, 
MT_Lock *lock)
-{
-       return HEAPsave_intern(h, nme, ext, ".new", dosync, free, lock);
-}
-
 int
 HEAPwarm(Heap *h)
 {
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -206,8 +206,10 @@ logbat_new(int tt, BUN size, role_t role
 
        if (nb) {
                BBP_pid(nb->batCacheid) = 0;
-               if (role == PERSISTENT)
+               if (role == PERSISTENT) {
                        BATmode(nb, false);
+                       nb = BATsetaccess(nb, BAT_READ);
+               }
        } else {
                TRC_CRITICAL(GDK, "creating new BAT[%s]#" BUNFMT " failed\n", 
ATOMname(tt), size);
        }
@@ -1661,14 +1663,14 @@ cleanup_and_swap(logger *lg, int *r, con
                if (lid == -1)
                        continue;       /* remove */
 
-               if (BUNappend(nbids, &col, false) != GDK_SUCCEED ||
-                   BUNappend(noids, &nid, false) != GDK_SUCCEED ||
+               if (BUNappend(nbids, &col, true) != GDK_SUCCEED ||
+                   BUNappend(noids, &nid, true) != GDK_SUCCEED ||
                    BUNappend(nlids, &lid, false) != GDK_SUCCEED ||
                    BUNappend(ncnts, &cnt, false) != GDK_SUCCEED)
                        err = 1;
                if (BUNfnd(lg->dcatalog, &pos) != BUN_NONE) {
                        pos = (oid) (BATcount(nbids) - 1);
-                       if (BUNappend(ndels, &pos, false) != GDK_SUCCEED)
+                       if (BUNappend(ndels, &pos, true) != GDK_SUCCEED)
                                err = 1;
                }
        }
@@ -1684,10 +1686,7 @@ cleanup_and_swap(logger *lg, int *r, con
        /* point of no return */
        if (log_switch_bat(catalog_bid, nbids, lg->fn, "catalog_bid") != 
GDK_SUCCEED ||
            log_switch_bat(catalog_id, noids, lg->fn, "catalog_id") != 
GDK_SUCCEED ||
-           log_switch_bat(dcatalog, ndels, lg->fn, "dcatalog") != GDK_SUCCEED 
||
-           (nbids = BATsetaccess(nbids, BAT_READ)) == NULL ||
-           (noids = BATsetaccess(noids, BAT_READ)) == NULL ||
-           (ndels = BATsetaccess(ndels, BAT_READ)) == NULL) {
+           log_switch_bat(dcatalog, ndels, lg->fn, "dcatalog") != GDK_SUCCEED) 
{
                logbat_destroy(nbids);
                logbat_destroy(noids);
                logbat_destroy(ndels);
@@ -1869,9 +1868,7 @@ bm_subcommit(logger *lg, logged_range *p
                BATclear(lg->dseqs, true);
 
                if (log_switch_bat(lg->seqs_id, ids, lg->fn, "seqs_id") != 
GDK_SUCCEED ||
-                   log_switch_bat(lg->seqs_val, vals, lg->fn, "seqs_val") != 
GDK_SUCCEED ||
-                   (ids = BATsetaccess(ids, BAT_READ)) == NULL ||
-                   (vals = BATsetaccess(vals, BAT_READ)) == NULL) {
+                   log_switch_bat(lg->seqs_val, vals, lg->fn, "seqs_val") != 
GDK_SUCCEED) {
                        logbat_destroy(ids);
                        logbat_destroy(vals);
                        GDKfree(n);
@@ -2056,11 +2053,6 @@ log_load(const char *fn, const char *log
                        GDKerror("cannot create catalog bats");
                        goto error;
                }
-               if ((lg->catalog_bid = BATsetaccess(lg->catalog_bid, BAT_READ)) 
== NULL ||
-                   (lg->catalog_id = BATsetaccess(lg->catalog_id, BAT_READ)) 
== NULL ||
-                   (lg->dcatalog = BATsetaccess(lg->dcatalog, BAT_READ)) == 
NULL) {
-                       goto error;
-               }
                TRC_INFO(WAL, "create %s catalog\n", fn);
 
                /* give the catalog bats names so we can find them
@@ -2211,6 +2203,11 @@ log_load(const char *fn, const char *log
                        GDKerror("Logger_new: cannot load seqs bats");
                        goto error;
                }
+               if ((lg->seqs_val = BATsetaccess(lg->seqs_val, BAT_READ)) == 
NULL ||
+                   (lg->seqs_id = BATsetaccess(lg->seqs_id, BAT_READ)) == NULL 
||
+                   (lg->dseqs = BATsetaccess(lg->dseqs, BAT_READ)) == NULL) {
+                       goto error;
+               }
        } else {
                lg->seqs_id = logbat_new(TYPE_int, 1, PERSISTENT);
                lg->seqs_val = logbat_new(TYPE_lng, 1, PERSISTENT);
@@ -2238,11 +2235,6 @@ log_load(const char *fn, const char *log
                }
                needcommit = true;
        }
-       if ((lg->seqs_val = BATsetaccess(lg->seqs_val, BAT_READ)) == NULL ||
-           (lg->seqs_id = BATsetaccess(lg->seqs_id, BAT_READ)) == NULL ||
-           (lg->dseqs = BATsetaccess(lg->dseqs, BAT_READ)) == NULL) {
-               goto error;
-       }
        dbg = ATOMIC_GET(&GDKdebug);
        ATOMIC_AND(&GDKdebug, ~CHECKMASK);
        if (needcommit && bm_commit(lg, NULL, NULL, 0) != GDK_SUCCEED) {
diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -69,6 +69,9 @@
 #include <iconv.h>
 #include <locale.h>
 #endif
+#ifdef HAVE_WCWIDTH
+#include <wchar.h>
+#endif
 #include "mal_interpreter.h"
 
 #include "utf8.h"
@@ -3022,55 +3025,29 @@ STRepilogue(void *ret)
 }
 
 #ifndef NDEBUG
-static void
-UTF8_assert(const char *restrict s)
+static inline void
+UTF8_assert(const char *s)
 {
-       int c;
-
-       if (s == NULL)
-               return;
-       if (*s == '\200' && s[1] == '\0')
-               return;                                 /* str_nil */
-       while ((c = *s++) != '\0') {
-               if ((c & 0x80) == 0)
-                       continue;
-               if ((*s++ & 0xC0) != 0x80)
-                       assert(0);
-               if ((c & 0xE0) == 0xC0)
-                       continue;
-               if ((*s++ & 0xC0) != 0x80)
-                       assert(0);
-               if ((c & 0xF0) == 0xE0)
-                       continue;
-               if ((*s++ & 0xC0) != 0x80)
-                       assert(0);
-               if ((c & 0xF8) == 0xF0)
-                       continue;
-               assert(0);
-       }
+       assert(strNil(s) || utf8valid(s) == 0);
 }
 #else
 #define UTF8_assert(s)         ((void) 0)
 #endif
 
+/* return how many codepoints in the substring end in s starts */
 static inline int
 UTF8_strpos(const char *s, const char *end)
 {
-       int pos = 0;
-
        UTF8_assert(s);
 
        if (s > end) {
                return -1;
        }
-       while (s < end) {
-               /* just count leading bytes of encoded code points; only works
-                * for correctly encoded UTF-8 */
-               pos += (*s++ & 0xC0) != 0x80;
-       }
-       return pos;
+       return (int) utf8nlen(s, (size_t) (end - s));
 }
 
+/* return a pointer to the byte that starts the pos'th (0-based)
+ * codepoint in s */
 static inline str
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to