Changeset: 024ae45f73f8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/024ae45f73f8
Modified Files:
        gdk/gdk_atoms.c
        gdk/gdk_utils.c
        gdk/gdk_value.c
        geom/monetdb5/geom.c
        monetdb5/mal/mal_exception.c
        monetdb5/mal/mal_type.c
        monetdb5/modules/atoms/inet.c
        monetdb5/modules/atoms/json.c
        monetdb5/modules/atoms/str.c
        monetdb5/modules/atoms/url.c
        monetdb5/modules/atoms/xml.c
        monetdb5/modules/kernel/bat5.c
        monetdb5/modules/mal/calc.c
        monetdb5/modules/mal/clients.c
        monetdb5/modules/mal/mal_mapi.c
        monetdb5/modules/mal/pcre.c
        monetdb5/modules/mal/txtsim.c
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_rank.c
        sql/backends/monet5/sql_statement.c
        sql/server/rel_prop.c
        sql/server/sql_atom.c
        sql/server/sql_parser.y
        sql/server/sql_semantic.c
        sql/server/sqlparse.c
Branch: Dec2025
Log Message:

There is no need to use ma_strdup on globally constant strings, including 
str_nil.
Since the returned value is never explicitly freed, nor are the result
values ever changed, we don't need a freeable copy.


diffs (truncated from 2396 to 300 lines):

diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -418,7 +418,7 @@ ATOMformat(allocator *ma, int t, const v
                }
                return buf;
        }
-       return ma_strdup(ma, "nil");
+       return "nil";
 }
 
 /*
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -2403,6 +2403,8 @@ ma_strndup(allocator *sa, const char *s,
 char *
 ma_strdup(allocator *sa, const char *s)
 {
+       if (strNil(s))
+               return (char *) str_nil;
        return ma_strndup(sa, s, strlen(s));
 }
 
diff --git a/gdk/gdk_value.c b/gdk/gdk_value.c
--- a/gdk/gdk_value.c
+++ b/gdk/gdk_value.c
@@ -302,9 +302,8 @@ char *
 VALformat(allocator *ma, const ValRecord *res)
 {
        if (res->bat) {
-               if (is_bat_nil(res->val.bval)) {
-                       return ma_strdup(ma, "nil");
-               }
+               if (is_bat_nil(res->val.bval))
+                       return "nil";
                else
                        return ATOMformat(ma, TYPE_int, (const void *) 
&res->val.ival);
        } else
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -2380,8 +2380,7 @@ geoGetType(Client ctx, char **res, int *
 {
        allocator *ma = ctx->curprg->def->ma;
        if (is_int_nil(*info) || is_int_nil(*flag)) {
-               if ((*res = ma_strdup(ma, str_nil)) == NULL)
-                       throw(MAL, "geom.getType", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *res = (char *) str_nil;
                return MAL_SUCCEED;
        }
        if ((*res = ma_strdup(ma, geom_type2str(*info >> 2, *flag))) == NULL)
@@ -2533,8 +2532,7 @@ wkbAsBinary(Client ctx, char **toStr, wk
        int i;
 
        if (is_wkb_nil(*geomWKB)) {
-               if ((*toStr = ma_strdup(ma, str_nil)) == NULL)
-                       throw(MAL, "geom.AsBinary", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *toStr = (char *) str_nil;
                return MAL_SUCCEED;
        }
        if ((*toStr = ma_alloc(ma, 1 + (*geomWKB)->len * 2)) == NULL)
@@ -2729,8 +2727,7 @@ wkbAsText(Client ctx, char **txt, wkb **
        const char sridTxt[] = "SRID:";
 
        if (is_wkb_nil(*geomWKB) || (withSRID && is_int_nil(*withSRID))) {
-               if ((*txt = ma_strdup(ma, str_nil)) == NULL)
-                       throw(MAL, "geom.AsText", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *txt = (char *) str_nil;
                return MAL_SUCCEED;
        }
 
@@ -4305,8 +4302,7 @@ wkbIsValidReason(Client ctx, char **reas
        char *GEOSReason = NULL;
 
        if (is_wkb_nil(*geomWKB)) {
-               if ((*reason = ma_strdup(ma, str_nil)) == NULL)
-                       throw(MAL, "geom.IsValidReason", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *reason = (char *) str_nil;
                return MAL_SUCCEED;
        }
 
@@ -4340,8 +4336,7 @@ wkbIsValidDetail(Client ctx, char **out,
        GEOSGeom geosGeometry;
 
        if (is_wkb_nil(*geom)) {
-               if ((*out = ma_strdup(ma, str_nil)) == NULL)
-                       throw(MAL, "geom.IsValidReason", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *out = (char *) str_nil;
                return MAL_SUCCEED;
        }
 
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
@@ -323,7 +323,7 @@ getExceptionPlace(allocator *ma, const c
                        break;
                }
        }
-       return ma_strdup(ma, "(unknown)");
+       return "(unknown)";
 }
 
 /**
diff --git a/monetdb5/mal/mal_type.c b/monetdb5/mal/mal_type.c
--- a/monetdb5/mal/mal_type.c
+++ b/monetdb5/mal/mal_type.c
@@ -42,7 +42,7 @@ getTypeName(allocator *ma, malType tpe)
        int k;
 
        if (tpe == TYPE_any)
-               return ma_strdup(ma, "any");
+               return "any";
        if (isaBatType(tpe)) {
                k = getTypeIndex(tpe);
                if (k)
diff --git a/monetdb5/modules/atoms/inet.c b/monetdb5/modules/atoms/inet.c
--- a/monetdb5/modules/atoms/inet.c
+++ b/monetdb5/modules/atoms/inet.c
@@ -563,9 +563,7 @@ INEThost(Client ctx, str *retval, const 
        str ip;
 
        if (is_inet_nil(val)) {
-               *retval = ma_strdup(ma, str_nil);
-               if (*retval == NULL)
-                       throw(MAL, "INEThost", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+               *retval = (char *) str_nil;
        } else {
                ip = ma_alloc(ma, sizeof(char) * 16);
                if (ip == NULL)
@@ -722,9 +720,7 @@ INETtext(Client ctx, str *retval, const 
        str ip;
 
        if (is_inet_nil(val)) {
-               *retval = ma_strdup(ma, str_nil);
-               if (*retval == NULL)
-                       throw(MAL, "INETtext", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+               *retval = (char *) str_nil;
        } else {
                ip = ma_alloc(ma, sizeof(char) * 20);
                if (ip == NULL)
@@ -749,9 +745,7 @@ INETabbrev(Client ctx, str *retval, cons
        str ip;
 
        if (is_inet_nil(val)) {
-               *retval = ma_strdup(ma, str_nil);
-               if (*retval == NULL)
-                       throw(MAL, "inet.abbrev", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *retval = (char *) str_nil;
        } else {
                unsigned int mask;
                unsigned char m[4];
diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -820,7 +820,7 @@ JSONgetValue(allocator *ma, const JSON *
        str s;
 
        if (jt->elm[idx].valuelen == 0)
-               return ma_strdup(ma, str_nil);
+               return (char *) str_nil;
        s = ma_alloc(ma, jt->elm[idx].valuelen + 1);
        if (s)
                strcpy_len(s, jt->elm[idx].value, jt->elm[idx].valuelen + 1);
@@ -1045,7 +1045,7 @@ JSONfilterInternal(Client ctx, json *ret
                        snprintf(s, l + 3, "[%s]", (result ? result : ""));
        }
        else if (result == NULL || *result == 0) {
-               s = ma_strdup(ma, "[]");
+               s = "[]";
        }
        else {
                s = ma_alloc(ma, l + 1);
@@ -1533,10 +1533,8 @@ JSONfilterArrayDefault(Client ctx, json 
 static str
 JSONfilterArray_bte(Client ctx, json *ret, const json *js, const bte *index)
 {
-       allocator *ma = ctx->curprg->def->ma;
        if (strNil(*js) || is_bte_nil(*index)) {
-               if (!(*ret = ma_strdup(ma, str_nil)))
-                       throw(MAL, "json.filter", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *ret = (json) str_nil;
                return MAL_SUCCEED;
        }
        return JSONfilterArrayDefault(ctx, ret, js, (lng) *index, 0);
@@ -1545,10 +1543,8 @@ JSONfilterArray_bte(Client ctx, json *re
 static str
 JSONfilterArrayDefault_bte(Client ctx, json *ret, const json *js, const bte 
*index, const char *const *other)
 {
-       allocator *ma = ctx->curprg->def->ma;
        if (strNil(*js) || is_bte_nil(*index) || strNil(*other)) {
-               if (!(*ret = ma_strdup(ma, str_nil)))
-                       throw(MAL, "json.filter", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *ret = (json) str_nil;
                return MAL_SUCCEED;
        }
        return JSONfilterArrayDefault(ctx, ret, js, (lng) *index, *other);
@@ -1557,10 +1553,8 @@ JSONfilterArrayDefault_bte(Client ctx, j
 static str
 JSONfilterArray_sht(Client ctx, json *ret, const json *js, const sht *index)
 {
-       allocator *ma = ctx->curprg->def->ma;
        if (strNil(*js) || is_sht_nil(*index)) {
-               if (!(*ret = ma_strdup(ma, str_nil)))
-                       throw(MAL, "json.filter", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *ret = (json) str_nil;
                return MAL_SUCCEED;
        }
        return JSONfilterArrayDefault(ctx, ret, js, (lng) *index, 0);
@@ -1569,10 +1563,8 @@ JSONfilterArray_sht(Client ctx, json *re
 static str
 JSONfilterArrayDefault_sht(Client ctx, json *ret, const json *js, const sht 
*index, const char *const *other)
 {
-       allocator *ma = ctx->curprg->def->ma;
        if (strNil(*js) || is_sht_nil(*index) || strNil(*other)) {
-               if (!(*ret = ma_strdup(ma, str_nil)))
-                       throw(MAL, "json.filter", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *ret = (json) str_nil;
                return MAL_SUCCEED;
        }
        return JSONfilterArrayDefault(ctx, ret, js, (lng) *index, *other);
@@ -1581,10 +1573,8 @@ JSONfilterArrayDefault_sht(Client ctx, j
 static str
 JSONfilterArray_int(Client ctx, json *ret, const json *js, const int *index)
 {
-       allocator *ma = ctx->curprg->def->ma;
        if (strNil(*js) || is_int_nil(*index)) {
-               if (!(*ret = ma_strdup(ma, str_nil)))
-                       throw(MAL, "json.filter", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *ret = (json) str_nil;
                return MAL_SUCCEED;
        }
        return JSONfilterArrayDefault(ctx, ret, js, (lng) *index, 0);
@@ -1593,10 +1583,8 @@ JSONfilterArray_int(Client ctx, json *re
 static str
 JSONfilterArrayDefault_int(Client ctx, json *ret, const json *js, const int 
*index, const char *const *other)
 {
-       allocator *ma = ctx->curprg->def->ma;
        if (strNil(*js) || is_int_nil(*index) || strNil(*other)) {
-               if (!(*ret = ma_strdup(ma, str_nil)))
-                       throw(MAL, "json.filter", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *ret = (json) str_nil;
                return MAL_SUCCEED;
        }
        return JSONfilterArrayDefault(ctx, ret, js, (lng) *index, *other);
@@ -1605,10 +1593,8 @@ JSONfilterArrayDefault_int(Client ctx, j
 static str
 JSONfilterArray_lng(Client ctx, json *ret, const json *js, const lng *index)
 {
-       allocator *ma = ctx->curprg->def->ma;
        if (strNil(*js) || is_lng_nil(*index)) {
-               if (!(*ret = ma_strdup(ma, str_nil)))
-                       throw(MAL, "json.filter", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *ret = (json) str_nil;
                return MAL_SUCCEED;
        }
        return JSONfilterArrayDefault(ctx, ret, js, (lng) *index, 0);
@@ -1617,10 +1603,8 @@ JSONfilterArray_lng(Client ctx, json *re
 static str
 JSONfilterArrayDefault_lng(Client ctx, json *ret, const json *js, const lng 
*index, const char *const *other)
 {
-       allocator *ma = ctx->curprg->def->ma;
        if (strNil(*js) || is_lng_nil(*index) || strNil(*other)) {
-               if (!(*ret = ma_strdup(ma, str_nil)))
-                       throw(MAL, "json.filter", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *ret = (json) str_nil;
                return MAL_SUCCEED;
        }
        return JSONfilterArrayDefault(ctx, ret, js, (lng) *index, *other);
@@ -1630,10 +1614,8 @@ JSONfilterArrayDefault_lng(Client ctx, j
 static str
 JSONfilterArray_hge(Client ctx, json *ret, const json *js, const hge *index)
 {
-       allocator *ma = ctx->curprg->def->ma;
        if (strNil(*js) || is_hge_nil(*index)) {
-               if (!(*ret = ma_strdup(ma, str_nil)))
-                       throw(MAL, "json.filter", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *ret = (json) str_nil;
                return MAL_SUCCEED;
        }
        if (*index < (hge) GDK_lng_min || *index > (hge) GDK_lng_max)
@@ -1644,10 +1626,8 @@ JSONfilterArray_hge(Client ctx, json *re
 static str
 JSONfilterArrayDefault_hge(Client ctx, json *ret, const json *js, const hge 
*index, const char *const *other)
 {
-       allocator *ma = ctx->curprg->def->ma;
        if (strNil(*js) || is_hge_nil(*index) || strNil(*other)) {
-               if (!(*ret = ma_strdup(ma, str_nil)))
-                       throw(MAL, "json.filter", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               *ret = (json) str_nil;
                return MAL_SUCCEED;
        }
        if (*index < (hge) GDK_lng_min || *index > (hge) GDK_lng_max)
@@ -1659,10 +1639,8 @@ JSONfilterArrayDefault_hge(Client ctx, j
 static str
 JSONfilter(Client ctx, json *ret, const json *js, const char *const *expr)
 {
-       allocator *ma = ctx->curprg->def->ma;
        if (strNil(*js) || strNil(*expr)) {
-               if (!(*ret = ma_strdup(ma, str_nil)))
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to