_MBCS,_UNICODE,Tcl_WinUtfToTChar abuse!
Closed / Invalid459115ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 25 years ago
Descriptionplain2001-09-06 10:53:28
example, line 408:
tail = Tcl_WinUtfToTChar(tail, -1, &buf);
tail is a char*. Only under !ONE! condition is a
TCHAR* a char*. Here's the big list:
D:\thread_WS\tcl\win>c:\dev\bcc55\bin\bcc32.exe -Q -v-
-vi- -O2 -D_DEBUG -c -q -3 -a4 -g0 -tWM -Ve -Vx -X- -
I"c:\dev\bcc55\include" -I"..\win" -I"..\generic" -w-
rch -w-pch -w-par -w-dup -w-pro -w-dpu -
D_MT;NO_STRICT;_NO_VCL -DUSE_TCL_STUBS -
o.\Release\tclWinReg.obj ..\win\tclWinReg.c
..\win\tclWinReg.c:
Warning W8075 ..\win\tclWinReg.c 407: Suspicious
pointer conversion in function
DeleteKey
Warning W8075 ..\win\tclWinReg.c 408: Suspicious
pointer conversion in function
DeleteKey
Warning W8075 ..\win\tclWinReg.c 465: Suspicious
pointer conversion in function
DeleteValue
Warning W8075 ..\win\tclWinReg.c 534: Suspicious
pointer conversion in function
GetKeyNames
Warning W8075 ..\win\tclWinReg.c 600: Suspicious
pointer conversion in function
GetType
Warning W8075 ..\win\tclWinReg.c 602: Suspicious
pointer conversion in function
GetType
Warning W8075 ..\win\tclWinReg.c 684: Suspicious
pointer conversion in function
GetValue
Warning W8075 ..\win\tclWinReg.c 687: Suspicious
pointer conversion in function
GetValue
Warning W8075 ..\win\tclWinReg.c 697: Suspicious
pointer conversion in function
GetValue
Warning W8075 ..\win\tclWinReg.c 839: Suspicious
pointer conversion in function
GetValueNames
Warning W8075 ..\win\tclWinReg.c 955: Suspicious
pointer conversion in function
OpenSubKey
Warning W8075 ..\win\tclWinReg.c 957: Suspicious
pointer conversion in function
OpenSubKey
Warning W8075 ..\win\tclWinReg.c 969: Suspicious
pointer conversion in function
OpenSubKey
Warning W8075 ..\win\tclWinReg.c 973: Suspicious
pointer conversion in function
OpenSubKey
Warning W8075 ..\win\tclWinReg.c 973: Suspicious
pointer conversion in function
OpenSubKey
Warning W8075 ..\win\tclWinReg.c 985: Suspicious
pointer conversion in function
OpenSubKey
Warning W8075 ..\win\tclWinReg.c 1143: Suspicious
pointer conversion in function
RecursiveDeleteKey
Warning W8075 ..\win\tclWinReg.c 1148: Suspicious
pointer conversion in function
RecursiveDeleteKey
Warning W8075 ..\win\tclWinReg.c 1203: Suspicious
pointer conversion in function
SetValue
Warning W8075 ..\win\tclWinReg.c 1216: Suspicious
pointer conversion in function
SetValue
Warning W8075 ..\win\tclWinReg.c 1252: Suspicious
pointer conversion in function
SetValue
Warning W8075 ..\win\tclWinReg.c 1259: Suspicious
pointer conversion in function
SetValue
Warning W8075 ..\win\tclWinReg.c 1271: Suspicious
pointer conversion in function
SetValue
Warning W8075 ..\win\tclWinReg.c 1282: Suspicious
pointer conversion in function
SetValue
kennykbplain2001-09-06 22:58:19
Logged In: YES user_id=99768 I tend to get lost in the maze of build flags for Windows. I understand that _TCHAR can be one of three things: - char (SBCS) - unsigned char (_MBCS) - wchar_t (_UNICODE) Is there actually ever a case for building Tcl with _UNICODE and not _MBCS ? Otherwise, the way I read things, it would appear that a simple #define _USE_INLINING might fix everything. I get that idea from a cursory reading of http://msdn.microsoft.com/library/en-us/vccore98/html/_core_using_tchar..h_data_types_with__mbcs_code .asp But I don't lay claim to any great expertise here! If you have a better idea, I'm eager to hear it!
davygrvyplain2001-09-07 03:31:34
Logged In: YES user_id=7549 I haven't read through the code yet, <blush>, but TCHAR is one of special entity things. I just finally got TCHAR properly declared for both Borland and MinGW. I'm a little nervy about this whole TCHAR thing as the Tcl headers need it declared before windows.h is included and for the oddest reason, we leave an unexpanded TCHAR as a return type to Tcl_WinUtfToTCharTcl(). I'm just rather touchy about TCHAR right now. It's a bug waiting to happen... "I tried to use Tcl in my NT service that's a unicode application (wmain) and Tcl_WinUtfToTChar() is giving me the wrong data. I thought I'd get 16-bit unicode chars, but got MCBS instead. Why's this? Is there a bug?" I think my concept of TCHAR is off. I'll read up some more.
dacutplain2001-09-10 08:33:02
Logged In: YES user_id=31992 Well, I'm waiting to hear back from Jeff on whether he has any insight on this. In the meantime, I'll post my ignorance... TCHAR is either a char (for SBCS or MBCS) or wchar_t (for Unicode); which definition it gets is defined by the UNICODE preprocessor macro. Along with the TEXT() macro and the various tcsxxx() functions, the intended usage is to port an application between SBCS/MBCS and Unicode easily -- that is, an application can be switched between the two by flipping the UNICODE macro. But this is reserved for the application. It is, IMHO, dangerous to have this *anywhere* in Tcl. Dave G points out the problem keenly (though reality is the reverse: Tcl_WinUtfToTChar always returns Unicode strings, never MBCS). Anyway... looking at the various files, it seems like the functions accepting/returning TCHARs and TCHAR *'s should use UTF-16 instead. Tcl_UniChar should work fine. Note that the C++ intrinsic wchar_t doesn't exist intrinsically in C, and is the wrong size on most Unix compilers -- UTF-32 instead of UTF-16. WCHAR could be used if we're willing to bring in the windows.h header (which may be just as well -- we'll know of clashes right away, and since both MSVC and BC implement precompiled headers...).
davygrvyplain2001-11-07 13:32:00
Logged In: YES user_id=7549 After header file fun with odd macros and a better understanding of Tcl_WinUtfToTChar(), I have to say that where in the example above char *tail is more like a typeless placeholder than really a char *. I'll mark this closed.
Log in (anonymous is fine) to add a comment.