Changeset: f71533bbfe1f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f71533bbfe1f
Modified Files:
        clients/mapilib/mapi.c
        sql/backends/monet5/sql_result.c
Branch: protocol
Log Message:

Eight-byte align data in new protocol messages.


diffs (102 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -4118,12 +4118,10 @@ static char* mapi_convert_clob(struct Ma
        return col->buffer_ptr;
 }
 
-#define mapi_string_conversion_function(type, gdktpe, sqltpe,EXTRANULLCHECK)   
                                                                                
                                                \
+#define mapi_string_conversion_function(type, gdktpe, sqltpe,EXTRANULLCHECK)   
                                                                                
                \
 static char* mapi_convert_##sqltpe(struct MapiColumn *col) {                   
                                                                                
                                \
-       type buffer_value; \
-       memcpy(&buffer_value, col->buffer_ptr, sizeof(type)); \
-       if (buffer_value == *((type*)col->null_value) EXTRANULLCHECK)   return 
NULL;                                                                           
                         \
-       if (conversion_##gdktpe##_to_string(col->write_buf, COLBUFSIZ, 
&buffer_value, *((type*)col->null_value)) < 0) {   \
+       if (*((type*)col->buffer_ptr) == *((type*)col->null_value) 
EXTRANULLCHECK)      return NULL;                                               
                     \
+       if (conversion_##gdktpe##_to_string(col->write_buf, COLBUFSIZ, (type*) 
col->buffer_ptr, *((type*)col->null_value)) < 0) {   \
                return NULL;                                                    
                                                                                
                                                                                
\
        }                                                                       
                                                                                
                                                                                
                \
        return (char*) col->write_buf;                                          
                                                                                
                                                                \
@@ -4220,7 +4218,6 @@ static char* mapi_convert_unknown(struct
        return "<unknown>";
 }
 
-
 static MapiMsg
 read_into_cache(MapiHdl hdl, int lookahead)
 {
@@ -5698,6 +5695,10 @@ mapi_split_line(MapiHdl hdl)
        return n;
 }
 
+char* eight_byte_align(char* ptr) {
+       return (char*) (((size_t) ptr + 7) & ~7);
+}
+
 int
 mapi_fetch_row(MapiHdl hdl)
 {
@@ -5773,11 +5774,11 @@ mapi_fetch_row(MapiHdl hdl)
 
                        // iterate over cols
                        for (i = 0; i < (size_t) result->fieldcnt; i++) {
+                               buf = eight_byte_align(buf);
                                result->fields[i].buffer_ptr = buf;
                                if (result->fields[i].typelen < 0) {
-                                       lng col_len;
                                        // variable length column
-                                       memcpy(&col_len, buf, sizeof(lng));
+                                       lng col_len = *((lng*) buf);
                                        assert((size_t) col_len < 
hdl->mid->blocksize && col_len > 0);
                                        result->fields[i].buffer_ptr += 
sizeof(lng);
                                        buf += col_len + sizeof(lng);
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
@@ -1887,6 +1887,12 @@ static size_t mymax(size_t a, size_t b) 
        return a > b ? a : b;
 }
 
+// align to 8 bytes
+char* eight_byte_align(char* ptr) {
+       return (char*) (((size_t) ptr + 7) & ~7);
+}
+
+
 int mvc_export_resultset_prot10(mvc *m, res_table* t, stream* s, stream *c, 
size_t bsize, int compute_lengths, ptr p) {
        BAT *order;
        lng count;
@@ -2105,6 +2111,8 @@ int mvc_export_resultset_prot10(mvc *m, 
                char *buf = bs2_buffer(s).buf;
                size_t crow = 0;
                size_t bytes_left = bsize - sizeof(lng) - 1;
+               // potential padding that has to be added for each column
+               bytes_left -= t->nr_cols * 7;
 
                // every varsized member has an 8-byte header indicating the 
length of the header in the block
                // subtract this from the amount of bytes left
@@ -2201,6 +2209,7 @@ int mvc_export_resultset_prot10(mvc *m, 
                        res_col *c = t->cols + i;
                        int mtype = iterators[i].b->ttype;
                        int convert_to_string = 
!type_supports_binary_transfer(c->type.type);
+                       buf = eight_byte_align(buf);
                        if (ATOMvarsized(mtype) || convert_to_string) {
                                if (!convert_to_string && c->type.digits > 0 && 
(int) c->type.digits < VARCHAR_MAXIMUM_FIXED) {
                                        char *bufptr = buf;
@@ -2235,15 +2244,13 @@ int mvc_export_resultset_prot10(mvc *m, 
                                        // variable columns are prefixed by a 
length, 
                                        // but since we don't know the length 
yet, just skip over it for now
                                        char *startbuf = buf;
-                                       lng lenval;
                                        buf += sizeof(lng);
                                        for (crow = srow; crow < row; crow++) {
                                                char *str = (char*) 
BUNtail(iterators[i], crow);
                                                buf = mystpcpy(buf, str) + 1;
                                                assert(buf - bs2_buffer(s).buf 
<= (lng) bsize);
                                        }
-                                       lenval = mnstr_swap_lng(s, (lng) (buf - 
(startbuf + sizeof(lng))));
-                                       memcpy(startbuf, &lenval, sizeof(lng));
+                                       *((lng*)startbuf) = mnstr_swap_lng(s, 
buf - (startbuf + sizeof(lng)));
                                }
                        } else {
                                int atom_size = ATOMsize(mtype);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to