Changeset: 13d1e98e03f4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/13d1e98e03f4
Modified Files:
gdk/gdk_string.c
sql/server/sql_scan.c
Branch: Oct2020
Log Message:
Merge with Jun2020 branch.
diffs (159 lines):
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -108,11 +108,14 @@ strCleanHash(Heap *h, bool rebuild)
* started. */
memset(newhash, 0, sizeof(newhash));
pos = GDK_STRHASHSIZE;
- while (pos < h->free &&
- pos + (pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1))) <
GDK_ELIMLIMIT) {
+ while (pos < h->free) {
+ pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
if (pad < sizeof(stridx_t))
pad += GDK_VARALIGN;
- pos += pad + extralen;
+ pos += pad;
+ if (pos >= GDK_ELIMLIMIT)
+ break;
+ pos += extralen;
s = h->base + pos;
if (h->hashash)
strhash = ((const BUN *) s)[-1];
@@ -276,9 +279,11 @@ strPut(Heap *h, var_t *dst, const char *
pad = 0;
}
+ pad += extralen;
+
/* check heap for space (limited to a certain maximum after
* which nils are inserted) */
- if (h->free + pad + len + extralen >= h->size) {
+ if (h->free + pad + len >= h->size) {
size_t newsize = MAX(h->size, 4096);
/* double the heap size until we have enough space */
@@ -287,11 +292,11 @@ strPut(Heap *h, var_t *dst, const char *
newsize <<= 1;
else
newsize += 4 * 1024 * 1024;
- } while (newsize <= h->free + pad + len + extralen);
+ } while (newsize <= h->free + pad + len);
assert(newsize);
- if (h->free + pad + len + extralen >= (size_t) VAR_MAX) {
+ if (h->free + pad + len >= (size_t) VAR_MAX) {
GDKerror("string heaps gets larger than %zuGiB.\n",
(size_t) VAR_MAX >> 30);
return 0;
}
@@ -299,19 +304,16 @@ strPut(Heap *h, var_t *dst, const char *
if (HEAPextend(h, newsize, true) != GDK_SUCCEED) {
return 0;
}
-#ifndef NDEBUG
- /* fill should solve initialization problems within
- * valgrind */
- memset(h->base + h->free, 0, h->size - h->free);
-#endif
/* make bucket point into the new heap */
bucket = ((stridx_t *) h->base) + off;
}
/* insert string */
- pos = h->free + pad + extralen;
+ pos = h->free + pad;
*dst = (var_t) pos;
+ if (pad > 0)
+ memset(h->base + h->free, 0, pad);
memcpy(h->base + pos, v, len);
if (h->hashash) {
((BUN *) (h->base + pos))[-1] = strhash;
@@ -319,7 +321,7 @@ strPut(Heap *h, var_t *dst, const char *
((BUN *) (h->base + pos))[-2] = (BUN) len;
#endif
}
- h->free += pad + len + extralen;
+ h->free += pad + len;
h->dirty = true;
/* maintain hash table */
diff --git a/sql/server/sql_scan.c b/sql/server/sql_scan.c
--- a/sql/server/sql_scan.c
+++ b/sql/server/sql_scan.c
@@ -24,30 +24,50 @@
#include <ctype.h>
#include "sql_keyword.h"
+/**
+ * Removes all comments before the query. In query comments are kept.
+ */
char *
query_cleaned(sql_allocator *sa, const char *query)
{
- char *q, *r;
+ char *q, *r, *c;
+ int lines = 0;
int quote = 0; /* inside quotes ('..', "..", {..}) */
bool bs = false; /* seen a backslash in a quoted string
*/
bool incomment1 = false; /* inside traditional C style comment */
bool incomment2 = false; /* inside comment starting with -- */
+ bool inline_comment = false;
+
r = SA_NEW_ARRAY(sa, char, strlen(query) + 1);
if(!r)
return NULL;
+ (void) c;
+
for (q = r; *query; query++) {
if (incomment1) {
if (*query == '/' && query[-1] == '*') {
incomment1 = false;
+ if (c == r && lines > 0) {
+ q = r; // reset to beginning
+ lines = 0;
+ continue;
+ }
}
+ if (*query == '\n') lines++;
+ *q++ = *query;
} else if (incomment2) {
if (*query == '\n') {
incomment2 = false;
+ inline_comment = false;
/* add newline only if comment doesn't
* occupy whole line */
- if (q > r && q[-1] != '\n')
+ if (q > r && q[-1] != '\n'){
*q++ = '\n';
+ lines++;
+ }
+ } else if (inline_comment){
+ *q++ = *query; // preserve in line query
comments
}
} else if (quote) {
if (bs) {
@@ -65,13 +85,21 @@ query_cleaned(sql_allocator *sa, const c
quote = '}';
*q++ = *query;
} else if (*query == '-' && query[1] == '-') {
+ if (q > r && q[-1] != '\n') {
+ inline_comment = true;
+ *q++ = *query; // preserve in line query
comments
+ }
incomment2 = true;
} else if (*query == '/' && query[1] == '*') {
incomment1 = true;
+ c = q;
+ *q++ = *query;
} else if (*query == '\n') {
/* collapse newlines */
- if (q > r && q[-1] != '\n')
+ if (q > r && q[-1] != '\n') {
*q++ = '\n';
+ lines++;
+ }
} else if (*query == ' ' || *query == '\t') {
/* collapse white space */
if (q > r && q[-1] != ' ')
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list