Changeset: fc88479cf1b3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fc88479cf1b3
Modified Files:
MonetDB.spec
buildtools/autogen/autogen/msc.py
buildtools/doc/windowsbuild.rst
clients/odbc/driver/ODBCConvert.c
clients/odbc/driver/ODBCUtil.c
clients/odbc/driver/ODBCUtil.h
clients/odbc/driver/SQLError.c
clients/odbc/driver/SQLGetDescRec.c
clients/odbc/driver/SQLGetDiagField.c
clients/odbc/driver/SQLGetDiagRec.c
common/stream/stream.c
configure.ag
monetdb5/modules/atoms/str.c
monetdb5/modules/mal/pcre.c
tools/merovingian/daemon/config/monetdbd.in
Branch: default
Log Message:
Merge with Aug2018 branch.
diffs (truncated from 1464 to 300 lines):
diff --git a/buildtools/autogen/autogen/msc.py
b/buildtools/autogen/autogen/msc.py
--- a/buildtools/autogen/autogen/msc.py
+++ b/buildtools/autogen/autogen/msc.py
@@ -326,18 +326,16 @@ def msc_dep(fd, tar, deplist, msc):
fd.write(getsrc)
x, de = split_filename(deplist[0])
of = b + '.' + de
- of = msc_translate_file(of, msc)
fd.write('\t$(YACC) $(YFLAGS) $(AM_YFLAGS) "%s"\n' % of)
- if ext == "tab.c":
+ elif ext == "tab.c":
fd.write(getsrc)
x, de = split_filename(deplist[0])
of = b + '.' + de
- of = msc_translate_file(of, msc)
fd.write('\t$(YACC) $(YFLAGS) $(AM_YFLAGS) "%s"\n' % of)
- if ext == "yy.c":
+ elif ext == "yy.c":
fd.write(getsrc)
fd.write('\t$(LEX) $(LFLAGS) $(AM_LFLAGS) "%s.l"\n' % b)
- if ext in ("obj", "tab.obj", "yy.obj"):
+ elif ext in ("obj", "tab.obj", "yy.obj"):
target, name = msc_find_target(tar, msc)
if name[0] == '_':
name = name[1:]
@@ -346,7 +344,7 @@ def msc_dep(fd, tar, deplist, msc):
if dext in ("c", "cpp", "yy.c", "tab.c"):
fd.write('\t$(CC) /EHsc $(CFLAGS) $(%s_CFLAGS) $(GENDLL)
-D_CRT_SECURE_NO_WARNINGS -DLIB%s "-Fo%s" -c "%s"\n' %
(split_filename(msc_basename(src))[0], name, t, src))
- if ext == 'res':
+ elif ext == 'res':
fd.write("\t$(RC) -fo%s %s\n" % (t, src))
def msc_deps(fd, deps, objext, msc):
diff --git a/buildtools/doc/windowsbuild.rst b/buildtools/doc/windowsbuild.rst
--- a/buildtools/doc/windowsbuild.rst
+++ b/buildtools/doc/windowsbuild.rst
@@ -805,7 +805,7 @@ The contents of the file referred to wit
parameter may contain something like::
bits=32
- LIBPCRE=C:\Program Files\PCRE
+ LIBPCRE=C:\Program Files\PCRE
LIBICONV=C:\Libraries\iconv-1.11.win32
LIBZLIB=C:\Libraries\zlib-1.2.8.win32
LIBXML2=C:\Libraries\libxml2-2.9.2.win32
diff --git a/clients/odbc/driver/ODBCConvert.c
b/clients/odbc/driver/ODBCConvert.c
--- a/clients/odbc/driver/ODBCConvert.c
+++ b/clients/odbc/driver/ODBCConvert.c
@@ -1873,7 +1873,8 @@ ODBCFetch(ODBCStmt *stmt,
if (type == SQL_C_WCHAR) {
SQLSMALLINT n;
- ODBCutf82wchar((SQLCHAR *) ptr, SQL_NTS, (SQLWCHAR *)
origptr, origbuflen, &n);
+ ODBCutf82wchar((SQLCHAR *) ptr, SQL_NTS,
+ (SQLWCHAR *) origptr, origbuflen, &n);
#ifdef ODBCDEBUG
ODBCLOG("Writing %d bytes to %p\n",
(int) (n * sizeof(SQLWCHAR)),
diff --git a/clients/odbc/driver/ODBCUtil.c b/clients/odbc/driver/ODBCUtil.c
--- a/clients/odbc/driver/ODBCUtil.c
+++ b/clients/odbc/driver/ODBCUtil.c
@@ -69,16 +69,6 @@ dupODBCstring(const SQLCHAR *inStr, size
return tmp;
}
-/* Conversion to and from SQLWCHAR */
-static int utf8chkmsk[] = {
- 0x0000007f,
- 0x00000780,
- 0x0000f800,
- 0x001f0000,
- 0x03e00000,
- 0x7c000000
-};
-
/* Convert a SQLWCHAR (UTF-16 encoded string) to UTF-8. On success,
clears the location pointed to by errmsg and returns NULL or a
newly allocated buffer. On error, assigns a string with an error
@@ -87,161 +77,225 @@ static int utf8chkmsk[] = {
ODBC fashion.
*/
SQLCHAR *
-ODBCwchar2utf8(const SQLWCHAR *s, SQLLEN length, char **errmsg)
+ODBCwchar2utf8(const SQLWCHAR *src, SQLLEN length, const char **errmsg)
{
- const SQLWCHAR *s1, *e;
- unsigned long c;
- SQLCHAR *buf, *p;
- int l, n;
+ size_t i = 0;
+ SQLLEN j = 0;
+ uint32_t c;
+ SQLCHAR *dest;
if (errmsg)
*errmsg = NULL;
- if (s == NULL)
+ if (src == NULL || length == SQL_NULL_DATA)
return NULL;
- if (length == SQL_NTS)
- for (s1 = s, length = 0; *s1; s1++)
- length++;
- else if (length == SQL_NULL_DATA)
- return NULL;
- else if (length < 0) {
+ if (length == SQL_NTS) {
+ /* a very large (positive) number that fits in SQLLEN */
+ length = (SQLLEN) (~(SQLULEN)0 >> 1);
+ } else if (length < 0) {
if (errmsg)
*errmsg = "Invalid length parameter";
return NULL;
}
- e = s + length;
- /* count necessary length */
- l = 1; /* space for NULL byte */
- for (s1 = s; s1 < e && *s1; s1++) {
- c = *s1;
- if (0xD800 <= c && c <= 0xDBFF) {
- /* high surrogate, must be followed by low surrogate */
- s1++;
- if (s1 >= e || *s1 < 0xDC00 || *s1 > 0xDFFF) {
+ while (j < length && src[j]) {
+ if (src[j] <= 0x7F) {
+ i += 1;
+ } else if (src[j] <= 0x7FF) {
+ i += 2;
+ } else if (
+#if SIZEOF_SQLWCHAR == 2
+ (src[j] & 0xFC00) != 0xD800
+#else
+ src[j] <= 0xFFFF
+#endif
+ ) {
+ if ((src[j] & 0xF800) == 0xD800) {
if (errmsg)
- *errmsg = "High surrogate not followed
by low surrogate";
+ *errmsg = "Illegal surrogate";
+ return NULL;
+ }
+ i += 3;
+ } else {
+#if SIZEOF_SQLWCHAR == 2
+ /* (src[j] & 0xFC00) == 0xD800, i.e. high surrogate */
+ if ((src[j+1] & 0xFC00) != 0xDC00) {
+ if (errmsg)
+ *errmsg = "Illegal surrogate";
+ return NULL;
+ }
+ j++;
+#else
+ c = src[j+0];
+ if (c > 0x10FFFF || (c & 0x1FF800) == 0xD800) {
+ if (errmsg)
+ *errmsg = "Illegal wide character
value";
return NULL;
}
- c = (((c & 0x03FF) << 10) | (*s1 & 0x3FF)) + 0x10000;
- } else if (0xDC00 <= c && c <= 0xDFFF) {
- /* low surrogate--illegal */
- if (errmsg)
- *errmsg = "Low surrogate not preceded by high
surrogate";
- return NULL;
+#endif
+ i += 4;
}
- for (n = 5; n > 0; n--)
- if (c & utf8chkmsk[n])
- break;
- l += n + 1;
- }
- /* convert */
- buf = (SQLCHAR *) malloc(l);
- if (buf == NULL) {
- if (errmsg)
- *errmsg = "Memory allocation error";
- return NULL;
+ j++;
}
- for (s1 = s, p = buf; s1 < e && *s1; s1++) {
- c = *s1;
- if (0xD800 <= c && c <= 0xDBFF) {
- /* high surrogate followed by low surrogate */
- s1++;
- c = (((c & 0x03FF) << 10) | (*s1 & 0x3FF)) + 0x10000;
+ length = j; /* figured out the real length (might not change) */
+ dest = malloc((i + 1) * sizeof(SQLCHAR));
+ if (dest == NULL)
+ return NULL;
+ i = 0;
+ j = 0;
+ while (j < length) {
+ if (src[j] <= 0x7F) {
+ dest[i++] = src[j];
+ } else if (src[j] <= 0x7FF) {
+ dest[i++] = 0xC0 | (src[j] >> 6);
+ dest[i++] = 0x80 | (src[j] & 0x3F);
+ } else if (
+#if SIZEOF_SQLWCHAR == 2
+ (src[j] & 0xFC00) != 0xD800
+#else
+ src[j] <= 0xFFFF
+#endif
+ ) {
+ dest[i++] = 0xE0 | (src[j] >> 12);
+ dest[i++] = 0x80 | ((src[j] >> 6) & 0x3F);
+ dest[i++] = 0x80 | (src[j] & 0x3F);
+ } else {
+#if SIZEOF_SQLWCHAR == 2
+ c = ((src[j+0] & 0x03FF) + 0x40) << 10
+ | (src[j+1] & 0x03FF);
+ j++;
+#else
+ c = src[j+0];
+#endif
+ dest[i++] = 0xF0 | (c >> 18);
+ dest[i++] = 0x80 | ((c >> 12) & 0x3F);
+ dest[i++] = 0x80 | ((c >> 6) & 0x3F);
+ dest[i++] = 0x80 | (c & 0x3F);
}
- for (n = 5; n > 0; n--)
- if (c & utf8chkmsk[n])
- break;
- if (n == 0)
- *p++ = (SQLCHAR) c;
- else {
- *p++ = (SQLCHAR) (((c >> (n * 6)) | (0x1F80 >> n)) &
0xFF);
- while (--n >= 0)
- *p++ = (SQLCHAR) (((c >> (n * 6)) & 0x3F) |
0x80);
- }
+ j++;
}
- *p = 0;
- return buf;
+ dest[i] = 0;
+ return dest;
}
/* Convert a UTF-8 encoded string to UTF-16 (SQLWCHAR). On success
returns NULL, on error returns a string with an error message. The
first two arguments describe the input, the last three arguments
describe the output, both in the normal ODBC fashion. */
-char *
-ODBCutf82wchar(const SQLCHAR *s,
+const char *
+ODBCutf82wchar(const SQLCHAR *src,
SQLINTEGER length,
SQLWCHAR *buf,
SQLLEN buflen,
SQLSMALLINT *buflenout)
{
- SQLWCHAR *p;
- const SQLCHAR *e;
- int m, n;
- unsigned int c;
- SQLSMALLINT len = 0;
+ SQLLEN i = 0;
+ SQLINTEGER j = 0;
+ uint32_t c;
- if (s == NULL || length == SQL_NULL_DATA) {
- if (buf && buflen > 0)
- *buf = 0;
+ if (buf == NULL)
+ buflen = 0;
+ else if (buflen == 0)
+ buf = NULL;
+
+ if (src == NULL || length == SQL_NULL_DATA) {
+ if (buflen > 0)
+ buf[0] = 0;
if (buflenout)
*buflenout = 0;
return NULL;
}
if (length == SQL_NTS)
- length = (SQLINTEGER) strlen((const char *) s);
+ length = (SQLINTEGER) (~(SQLUINTEGER)0 >> 1);
else if (length < 0)
return "Invalid length parameter";
- if (buf == NULL)
- buflen = 0;
-
- for (p = buf, e = s + length; s < e; ) {
- c = *s++;
- if ((c & 0x80) != 0) {
- for (n = 0, m = 0x40; c & m; n++, m >>= 1)
- ;
- /* n now is number of 10xxxxxx bytes that
- * should follow */
- if (n == 0 || n >= 4)
- return "Illegal UTF-8 sequence";
- if (s + n > e)
- return "Truncated UTF-8 sequence";
- c &= ~(0xFFC0) >> n;
- while (--n >= 0) {
- c <<= 6;
- c |= *s++ & 0x3F;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list