Changeset: 89358d4f40bb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=89358d4f40bb
Modified Files:
        NT/monetdb_config.h.in
        gdk/gdk_posix.c
        gdk/gdk_posix.h
        gdk/gdk_system.h
        gdk/gdk_utils.c
        monetdb5/extras/rapi/rapi.c
        monetdb5/mal/mal.c
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_debugger.c
        monetdb5/mal/mal_private.h
        monetdb5/mal/mal_readline.c
        monetdb5/mal/mal_scenario.c
        monetdb5/mal/mal_session.c
        monetdb5/modules/atoms/mcurl.c
        sql/backends/monet5/UDF/pyapi/pyapi.c
        sql/backends/monet5/sql_scenario.c
        sql/backends/monet5/vaults/lidar/lidar.c
        sql/common/sql_list.c
        sql/server/rel_optimizer.c
        sql/server/rel_select.c
        sql/server/sql_parser.y
        sql/storage/store.c
        tools/mserver/mserver5.c
        tools/mserver/shutdowntest.c
Branch: default
Log Message:

Merge with Jul2017 branch.


diffs (truncated from 1089 to 300 lines):

diff --git a/NT/monetdb_config.h.in b/NT/monetdb_config.h.in
--- a/NT/monetdb_config.h.in
+++ b/NT/monetdb_config.h.in
@@ -347,9 +347,6 @@
 /* Define to 1 if you have the <malloc.h> header file. */
 #define HAVE_MALLOC_H 1
 
-/* Define to 1 if you have the `mallopt' function. */
-/* #undef HAVE_MALLOPT */
-
 /* Define to 1 if you have the <memory.h> header file. */
 #define HAVE_MEMORY_H 1
 
diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c
--- a/gdk/gdk_posix.c
+++ b/gdk/gdk_posix.c
@@ -1002,8 +1002,11 @@ int
 win_stat(const char *pathname, struct _stat64 *st)
 {
        char buf[128], *p = reduce_dir_name(pathname, buf, sizeof(buf));
-       int ret = _stat64(p, st);
+       int ret;
 
+       if (p == NULL)
+               return -1;
+       ret = _stat64(p, st);
        if (p != buf)
                free(p);
        return ret;
@@ -1013,8 +1016,11 @@ int
 win_rmdir(const char *pathname)
 {
        char buf[128], *p = reduce_dir_name(pathname, buf, sizeof(buf));
-       int ret = _rmdir(p);
+       int ret;
 
+       if (p == NULL)
+               return -1;
+       ret = _rmdir(p);
        if (ret < 0 && errno != ENOENT) {
                /* it could be the <expletive deleted> indexing
                 * service which prevents us from doing what we have a
@@ -1080,9 +1086,12 @@ int
 win_mkdir(const char *pathname, const int mode)
 {
        char buf[128], *p = reduce_dir_name(pathname, buf, sizeof(buf));
-       int ret = _mkdir(p);
+       int ret;
 
        (void) mode;
+       if (p == NULL)
+               return -1;
+       ret = _mkdir(p);
        if (p != buf)
                free(p);
        return ret;
diff --git a/gdk/gdk_posix.h b/gdk/gdk_posix.h
--- a/gdk/gdk_posix.h
+++ b/gdk/gdk_posix.h
@@ -41,29 +41,6 @@
 #include <direct.h>
 #endif
 
-/* Some systems (SGI, Sun) call malloc before we get a chance to call
- * mallopt, and mallopt should be called before the first call to
- * malloc.  Therefore we do as if we don't have mallopt, even though
- * in reality we do. */
-#ifdef HAVE_MALLOPT
-#undef HAVE_MALLOPT
-#endif
-
-#ifndef M_MXFAST
-#define M_MXFAST       1       /* set size of blocks to be fast */
-#endif
-#ifndef M_NLBLKS
-#define M_NLBLKS       2       /* set number of block in a holding block */
-#endif
-#ifndef M_GRAIN
-#define M_GRAIN                3       /* set number of sizes mapped to one, 
for */
-                               /* small blocks */
-#endif
-#ifndef M_KEEP
-#define M_KEEP         4       /* retain contents of block after a free */
-                               /* until another allocation */
-#endif
-
 /*
  * @- locking, sleep
  */
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -209,8 +209,11 @@ gdk_export ATOMIC_TYPE volatile GDKlocks
                /* SQL storage allocator, and hence we have no control */ \
                /* over when the lock is destroyed and the memory freed */ \
                if (strncmp((n), "sa_", 3) != 0) {                      \
+                       MT_Lock * volatile _p;                          \
                        while (ATOMIC_TAS(GDKlocklistlock, dummy) != 0) \
                                ;                                       \
+                       for (_p = GDKlocklist; _p; _p = _p->next)       \
+                               assert(_p != (l));                      \
                        (l)->next = GDKlocklist;                        \
                        GDKlocklist = (l);                              \
                        ATOMIC_CLEAR(GDKlocklistlock, dummy);           \
@@ -225,19 +228,12 @@ gdk_export ATOMIC_TYPE volatile GDKlocks
                /* SQL storage allocator, and hence we have no control */ \
                /* over when the lock is destroyed and the memory freed */ \
                if (strncmp((l)->name, "sa_", 3) != 0) {                \
-                       MT_Lock * volatile _p;                          \
-                       /* save a copy for statistical purposes */      \
-                       _p = GDKmalloc(sizeof(MT_Lock));                \
+                       MT_Lock * volatile *_p;                         \
                        while (ATOMIC_TAS(GDKlocklistlock, dummy) != 0) \
                                ;                                       \
-                       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;           \
+                       for (_p = &GDKlocklist; *_p; _p = &(*_p)->next) \
+                               if ((l) == *_p) {                       \
+                                       *_p = (l)->next;                \
                                        break;                          \
                                }                                       \
                        ATOMIC_CLEAR(GDKlocklistlock, dummy);           \
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -521,6 +521,8 @@ GDKinit(opt *set, int setlen)
        }
 
        n = (opt *) malloc(setlen * sizeof(opt));
+       if (n == NULL)
+               GDKfatal("GDKinit: malloc failed\n");
        for (i = 0; i < setlen; i++) {
                int done = 0;
                int j;
@@ -698,6 +700,7 @@ GDKreset(int status, int exit)
        Thread t, s;
        struct serverthread *st;
        int farmid;
+       int i;
 
        if( GDKkey){
                BBPunfix(GDKkey->batCacheid);
@@ -786,8 +789,16 @@ GDKreset(int status, int exit)
                GDKnrofthreads = 0;
                close_stream((stream *) THRdata[0]);
                close_stream((stream *) THRdata[1]);
-               memset((char*) GDKbatLock,0, sizeof(GDKbatLock));
-               memset((char*) GDKbbpLock,0,sizeof(GDKbbpLock));
+               for (i = 0; i <= BBP_BATMASK; i++) {
+                       MT_lock_destroy(&GDKbatLock[i].swap);
+                       MT_lock_destroy(&GDKbatLock[i].hash);
+                       MT_lock_destroy(&GDKbatLock[i].imprints);
+               }
+               for (i = 0; i <= BBP_THREADMASK; i++) {
+                       MT_lock_destroy(&GDKbbpLock[i].alloc);
+                       MT_lock_destroy(&GDKbbpLock[i].trim);
+                       GDKbbpLock[i].free = 0;
+               }
 
                memset((char*) GDKthreads, 0, sizeof(GDKthreads));
                memset((char*) THRdata, 0, sizeof(THRdata));
@@ -796,6 +807,19 @@ GDKreset(int status, int exit)
                MT_lock_unset(&GDKthreadLock);
                //gdk_system_reset(); CHECK OUT
        }
+#ifdef NEED_MT_LOCK_INIT
+       MT_lock_destroy(&MT_system_lock);
+#if defined(USE_PTHREAD_LOCKS) && defined(ATOMIC_LOCK)
+       MT_lock_destroy(&GDKstoppedLock);
+       MT_lock_destroy(&mbyteslock);
+#endif
+       MT_lock_destroy(&GDKnameLock);
+       MT_lock_destroy(&GDKthreadLock);
+       MT_lock_destroy(&GDKtmLock);
+#ifndef NDEBUG
+       MT_lock_destroy(&mallocsuccesslock);
+#endif
+#endif
 #ifndef HAVE_EMBEDDED
        if (exit) {
                MT_global_exit(status);
@@ -1046,7 +1070,7 @@ GDKerror(const char *format, ...)
        }
        va_start(ap, format);
        if (vsnprintf(message + len, sizeof(message) - (len + 2), format, ap) < 
0)
-               strcpy(message, GDKERROR "an error occurred within GDKerror, 
possibly malloc failure.\n");
+               strcpy(message, GDKERROR "an error occurred within 
GDKerror.\n");
        va_end(ap);
 
        GDKaddbuf(message);
@@ -1400,7 +1424,8 @@ THRprintf(stream *s, const char *format,
                if (bf != THRprintbuf)
                        free(bf);
                bf = (str) malloc(bfsz);
-               assert(bf != NULL);
+               if (bf == NULL)
+                       return -1;
        } while (1);
 
        p += n;
diff --git a/monetdb5/extras/rapi/rapi.c b/monetdb5/extras/rapi/rapi.c
--- a/monetdb5/extras/rapi/rapi.c
+++ b/monetdb5/extras/rapi/rapi.c
@@ -57,7 +57,7 @@ int RAPIEnabled(void) {
 }
 
 // The R-environment should be single threaded, calling for some protective 
measures.
-static MT_Lock rapiLock;
+static MT_Lock rapiLock MT_LOCK_INITIALIZER("rapiLock");
 static int rapiInitialized = FALSE;
 static char* rtypenames[] = { "NIL", "SYM", "LIST", "CLO", "ENV", "PROM",
                "LANG", "SPECIAL", "BUILTIN", "CHAR", "LGL", "unknown", 
"unknown",
@@ -511,8 +511,14 @@ void* RAPIloopback(void *query) {
 
 
 str RAPIprelude(void *ret) {
+#ifdef NEED_MT_LOCK_INIT
+       static int initialized = 0;
+       /* since we don't destroy the lock, only initialize it once */
+       if (!initialized)
+               MT_lock_init(&rapiLock, "rapi_lock");
+       initialized = 1;
+#endif
        (void) ret;
-       MT_lock_init(&rapiLock, "rapi_lock");
 
        if (RAPIEnabled()) {
                MT_lock_set(&rapiLock);
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -151,12 +151,14 @@ void mserver_reset(int exit)
        GDKfree(mal_clients->prompt);
        GDKfree(mal_clients->username);
        freeStack(mal_clients->glb);
-       freeSymbol(mal_clients->curprg);
+       if (mal_clients->nspace)
+               freeModule(mal_clients->nspace);
        mal_client_reset();
        mal_linker_reset();
        mal_resource_reset();
        mal_runtime_reset();
        mal_module_reset();
+       mdbExit();
 
        memset((char*)monet_cwd,0, sizeof(monet_cwd));
        monet_memory = 0;
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -57,7 +57,7 @@ void
 mal_client_reset(void)
 {
        MAL_MAXCLIENTS = 0;
-       if ( mal_clients)
+       if (mal_clients) 
                GDKfree(mal_clients);
 }
 
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
@@ -77,6 +77,15 @@ mdbInit(void)
        return 0;
 }
 
+void
+mdbExit(void)
+{
+       if (mdbTable) {
+               GDKfree(mdbTable);
+               mdbTable = 0;
+       }
+}
+
 static char
 isBreakpoint(Client cntxt, MalBlkPtr mb, InstrPtr p, int pc)
 {
diff --git a/monetdb5/mal/mal_private.h b/monetdb5/mal/mal_private.h
--- a/monetdb5/mal/mal_private.h
+++ b/monetdb5/mal/mal_private.h
@@ -22,8 +22,6 @@
        __attribute__((__visibility__("hidden")));
 __hidden str defaultScenario(Client c) /* used in src/mal/mal_session.c */
        __attribute__((__visibility__("hidden")));
-__hidden void exitScenario(Client c)           /* used in 
src/mal/mal_session.c */
-       __attribute__((__visibility__("hidden")));
 __hidden void mdbStep(Client cntxt, MalBlkPtr mb, MalStkPtr stk, int pc)
        __attribute__((__visibility__("hidden")));
 
@@ -54,6 +52,8 @@
 
 __hidden int mdbInit(void)
        __attribute__((__visibility__("hidden")));
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to