Ticket UUID: | 442178 | |||
Title: | Cygwin TCHAR in tclPlatDecls.h fix | |||
Type: | Patch | Version: | None | |
Submitter: | mdejong | Created on: | 2001-07-17 22:11:51 | |
Subsystem: | 52. Portability Support | Assigned To: | davygrvy | |
Priority: | 7 High | Severity: | ||
Status: | Closed | Last Modified: | 2001-07-19 14:04:31 | |
Resolution: | Accepted | Closed By: | mdejong | |
Closed on: | 2001-07-19 07:04:31 | |||
Description: |
This patch should fix the last of the Cygwin include errors. I wanted to have David Gravereaux take a look at this since he has worked in this code before. The problem is that Cygwin does not have a <tchar.h> file. The TCHAR type is defined in <winnt.h> but you need to pull in <windows.h> to get at it. Does this seem ok? I took out the bit that checks for _INC_TCHAR because that should not be needed and it is MSVC specific. I also made it depend on _MSC_VER instead of __WIN32__ since Cygwin, Mingw, and VC++ each define __WIN32__. | |||
User Comments: |
mdejong added on 2001-07-19 14:04:31:
Logged In: YES user_id=90858 Ok, I went ahead and checked in the version that pulled in <windows.h> in tclPlatDecls.h. Things now compile with VC++, mingw, and cygwin (minus the CreateThread changes). hobbs added on 2001-07-19 11:57:33: Logged In: YES user_id=72656 These are only includes we are talking about, so I'm not so sure that we should be using these verbose #define checks instead of just including what we know works in the end (like windows.h). Checking on things like _INC_TCHAR seems like an unnecessarily fragile thing to do. Also, we should keep the patches to the upload bit, because the comment area doesn't maintain plain text formatting. I'm for whatever it guaranteed to be correct for VC++ and cygwin without unneeded complexity in #def checks. mdejong added on 2001-07-18 15:22:13: Logged In: YES user_id=90858 Ok, I took another look at things and I think one of these two options is the ticket. The first option is to pull <windows.h> into tclPlatDecls.h. This moves the currently unused TCHAR defines in the CHECK_UNICODE_DEFINES block. Index: generic/tclPlatDecls.h =================================================================== RCS file: /cvsroot/tcl/tcl/generic/tclPlatDecls.h,v retrieving revision 1.6 diff -u -r1.6 tclPlatDecls.h --- generic/tclPlatDecls.h2000/08/20 03:51:231.6 +++ generic/tclPlatDecls.h2001/07/18 08:04:32 @@ -13,13 +13,29 @@ #define _TCLPLATDECLS /* - * Pull in the definition of TCHAR. Hopefully the compile flags - * of the core are matching against your project build for these - * public functions. BE AWARE. + * Define TCHAR by pulling in <windows.h>. If the + * core uses unicode but an extension does not, a compile + * time error should be generated. BE AWARE. */ -#if defined(__WIN32__) && !defined(_INC_TCHAR) -#include <tchar.h> -#endif +#ifdef __WIN32__ + +#ifdef CHECK_UNICODE_CALLS + +#define _UNICODE +#define UNICODE + +#define __TCHAR_DEFINED +typedef float *_TCHAR; + +#define _TCHAR_DEFINED +typedef float *TCHAR; + +#endif /* CHECK_UNICODE_CALLS */ + +# define WIN32_LEAN_AND_MEAN +# include <windows.h> +# undef WIN32_LEAN_AND_MEAN +#endif /* __WIN32__ */ /* !BEGIN!: Do not edit below this line. */ Index: win/tclWinPort.h =================================================================== RCS file: /cvsroot/tcl/tcl/win/tclWinPort.h,v retrieving revision 1.16 diff -u -r1.16 tclWinPort.h --- win/tclWinPort.h2001/07/17 18:33:241.16 +++ win/tclWinPort.h2001/07/18 08:04:32 @@ -20,19 +20,6 @@ # include "tclInt.h" #endif -#ifdef CHECK_UNICODE_CALLS - -#define _UNICODE -#define UNICODE - -#define __TCHAR_DEFINED -typedef float *_TCHAR; - -#define _TCHAR_DEFINED -typedef float *TCHAR; - -#endif - /* *--------------------------------------------------------------------------- * The following sets of #includes and #ifdefs are required to get Tcl to @@ -66,10 +53,6 @@ #include <time.h> #include <winsock.h> -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#undef WIN32_LEAN_AND_MEAN - #ifdef BUILD_tcl # undef TCL_STORAGE_CLASS # define TCL_STORAGE_CLASS DLLEXPORT The second option would be to leave the #include <windows.h> in tclWinPort.h and just #define TCHAR for ourselves in tclPlatDecls.h. Index: generic/tclPlatDecls.h =================================================================== RCS file: /cvsroot/tcl/tcl/generic/tclPlatDecls.h,v retrieving revision 1.6 diff -u -r1.6 tclPlatDecls.h --- generic/tclPlatDecls.h2000/08/20 03:51:231.6 +++ generic/tclPlatDecls.h2001/07/18 07:50:42 @@ -13,13 +13,17 @@ #define _TCLPLATDECLS /* - * Pull in the definition of TCHAR. Hopefully the compile flags - * of the core are matching against your project build for these - * public functions. BE AWARE. + * Define TCHAR without pulling in <windows.h>. If the + * core uses unicode but an extension does not, a compile + * time error should be generated. BE AWARE. */ -#if defined(__WIN32__) && !defined(_INC_TCHAR) -#include <tchar.h> -#endif +#ifdef __WIN32__ +#ifdef UNICODE +#define TCHAR wchar_t +#else +#define TCHAR char +#endif /* UNICODE */ +#endif /* __WIN32__ */ /* !BEGIN!: Do not edit below this line. */ @@ -96,6 +100,10 @@ #ifdef __cplusplus } #endif + +#ifdef __WIN32__ +#undef TCHAR +#endif /* __WIN32__ */ #if defined(USE_TCL_STUBS) && !defined(USE_TCL_STUB_PROCS) Comments? Does one seem better than the other? mdejong added on 2001-07-18 13:27:02: Logged In: YES user_id=90858 Humm, that is an interesting point. If you look at the top of the tclWinPort.h file, you will find the following: #ifndef _TCLINT # include "tclInt.h" #endif #ifdef CHECK_UNICODE_CALLS #define _UNICODE #define UNICODE #define __TCHAR_DEFINED typedef float *_TCHAR; #define _TCHAR_DEFINED typedef float *TCHAR; #endif I was under the impression that defining _UNICODE and then pulling in <windows.h> would define TCHAR as wchar_t. It seems odd that it is already typedefed as a float* here. Any idea what is going on there? If we pull in <windows.h> in tclPlatDecls.h then it will not be defined the same way as in tclWinPort.h because _UNICODE is not defined. Also, it seems like <windows.h> is getting pulled in multiple times, even when it is not needed. For example, removing this include seems fine since <tclPort.h> already pulls <tclWinPort.h> which includes <windows.h>. There is also one in tclAppInit.c, but I am not sure about that on. diff -u -r1.12 tclWinReg.c --- win/tclWinReg.c 2000/06/13 20:30:24 1.12 +++ win/tclWinReg.c 2001/07/18 06:20:08 @@ -17,10 +17,6 @@ #include <tclPort.h> #include <stdlib.h> -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#undef WIN32_LEAN_AND_MEAN - davygrvy added on 2001-07-18 08:51:35: Logged In: YES user_id=7549 Oh. tchar.h isn't in the platform SDK. I understand. #if defined(__WIN32__) && !define(_TCHAR_DEFINED) # define WIN32_LEAN_AND_MEAN # include <windows.h> # undef WIN32_LEAN_AND_MEAN #endif What would be nicer, might be the expansion of TCHAR instead. This is the external API and TCHAR has different meanings with _UNICODE and _MCBS defined. mdejong added on 2001-07-18 07:43:52: Logged In: YES user_id=90858 I looked at the patch, but I still don't understand what that "elif !defined(_INC_TCHAR)" bit is for. The MSVC include file checks to see if _INC_TCHAR is defined so there is no danger of including tchar.h twice: % cat t3.c #include <tchar.h> #include <tchar.h> int main() {} % cl -c t3.c What is up with that? Why not just do this: #if defined(__WIN32__) # if defined(__CYGWIN__) # define WIN32_LEAN_AND_MEAN # include <windows.h> # undef WIN32_LEAN_AND_MEAN # else # include <tchar.h> # endif #endif Or, if it does not matter, could we just do this? #ifdef __WIN32__ # define WIN32_LEAN_AND_MEAN # include <windows.h> # undef WIN32_LEAN_AND_MEAN #endif davygrvy added on 2001-07-18 07:28:50: File Deleted - 8544: davygrvy added on 2001-07-18 07:28:03: File Added - 8545: patch3.txt Logged In: YES user_id=7549 whoop.. forgot a closing #endif. davygrvy added on 2001-07-18 07:24:53: File Added - 8544: patch2.txt Logged In: YES user_id=7549 yeah, I see where you're going with this. Lets not forget borland, too. How does this look? mdejong added on 2001-07-18 05:11:52: File Added - 8538: patch |