Changeset: 626b8794d02f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=626b8794d02f
Modified Files:
        monetdb5/modules/atoms/mtime.c
        monetdb5/modules/atoms/url.c
        monetdb5/modules/atoms/uuid.c
Branch: malparsing
Log Message:

Stratified error handling and checking BUNappend


diffs (truncated from 313 to 300 lines):

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
@@ -1266,22 +1266,28 @@ union lng_tzone {
  * Wrapper
  * The Monet V5 API interface is defined here
  */
-#define TIMEZONES(X1, X2)                                                      
                        \
-       do {                                                                    
                                        \
-               ticks = (X2);                                                   
                                \
-               MTIMEtzone_create(&ltz.tzval, &ticks);                          
        \
-               vr.val.lval = ltz.lval;                                         
                        \
-               BUNappend(tzbatnme, (X1), FALSE);                       \
-               BUNappend(tzbatdef, &vr.val.lval, FALSE);       \
+#define TIMEZONES(X1, X2)                                                      
                                        \
+       do {                                                                    
                                                        \
+               str err;                                                        
                                                        \
+               ticks = (X2);                                                   
                                                \
+               if ((err = MTIMEtzone_create(&ltz.tzval, &ticks)) != 
MAL_SUCCEED) \
+                       return err;                                             
                                                        \
+               vr.val.lval = ltz.lval;                                         
                                        \
+               if (BUNappend(tzbatnme, (X1), FALSE) != GDK_SUCCEED ||          
        \
+                       BUNappend(tzbatdef, &vr.val.lval, FALSE) != 
GDK_SUCCEED)        \
+                       goto bailout;                                           
                                                \
        } while (0)
 
-#define TIMEZONES2(X1, X2, X3, X4)                                             
                        \
-       do {                                                                    
                                                \
-               ticks = (X2);                                                   
                                        \
-               MTIMEtzone_create_dst(&ltz.tzval, &ticks, &(X3), &(X4));        
\
-               vr.val.lval = ltz.lval;                                         
                                \
-               BUNappend(tzbatnme, (X1), FALSE);                               
\
-               BUNappend(tzbatdef, &vr.val.lval, FALSE);               \
+#define TIMEZONES2(X1, X2, X3, X4)                                             
                                \
+       do {                                                                    
                                                        \
+               str err;                                                        
                                                        \
+               ticks = (X2);                                                   
                                                \
+               if ((err = MTIMEtzone_create_dst(&ltz.tzval, &ticks, &(X3), 
&(X4))) != MAL_SUCCEED) \
+                       return err;                                             
                                                        \
+               vr.val.lval = ltz.lval;                                         
                                        \
+               if (BUNappend(tzbatnme, (X1), FALSE) != GDK_SUCCEED ||          
        \
+                       BUNappend(tzbatdef, &vr.val.lval, FALSE) != 
GDK_SUCCEED)        \
+                       goto bailout;                                           
                                                \
        } while (0)
 
 /*
@@ -1414,6 +1420,8 @@ MTIMEprelude(void *ret)
        TIMEZONES2("Alaska/USA", -9 * 60, RULE_MAR, RULE_OCT);
        msg = "West/Europe";
        return MTIMEtimezone(&tz, &msg);
+  bailout:
+       throw(MAL, "mtime.prelude", MAL_MALLOC_FAIL);
 }
 
 str
@@ -3053,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;
@@ -3098,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;
@@ -3142,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;
@@ -3187,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;
@@ -3231,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);
@@ -3273,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);
@@ -3314,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);
@@ -3357,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);
@@ -3421,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
@@ -3465,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
@@ -3513,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)
                }
        }
        if (*retval == NULL)
-               throw(MAL, "url.getDomain", "Allocation failed");
+               throw(MAL, "url.getDomain", MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
@@ -608,7 +608,7 @@ URLgetPort(str *retval, url *val)
                }
        }
        if (*retval == NULL)
-               throw(MAL, "url.getPort", "Allocation failed");
+               throw(MAL, "url.getPort", MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
@@ -626,7 +626,7 @@ URLgetProtocol(str *retval, url *val)
                throw(ILLARG, "url.getProtocol", "bad url");
        l = s - *val;
        if ((*retval = GDKmalloc(l)) == NULL)
-               throw(MAL, "url.getProtocol", "Allocation failed");
+               throw(MAL, "url.getProtocol", MAL_MALLOC_FAIL);
        strncpy(*retval, *val, l - 1);
        (*retval)[l - 1] = 0;
        return MAL_SUCCEED;
@@ -660,7 +660,7 @@ URLgetQuery(str *retval, url *val)
                *retval = GDKstrdup(str_nil);
        }
        if (*retval == NULL)
-               throw(MAL, "url.getQuery", "Allocation failed");
+               throw(MAL, "url.getQuery", MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
@@ -679,7 +679,7 @@ URLgetRobotURL(str *retval, url *val)
                throw(ILLARG, "url.getQuery", "bad url");
        l = s - *val;
        if ((*retval = GDKmalloc(l + sizeof("/robots.txt"))) == NULL)
-               throw(MAL, "url.getQuery", "Allocation failed");
+               throw(MAL, "url.getQuery", MAL_MALLOC_FAIL);
        sprintf(*retval, "%.*s/robots.txt", (int) l, *val);
        return MAL_SUCCEED;
 }
@@ -715,7 +715,7 @@ URLgetUser(str *retval, url *val)
                }
        }
        if (*retval == NULL)
-               throw(MAL, "url.getUser", "Allocation failed");
+               throw(MAL, "url.getUser", MAL_MALLOC_FAIL);
        return MAL_SUCCEED;
 }
 
@@ -745,7 +745,7 @@ URLnew3(url *u, str *protocol, str *serv
        l = GDK_STRLEN(*file) + GDK_STRLEN(*server) + GDK_STRLEN(*protocol) + 
10;
        *u = GDKmalloc(l);
        if (*u == NULL)
-               throw(MAL, "url.newurl", "Allocation failed");
+               throw(MAL, "url.newurl", MAL_MALLOC_FAIL);
        snprintf(*u, l, "%s://%s/%s", *protocol, *server, *file);
        return MAL_SUCCEED;
 }
@@ -769,7 +769,7 @@ URLnew4(url *u, str *protocol, str *serv
        l = strlen(File) + strlen(Server) + strlen(Protocol) + 20;
        *u = GDKmalloc(l);
        if (*u == NULL)
-               throw(MAL, "url.newurl", "Allocation failed");
+               throw(MAL, "url.newurl", MAL_MALLOC_FAIL);
        snprintf(*u, l, "%s://%s:%d/%s", Protocol, Server, *port, File);
        return MAL_SUCCEED;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to