serialize and deserialize wchar_t as char for compatibility between linux and windows 14/16614/2
Antoine ELIAS [Tue, 9 Jun 2015 07:32:13 +0000 (09:32 +0200)]
Change-Id: I2188aaeb634121f66509ecada08c1fdba2be0ea7

scilab/modules/ast/includes/ast/deserializervisitor.hxx
scilab/modules/ast/includes/ast/serializervisitor.hxx

index d557606..c6a7309 100644 (file)
@@ -190,10 +190,13 @@ private :
     std::wstring* get_wstring(void)
     {
         unsigned int size = get_uint32();
-        wchar_t* ss = (wchar_t*)buf;
-        std::wstring* s = new std::wstring(ss, size / sizeof(wchar_t));
+        char* ss = (char*)buf;
+        std::string s(ss, size / sizeof(char));
+        wchar_t* ws = to_wide_string(s.data());
+        std::wstring* w = new std::wstring(ws);
+        FREE(ws);
         buf += size;
-        return s;
+        return w;
     }
 
     symbol::Symbol* get_Symbol(void)
index 5e08a65..6f55013 100644 (file)
@@ -17,6 +17,7 @@
 #include "dummyvisitor.hxx"
 #include "deserializervisitor.hxx"
 #include "timer.hxx"
+#include "charEncoding.h"
 #include "version.h"
 
 #define FAGMENT_SIZE 65536
@@ -176,11 +177,12 @@ private :
     void add_wstring(const std::wstring &w)
     {
         int size = (int)w.size();
-        const wchar_t *c_str = w.c_str();
-        int final_size = size * sizeof(wchar_t);
+        char *c_str = wide_string_to_UTF8(w.c_str());
+        int final_size = size * sizeof(char);
         add_uint32(final_size);
         need(final_size);
         memcpy(buf + buflen, c_str, final_size);
+        FREE(c_str);
         buflen += final_size;
     }