Changeset: 92aed1c159d5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/92aed1c159d5
Modified Files:
        monetdb5/modules/mal/tablet.c
        monetdb5/modules/mal/tablet.h
        sql/backends/monet5/sql_result.c
Branch: directappend
Log Message:

Do not implicitly convert into fmt->data, pass dest buffer explicitly

Unfortunately some implementations of atomFromStr want to reallocate it
so for the time being we pass pointers to pointers.


diffs (125 lines):

diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -881,7 +881,7 @@ SQLconvert_val(READERtask *task, int col
        }
 
        // Now parse the value into fmt->data.
-       void *p = fmt->frstr(fmt, fmt->adt, unescaped);
+       void *p = fmt->frstr(fmt, fmt->adt, &fmt->data, &fmt->len, unescaped);
        if (p == NULL) {
                int ret = report_conversion_failed(task, fmt, idx, col + 1, s);
                make_it_nil(fmt);
diff --git a/monetdb5/modules/mal/tablet.h b/monetdb5/modules/mal/tablet.h
--- a/monetdb5/modules/mal/tablet.h
+++ b/monetdb5/modules/mal/tablet.h
@@ -41,7 +41,7 @@ typedef struct Column_t {
        int fieldwidth;
        int scale, precision;
        ssize_t (*tostr)(void *extra, char **buf, size_t *len, int type, const 
void *a);
-       void *(*frstr)(struct Column_t *fmt, int type, const char *s);
+       void *(*frstr)(struct Column_t *fmt, int type, void **dst, size_t 
*dst_len, const char *s);
        void *extra;
        void *data;
        int skip;                                       /* only skip to the 
next field */
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -498,11 +498,8 @@ bat_max_length(hge, hge)
                }                                                               
                                                                \
                if (*s)                                                         
                                                        \
                        return NULL;                                            
                                                \
-               r = c->data;                                                    
                                                \
-               if (r == NULL &&                                                
                                                \
-                   (r = GDKzalloc(sizeof(X))) == NULL)                         
                        \
-                       return NULL;                                            
                                                \
-               c->data = r;                                                    
                                                \
+               assert(*dst_len >= sizeof(X));                                  
                                \
+               r = *dst;                                                       
                                                \
                if (neg)                                                        
                                                        \
                        *r = -res;                                              
                                                        \
                else                                                            
                                                        \
@@ -511,7 +508,7 @@ bat_max_length(hge, hge)
        } while (0)
 
 static void *
-dec_frstr(Column *c, int type, const char *s)
+dec_frstr(Column *c, int type, void **dst, size_t *dst_len, const char *s)
 {
        /* support dec map to bte, sht, int and lng */
        if( strcmp(s,"nil")== 0)
@@ -533,7 +530,7 @@ dec_frstr(Column *c, int type, const cha
 }
 
 static void *
-sec_frstr(Column *c, int type, const char *s)
+sec_frstr(Column *c, int type, void **dst, size_t *dst_len, const char *s)
 {
        /* read a sec_interval value
         * this knows that the stored scale is always 3 */
@@ -541,6 +538,8 @@ sec_frstr(Column *c, int type, const cha
        lng *r;
        lng res = 0;
 
+       assert(*dst_len >= sizeof(lng));
+
        (void) c;
        (void) type;
        assert(type == TYPE_lng);
@@ -575,10 +574,7 @@ sec_frstr(Column *c, int type, const cha
        for (; i < 3; i++) {
                res *= 10;
        }
-       r = c->data;
-       if (r == NULL && (r = (lng *) GDKzalloc(sizeof(lng))) == NULL)
-               return NULL;
-       c->data = r;
+       r = *dst;
        if (neg)
                *r = -res;
        else
@@ -588,11 +584,11 @@ sec_frstr(Column *c, int type, const cha
 
 /* Literal parsing for SQL all pass through this routine */
 static void *
-_ASCIIadt_frStr(Column *c, int type, const char *s)
+_ASCIIadt_frStr(Column *c, int type, void **dst, size_t *dst_len, const char 
*s)
 {
        ssize_t len;
 
-       len = (*BATatoms[type].atomFromStr) (s, &c->len, &c->data, false);
+       len = (*BATatoms[type].atomFromStr) (s, dst_len, dst, false);
        if (len < 0)
                return NULL;
        switch (type) {
@@ -609,7 +605,7 @@ static void *
                                while (s[len] == '0')
                                        len++;
                                if (s[len] == 0)
-                                       return c->data;
+                                       return *dst;
                        }
                        return NULL;
                }
@@ -618,10 +614,10 @@ static void *
                sql_column *col = (sql_column *) c->extra;
                int slen;
 
-               s = c->data;
+               s = *dst;
                slen = strNil(s) ? int_nil : UTF8_strlen(s);
                if (col->type.digits > 0 && len > 0 && slen > (int) 
col->type.digits) {
-                       len = STRwidth(c->data);
+                       len = STRwidth(*dst);
                        if (len > (ssize_t) col->type.digits)
                                return NULL;
                }
@@ -630,7 +626,7 @@ static void *
        default:
                break;
        }
-       return c->data;
+       return *dst;
 }
 
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to