WINE_UNICODE_TEXT fix
François Gouget
fgouget at codeweavers.com
Tue Feb 27 15:44:01 CST 2001
This is a follow-up on the discussion that happened at the beginning
of the month regarding WINE_UNICODE_TEXT.
To refresh memories, in C we have the following problem:
* in its current form
WINE_UNICODE_TEXT('a')+1 gives 'c' instead of 'b'
* if we fix that then
WINE_UNICODE_TEXT("abc")+1 gives, ummm, well, something so incorrect
I cannot really write it here!
This is all due to the two sides of '?:' having a type of a different
size. And in addition to that we get warnings each time
WINE_UNICODE_TEXT is used (e.g. in OLESTR).
I attached a sample program that puts this problem in evidence.
So it appears we cannot handle both forms properly in C. Since the
string form is by far the most common I dropped support for
WINE_UNICODE_TEXT('c'). I think this is better than having a macro that
will generate a warning whenever it is used, and that will sometimes
give you an incorrect result.
Changelog:
François Gouget <fgouget at codeweavers.com>
* include/winnt.h
WINE_UNICODE_TEXT was incorrect
Dropped support for WINE_UNICODE_TEXT('c') in C
--
François Gouget
fgouget at codeweavers.com
-------------- next part --------------
Index: include/winnt.h
===================================================================
RCS file: /home/wine/wine/include/winnt.h,v
retrieving revision 1.85
diff -u -r1.85 winnt.h
--- include/winnt.h 2001/02/20 00:49:12 1.85
+++ include/winnt.h 2001/02/27 19:37:01
@@ -287,6 +287,13 @@
*/
#ifndef __WINE__
# ifdef WINE_UNICODE_REWRITE
+
+/* Use this if your compiler does not provide a 16bit wchar_t type.
+ * Note that you will need to specify -fwritable-strings or an option
+ * to this effect.
+ * In C++ both WINE_UNICODE_TEXT('c') and WINE_UNICODE_TEXT("str") are
+ * supported, but only the string form can be supported in C.
+ */
EXTERN_C unsigned short* wine_rewrite_s4tos2(const wchar_t* str4);
# ifdef __cplusplus
inline WCHAR* wine_unicode_text(const wchar_t* str4)
@@ -299,13 +306,22 @@
}
# define WINE_UNICODE_TEXT(x) wine_unicode_text(L##x)
# else /* __cplusplus */
-# define WINE_UNICODE_TEXT(x) ((sizeof(x)==1) || (sizeof(L##x)>4) ? \
- (WCHAR*)wine_rewrite_s4tos2(L##x) : \
- ((WCHAR)L##x))
+# define WINE_UNICODE_TEXT(x) ((WCHAR*)wine_rewrite_s4tos2(L##x))
# endif /* __cplusplus */
+
# else /* WINE_UNICODE_REWRITE */
-/* WINE_UNICODE_NATIVE or nothing at all */
+
+/* Define WINE_UNICODE_NATIVE if:
+ * - your compiler provides a 16bit wchar_t type, e.g. gcc >= 2.96 with
+ * -fshort-wchar option
+ * - or if you decide to use the native 32bit Unix wchar_t type. Be aware
+ * though that the Wine APIs only support 16bit WCHAR characters for
+ * binary compatibility reasons.
+ * - or define nothing at all if you don't use Unicode, and blissfully
+ * ignore the issue :-)
+ */
# define WINE_UNICODE_TEXT(string) L##string
+
# endif /* WINE_UNICODE_REWRITE */
# ifdef UNICODE
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ternary.c
Type: text/x-csrc
Size: 1249 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20010227/f16e605c/ternary.c
More information about the wine-patches
mailing list