Changeset: 45fabf71954c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=45fabf71954c
Modified Files:
        gdk/gdk_atoms.c
        gdk/gdk_logger.c
        geom/monetdb5/geom.c
        monetdb5/modules/atoms/uuid.c
Branch: default
Log Message:

Changed interface of atomRead somewhat.
The buffer pointer that is passed to the function may now be NULL.  In
any case, the read function may allocate and return new memory.  It
will not free the passed in memory.  In case of failure, NULL is
returned and no new memory was allocated; in case of success, a
pointer to the buffer that was filled is returned.  This pointer may
or may not be the same as the pointer that was passed in.


diffs (175 lines):

diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -496,25 +496,6 @@ bitToStr(char **dst, int *len, const bit
        return snprintf(*dst, *len, "false");
 }
 
-static bit *
-bitRead(bit *a, stream *s, size_t cnt)
-{
-       if (mnstr_read(s, (char *) a, 1, cnt) < 0)
-               return NULL;
-       return mnstr_errnr(s) ? NULL : a;
-}
-
-static gdk_return
-bitWrite(const bit *a, stream *s, size_t cnt)
-{
-       if (mnstr_write(s, (const char *) a, 1, cnt) == (ssize_t) cnt)
-               return GDK_SUCCEED;
-       else {
-               GDKsyserror("bitWrite: write failure\n");
-               return GDK_FAIL;
-       }
-}
-
 int
 batFromStr(const char *src, int *len, bat **dst)
 {
@@ -565,20 +546,6 @@ batToStr(char **dst, int *len, const bat
        return snprintf(*dst, *len, "<%s>", s);
 }
 
-static bat *
-batRead(bat *a, stream *s, size_t cnt)
-{
-       /* bat==int */
-       return mnstr_readIntArray(s, (int *) a, cnt) ? a : NULL;
-}
-
-static gdk_return
-batWrite(const bat *a, stream *s, size_t cnt)
-{
-       /* bat==int */
-       return mnstr_writeIntArray(s, (const int *) a, cnt) ? GDK_SUCCEED : 
GDK_FAIL;
-}
-
 
 /*
  * numFromStr parses the head of the string for a number, accepting an
@@ -761,10 +728,18 @@ hgeFromStr(const char *src, int *len, hg
 
 #define atom_io(TYPE, NAME, CAST)                                      \
 static TYPE *                                                          \
-TYPE##Read(TYPE *a, stream *s, size_t cnt)                             \
+TYPE##Read(TYPE *A, stream *s, size_t cnt)                             \
 {                                                                      \
-       mnstr_read##NAME##Array(s, (CAST *) a, cnt);                    \
-       return mnstr_errnr(s) ? NULL : a;                               \
+       TYPE *a = A;                                                    \
+       if (a == NULL && (a = GDKmalloc(cnt * sizeof(TYPE))) == NULL)   \
+               return NULL;                                            \
+       if (mnstr_read##NAME##Array(s, (CAST *) a, cnt) == 0 ||         \
+           mnstr_errnr(s)) {                                           \
+               if (a != A)                                             \
+                       GDKfree(a);                                     \
+               return NULL;                                            \
+       }                                                               \
+       return a;                                                       \
 }                                                                      \
 static gdk_return                                                      \
 TYPE##Write(const TYPE *a, stream *s, size_t cnt)                      \
@@ -773,6 +748,9 @@ TYPE##Write(const TYPE *a, stream *s, si
                GDK_SUCCEED : GDK_FAIL;                                 \
 }
 
+atom_io(bat, Int, int)
+atom_io(bit, Bte, bte)
+
 atomtostr(bte, "%hhd", )
 atom_io(bte, Bte, bte)
 
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -346,12 +346,8 @@ log_read_updates(logger *lg, trans *tr, 
                void *(*rt) (ptr, stream *, size_t) = BATatoms[tt].atomRead;
                void *tv = NULL;
 
-               if (tt < TYPE_str)
+               if (ATOMstorage(tt) < TYPE_str)
                        tv = lg->buf;
-               else if (tt > TYPE_str)
-                       // FIXME unchecked_malloc ATOMnil can return NULL
-
-                       tv = ATOMnil(tt);
 
                assert(l->nr <= (lng) BUN_MAX);
                if (l->flag == LOG_UPDATE) {
@@ -369,7 +365,7 @@ log_read_updates(logger *lg, trans *tr, 
                        for (; l->nr > 0; l->nr--) {
                                void *t = rt(tv, lg->log, 1);
 
-                               if (!t) {
+                               if (t == NULL) {
                                        res = GDK_FAIL;
                                        break;
                                }
@@ -383,11 +379,14 @@ log_read_updates(logger *lg, trans *tr, 
 
                        void *hv = ATOMnil(ht);
 
+                       if (hv == NULL)
+                               res = GDK_FAIL;
+
                        for (; l->nr > 0; l->nr--) {
                                void *h = rh(hv, lg->log, 1);
                                void *t = rt(tv, lg->log, 1);
 
-                               if (!h || !t) {
+                               if (h == NULL || t == NULL)
                                        res = GDK_FAIL;
                                        break;
                                }
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -5353,16 +5353,22 @@ mbrCOMP(mbr *l, mbr *r)
 
 /* read mbr from log */
 mbr *
-mbrREAD(mbr *a, stream *s, size_t cnt)
-{
+mbrREAD(mbr *A, stream *s, size_t cnt)
+{
+       mbr *a = A;
        mbr *c;
        size_t i;
        int v[4];
        flt vals[4];
 
+       if (a == NULL && (a = GDKmalloc(cnt * sizeof(mbr))) == NULL)
+               return NULL;
        for (i = 0, c = a; i < cnt; i++, c++) {
-               if (!mnstr_readIntArray(s, v, 4))
+               if (!mnstr_readIntArray(s, v, 4)) {
+                       if (a != A)
+                               GDKfree(a);
                        return NULL;
+               }
                memcpy(vals, v, 4 * sizeof(int));
                c->xmin = vals[0];
                c->ymin = vals[1];
diff --git a/monetdb5/modules/atoms/uuid.c b/monetdb5/modules/atoms/uuid.c
--- a/monetdb5/modules/atoms/uuid.c
+++ b/monetdb5/modules/atoms/uuid.c
@@ -265,10 +265,16 @@ UUIDnull(void)
 }
 
 uuid *
-UUIDread(uuid *u, stream *s, size_t cnt)
+UUIDread(uuid *U, stream *s, size_t cnt)
 {
-       if (mnstr_read(s, u, UUID_SIZE, cnt) < (ssize_t) cnt)
+       uuid *u = U;
+       if (u == NULL && (u = GDKmalloc(cnt * sizeof(uuid))) == NULL)
                return NULL;
+       if (mnstr_read(s, u, UUID_SIZE, cnt) < (ssize_t) cnt) {
+               if (u != U)
+                       GDKfree(u);
+               return NULL;
+       }
        return u;
 }
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to