tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] [patch] wchar_t should be "unsigned char" on win32


From: Filip Navara
Subject: [Tinycc-devel] [patch] wchar_t should be "unsigned char" on win32
Date: Tue, 05 Jul 2005 02:16:06 +0200
User-agent: Mozilla Thunderbird 0.9 (Windows/20041103)

As the subject says ... wide-character string literals are in UCS2 on Win32.
--- tcc.c       Sun Jul  3 18:58:34 2005
+++ tcc.c       Mon Jul  4 18:11:07 2005
@@ -131,9 +131,15 @@
     char str[1];
 } TokenSym;
 
+#ifdef TCC_TARGET_PE
+typedef unsigned short nwchar_t;
+#else
+typedef int nwchar_t;
+#endif
+
 typedef struct CString {
     int size; /* size in bytes */
-    void *data; /* either 'char *' or 'int *' */
+    void *data; /* either 'char *' or 'nwchar_t *' */
     int size_allocated;
     void *data_allocated; /* if non NULL, data has been malloced */
 } CString;
@@ -1557,10 +1563,10 @@
 static void cstr_wccat(CString *cstr, int ch)
 {
     int size;
-    size = cstr->size + sizeof(int);
+    size = cstr->size + sizeof(nwchar_t);
     if (size > cstr->size_allocated)
         cstr_realloc(cstr, size);
-    *(int *)(((unsigned char *)cstr->data) + size - sizeof(int)) = ch;
+    *(nwchar_t *)(((unsigned char *)cstr->data) + size - sizeof(nwchar_t)) = 
ch;
     cstr->size = size;
 }
 
@@ -1650,9 +1656,9 @@
             for(i=0;i<len;i++)
                 add_char(&cstr_buf, ((unsigned char *)cstr->data)[i]);
         } else {
-            len = (cstr->size / sizeof(int)) - 1;
+            len = (cstr->size / sizeof(nwchar_t)) - 1;
             for(i=0;i<len;i++)
-                add_char(&cstr_buf, ((int *)cstr->data)[i]);
+                add_char(&cstr_buf, ((nwchar_t *)cstr->data)[i]);
         }
         cstr_ccat(&cstr_buf, '\"');
         cstr_ccat(&cstr_buf, '\0');
@@ -3725,7 +3731,7 @@
                 if (!is_long)
                     char_size = 1;
                 else
-                    char_size = sizeof(int);
+                    char_size = sizeof(nwchar_t);
                 if (tokcstr.size <= char_size)
                     error("empty character constant");
                 if (tokcstr.size > 2 * char_size)
@@ -3734,7 +3740,7 @@
                     tokc.i = *(int8_t *)tokcstr.data;
                     tok = TOK_CCHAR;
                 } else {
-                    tokc.i = *(int *)tokcstr.data;
+                    tokc.i = *(nwchar_t *)tokcstr.data;
                     tok = TOK_LCHAR;
                 }
             } else {
@@ -7146,7 +7153,11 @@
         }
         break;
     case TOK_LSTR:
+#ifdef TCC_TARGET_PE
+        t = VT_SHORT | VT_UNSIGNED;
+#else
         t = VT_INT;
+#endif
         goto str_init;
     case TOK_STR:
         /* string parsing */
@@ -8427,7 +8438,11 @@
         /* only parse strings here if correct type (otherwise: handle
            them as ((w)char *) expressions */
         if ((tok == TOK_LSTR && 
+#ifdef TCC_TARGET_PE
+             (t1->t & VT_BTYPE) == VT_SHORT && (t1->t & VT_UNSIGNED)) ||
+#else
              (t1->t & VT_BTYPE) == VT_INT) ||
+#endif
             (tok == TOK_STR &&
              (t1->t & VT_BTYPE) == VT_BYTE)) {
             while (tok == TOK_STR || tok == TOK_LSTR) {
@@ -8439,7 +8454,7 @@
                 if (tok == TOK_STR)
                     cstr_len = cstr->size;
                 else
-                    cstr_len = cstr->size / sizeof(int);
+                    cstr_len = cstr->size / sizeof(nwchar_t);
                 cstr_len--;
                 nb = cstr_len;
                 if (n >= 0 && nb > (n - array_length))
@@ -8457,7 +8472,7 @@
                             if (tok == TOK_STR)
                                 ch = ((unsigned char *)cstr->data)[i];
                             else
-                                ch = ((int *)cstr->data)[i];
+                                ch = ((nwchar_t *)cstr->data)[i];
                             init_putv(t1, sec, c + (array_length + i) * size1,
                                       ch, EXPR_VAL);
                         }
@@ -9745,7 +9764,11 @@
     /* tiny C & gcc defines */
     tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned int");
     tcc_define_symbol(s, "__PTRDIFF_TYPE__", "int");
+#ifdef TCC_TARGET_PE
+    tcc_define_symbol(s, "__WCHAR_TYPE__", "unsigned short");
+#else
     tcc_define_symbol(s, "__WCHAR_TYPE__", "int");
+#endif
     
     /* default library paths */
 #ifdef TCC_TARGET_PE

reply via email to

[Prev in Thread] Current Thread [Next in Thread]