Changeset: 9e0bb207527b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9e0bb207527b
Modified Files:
gdk/gdk.h
gdk/gdk_bat.c
gdk/gdk_system.c
gdk/gdk_tracer.c
gdk/gdk_tracer.h
gdk/gdk_utils.c
monetdb5/modules/atoms/json.c
monetdb5/modules/mal/mal_mapi.c
sql/backends/monet5/rel_bin.c
sql/include/sql_relation.h
sql/rel.txt
sql/server/rel_dump.c
sql/server/rel_optimizer.c
sql/server/rel_rel.c
sql/server/rel_unnest.c
sql/server/sql_mvc.c
sql/test/json/Tests/jsonvalidity.Bug-3753.sql
sql/test/json/Tests/jsonvalidity.Bug-3753.stable.out
sql/test/subquery/Tests/subquery3.sql
sql/test/subquery/Tests/subquery3.stable.err
sql/test/subquery/Tests/subquery3.stable.out
sql/test/subquery/Tests/subquery4.sql
sql/test/subquery/Tests/subquery4.stable.err
sql/test/subquery/Tests/subquery4.stable.out
sql/test/sys-schema/Tests/systemfunctions.stable.out
sql/test/sys-schema/Tests/systemfunctions.stable.out.int128
Branch: timezone
Log Message:
Merge with default branch.
diffs (truncated from 1518 to 300 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -523,7 +523,11 @@ typedef struct {
size_t free; /* index where free area starts. */
size_t size; /* size of the heap (bytes) */
char *base; /* base pointer in memory. */
+#if SIZEOF_VOID_P == 4
char filename[32]; /* file containing image of the heap */
+#else
+ char filename[40]; /* file containing image of the heap */
+#endif
bte farmid; /* id of farm where heap is located */
bool copied:1, /* a copy of an existing map. */
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -2093,8 +2093,8 @@ BATmode(BAT *b, bool transient)
#ifdef NDEBUG
/* assertions are disabled, turn failing tests into a message */
-//#undef assert
-//#define assert(test) ((void) ((test) || TRC_ERROR(BAT_, "Assertion `%s'
failed\n", #test)))
+#undef assert
+#define assert(test) ((void) ((test) || TRC_CRITICAL_ENDIF(BAT_, "Assertion
`%s' failed\n", #test)))
#endif
/* Assert that properties are set correctly.
@@ -2136,6 +2136,7 @@ BATmode(BAT *b, bool transient)
void
BATassertProps(BAT *b)
{
+ unsigned bbpstatus;
BATiter bi = bat_iterator(b);
BUN p, q;
int (*cmpf)(const void *, const void *);
@@ -2151,9 +2152,7 @@ BATassertProps(BAT *b)
assert(b->hseqbase <= GDK_oid_max); /* non-nil seqbase */
assert(b->hseqbase + BATcount(b) <= GDK_oid_max);
-#ifndef NDEBUG
- unsigned bbpstatus = BBP_status(b->batCacheid);
-#endif
+ bbpstatus = BBP_status(b->batCacheid);
/* only at most one of BBPDELETED, BBPEXISTING, BBPNEW may be set */
assert(((bbpstatus & BBPDELETED) != 0) +
((bbpstatus & BBPEXISTING) != 0) +
@@ -2214,9 +2213,7 @@ BATassertProps(BAT *b)
assert(b->tvheap->free <= b->tvheap->size);
assert(b->tvheap->free % SIZEOF_OID == 0);
if (b->tvheap->free > 0) {
-#ifndef NDEBUG
const oid *oids = (const oid *)
b->tvheap->base;
-#endif
q = b->tvheap->free / SIZEOF_OID;
assert(oids != NULL);
assert(b->tseqbase + BATcount(b) + q <=
GDK_oid_max);
@@ -2243,9 +2240,7 @@ BATassertProps(BAT *b)
assert(b->tkey);
assert(b->tnonil);
if ((q = b->batCount) != 0) {
-#ifndef NDEBUG
const oid *o = (const oid *) Tloc(b, 0);
-#endif
assert(*o == b->tseqbase);
for (p = 1; p < q; p++)
assert(o[p - 1] + 1 == o[p]);
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -214,10 +214,17 @@ MT_thread_init(void)
{
if (threadslot == TLS_OUT_OF_INDEXES) {
threadslot = TlsAlloc();
- if (threadslot == TLS_OUT_OF_INDEXES)
+ if (threadslot == TLS_OUT_OF_INDEXES) {
+ char errmsg[256];
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL,
GetLastError(), 0, errmsg, sizeof(errmsg), NULL);
+ TRC_CRITICAL(GDK, "Creating thread-local slot for
thread failed: %s\n", errmsg);
return false;
+ }
mainthread.tid = GetCurrentThreadId();
if (TlsSetValue(threadslot, &mainthread) == 0) {
+ char errmsg[256];
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL,
GetLastError(), 0, errmsg, sizeof(errmsg), NULL);
+ TRC_CRITICAL(GDK, "Setting thread-local value failed:
%s\n", errmsg);
TlsFree(threadslot);
threadslot = TLS_OUT_OF_INDEXES;
return false;
@@ -386,12 +393,24 @@ join_detached_threads(void)
int
MT_create_thread(MT_Id *t, void (*f) (void *), void *arg, enum MT_thr_detach
d, const char *threadname)
{
- struct winthread *w = malloc(sizeof(*w));
-
- if (w == NULL)
- return -1;
+ struct winthread *w;
join_threads();
+ if (threadname == NULL) {
+ TRC_CRITICAL(GDK, "Thread must have a name\n");
+ return -1;
+ }
+ if (strlen(threadname) >= sizeof(w->threadname)) {
+ TRC_CRITICAL(GDK, "Thread's name is too large\n");
+ return -1;
+ }
+
+ w = malloc(sizeof(*w));
+ if (w == NULL) {
+ TRC_ERROR(GDK, "Cannot allocate memory\n");
+ return -1;
+ }
+
*w = (struct winthread) {
.func = f,
.data = arg,
@@ -405,13 +424,18 @@ MT_create_thread(MT_Id *t, void (*f) (vo
w->hdl = CreateThread(NULL, THREAD_STACK_SIZE, thread_starter, w,
0, &w->tid);
if (w->hdl == NULL) {
+ char errmsg[256];
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
+ 0, errmsg, sizeof(errmsg), NULL);
LeaveCriticalSection(&winthread_cs);
+ free(w);
+ TRC_ERROR(GDK, "Failed to create thread: %s\n", errmsg);
return -1;
}
+ /* must not fail after this: the thread has been started */
w->next = winthreads;
winthreads = w;
LeaveCriticalSection(&winthread_cs);
- /* must not fail after this: the thread has been started */
*t = (MT_Id) w->tid;
return 0;
}
@@ -534,12 +558,12 @@ MT_thread_init(void)
int ret;
if ((ret = pthread_key_create(&threadkey, NULL)) != 0) {
- TRC_ERROR(GDK, "Creating specific key for thread failed: %s\n",
strerror(ret));
+ TRC_CRITICAL(GDK, "Creating specific key for thread failed:
%s\n", strerror(ret));
return false;
}
mainthread.tid = pthread_self();
if ((ret = pthread_setspecific(threadkey, &mainthread)) != 0) {
- TRC_ERROR(GDK, "Setting specific value failed: %s\n",
strerror(ret));
+ TRC_CRITICAL(GDK, "Setting specific value failed: %s\n",
strerror(ret));
}
return true;
}
@@ -723,16 +747,14 @@ MT_create_thread(MT_Id *t, void (*f) (vo
pthread_attr_t attr;
int ret;
struct posthread *p;
- size_t tlen;
join_threads();
if (threadname == NULL) {
- TRC_ERROR(GDK, "Thread must have a name\n");
+ TRC_CRITICAL(GDK, "Thread must have a name\n");
return -1;
}
- tlen = strlen(threadname);
- if (tlen >= sizeof(p->threadname)) {
- TRC_ERROR(GDK, "Thread's name is too large\n");
+ if (strlen(threadname) >= sizeof(p->threadname)) {
+ TRC_CRITICAL(GDK, "Thread's name is too large\n");
return -1;
}
if ((ret = pthread_attr_init(&attr)) != 0) {
@@ -746,7 +768,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo
}
p = malloc(sizeof(struct posthread));
if (p == NULL) {
- TRC_ERROR(GDK, "Cannot allocate memory: %s\n", strerror(errno));
+ TRC_ERROR(GDK, "Cannot allocate memory\n");
pthread_attr_destroy(&attr);
return -1;
}
@@ -758,7 +780,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo
};
ATOMIC_INIT(&p->exited, 0);
- memcpy(p->threadname, threadname, tlen + 1);
+ strcpy_len(p->threadname, threadname, sizeof(p->threadname));
#ifdef HAVE_PTHREAD_SIGMASK
sigset_t new_mask, orig_mask;
(void) sigfillset(&new_mask);
@@ -772,6 +794,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo
ret = pthread_create(&p->tid, &attr, thread_starter, p);
if (ret != 0) {
TRC_ERROR(GDK, "Cannot start thread: %s\n", strerror(ret));
+ free(p);
ret = -1;
} else {
/* must not fail after this: the thread has been started */
@@ -779,6 +802,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo
posthreads = p;
}
pthread_mutex_unlock(&posthread_lock);
+ (void) pthread_attr_destroy(&attr); /* not interested in errors */
#ifdef HAVE_PTHREAD_SIGMASK
MT_thread_sigmask(&orig_mask, NULL);
#endif
diff --git a/gdk/gdk_tracer.c b/gdk/gdk_tracer.c
--- a/gdk/gdk_tracer.c
+++ b/gdk/gdk_tracer.c
@@ -75,7 +75,7 @@ const char *LEVEL_STR[] = {
*/
// Exception
#define GDK_TRACER_EXCEPTION(MSG, ...) \
- mnstr_printf(GDKstdout, \
+ fprintf(stderr, \
"%s " \
"%-"MXW"s " \
"%"MXW"s:%d " \
@@ -122,31 +122,6 @@ static gdk_return
}
-// Candidate for 'gnu_printf' format attribute
[-Werror=suggest-attribute=format]
-static int _GDKtracer_fill_tracer(gdk_tracer *sel_tracer, const char *fmt,
va_list va)
- __attribute__((__format__(__printf__, 2, 0)));
-
-static int
-_GDKtracer_fill_tracer(gdk_tracer *sel_tracer, const char *fmt, va_list va)
-{
- size_t fmt_len = strlen(fmt);
- int bytes_written = 0;
-
- // vsnprintf(char *str, size_t count, ...) -> including null
terminating character
- bytes_written = vsnprintf(sel_tracer->buffer
+sel_tracer->allocated_size, BUFFER_SIZE - sel_tracer->allocated_size, fmt, va);
- // Add \n if it doesn't exist
- if (bytes_written && fmt[fmt_len - 1] != '\n')
- bytes_written += snprintf(sel_tracer->buffer
+sel_tracer->allocated_size, BUFFER_SIZE - sel_tracer->allocated_size, "\n");
-
- // Let GDKtracer_log to know about the failure
- if (bytes_written < 0)
- return -1;
-
- // vsnprintf returned value -> does not include the null terminating
character
- return bytes_written++;
-}
-
-
static gdk_return
_GDKtracer_layer_level_helper(int layer, int lvl)
{
@@ -468,51 +443,35 @@ GDKtracer_reset_adapter(void)
gdk_return
GDKtracer_log(LOG_LEVEL level, const char *fmt, ...)
{
- int bytes_written = 0;
-
- MT_lock_set(&lock);
+ int bytes_written;
+ char buffer[512]; /* should be plenty big enough for a message */
va_list va;
va_start(va, fmt);
- bytes_written = _GDKtracer_fill_tracer(active_tracer, fmt, va);
+ bytes_written = vsnprintf(buffer, sizeof(buffer), fmt, va);
va_end(va);
-
- if (bytes_written >= 0) {
- // The message fits the buffer OR the buffer is empty but the
message does not fit (we cut it off)
- if (bytes_written < (BUFFER_SIZE -
active_tracer->allocated_size) || active_tracer->allocated_size == 0) {
- active_tracer->allocated_size += bytes_written;
- } else {
- _GDKtracer_flush_buffer_locked();
-
- va_list va;
- va_start(va, fmt);
- bytes_written = _GDKtracer_fill_tracer(active_tracer,
fmt, va);
- va_end(va);
+ if (bytes_written < 0) {
+ GDK_TRACER_EXCEPTION(GDKTRACER_FAILED "\n");
+ return GDK_FAIL;
+ }
+ if (bytes_written >= (int) sizeof(buffer) - 1) {
+ /* message is truncated */
+ bytes_written = (int) sizeof(buffer) - 2;
+ }
+ /* make sure message ends with a newline */
+ if (buffer[bytes_written - 1] != '\n') {
+ buffer[bytes_written++] = '\n';
+ buffer[bytes_written] = '\0';
+ }
- if (bytes_written >= 0) {
- // The second buffer will always be empty at
start
- // So if the message does not fit we cut it off
- // message might be > BUFFER_SIZE
- active_tracer->allocated_size += bytes_written;
- } else {
-
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list