Changeset: 07870737ce9f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=07870737ce9f
Modified Files:
        clients/Tests/exports.stable.out
        gdk/ChangeLog
        gdk/gdk.h
        gdk/gdk_atoms.c
        gdk/gdk_value.c
        monetdb5/mal/mal_instruction.c
        monetdb5/mal/mal_listing.c
        monetdb5/mal/mal_profiler.c
        monetdb5/modules/atoms/json.c
        monetdb5/modules/mal/mal_mapi.c
        monetdb5/modules/mal/mdb.c
        monetdb5/modules/mal/remote.c
        monetdb5/optimizer/opt_remoteQueries.c
        sql/server/sql_atom.c
Branch: default
Log Message:

Changed the interface of ATOMformat and VALformat.
They now return a pointer to the allocated string.


diffs (truncated from 352 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
@@ -13,7 +13,7 @@ int ATOMallocate(const char *nme);
 int ATOMcmp(int id, const void *v_1, const void *v_2);
 ptr ATOMdup(int id, const void *val);
 bte ATOMelmshift(int sz);
-ssize_t ATOMformat(int id, const void *val, char **buf);
+char *ATOMformat(int id, const void *val);
 int ATOMindex(const char *nme);
 size_t ATOMlen(int id, const void *v);
 str ATOMname(int id);
@@ -330,7 +330,7 @@ int VALcmp(const ValRecord *p, const Val
 ptr VALconvert(int typ, ValPtr t);
 ValPtr VALcopy(ValPtr dst, const ValRecord *src);
 void VALempty(ValPtr v);
-ssize_t VALformat(char **buf, const ValRecord *res);
+char *VALformat(const ValRecord *res);
 void *VALget(ValPtr v);
 ValPtr VALinit(ValPtr d, int tpe, const void *s);
 int VALisnil(const ValRecord *v);
diff --git a/gdk/ChangeLog b/gdk/ChangeLog
--- a/gdk/ChangeLog
+++ b/gdk/ChangeLog
@@ -1,6 +1,10 @@
 # ChangeLog file for MonetDB
 # This file is updated with Maddlog
 
+* Mon Sep 18 2017 Sjoerd Mullender <sjo...@acm.org>
+- Changed the interface of ATOMformat and VALformat: they now return a
+  pointer to the allocated string.
+
 * Thu Sep 14 2017 Sjoerd Mullender <sjo...@acm.org>
 - The length "method" for atoms now returns a size_t, the "len" field of
   a ValRecord is now a size_t, the "size" field of the atomDesc structure
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -733,7 +733,7 @@ typedef struct {
 
 /* interface definitions */
 gdk_export ptr VALconvert(int typ, ValPtr t);
-gdk_export ssize_t VALformat(char **buf, const ValRecord *res);
+gdk_export char *VALformat(const ValRecord *res);
 gdk_export ValPtr VALcopy(ValPtr dst, const ValRecord *src);
 gdk_export ValPtr VALinit(ValPtr d, int tpe, const void *s);
 gdk_export void VALempty(ValPtr v);
@@ -1894,7 +1894,7 @@ gdk_export size_t ATOMlen(int id, const 
 gdk_export ptr ATOMnil(int id);
 gdk_export int ATOMcmp(int id, const void *v_1, const void *v_2);
 gdk_export int ATOMprint(int id, const void *val, stream *fd);
-gdk_export ssize_t ATOMformat(int id, const void *val, char **buf);
+gdk_export char *ATOMformat(int id, const void *val);
 
 gdk_export ptr ATOMdup(int id, const void *val);
 
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -347,24 +347,22 @@ ATOMprint(int t, const void *p, stream *
 }
 
 
-ssize_t
-ATOMformat(int t, const void *p, char **buf)
+char *
+ATOMformat(int t, const void *p)
 {
        ssize_t (*tostr) (str *, size_t *, const void *);
 
        if (p && 0 <= t && t < GDKatomcnt && (tostr = BATatoms[t].atomToStr)) {
                size_t sz = 0;
-               ssize_t res = (*tostr) (buf, &sz, p);
-               if (res < 0 && *buf) {
-                       GDKfree(*buf);
-                       *buf = NULL;
+               char *buf = NULL;
+               ssize_t res = (*tostr) (&buf, &sz, p);
+               if (res < 0 && buf) {
+                       GDKfree(buf);
+                       buf = NULL;
                }
-               return res;
+               return buf;
        }
-       *buf = GDKstrdup("nil");
-       if (*buf == NULL)
-               return -1;
-       return 3;               /* strlen(*buf) */
+       return GDKstrdup("nil");
 }
 
 ptr
diff --git a/gdk/gdk_value.c b/gdk/gdk_value.c
--- a/gdk/gdk_value.c
+++ b/gdk/gdk_value.c
@@ -226,11 +226,10 @@ VALinit(ValPtr d, int tpe, const void *s
 
 /* Format the value in RES in the standard way for the type of RES
  * into a newly allocated buffer which is returned through BUF. */
-ssize_t
-VALformat(char **buf, const ValRecord *res)
+char *
+VALformat(const ValRecord *res)
 {
-       *buf = 0;
-       return ATOMformat(res->vtype, VALptr(res), buf);
+       return ATOMformat(res->vtype, VALptr(res));
 }
 
 /* Convert (cast) the value in T to the type TYP, do this in place.
diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c
--- a/monetdb5/mal/mal_instruction.c
+++ b/monetdb5/mal/mal_instruction.c
@@ -1046,15 +1046,16 @@ convertConstant(int type, ValPtr vr)
                return MAL_SUCCEED;
        case TYPE_str:
        {
-               str w = 0;
+               str w;
                if (vr->vtype == TYPE_void || ATOMcmp(vr->vtype, 
ATOMnilptr(vr->vtype), VALptr(vr)) == 0) {
                        vr->vtype = type;
                        vr->val.sval = GDKstrdup(str_nil);
                        vr->len = (int) strlen(vr->val.sval);
                        return MAL_SUCCEED;
                }
-               ATOMformat(vr->vtype, VALptr(vr), &w);
-               assert(w != NULL);
+               w = ATOMformat(vr->vtype, VALptr(vr));
+               if (w == NULL)
+                       throw(SYNTAX, "convertConstant", GDK_EXCEPTION);
                vr->vtype = TYPE_str;
                vr->len = (int) strlen(w);
                vr->val.sval = w;
@@ -1130,10 +1131,10 @@ convertConstant(int type, ValPtr vr)
                /* if what we're converting from is not a string */
                if (vr->vtype != TYPE_str) {
                        /* an extern type */
-                       str w = NULL;
+                       str w;
 
                        /* dump the non-string atom as string in w */
-                       if (ATOMformat(vr->vtype, VALptr(vr), &w) < 0 ||
+                       if ((w = ATOMformat(vr->vtype, VALptr(vr))) == NULL ||
                                /* and try to parse it from string as the 
desired type */
                                ATOMfromstr(type, &d, &ll, w) < 0 ||
                                d == NULL) {
diff --git a/monetdb5/mal/mal_listing.c b/monetdb5/mal/mal_listing.c
--- a/monetdb5/mal/mal_listing.c
+++ b/monetdb5/mal/mal_listing.c
@@ -70,7 +70,10 @@ renderTerm(MalBlkPtr mb, MalStkPtr stk, 
                } else if( stk)
                        val = &stk->stk[varid];
 
-               VALformat(&cv, val);
+               if ((cv = VALformat(val)) == NULL) {
+                       addMalException(mb, "renderTerm:Failed to allocate");
+                       return NULL;
+               }
                if (len + strlen(cv) >= maxlen)
                        buf= GDKrealloc(buf, maxlen =len + strlen(cv) + BUFSIZ);
 
@@ -412,13 +415,17 @@ shortRenderingTerm(MalBlkPtr mb, MalStkP
 
        if( isVarConstant(mb,varid) ){
                val =&getVarConstant(mb, varid);
-               VALformat(&cv, val);
+               if ((cv = VALformat(val)) == NULL) {
+                       GDKfree(s);
+                       return NULL;
+               }
                if (strlen(cv) >= len) {
                        char *nbuf;
                        len = strlen(cv);
                        nbuf = GDKrealloc(s, len + 1);
                        if (nbuf == NULL) {
                                GDKfree(s);
+                               GDKfree(cv);
                                return NULL;
                        }
                        s = nbuf;
@@ -426,7 +433,10 @@ shortRenderingTerm(MalBlkPtr mb, MalStkP
                snprintf(s,len + 1,"%s",cv);
        } else {
                val = &stk->stk[varid];
-               VALformat(&cv, val);
+               if ((cv = VALformat(val)) == NULL) {
+                       GDKfree(s);
+                       return NULL;
+               }
                nme = getVarName(mb, varid);
                if ( isaBatType(getArgType(mb,p,idx))){
                        b = BBPquickdesc(stk->stk[varid].val.bval,TRUE);
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -348,8 +348,7 @@ This information can be used to determin
                                        char *truncated = NULL;
                                        tname = getTypeName(tpe);
                                        logadd("\"type\":\"%s\",%s", 
tname,pret);
-                                       cv = 0;
-                                       VALformat(&cv, 
&stk->stk[getArg(pci,j)]);
+                                       cv = 
VALformat(&stk->stk[getArg(pci,j)]);
                                        stmtq = mal_quote(cv, strlen(cv));
                                        if (stmtq != NULL && strlen(stmtq) > 
LOGLEN/2) {
                                                truncated = 
truncate_string(stmtq);
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
@@ -1626,8 +1626,7 @@ JSONrenderRowObject(BAT **bl, MalBlkPtr 
                bi = bat_iterator(bl[i + 1]);
                p = BUNtail(bi, idx);
                tpe = getBatType(getArgType(mb, pci, i + 1));
-               val = NULL;
-               if (ATOMformat(tpe, p, &val) < 0) {
+               if ((val = ATOMformat(tpe, p)) == NULL) {
                        GDKfree(row);
                        return NULL;
                }
@@ -1742,8 +1741,7 @@ JSONrenderRowArray(BAT **bl, MalBlkPtr m
                bi = bat_iterator(bl[i]);
                p = BUNtail(bi, idx);
                tpe = getBatType(getArgType(mb, pci, i));
-               val = NULL;
-               if (ATOMformat(tpe, p, &val) < 0) {
+               if ((val = ATOMformat(tpe, p)) == NULL) {
                        goto memfail;
                }
                if (strcmp(val, "nil") == 0) {
@@ -1915,8 +1913,7 @@ JSONfoldKeyValue(str *ret, const bat *id
                if (tpe == TYPE_json)
                        val = p;
                else {
-                       val = NULL;
-                       if (ATOMformat(tpe, p, &val) < 0)
+                       if ((val = ATOMformat(tpe, p))  == NULL)
                                goto memfail;
                        if (strcmp(val, "nil") == 0) {
                                GDKfree(val);
diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c
--- a/monetdb5/modules/mal/mal_mapi.c
+++ b/monetdb5/modules/mal/mal_mapi.c
@@ -1799,7 +1799,8 @@ SERVERput(Client cntxt, MalBlkPtr mb, Ma
                SERVERsessions[i].hdl= mapi_query(mid, buf);
                break;
        default:
-               ATOMformat(tpe,val,&w);
+               if ((w = ATOMformat(tpe,val)) == NULL)
+                       throw(MAL, "mapi.put", GDK_EXCEPTION);
                snprintf(buf,BUFSIZ,"%s:=%s;",*nme,w);
                GDKfree(w);
                if( SERVERsessions[i].hdl)
@@ -1830,7 +1831,8 @@ SERVERputLocal(Client cntxt, MalBlkPtr m
                snprintf(buf,BUFSIZ,"%s:=%s;",*nme,*(char**)val);
                break;
        default:
-               ATOMformat(tpe,val,&w);
+               if ((w = ATOMformat(tpe,val)) == NULL)
+                       throw(MAL, "mapi.glue", GDK_EXCEPTION);
                snprintf(buf,BUFSIZ,"%s:=%s;",*nme,w);
                GDKfree(w);
                break;
diff --git a/monetdb5/modules/mal/mdb.c b/monetdb5/modules/mal/mdb.c
--- a/monetdb5/modules/mal/mdb.c
+++ b/monetdb5/modules/mal/mdb.c
@@ -289,8 +289,8 @@ MDBgetFrame(BAT *b, BAT *bn, MalBlkPtr m
        if (s != 0)
                for (i = 0; i < s->stktop; i++, v++) {
                        v = &s->stk[i];
-                       ATOMformat(v->vtype, VALptr(v), &buf);
-                       if (BUNappend(b, getVarName(mb, i), FALSE) != 
GDK_SUCCEED ||
+                       if ((buf = ATOMformat(v->vtype, VALptr(v))) == NULL ||
+                               BUNappend(b, getVarName(mb, i), FALSE) != 
GDK_SUCCEED ||
                                BUNappend(bn, buf, FALSE) != GDK_SUCCEED) {
                                BBPunfix(b->batCacheid);
                                BBPunfix(bn->batCacheid);
diff --git a/monetdb5/modules/mal/remote.c b/monetdb5/modules/mal/remote.c
--- a/monetdb5/modules/mal/remote.c
+++ b/monetdb5/modules/mal/remote.c
@@ -741,8 +741,12 @@ str RMTput(Client cntxt, MalBlkPtr mb, M
                if (b) {
                        bi = bat_iterator(b);
                        BATloop(b, p, q) {
-                               tailv = NULL;
-                               ATOMformat(getBatType(type), BUNtail(bi, p), 
&tailv);
+                               tailv = ATOMformat(getBatType(type), 
BUNtail(bi, p));
+                               if (tailv == NULL) {
+                                       BBPunfix(b->batCacheid);
+                                       MT_lock_unset(&c->lock);
+                                       throw(MAL, "remote.put", GDK_EXCEPTION);
+                               }
                                if (getBatType(type) > TYPE_str)
                                        mnstr_printf(sout, "\"%s\"\n", tailv);
                                else
@@ -771,16 +775,16 @@ str RMTput(Client cntxt, MalBlkPtr mb, M
                mnstr_flush(sout);
                GDKfree(typename);
        } else {
-               ssize_t l = 0;
-               str val = NULL;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to