Changeset: f3f489edfd9f for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f3f489edfd9f Modified Files: gdk/gdk_firstn.c gdk/gdk_group.c gdk/gdk_logger.c gdk/gdk_posix.c gdk/gdk_private.h gdk/gdk_project.c gdk/gdk_system.c gdk/gdk_system.h gdk/gdk_system_private.h gdk/gdk_utils.c gdk/gdk_value.c monetdb5/mal/mal_dataflow.c monetdb5/mal/mal_debugger.c monetdb5/mal/mal_function.c monetdb5/mal/mal_import.c monetdb5/mal/mal_interpreter.c monetdb5/mal/mal_listing.c monetdb5/mal/mal_module.c monetdb5/mal/mal_parser.c monetdb5/mal/mal_profiler.c monetdb5/mal/mal_resolve.c monetdb5/mal/mal_session.c monetdb5/mal/mal_stack.h monetdb5/modules/atoms/blob.c monetdb5/modules/atoms/color.c monetdb5/modules/atoms/identifier.c monetdb5/modules/atoms/inet.c monetdb5/modules/atoms/json.c monetdb5/modules/atoms/mtime.c monetdb5/modules/atoms/streams.c monetdb5/modules/kernel/algebra.c monetdb5/modules/mal/inspect.c monetdb5/modules/mal/mal_mapi.c monetdb5/modules/mal/tablet.c monetdb5/modules/mal/tokenizer.c monetdb5/optimizer/opt_pipes.c sql/backends/monet5/sql_gencode.c sql/backends/monet5/sql_scenario.c Branch: default Log Message:
Merge with Jun2016 branch. diffs (truncated from 1362 to 300 lines): diff --git a/gdk/gdk_firstn.c b/gdk/gdk_firstn.c --- a/gdk/gdk_firstn.c +++ b/gdk/gdk_firstn.c @@ -656,6 +656,8 @@ BATfirstn_grouped(BAT **topn, BAT **gids * can use the base type */ tpe = ATOMbasetype(tpe); /* takes care of oid */ groups = GDKmalloc(sizeof(*groups) * n); + if( groups == NULL) + return GDK_FAIL; oldcand = cand; if (asc) { switch (tpe) { @@ -960,6 +962,8 @@ BATfirstn_grouped_with_groups(BAT **topn * can use the base type */ tpe = ATOMbasetype(tpe); /* takes care of oid */ groups = GDKmalloc(sizeof(*groups) * n); + if( groups == NULL) + return GDK_FAIL; gv = (const oid *) Tloc(g, 0); oldcand = cand; if (asc) { diff --git a/gdk/gdk_group.c b/gdk/gdk_group.c --- a/gdk/gdk_group.c +++ b/gdk/gdk_group.c @@ -711,6 +711,9 @@ BATgroup_internal(BAT **groups, BAT **ex unsigned char *restrict bgrps = GDKmalloc(256); const unsigned char *restrict w = (const unsigned char *) Tloc(b, 0); unsigned char v; + + if( bgrps == NULL) + goto error; memset(bgrps, 0xFF, 256); if (histo) memset(cnts, 0, maxgrps * sizeof(lng)); @@ -737,6 +740,9 @@ BATgroup_internal(BAT **groups, BAT **ex unsigned short *restrict sgrps = GDKmalloc(65536 * sizeof(short)); const unsigned short *restrict w = (const unsigned short *) Tloc(b, 0); unsigned short v; + + if( sgrps == NULL) + goto error; memset(sgrps, 0xFF, 65536 * sizeof(short)); if (histo) memset(cnts, 0, maxgrps * sizeof(lng)); diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c --- a/gdk/gdk_logger.c +++ b/gdk/gdk_logger.c @@ -1219,6 +1219,9 @@ bm_subcommit(logger *lg, BAT *list_bid, BATiter iter = (list_nme)?bat_iterator(list_nme):bat_iterator(list_bid); gdk_return res; + if( n == NULL) + return GDK_FAIL; + n[i++] = 0; /* n[0] is not used */ BATloop(list_bid, p, q) { bat col = *(log_bid *) Tloc(list_bid, p); diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c --- a/gdk/gdk_posix.c +++ b/gdk/gdk_posix.c @@ -582,6 +582,12 @@ MT_mremap(const char *path, int mode, vo if (fd >= 0) close(fd); p = malloc(strlen(path) + 5); + if ( p == NULL){ + GDKsyserror("MT_mremap: malloc() failed\n"); + fprintf(stderr, "= %s:%d: MT_mremap(%s,"PTRFMT","SZFMT","SZFMT"): fd < 0\n", __FILE__, __LINE__, path, PTRFMTCAST old_address, old_size, *new_size); + return NULL; + } + strcat(strcpy(p, path), ".tmp"); fd = open(p, O_RDWR | O_CREAT, MONETDB_MODE); @@ -1048,6 +1054,8 @@ reduce_dir_name(const char *src, char *d if (len >= cap) buf = malloc(len + 1); + if( buf == NULL) + return NULL; while (--len > 0 && src[len - 1] != ':' && src[len] == DIR_SEP) ; for (buf[++len] = 0; len > 0; buf[len] = src[len]) diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h --- a/gdk/gdk_private.h +++ b/gdk/gdk_private.h @@ -161,8 +161,6 @@ void BBPdump(void); /* never called: fo __hidden void IMPSprint(BAT *b) __attribute__((__visibility__("hidden"))); #endif -__hidden gdk_return unshare_string_heap(BAT *b) - __attribute__((__visibility__("hidden"))); __hidden void MT_init_posix(void) __attribute__((__visibility__("hidden"))); __hidden void *MT_mremap(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size) @@ -189,6 +187,8 @@ void BBPdump(void); /* never called: fo __attribute__((__visibility__("hidden"))); __hidden var_t strLocate(Heap *h, const char *v) __attribute__((__visibility__("hidden"))); +__hidden gdk_return unshare_string_heap(BAT *b) + __attribute__((__visibility__("hidden"))); __hidden void VIEWdestroy(BAT *b) __attribute__((__visibility__("hidden"))); __hidden gdk_return VIEWreset(BAT *b) diff --git a/gdk/gdk_project.c b/gdk/gdk_project.c --- a/gdk/gdk_project.c +++ b/gdk/gdk_project.c @@ -443,6 +443,8 @@ BATprojectchain(BAT **bats) for (n = 0; bats[n]; n++) ; ba = GDKmalloc(sizeof(*ba) * n); + if( ba == NULL) + return NULL; b = *bats++; cnt = BATcount(b); /* this will be the size of the output */ hseq = b->hseqbase; /* this will be the seqbase of the output */ diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c --- a/gdk/gdk_system.c +++ b/gdk/gdk_system.c @@ -497,6 +497,30 @@ join_threads(void) pthread_mutex_unlock(&posthread_lock); } +void +join_detached_threads(void) +{ + struct posthread *p; + int waited; + pthread_t tid; + + pthread_mutex_lock(&posthread_lock); + do { + waited = 0; + for (p = posthreads; p; p = p->next) { + tid = p->tid; + rm_posthread_locked(p); + free(p); + pthread_mutex_unlock(&posthread_lock); + pthread_join(tid, NULL); + pthread_mutex_lock(&posthread_lock); + waited = 1; + break; + } + } while (waited); + pthread_mutex_unlock(&posthread_lock); +} + int MT_create_thread(MT_Id *t, void (*f) (void *), void *arg, enum MT_thr_detach d) { diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h --- a/gdk/gdk_system.h +++ b/gdk/gdk_system.h @@ -228,11 +228,13 @@ gdk_export ATOMIC_TYPE volatile GDKlocks MT_Lock * volatile _p; \ /* save a copy for statistical purposes */ \ _p = GDKmalloc(sizeof(MT_Lock)); \ - memcpy(_p, l, sizeof(MT_Lock)); \ while (ATOMIC_TAS(GDKlocklistlock, dummy) != 0) \ ; \ - _p->next = GDKlocklist; \ - GDKlocklist = _p; \ + if( _p) { \ + memcpy(_p, l, sizeof(MT_Lock)); \ + _p->next = GDKlocklist; \ + GDKlocklist = _p; \ + } \ for (_p = GDKlocklist; _p; _p = _p->next) \ if (_p->next == (l)) { \ _p->next = (l)->next; \ diff --git a/gdk/gdk_system_private.h b/gdk/gdk_system_private.h --- a/gdk/gdk_system_private.h +++ b/gdk/gdk_system_private.h @@ -12,6 +12,8 @@ #error this file should not be included outside its source directory #endif +__hidden void join_detached_threads(void) + __attribute__((__visibility__("hidden"))); __declspec(noreturn) void MT_exit_thread(int status) __attribute__((__noreturn__)); __hidden void MT_global_exit(int status) diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c --- a/gdk/gdk_utils.c +++ b/gdk/gdk_utils.c @@ -687,6 +687,7 @@ GDKreset(int status) GDKfree(st); } MT_lock_unset(&GDKthreadLock); + join_detached_threads(); if (status == 0) { /* they had their chance, now kill them */ diff --git a/gdk/gdk_value.c b/gdk/gdk_value.c --- a/gdk/gdk_value.c +++ b/gdk/gdk_value.c @@ -157,7 +157,8 @@ VALcopy(ValPtr d, const ValRecord *s) d->vtype = s->vtype; d->len = ATOMlen(d->vtype, p); d->val.pval = GDKmalloc(d->len); - memcpy(d->val.pval, p, d->len); + if( d->val.pval) + memcpy(d->val.pval, p, d->len); } return d; } @@ -208,7 +209,8 @@ VALinit(ValPtr d, int tpe, const void *s assert(ATOMextern(ATOMstorage(tpe))); d->len = ATOMlen(tpe, s); d->val.pval = GDKmalloc(d->len); - memcpy(d->val.pval, s, d->len); + if( d->val.pval) + memcpy(d->val.pval, s, d->len); break; } return d; diff --git a/monetdb5/mal/mal_dataflow.c b/monetdb5/mal/mal_dataflow.c --- a/monetdb5/mal/mal_dataflow.c +++ b/monetdb5/mal/mal_dataflow.c @@ -336,7 +336,10 @@ DFLOWworker(void *T) srand((unsigned int) GDKusec()); #endif GDKsetbuf(GDKmalloc(GDKMAXERRLEN)); /* where to leave errors */ - GDKerrbuf[0] = 0; + if( GDKerrbuf == 0) + fprintf(stderr,"DFLOWworker:Could not allocate GDKerrbuf\n"); + else + GDKerrbuf[0] = 0; MT_lock_set(&dataflowLock); cntxt = t->cntxt; MT_lock_unset(&dataflowLock); diff --git a/monetdb5/mal/mal_debugger.c b/monetdb5/mal/mal_debugger.c --- a/monetdb5/mal/mal_debugger.c +++ b/monetdb5/mal/mal_debugger.c @@ -272,7 +272,7 @@ printCall(Client cntxt, MalBlkPtr mb, Ma { str msg; msg = instruction2str(mb, stk, getInstrPtr(mb, pc), LIST_MAL_CALL); - mnstr_printf(cntxt->fdout, "#%s at %s.%s[%d]\n", msg, + mnstr_printf(cntxt->fdout, "#%s at %s.%s[%d]\n", (msg?msg:"failed instruction2str()") , getModuleId(getInstrPtr(mb, 0)), getFunctionId(getInstrPtr(mb, 0)), pc); GDKfree(msg); @@ -287,7 +287,7 @@ printTraceCall(stream *out, MalBlkPtr mb p = getInstrPtr(mb, pc); msg = instruction2str(mb, stk, p, flags); - mnstr_printf(out, "#%s%s\n", (mb->errors ? "!" : ""), msg); + mnstr_printf(out, "#%s%s\n", (mb->errors ? "!" : ""), msg?msg:"failed instruction2str()"); GDKfree(msg); } diff --git a/monetdb5/mal/mal_function.c b/monetdb5/mal/mal_function.c --- a/monetdb5/mal/mal_function.c +++ b/monetdb5/mal/mal_function.c @@ -398,6 +398,10 @@ cloneFunction(stream *out, Module scope, printInstruction(out,mb,0,p,LIST_MAL_ALL); #endif new = newFunction(scope->name, proc->name, getSignature(proc)->token); + if( new == NULL){ + fprintf(stderr,"cloneFunction() failed"); + return NULL; + } freeMalBlk(new->def); new->def = copyMalBlk(proc->def); /* now change the definition of the original proc */ @@ -498,7 +502,7 @@ debugFunction(stream *fd, MalBlkPtr mb, mnstr_printf(fd,"\n"); } GDKfree(ps); - } + } else mnstr_printf(fd,"#failed instruction2str()\n"); } } @@ -529,7 +533,7 @@ listFunction(stream *fd, MalBlkPtr mb, M if (l > len) len = l; GDKfree(ps); - } + } else mnstr_printf(fd,"#failed instruction2str()\n"); } mnstr_printf(fd, "%% " SZFMT " # length\n", len); } diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c --- a/monetdb5/mal/mal_import.c +++ b/monetdb5/mal/mal_import.c @@ -290,8 +290,10 @@ evalFile(Client c, str fname, int listin c->yycur = 0; c->bak = NULL; MSinitClientPrg(c, "user", "main"); /* re-initialize context */ - MCpushClientInput(c, bstream_create(fd, 128 * BLOCK), c->listing, ""); - msg = runScenario(c); + if( MCpushClientInput(c, bstream_create(fd, 128 * BLOCK), c->listing, "") < 0){ + msg = createException(MAL,"mal.eval", "WARNING: could not switch client input stream\n"); + } else + msg = runScenario(c); if (msg != MAL_SUCCEED) { dumpExceptionsToStream(c->fdout, msg); GDKfree(msg); @@ -309,8 +311,10 @@ evalFile(Client c, str fname, int listin _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list