diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-03-30 14:57:51 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-03-30 14:57:51 (GMT) |
commit | 876a8aba8471fbe03407e0b3af2e44c194942141 (patch) | |
tree | 6393b23c79b1d63c845cc4f06fffecf6444a3c6b | |
parent | 59c52ee2fb7fcc819a92861101a8dd4b77c9f606 (diff) | |
parent | f3146e6826308cf112fccc9ac29ab18bca2a6071 (diff) | |
download | tcl-876a8aba8471fbe03407e0b3af2e44c194942141.zip tcl-876a8aba8471fbe03407e0b3af2e44c194942141.tar.gz tcl-876a8aba8471fbe03407e0b3af2e44c194942141.tar.bz2 |
[Bug 3508771] load tclreg.dll in cygwin tclsh
Implement TclWinGetTclInstance, TclpGetTZName,
and various others for Cygwin
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | generic/tclInt.decls | 10 | ||||
-rw-r--r-- | generic/tclIntPlatDecls.h | 32 | ||||
-rw-r--r-- | generic/tclStubInit.c | 49 | ||||
-rw-r--r-- | win/tclWinError.c | 32 | ||||
-rw-r--r-- | win/tclWinSock.c | 8 |
6 files changed, 79 insertions, 59 deletions
@@ -1,5 +1,12 @@ 2012-03-30 Jan Nijtmans <nijtmans@users.sf.net> + * generic/tclInt.decls: [Bug 3508771] load tclreg.dll in cygwin tclsh + * generic/tclIntPlatDecls.h: Implement TclWinGetTclInstance, TclpGetTZName, + * generic/tclStubInit.c: and various more win32-specific internal functions for + Cygwin, so win32 extensions using those can be loaded in the cygwin version of tclsh. + +2012-03-30 Jan Nijtmans <nijtmans@users.sf.net> + * unix/tcl.m4: [Bug 3511806] Compiler checks too early * unix/configure.in: This change allows to build the cygwin * unix/tclUnixPort.h: and mingw32 ports of Tcl/Tk to build diff --git a/generic/tclInt.decls b/generic/tclInt.decls index 3f977d3..c115d23 100644 --- a/generic/tclInt.decls +++ b/generic/tclInt.decls @@ -965,7 +965,7 @@ declare 2 win { } declare 3 win { int TclWinGetSockOpt(SOCKET s, int level, int optname, - char FAR *optval, int FAR *optlen) + char *optval, int *optlen) } declare 4 win { HINSTANCE TclWinGetTclInstance(void) @@ -979,7 +979,7 @@ declare 6 win { } declare 7 win { int TclWinSetSockOpt(SOCKET s, int level, int optname, - const char FAR *optval, int optlen) + const char *optval, int optlen) } declare 8 win { unsigned long TclpGetPid(Tcl_Pid pid) @@ -1089,7 +1089,7 @@ declare 3 unix { } # On non-cygwin, this is actually a reference to TclpCreateProcess declare 4 unix { - int TclWinGetTclInstance(void) + void *TclWinGetTclInstance(void) } # Signature changed in 8.1: # declare 5 unix { @@ -1102,7 +1102,7 @@ declare 6 unix { } # On non-cygwin, this is actually a reference to TclpOpenFile declare 7 unix { - int TclWinSetSockOpt(int s, int level, int optname, + int TclWinSetSockOpt(void *s, int level, int optname, const char *optval, int optlen) } declare 8 unix { @@ -1169,7 +1169,7 @@ declare 19 {unix macosx} { void TclMacOSXNotifierAddRunLoopMode(const void *runLoopMode) } declare 20 unix { - void TclWinAddProcess(void *hProcess, unsigned long id) + void TclWinAddProcess(void *hProcess, unsigned int id) } declare 22 unix { TclFile TclpCreateTempFile(const char *contents) diff --git a/generic/tclIntPlatDecls.h b/generic/tclIntPlatDecls.h index 0e9200b..801ee49 100644 --- a/generic/tclIntPlatDecls.h +++ b/generic/tclIntPlatDecls.h @@ -72,7 +72,7 @@ EXTERN int TclpCreatePipe(TclFile *readPipe, TclFile *writePipe); #ifndef TclWinGetTclInstance_TCL_DECLARED #define TclWinGetTclInstance_TCL_DECLARED /* 4 */ -EXTERN int TclWinGetTclInstance(void); +EXTERN VOID * TclWinGetTclInstance(void); #endif /* Slot 5 is reserved */ #ifndef TclWinNToHS_TCL_DECLARED @@ -83,7 +83,7 @@ EXTERN unsigned short TclWinNToHS(unsigned short ns); #ifndef TclWinSetSockOpt_TCL_DECLARED #define TclWinSetSockOpt_TCL_DECLARED /* 7 */ -EXTERN int TclWinSetSockOpt(int s, int level, int optname, +EXTERN int TclWinSetSockOpt(VOID *s, int level, int optname, CONST char *optval, int optlen); #endif #ifndef TclUnixWaitForFile_TCL_DECLARED @@ -149,7 +149,7 @@ EXTERN void TclMacOSXNotifierAddRunLoopMode( #ifndef TclWinAddProcess_TCL_DECLARED #define TclWinAddProcess_TCL_DECLARED /* 20 */ -EXTERN void TclWinAddProcess(VOID *hProcess, unsigned long id); +EXTERN void TclWinAddProcess(VOID *hProcess, unsigned int id); #endif /* Slot 21 is reserved */ #ifndef TclpCreateTempFile_TCL_DECLARED @@ -221,7 +221,7 @@ EXTERN struct servent * TclWinGetServByName(CONST char *nm, #define TclWinGetSockOpt_TCL_DECLARED /* 3 */ EXTERN int TclWinGetSockOpt(SOCKET s, int level, int optname, - char FAR *optval, int FAR *optlen); + char *optval, int *optlen); #endif #ifndef TclWinGetTclInstance_TCL_DECLARED #define TclWinGetTclInstance_TCL_DECLARED @@ -238,7 +238,7 @@ EXTERN u_short TclWinNToHS(u_short ns); #define TclWinSetSockOpt_TCL_DECLARED /* 7 */ EXTERN int TclWinSetSockOpt(SOCKET s, int level, int optname, - CONST char FAR *optval, int optlen); + CONST char *optval, int optlen); #endif #ifndef TclpGetPid_TCL_DECLARED #define TclpGetPid_TCL_DECLARED @@ -363,7 +363,7 @@ EXTERN int TclpCreatePipe(TclFile *readPipe, TclFile *writePipe); #ifndef TclWinGetTclInstance_TCL_DECLARED #define TclWinGetTclInstance_TCL_DECLARED /* 4 */ -EXTERN int TclWinGetTclInstance(void); +EXTERN VOID * TclWinGetTclInstance(void); #endif /* Slot 5 is reserved */ #ifndef TclWinNToHS_TCL_DECLARED @@ -374,7 +374,7 @@ EXTERN unsigned short TclWinNToHS(unsigned short ns); #ifndef TclWinSetSockOpt_TCL_DECLARED #define TclWinSetSockOpt_TCL_DECLARED /* 7 */ -EXTERN int TclWinSetSockOpt(int s, int level, int optname, +EXTERN int TclWinSetSockOpt(VOID *s, int level, int optname, CONST char *optval, int optlen); #endif #ifndef TclUnixWaitForFile_TCL_DECLARED @@ -452,7 +452,7 @@ EXTERN void TclMacOSXNotifierAddRunLoopMode( #ifndef TclWinAddProcess_TCL_DECLARED #define TclWinAddProcess_TCL_DECLARED /* 20 */ -EXTERN void TclWinAddProcess(VOID *hProcess, unsigned long id); +EXTERN void TclWinAddProcess(VOID *hProcess, unsigned int id); #endif /* Slot 21 is reserved */ #ifndef TclpCreateTempFile_TCL_DECLARED @@ -513,10 +513,10 @@ typedef struct TclIntPlatStubs { void (*tclWinConvertWSAError) (unsigned int errCode); /* 1 */ Tcl_Channel (*tclpCreateCommandChannel) (TclFile readFile, TclFile writeFile, TclFile errorFile, int numPids, Tcl_Pid *pidPtr); /* 2 */ int (*tclpCreatePipe) (TclFile *readPipe, TclFile *writePipe); /* 3 */ - int (*tclWinGetTclInstance) (void); /* 4 */ + VOID * (*tclWinGetTclInstance) (void); /* 4 */ VOID *reserved5; unsigned short (*tclWinNToHS) (unsigned short ns); /* 6 */ - int (*tclWinSetSockOpt) (int s, int level, int optname, CONST char *optval, int optlen); /* 7 */ + int (*tclWinSetSockOpt) (VOID *s, int level, int optname, CONST char *optval, int optlen); /* 7 */ int (*tclUnixWaitForFile) (int fd, int mask, int timeout); /* 8 */ int (*tclWinGetPlatformId) (void); /* 9 */ Tcl_DirEntry * (*tclpReaddir) (DIR *dir); /* 10 */ @@ -529,7 +529,7 @@ typedef struct TclIntPlatStubs { VOID *reserved17; int (*tclMacOSXMatchType) (Tcl_Interp *interp, CONST char *pathName, CONST char *fileName, Tcl_StatBuf *statBufPtr, Tcl_GlobTypeData *types); /* 18 */ void (*tclMacOSXNotifierAddRunLoopMode) (CONST VOID *runLoopMode); /* 19 */ - void (*tclWinAddProcess) (VOID *hProcess, unsigned long id); /* 20 */ + void (*tclWinAddProcess) (VOID *hProcess, unsigned int id); /* 20 */ VOID *reserved21; TclFile (*tclpCreateTempFile) (CONST char *contents); /* 22 */ char * (*tclpGetTZName) (int isdst); /* 23 */ @@ -546,11 +546,11 @@ typedef struct TclIntPlatStubs { void (*tclWinConvertError) (DWORD errCode); /* 0 */ void (*tclWinConvertWSAError) (DWORD errCode); /* 1 */ struct servent * (*tclWinGetServByName) (CONST char *nm, CONST char *proto); /* 2 */ - int (*tclWinGetSockOpt) (SOCKET s, int level, int optname, char FAR *optval, int FAR *optlen); /* 3 */ + int (*tclWinGetSockOpt) (SOCKET s, int level, int optname, char *optval, int *optlen); /* 3 */ HINSTANCE (*tclWinGetTclInstance) (void); /* 4 */ VOID *reserved5; u_short (*tclWinNToHS) (u_short ns); /* 6 */ - int (*tclWinSetSockOpt) (SOCKET s, int level, int optname, CONST char FAR *optval, int optlen); /* 7 */ + int (*tclWinSetSockOpt) (SOCKET s, int level, int optname, CONST char *optval, int optlen); /* 7 */ unsigned long (*tclpGetPid) (Tcl_Pid pid); /* 8 */ int (*tclWinGetPlatformId) (void); /* 9 */ VOID *reserved10; @@ -579,10 +579,10 @@ typedef struct TclIntPlatStubs { void (*tclWinConvertWSAError) (unsigned int errCode); /* 1 */ Tcl_Channel (*tclpCreateCommandChannel) (TclFile readFile, TclFile writeFile, TclFile errorFile, int numPids, Tcl_Pid *pidPtr); /* 2 */ int (*tclpCreatePipe) (TclFile *readPipe, TclFile *writePipe); /* 3 */ - int (*tclWinGetTclInstance) (void); /* 4 */ + VOID * (*tclWinGetTclInstance) (void); /* 4 */ VOID *reserved5; unsigned short (*tclWinNToHS) (unsigned short ns); /* 6 */ - int (*tclWinSetSockOpt) (int s, int level, int optname, CONST char *optval, int optlen); /* 7 */ + int (*tclWinSetSockOpt) (VOID *s, int level, int optname, CONST char *optval, int optlen); /* 7 */ int (*tclUnixWaitForFile) (int fd, int mask, int timeout); /* 8 */ int (*tclWinGetPlatformId) (void); /* 9 */ Tcl_DirEntry * (*tclpReaddir) (DIR *dir); /* 10 */ @@ -595,7 +595,7 @@ typedef struct TclIntPlatStubs { int (*tclMacOSXCopyFileAttributes) (CONST char *src, CONST char *dst, CONST Tcl_StatBuf *statBufPtr); /* 17 */ int (*tclMacOSXMatchType) (Tcl_Interp *interp, CONST char *pathName, CONST char *fileName, Tcl_StatBuf *statBufPtr, Tcl_GlobTypeData *types); /* 18 */ void (*tclMacOSXNotifierAddRunLoopMode) (CONST VOID *runLoopMode); /* 19 */ - void (*tclWinAddProcess) (VOID *hProcess, unsigned long id); /* 20 */ + void (*tclWinAddProcess) (VOID *hProcess, unsigned int id); /* 20 */ VOID *reserved21; TclFile (*tclpCreateTempFile) (CONST char *contents); /* 22 */ char * (*tclpGetTZName) (int isdst); /* 23 */ diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index 7e98a75..94f279e 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -63,21 +63,31 @@ MODULE_SCOPE TclTomMathStubs tclTomMathStubs; #ifdef __CYGWIN__ +/* Trick, so we don't have to include <windows.h> here, which + * - b.t.w. - lacks this function anyway */ +#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 0x00000004 +int __stdcall GetModuleHandleExW(unsigned int, const char *, void *); + #define TclWinGetPlatformId winGetPlatformId #define Tcl_WinUtfToTChar winUtfToTChar #define Tcl_WinTCharToUtf winTCharToUtf #define TclWinGetTclInstance winGetTclInstance #define TclWinNToHS winNToHS #define TclWinSetSockOpt winSetSockOpt -#define TclWinAddProcess winAddProcess #define TclpGetTZName pGetTZName #define TclWinNoBackslash winNoBackslash -#define TclWinSetInterfaces (void (*) _ANSI_ARGS_((int))) doNothing +#define TclWinSetInterfaces (void (*) (int)) doNothing +#define TclWinAddProcess (void (*) (void *, unsigned int)) doNothing #define TclWinFlushDirtyChannels doNothing #define TclWinResetInterfaces doNothing static Tcl_Encoding winTCharEncoding; +typedef struct ThreadSpecificData { + char tzName[64]; /* Time zone name */ +} ThreadSpecificData; +static Tcl_ThreadDataKey dataKey; + static int TclWinGetPlatformId() { @@ -86,38 +96,35 @@ TclWinGetPlatformId() return 2; /* VER_PLATFORM_WIN32_NT */; } -static int TclWinGetTclInstance() +static void *TclWinGetTclInstance() { - Tcl_Panic("TclWinGetTclInstance not yet implemented for CYGWIN"); - return 0; + void *hInstance = NULL; + GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, + (const char *)&winTCharEncoding, &hInstance); + return hInstance; } static unsigned short TclWinNToHS(unsigned short ns) { - Tcl_Panic("TclWinNToHS not yet implemented for CYGWIN"); - return (unsigned short) -1; + return ntohs(ns); } + static int -TclWinSetSockOpt(int s, int level, int optname, +TclWinSetSockOpt(void *s, int level, int optname, const char *optval, int optlen) { - Tcl_Panic("TclWinSetSockOpt not yet implemented for CYGWIN"); - return -1; -} - -static void -TclWinAddProcess(void *hProcess, unsigned long id) -{ - Tcl_Panic("TclWinAddProcess not yet implemented for CYGWIN"); + return setsockopt((int) s, level, optname, optval, optlen); } static char * TclpGetTZName(int isdst) { - /* TODO: implementation */ - Tcl_Panic("TclpGetTZName not yet implemented for CYGWIN"); - return 0; + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + const char *zone = getenv("TZ"); + Tcl_ExternalToUtf(NULL, NULL, zone, strlen(zone), 0, NULL, + tsdPtr->tzName, sizeof(tsdPtr->tzName), NULL, NULL, NULL); + return tsdPtr->tzName; } static char * @@ -181,9 +188,9 @@ Tcl_WinTCharToUtf( # define TclWinConvertError (void (*) _ANSI_ARGS_((unsigned int))) TclGetAndDetachPids # define TclWinConvertWSAError (void (*) _ANSI_ARGS_((unsigned int))) TclpCloseFile # define TclWinGetPlatformId (int (*)()) TclpCreateTempFile -# define TclWinGetTclInstance (int (*)()) TclpCreateProcess +# define TclWinGetTclInstance (void *(*)()) TclpCreateProcess # define TclWinNToHS (unsigned short (*) _ANSI_ARGS_((unsigned short ns))) TclpMakeFile -# define TclWinSetSockOpt (int (*) _ANSI_ARGS_((int, int, int, const char *, int))) TclpOpenFile +# define TclWinSetSockOpt (int (*) _ANSI_ARGS_((void *, int, int, const char *, int))) TclpOpenFile # define TclWinAddProcess 0 # define TclpGetTZName 0 # define TclWinNoBackslash 0 diff --git a/win/tclWinError.c b/win/tclWinError.c index b49271e..d3126b1 100644 --- a/win/tclWinError.c +++ b/win/tclWinError.c @@ -13,14 +13,6 @@ #include "tclInt.h" #include "tclPort.h" -#ifndef WSAEWOULDBLOCK -# define WSAEWOULDBLOCK 10035L -#endif - -#ifndef __WIN32__ -# define DWORD unsigned int -#endif - /* * The following table contains the mapping from Win32 errors to errno errors. */ @@ -341,6 +333,11 @@ static CONST int wsaErrorTable[] = { EREMOTE /* WSAEREMOTE */ }; +#ifdef __CYGWIN__ +# include <windows.h> +# define DWORD unsigned int +#endif + /* *---------------------------------------------------------------------- * @@ -362,7 +359,12 @@ TclWinConvertError( DWORD errCode) /* Win32 error code. */ { if (errCode >= sizeof(errorTable)/sizeof(errorTable[0])) { - Tcl_SetErrno(EINVAL); + errCode -= WSAEWOULDBLOCK; + if (errCode >= sizeof(wsaErrorTable)/sizeof(wsaErrorTable[0])) { + Tcl_SetErrno(errorTable[1]); + } else { + Tcl_SetErrno(wsaErrorTable[errCode]); + } } else { Tcl_SetErrno(errorTable[errCode]); } @@ -388,11 +390,15 @@ void TclWinConvertWSAError( DWORD errCode) /* Win32 error code. */ { - errCode -= WSAEWOULDBLOCK; - if (errCode >= sizeof(wsaErrorTable)/sizeof(wsaErrorTable[0])) { - Tcl_SetErrno(EINVAL); + if (errCode >= sizeof(errorTable)/sizeof(errorTable[0])) { + errCode -= WSAEWOULDBLOCK; + if (errCode >= sizeof(wsaErrorTable)/sizeof(wsaErrorTable[0])) { + Tcl_SetErrno(errorTable[1]); + } else { + Tcl_SetErrno(wsaErrorTable[errCode]); + } } else { - Tcl_SetErrno(wsaErrorTable[errCode]); + Tcl_SetErrno(errorTable[errCode]); } } diff --git a/win/tclWinSock.c b/win/tclWinSock.c index 1bf4f97..2973db1 100644 --- a/win/tclWinSock.c +++ b/win/tclWinSock.c @@ -2480,7 +2480,7 @@ InitializeHostName( int TclWinGetSockOpt( - int s, + SOCKET s, int level, int optname, char * optval, @@ -2496,12 +2496,12 @@ TclWinGetSockOpt( return SOCKET_ERROR; } - return getsockopt((SOCKET)s, level, optname, optval, optlen); + return getsockopt(s, level, optname, optval, optlen); } int TclWinSetSockOpt( - int s, + SOCKET s, int level, int optname, const char * optval, @@ -2517,7 +2517,7 @@ TclWinSetSockOpt( return SOCKET_ERROR; } - return setsockopt((SOCKET)s, level, optname, optval, optlen); + return setsockopt(s, level, optname, optval, optlen); } u_short |