Changeset: 92efabea0bc2 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=92efabea0bc2
Modified Files:
        monetdb5/modules/mal/mal_mapi.c
        sql/backends/monet5/sql_result.c
Branch: protocol
Log Message:

If the server and client have different endianness then the server swaps 
short/int/lng/hge columns on the wire.


diffs (98 lines):

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
@@ -160,7 +160,7 @@ doChallenge(void *data)
        /* generate the challenge string */
        generateChallenge(challenge, 8, 12);
        algos = mcrypt_getHashAlgorithms();
-       // FIXME: add the newproto flag to algos and rename to 'capabilities' 
to hide the crime
+       // FIXME: rename to 'capabilities' to hide the crime
 
        // send the challenge over the block stream
        mnstr_printf(fdout, "%s:mserver:9:%s:%s:%s:",
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
@@ -39,6 +39,29 @@ mystpcpy (char *yydest, const char *yysr
        return yyd - 1;
 }
 
+#ifdef _MSC_VER
+/* use intrinsic functions on Windows */
+#define short_int_SWAP(s)      ((short) _byteswap_ushort((unsigned short) (s)))
+/* on Windows, long is the same size as int */
+#define normal_int_SWAP(s)     ((int) _byteswap_ulong((unsigned long) (s)))
+#define long_long_SWAP(l)      ((lng) _byteswap_uint64((unsigned __int64) (s)))
+#else
+#define short_int_SWAP(s) ((short)(((0x00ff&(s))<<8) | ((0xff00&(s))>>8)))
+
+#define normal_int_SWAP(i) (((0x000000ff&(i))<<24) | ((0x0000ff00&(i))<<8) | \
+                           ((0x00ff0000&(i))>>8)  | ((0xff000000&(i))>>24))
+#define long_long_SWAP(l) \
+               ((((lng)normal_int_SWAP(l))<<32) |\
+                (0xffffffff&normal_int_SWAP(l>>32)))
+#endif
+
+#ifdef HAVE_HGE
+#define huge_int_SWAP(h) \
+               ((((hge)long_long_SWAP(h))<<64) |\
+                (0xffffffffffffffff&long_long_SWAP(h>>64)))
+#endif
+
+
 static int
 dec_tostr(void *extra, char **Buf, int *len, int type, const void *a)
 {
@@ -2209,10 +2232,50 @@ int mvc_export_resultset_prot10(mvc *m, 
                                }
                        } else {
                                int atom_size = ATOMsize(mtype);
-                               if (strcasecmp(c->type.type->sqlname, 
"decimal") == 0) {
+                               if (c->type.type->eclass == EC_DEC) {
                                        atom_size = 
ATOMsize(ATOMstorage(mtype));
                                }
-                               memcpy(buf, Tloc(iterators[i].b, srow), (row - 
srow) * atom_size);
+                               if (mnstr_byteorder(s) != 1234) {
+                                       size_t j = 0;
+                                       switch(ATOMstorage(mtype)) {
+                                               case TYPE_sht: {
+                                                       short *bufptr = 
(short*) buf;
+                                                       short *exported_values 
= (short*) Tloc(iterators[i].b, srow);
+                                                       for(j = 0; j < (row - 
srow); j++) {
+                                                               bufptr[j] = 
short_int_SWAP(exported_values[j]);
+                                                       }
+                                                       break;
+                                               }
+                                               case TYPE_int: {
+                                                       int *bufptr = (int*) 
buf;
+                                                       int *exported_values = 
(int*) Tloc(iterators[i].b, srow);
+                                                       for(j = 0; j < (row - 
srow); j++) {
+                                                               bufptr[j] = 
normal_int_SWAP(exported_values[j]);
+                                                       }
+                                                       break;
+                                               }
+                                               case TYPE_lng: {
+                                                       lng *bufptr = (lng*) 
buf;
+                                                       lng *exported_values = 
(lng*) Tloc(iterators[i].b, srow);
+                                                       for(j = 0; j < (row - 
srow); j++) {
+                                                               bufptr[j] = 
long_long_SWAP(exported_values[j]);
+                                                       }
+                                                       break;
+                                               }
+#ifdef HAVE_HGE
+                                               case TYPE_hge: {
+                                                       hge *bufptr = (hge*) 
buf;
+                                                       hge *exported_values = 
(hge*) Tloc(iterators[i].b, srow);
+                                                       for(j = 0; j < (row - 
srow); j++) {
+                                                               bufptr[j] = 
huge_int_SWAP(exported_values[j]);
+                                                       }
+                                                       break;
+                                               }
+#endif
+                                       }
+                               } else {
+                                       memcpy(buf, Tloc(iterators[i].b, srow), 
(row - srow) * atom_size);
+                               }
                                buf += (row - srow) * atom_size;
                        }
                }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to