Changeset: 8f12c1aae1c5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8f12c1aae1c5
Modified Files:
        clients/Tests/exports.stable.out
        gdk/gdk_bbp.c
        gdk/gdk_bbp.h
        gdk/gdk_heap.c
        gdk/gdk_private.h
        gdk/gdk_storage.c
        gdk/gdk_utils.c
        gdk/gdk_utils.h
        monetdb5/mal/mal_authorize.c
        sql/backends/monet5/sql_execute.c
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_gencode.h
        sql/backends/monet5/sql_scenario.c
        tools/merovingian/daemon/controlrunner.c
        tools/mserver/mserver5.c
        tools/mserver/shutdowntest.c
Branch: default
Log Message:

Get rid of all calls to GDKfatal inside the GDK and some others as well.
Instead, we call GDKerror (if needed) and return, and we check for
return values.


diffs (truncated from 1374 to 300 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -182,7 +182,7 @@ void BATtseqbase(BAT *b, oid o);
 void BATundo(BAT *b);
 BAT *BATunique(BAT *b, BAT *s);
 BBPrec *BBP[N_BBPINIT];
-void BBPaddfarm(const char *dirname, int rolemask);
+gdk_return BBPaddfarm(const char *dirname, int rolemask);
 void BBPclear(bat bid);
 BAT *BBPdescriptor(bat b);
 int BBPfix(bat b);
@@ -255,7 +255,7 @@ bool GDKgetenv_istrue(const char *name);
 bool GDKgetenv_isyes(const char *name);
 gdk_return GDKgetsem(int sem_id, int count, int *semid);
 gdk_return GDKgetsemval(int sem_id, int number, int *semval);
-bool GDKinit(opt *set, int setlen);
+gdk_return GDKinit(opt *set, int setlen);
 void *GDKinitmmap(size_t id, size_t size, size_t *return_size);
 BAT *GDKkey;
 ATOMIC_TYPE volatile GDKlockcnt;
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -394,7 +394,7 @@ static gdk_return BBPrecover_subdir(void
 static bool BBPdiskscan(const char *, size_t);
 
 #ifdef GDKLIBRARY_NIL_NAN
-static void
+static gdk_return
 fixfltheap(BAT *b)
 {
        long_str filename;
@@ -407,8 +407,9 @@ fixfltheap(BAT *b)
 
        nme = BBP_physical(b->batCacheid);
        srcdir = GDKfilepath(NOFARM, BATDIR, nme, NULL);
-       if (srcdir == NULL)
-               GDKfatal("fixfltheap: GDKmalloc failed\n");
+       if (srcdir == NULL) {
+               return GDK_FAIL;
+       }
        *strrchr(srcdir, DIR_SEP) = 0;
 
        if ((bnme = strrchr(nme, DIR_SEP)) != NULL)
@@ -418,23 +419,33 @@ fixfltheap(BAT *b)
        sprintf(filename, "BACKUP%c%s", DIR_SEP, bnme);
 
        /* make backup of heap */
-       if (GDKmove(b->theap.farmid, srcdir, bnme, "tail", BAKDIR, bnme, 
"tail") != GDK_SUCCEED)
-               GDKfatal("fixfltheap: cannot make backup of %s.tail\n", nme);
+       if (GDKmove(b->theap.farmid, srcdir, bnme, "tail", BAKDIR, bnme, 
"tail") != GDK_SUCCEED) {
+               GDKfree(srcdir);
+               GDKerror("fixfltheap: cannot make backup of %s.tail\n", nme);
+               return GDK_FAIL;
+       }
        /* load old heap */
        h1 = b->theap;
        stpconcat(h1.filename, filename, ".tail", NULL);
        h1.base = NULL;
        h1.dirty = false;
-       if (HEAPload(&h1, filename, "tail", false) != GDK_SUCCEED)
-               GDKfatal("fixfltheap: loading old tail heap "
+       if (HEAPload(&h1, filename, "tail", false) != GDK_SUCCEED) {
+               GDKfree(srcdir);
+               GDKerror("fixfltheap: loading old tail heap "
                         "for BAT %d failed\n", b->batCacheid);
+               return GDK_FAIL;
+       }
 
        /* create new heap */
        h2 = b->theap;
        stpconcat(h2.filename, nme, ".tail", NULL);
-       if (HEAPalloc(&h2, b->batCapacity, b->twidth) != GDK_SUCCEED)
-               GDKfatal("fixfltheap: allocating new tail heap "
+       if (HEAPalloc(&h2, b->batCapacity, b->twidth) != GDK_SUCCEED) {
+               GDKfree(srcdir);
+               HEAPfree(&h1, false);
+               GDKerror("fixfltheap: allocating new tail heap "
                         "for BAT %d failed\n", b->batCacheid);
+               return GDK_FAIL;
+       }
        h2.dirty = true;
        h2.free = h1.free;
 
@@ -500,20 +511,28 @@ fixfltheap(BAT *b)
        if (nofix) {
                /* didn't fix anything, move backup back */
                HEAPfree(&h2, true);
-               if (GDKmove(b->theap.farmid, BAKDIR, bnme, "tail", srcdir, 
bnme, "tail") != GDK_SUCCEED)
-                       GDKfatal("fixfltheap: cannot restore backup of 
%s.tail\n", nme);
+               if (GDKmove(b->theap.farmid, BAKDIR, bnme, "tail", srcdir, 
bnme, "tail") != GDK_SUCCEED) {
+                       GDKfree(srcdir);
+                       GDKerror("fixfltheap: cannot restore backup of 
%s.tail\n", nme);
+                       return GDK_FAIL;
+               }
        } else {
                /* heap was fixed */
                b->batDirtydesc = true;
-               if (HEAPsave(&h2, nme, "tail") != GDK_SUCCEED)
-                       GDKfatal("fixfltheap: saving heap failed\n");
+               if (HEAPsave(&h2, nme, "tail") != GDK_SUCCEED) {
+                       HEAPfree(&h2, false);
+                       GDKfree(srcdir);
+                       GDKerror("fixfltheap: saving heap failed\n");
+                       return GDK_FAIL;
+               }
                HEAPfree(&h2, false);
                b->theap = h2;
        }
        GDKfree(srcdir);
+       return GDK_SUCCEED;
 }
 
-static void
+static gdk_return
 fixfloatbats(void)
 {
        bat bid;
@@ -540,9 +559,11 @@ fixfloatbats(void)
                                 BBPfarms[0].dirname,
                                 (int) (len - 12), BBP_logical(bid));
                        fp = fopen(filename, "w");
-                       if (fp == NULL)
-                               GDKfatal("fixfloatbats: cannot create file 
%s\n",
+                       if (fp == NULL) {
+                               GDKsyserror("fixfloatbats: cannot create file 
%s\n",
                                         filename);
+                               return GDK_FAIL;
+                       }
                        fclose(fp);
                }
                if (b->batCount == 0 || b->tnonil) {
@@ -559,8 +580,10 @@ fixfloatbats(void)
                                continue;
                } else if (b->ttype != TYPE_flt && b->ttype != TYPE_dbl)
                        continue;
-               fixfltheap(b);
+               if (fixfltheap(b) != GDK_SUCCEED)
+                       return GDK_FAIL;
        }
+       return GDK_SUCCEED;
 }
 #endif
 
@@ -604,11 +627,15 @@ heapinit(BAT *b, const char *buf, int *h
                   type, &width, &var, &properties, &nokey0,
                   &nokey1, &nosorted, &norevsorted, &base,
                   &free, &size, &storage,
-                  &n) < 12)
-               GDKfatal("BBPinit: invalid format for BBP.dir\n%s", buf);
-
-       if (properties & ~0x0F81)
-               GDKfatal("BBPinit: unknown properties are set: incompatible 
database\n");
+                  &n) < 12) {
+               GDKerror("BBPinit: invalid format for BBP.dir\n%s", buf);
+               return -1;
+       }
+
+       if (properties & ~0x0F81) {
+               GDKerror("BBPinit: unknown properties are set: incompatible 
database\n");
+               return -1;
+       }
        *hashash = var & 2;
        var &= ~2;
 #ifdef HAVE_HGE
@@ -619,19 +646,24 @@ heapinit(BAT *b, const char *buf, int *h
        if (strcmp(type, "sqlblob") == 0)
                strcpy(type, "blob");
        if ((t = ATOMindex(type)) < 0) {
-               if ((t = ATOMunknown_find(type)) == 0)
-                       GDKfatal("BBPinit: no space for atom %s", type);
-       } else if (var != (t == TYPE_void || BATatoms[t].atomPut != NULL))
-               GDKfatal("BBPinit: inconsistent entry in BBP.dir: tvarsized 
mismatch for BAT %d\n", (int) bid);
-       else if (var && t != 0 ?
-                ATOMsize(t) < width ||
-                (width != 1 && width != 2 && width != 4
+               if ((t = ATOMunknown_find(type)) == 0) {
+                       GDKerror("BBPinit: no space for atom %s", type);
+                       return -1;
+               }
+       } else if (var != (t == TYPE_void || BATatoms[t].atomPut != NULL)) {
+               GDKerror("BBPinit: inconsistent entry in BBP.dir: tvarsized 
mismatch for BAT %d\n", (int) bid);
+               return -1;
+       } else if (var && t != 0 ?
+                  ATOMsize(t) < width ||
+                  (width != 1 && width != 2 && width != 4
 #if SIZEOF_VAR_T == 8
-                 && width != 8
+                   && width != 8
 #endif
-                        ) :
-                ATOMsize(t) != width)
-               GDKfatal("BBPinit: inconsistent entry in BBP.dir: tsize 
mismatch for BAT %d\n", (int) bid);
+                          ) :
+                  ATOMsize(t) != width) {
+               GDKerror("BBPinit: inconsistent entry in BBP.dir: tsize 
mismatch for BAT %d\n", (int) bid);
+               return -1;
+       }
        b->ttype = t;
        b->twidth = width;
        b->tvarsized = var != 0;
@@ -657,8 +689,10 @@ heapinit(BAT *b, const char *buf, int *h
        b->theap.newstorage = (storage_t) storage;
        b->theap.farmid = BBPselectfarm(PERSISTENT, b->ttype, offheap);
        b->theap.dirty = false;
-       if (b->theap.free > b->theap.size)
-               GDKfatal("BBPinit: \"free\" value larger than \"size\" in heap 
of bat %d\n", (int) bid);
+       if (b->theap.free > b->theap.size) {
+               GDKerror("BBPinit: \"free\" value larger than \"size\" in heap 
of bat %d\n", (int) bid);
+               return -1;
+       }
        return n;
 }
 
@@ -671,13 +705,17 @@ vheapinit(BAT *b, const char *buf, int h
 
        if (b->tvarsized && b->ttype != TYPE_void) {
                b->tvheap = GDKzalloc(sizeof(Heap));
-               if (b->tvheap == NULL)
-                       GDKfatal("BBPinit: cannot allocate memory for heap.");
+               if (b->tvheap == NULL) {
+                       GDKerror("BBPinit: cannot allocate memory for heap.");
+                       return -1;
+               }
                if (sscanf(buf,
                           " %" SCNu64 " %" SCNu64 " %" SCNu16
                           "%n",
-                          &free, &size, &storage, &n) < 3)
-                       GDKfatal("BBPinit: invalid format for BBP.dir\n%s", 
buf);
+                          &free, &size, &storage, &n) < 3) {
+                       GDKerror("BBPinit: invalid format for BBP.dir\n%s", 
buf);
+                       return -1;
+               }
                b->tvheap->free = (size_t) free;
                b->tvheap->size = (size_t) size;
                b->tvheap->base = NULL;
@@ -690,13 +728,15 @@ vheapinit(BAT *b, const char *buf, int h
                b->tvheap->dirty = false;
                b->tvheap->parentid = bid;
                b->tvheap->farmid = BBPselectfarm(PERSISTENT, b->ttype, 
varheap);
-               if (b->tvheap->free > b->tvheap->size)
-                       GDKfatal("BBPinit: \"free\" value larger than \"size\" 
in var heap of bat %d\n", (int) bid);
+               if (b->tvheap->free > b->tvheap->size) {
+                       GDKerror("BBPinit: \"free\" value larger than \"size\" 
in var heap of bat %d\n", (int) bid);
+                       return -1;
+               }
        }
        return n;
 }
 
-static void
+static gdk_return
 BBPreadEntries(FILE *fp, unsigned bbpversion)
 {
        bat bid = 0;
@@ -708,34 +748,42 @@ BBPreadEntries(FILE *fp, unsigned bbpver
                uint64_t batid;
                uint16_t status;
                char headname[129];
-               char filename[24];
+               char filename[20];
                unsigned int properties;
-               int nread;
+               int nread, n;
                char *s, *options = NULL;
                char logical[1024];
                uint64_t first = 0, count, capacity, base = 0;
                int Thashash;
 
+               static_assert(sizeof(BBP_physical(0)) == sizeof(filename),
+                       "filename should be same size as BBPrec.physical");
                if ((s = strchr(buf, '\r')) != NULL) {
                        /* convert \r\n into just \n */
-                       if (s[1] != '\n')
-                               GDKfatal("BBPinit: invalid format for BBP.dir");
+                       if (s[1] != '\n') {
+                               GDKerror("BBPinit: invalid format for BBP.dir");
+                               return GDK_FAIL;
+                       }
                        *s++ = '\n';
                        *s = 0;
                }
 
                if (sscanf(buf,
-                          "%" SCNu64 " %" SCNu16 " %128s %23s %u %" SCNu64
+                          "%" SCNu64 " %" SCNu16 " %128s %19s %u %" SCNu64
                           " %" SCNu64 " %" SCNu64
                           "%n",
                           &batid, &status, headname, filename,
                           &properties,
                           &count, &capacity, &base,
-                          &nread) < 8)
-                       GDKfatal("BBPinit: invalid format for BBP.dir\n%s", 
buf);
-
-               if (batid >= N_BBPINIT * BBPINIT)
-                       GDKfatal("BBPinit: bat ID (%" PRIu64 ") too large to 
accomodate (max %d).", batid, N_BBPINIT * BBPINIT - 1);
+                          &nread) < 8) {
+                       GDKerror("BBPinit: invalid format for BBP.dir\n%s", 
buf);
+                       return GDK_FAIL;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to