Changeset: 6321bfa91e1c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6321bfa91e1c
Modified Files:
        geom/monetdb5/geom.c
        monetdb5/mal/mal_dataflow.c
        monetdb5/mal/mal_errors.h
        monetdb5/mal/mal_exception.c
        monetdb5/modules/atoms/mtime.c
        monetdb5/modules/atoms/url.c
        monetdb5/modules/atoms/uuid.c
        monetdb5/modules/mal/tablet.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_result.c
        sql/backends/monet5/sql_scenario.c
        sql/backends/monet5/vaults/lidar/lidar.c
Branch: default
Log Message:

Unified error messages for allocation failures.


diffs (truncated from 523 to 300 lines):

diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -854,18 +854,18 @@ segmentizeLineString(GEOSGeometry **outG
        //store the points so that I do not have to read them multiple times 
using geos
        if ((xCoords_org = GDKmalloc(pointsNum * sizeof(double))) == NULL) {
                *outGeometry = NULL;
-               throw(MAL, "geom.Segmentize", "Could not allocate memory for %d 
double values", pointsNum);
+               throw(MAL, "geom.Segmentize", MAL_MALLOC_FAIL " for %d double 
values", pointsNum);
        }
        if ((yCoords_org = GDKmalloc(pointsNum * sizeof(double))) == NULL) {
                GDKfree(xCoords_org);
                *outGeometry = NULL;
-               throw(MAL, "geom.Segmentize", "Could not allocate memory for %d 
double values", pointsNum);
+               throw(MAL, "geom.Segmentize", MAL_MALLOC_FAIL " for %d double 
values", pointsNum);
        }
        if ((zCoords_org = GDKmalloc(pointsNum * sizeof(double))) == NULL) {
                GDKfree(xCoords_org);
                GDKfree(yCoords_org);
                *outGeometry = NULL;
-               throw(MAL, "geom.Segmentize", "Could not allocate memory for %d 
double values", pointsNum);
+               throw(MAL, "geom.Segmentize", MAL_MALLOC_FAIL " for %d double 
values", pointsNum);
        }
 
        if (!GEOSCoordSeq_getX(gcs_old, 0, &xCoords_org[0])) {
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
@@ -556,7 +556,7 @@ DFLOWinitBlk(DataFlow flow, MalBlkPtr mb
        PARDEBUG fprintf(stderr, "#Initialize dflow block\n");
        assign = (int *) GDKzalloc(mb->vtop * sizeof(int));
        if (assign == NULL)
-               throw(MAL, "dataflow", "DFLOWinitBlk(): Failed to allocate 
assign");
+               throw(MAL, "dataflow", MAL_MALLOC_FAIL " for assign");
        etop = flow->stop - flow->start;
        for (n = 0, pc = flow->start; pc < flow->stop; pc++, n++) {
                p = getInstrPtr(mb, pc);
@@ -878,7 +878,7 @@ runMALdataflow(Client cntxt, MalBlkPtr m
 
        flow = (DataFlow)GDKzalloc(sizeof(DataFlowRec));
        if (flow == NULL)
-               throw(MAL, "dataflow", "runMALdataflow(): Failed to allocate 
flow");
+               throw(MAL, "dataflow", MAL_MALLOC_FAIL " for flow");
 
        flow->cntxt = cntxt;
        flow->mb = mb;
@@ -902,7 +902,7 @@ runMALdataflow(Client cntxt, MalBlkPtr m
                q_destroy(flow->done);
                MT_lock_destroy(&flow->flowlock);
                GDKfree(flow);
-               throw(MAL, "dataflow", "runMALdataflow(): Failed to allocate 
flow->status");
+               throw(MAL, "dataflow", MAL_MALLOC_FAIL " for flow->status");
        }
        size = DFLOWgraphSize(mb, startpc, stoppc);
        size += stoppc - startpc;
@@ -912,7 +912,7 @@ runMALdataflow(Client cntxt, MalBlkPtr m
                q_destroy(flow->done);
                MT_lock_destroy(&flow->flowlock);
                GDKfree(flow);
-               throw(MAL, "dataflow", "runMALdataflow(): Failed to allocate 
flow->nodes");
+               throw(MAL, "dataflow", MAL_MALLOC_FAIL " for flow->nodes");
        }
        flow->edges = (int*)GDKzalloc(sizeof(int) * size);
        if (flow->edges == NULL) {
@@ -921,7 +921,7 @@ runMALdataflow(Client cntxt, MalBlkPtr m
                q_destroy(flow->done);
                MT_lock_destroy(&flow->flowlock);
                GDKfree(flow);
-               throw(MAL, "dataflow", "runMALdataflow(): Failed to allocate 
flow->edges");
+               throw(MAL, "dataflow", MAL_MALLOC_FAIL " for flow->edges");
        }
        msg = DFLOWinitBlk(flow, mb, size);
 
diff --git a/monetdb5/mal/mal_errors.h b/monetdb5/mal/mal_errors.h
--- a/monetdb5/mal/mal_errors.h
+++ b/monetdb5/mal/mal_errors.h
@@ -60,7 +60,7 @@
 #define INTERNAL_OBJ_CREATE "Can not create object"
 #define INTERNAL_AUTHORIZATION "authorization BATs not empty"
 
-#define MAL_MALLOC_FAIL        "could not allocate space"
+#define MAL_MALLOC_FAIL        "HY001!could not allocate space"
 #define MAL_STACK_FAIL "Running out of stack space."
 #define MAL_CALLDEPTH_FAIL     "Recursive call limit reached."
 
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -43,7 +43,7 @@ isExceptionVariable(str nme){
        return 0;
 }
 
-static char *M5OutOfMemory = "Out of memory. Memory allocation failed.";
+static char *M5OutOfMemory = MAL_MALLOC_FAIL;
 
 /**
  * Internal helper function for createException and
@@ -93,6 +93,22 @@ createException(enum malexception type, 
        va_list ap;
        str ret;
 
+       if (GDKerrbuf &&
+               /* prevent recursion
+                * note, sizeof("string") includes terminating NULL byte */
+               strncmp(format, MAL_MALLOC_FAIL ":", sizeof(MAL_MALLOC_FAIL)) 
!= 0 &&
+               (strncmp(GDKerrbuf, "GDKmalloc", 9) == 0 ||
+                strncmp(GDKerrbuf, "GDKrealloc", 10) == 0 ||
+                strncmp(GDKerrbuf, "GDKzalloc", 9) == 0 ||
+                strncmp(GDKerrbuf, "GDKstrdup", 9) == 0 ||
+                strncmp(GDKerrbuf, "allocating too much virtual address 
space", 41) == 0)) {
+               /* override errors when the underlying error is memory
+                * exhaustion, but include whatever it is that the GDK level
+                * reported */
+               ret = createException(type, fcn, MAL_MALLOC_FAIL ": %s", 
GDKerrbuf);
+               GDKclrerr();
+               return ret;
+       }
        va_start(ap, format);
        ret = createExceptionInternal(type, fcn, format, ap);
        va_end(ap);
diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c
--- a/monetdb5/modules/atoms/mtime.c
+++ b/monetdb5/modules/atoms/mtime.c
@@ -3061,7 +3061,7 @@ MTIMEdate_extract_year_bulk(bat *ret, co
        bn = COLnew(b->hseqbase, TYPE_int, BATcount(b), TRANSIENT);
        if (bn == NULL) {
                BBPunfix(b->batCacheid);
-               throw(MAL, "batmtime.year", "memory allocation failure");
+               throw(MAL, "batmtime.year", MAL_MALLOC_FAIL);
        }
        bn->tnonil = 1;
        bn->tnil = 0;
@@ -3106,7 +3106,7 @@ MTIMEdate_extract_month_bulk(bat *ret, c
        bn = COLnew(b->hseqbase, TYPE_int, BATcount(b), TRANSIENT);
        if (bn == NULL) {
                BBPunfix(b->batCacheid);
-               throw(MAL, "batmtime.month", "memory allocation failure");
+               throw(MAL, "batmtime.month", MAL_MALLOC_FAIL);
        }
        bn->tnonil = 1;
        bn->tnil = 0;
@@ -3150,7 +3150,7 @@ MTIMEdate_extract_day_bulk(bat *ret, con
        bn = COLnew(b->hseqbase, TYPE_int, BATcount(b), TRANSIENT);
        if (bn == NULL) {
                BBPunfix(b->batCacheid);
-               throw(MAL, "batmtime.day", "memory allocation failure");
+               throw(MAL, "batmtime.day", MAL_MALLOC_FAIL);
        }
        bn->tnonil = 1;
        bn->tnil = 0;
@@ -3195,7 +3195,7 @@ MTIMEdaytime_extract_hours_bulk(bat *ret
        bn = COLnew(b->hseqbase, TYPE_int, BATcount(b), TRANSIENT);
        if (bn == NULL) {
                BBPunfix(b->batCacheid);
-               throw(MAL, "batmtime.hours", "memory allocation failure");
+               throw(MAL, "batmtime.hours", MAL_MALLOC_FAIL);
        }
        bn->tnonil = 1;
        bn->tnil = 0;
@@ -3239,7 +3239,7 @@ MTIMEdaytime_extract_minutes_bulk(bat *r
        bn = COLnew(b->hseqbase, TYPE_int, BATcount(b), TRANSIENT);
        if (bn == NULL) {
                BBPunfix(b->batCacheid);
-               throw(MAL, "batmtime.minutes", "memory allocation failure");
+               throw(MAL, "batmtime.minutes", MAL_MALLOC_FAIL);
        }
 
        t = (const date *) Tloc(b, 0);
@@ -3281,7 +3281,7 @@ MTIMEdaytime_extract_seconds_bulk(bat *r
        bn = COLnew(b->hseqbase, TYPE_int, BATcount(b), TRANSIENT);
        if (bn == NULL) {
                BBPunfix(b->batCacheid);
-               throw(MAL, "batmtime.seconds", "memory allocation failure");
+               throw(MAL, "batmtime.seconds", MAL_MALLOC_FAIL);
        }
 
        t = (const date *) Tloc(b, 0);
@@ -3322,7 +3322,7 @@ MTIMEdaytime_extract_sql_seconds_bulk(ba
        bn = COLnew(b->hseqbase, TYPE_int, BATcount(b), TRANSIENT);
        if (bn == NULL) {
                BBPunfix(b->batCacheid);
-               throw(MAL, "batmtime.sql_seconds", "memory allocation failure");
+               throw(MAL, "batmtime.sql_seconds", MAL_MALLOC_FAIL);
        }
 
        t = (const date *) Tloc(b, 0);
@@ -3365,7 +3365,7 @@ MTIMEdaytime_extract_milliseconds_bulk(b
        bn = COLnew(b->hseqbase, TYPE_int, BATcount(b), TRANSIENT);
        if (bn == NULL) {
                BBPunfix(b->batCacheid);
-               throw(MAL, "batmtime.milliseconds", "memory allocation 
failure");
+               throw(MAL, "batmtime.milliseconds", MAL_MALLOC_FAIL);
        }
 
        t = (const date *) Tloc(b, 0);
@@ -3429,7 +3429,7 @@ MTIMEdate_to_str(str *s, const date *d, 
                throw(MAL, "mtime.date_to_str", "failed to convert date to 
string using format '%s'\n", *format);
        *s = GDKmalloc(sz + 1);
        if (*s == NULL)
-               throw(MAL, "mtime.date_to_str", "memory allocation failure");
+               throw(MAL, "mtime.date_to_str", MAL_MALLOC_FAIL);
        strncpy(*s, buf, sz + 1);
        return MAL_SUCCEED;
 #else
@@ -3473,7 +3473,7 @@ MTIMEtime_to_str(str *s, const daytime *
                throw(MAL, "mtime.time_to_str", "failed to convert time to 
string using format '%s'\n", *format);
        *s = GDKmalloc(sz + 1);
        if (*s == NULL)
-               throw(MAL, "mtime.time_to_str", "memory allocation failure");
+               throw(MAL, "mtime.time_to_str", MAL_MALLOC_FAIL);
        strncpy(*s, buf, sz + 1);
        return MAL_SUCCEED;
 #else
@@ -3521,7 +3521,7 @@ MTIMEtimestamp_to_str(str *s, const time
                throw(MAL, "mtime.timestamp_to_str", "failed to convert 
timestampt to string using format '%s'\n", *format);
        *s = GDKmalloc(sz + 1);
        if (*s == NULL)
-               throw(MAL, "mtime.timestamp_to_str", "memory allocation 
failure");
+               throw(MAL, "mtime.timestamp_to_str", MAL_MALLOC_FAIL);
        strncpy(*s, buf, sz + 1);
        return MAL_SUCCEED;
 #else
diff --git a/monetdb5/modules/atoms/url.c b/monetdb5/modules/atoms/url.c
--- a/monetdb5/modules/atoms/url.c
+++ b/monetdb5/modules/atoms/url.c
@@ -208,7 +208,7 @@ escape_str(str *retval, str s)
                throw(ILLARG, "url.escape", "url missing");
 
        if (!( res = (str) GDKmalloc( strlen(s) * 3 ) ))
-               throw(MAL, "url.escape", "malloc failed");
+               throw(MAL, "url.escape", MAL_MALLOC_FAIL);
        for (x = 0, y = 0; s[x]; ++x, ++y) {
                if (needEscape(s[x])) {
                        if (s[x] == ' ') {
@@ -241,7 +241,7 @@ unescape_str(str *retval, str s)
 
        res = (str) GDKmalloc(strlen(s));
        if (!res)
-               throw(MAL, "url.unescape", "malloc failed");
+               throw(MAL, "url.unescape", MAL_MALLOC_FAIL);
 
        for (x = 0, y = 0; s[x]; ++x, ++y) {
                if (s[x] == '%') {
@@ -335,7 +335,7 @@ URLgetAnchor(str *retval, url *val)
        else
                s = str_nil;
        if ((*retval = GDKstrdup(s)) == NULL)
-               throw(MAL, "url.getAnchor", "Allocation failed");
+               throw(MAL, "url.getAnchor", MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
@@ -371,7 +371,7 @@ URLgetBasename(str *retval, url *val)
                }
        }
        if (*retval == NULL)
-               throw(MAL, "url.getBasename", "Allocation failed");
+               throw(MAL, "url.getBasename", MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
@@ -448,7 +448,7 @@ URLgetContext(str *retval, url *val)
                (*retval)[s - p] = 0;
        }
        if (*retval == NULL)
-               throw(MAL, "url.getContext", "Allocation failed");
+               throw(MAL, "url.getContext", MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
@@ -478,7 +478,7 @@ URLgetExtension(str *retval, url *val)
                }
        }
        if (*retval == NULL)
-               throw(MAL, "url.getExtension", "Allocation failed");
+               throw(MAL, "url.getExtension", MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
@@ -508,7 +508,7 @@ URLgetFile(str *retval, url *val)
                }
        }
        if (*retval == NULL)
-               throw(MAL, "url.getFile", "Allocation failed");
+               throw(MAL, "url.getFile", MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
@@ -542,7 +542,7 @@ URLgetHost(str *retval, url *val)
                }
        }
        if (*retval == NULL)
-               throw(MAL, "url.getHost", "Allocation failed");
+               throw(MAL, "url.getHost", MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
@@ -580,7 +580,7 @@ URLgetDomain(str *retval, url *val)
                }
        }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to