summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-04-24 20:21:16 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-04-24 20:21:16 (GMT)
commit40cddf0eb5289dc809a95140da0fef1e2d2e2f82 (patch)
treef7587ec802d28b8abaedf99e98dd2ba9084c5e6f /unix
parent6f14ff020a548ab6adcb30836c498ab0fe921970 (diff)
parent4f07974ad48f283b3c7bc0aa520b59a8450771cb (diff)
downloadtcl-40cddf0eb5289dc809a95140da0fef1e2d2e2f82.zip
tcl-40cddf0eb5289dc809a95140da0fef1e2d2e2f82.tar.gz
tcl-40cddf0eb5289dc809a95140da0fef1e2d2e2f82.tar.bz2
[Bug 3508771] load tclreg.dll in cygwin tclsh
Implement TclWinGetSockOpt, TclWinGetServByName and TclWinCPUID for Cygwin
Diffstat (limited to 'unix')
-rwxr-xr-xunix/configure44
-rw-r--r--unix/configure.in14
-rw-r--r--unix/tclUnixCompat.c7
-rw-r--r--unix/tclUnixFile.c38
-rw-r--r--unix/tclUnixPort.h2
5 files changed, 95 insertions, 10 deletions
diff --git a/unix/configure b/unix/configure
index b933912..1a0d882 100755
--- a/unix/configure
+++ b/unix/configure
@@ -9324,6 +9324,48 @@ fi
echo "$ac_t""$tcl_ok" 1>&6
#--------------------------------------------------------------------
+# The check below checks whether the cpuid instruction is usable.
+#--------------------------------------------------------------------
+
+echo $ac_n "checking whether the cpuid instruction is usable""... $ac_c" 1>&6
+echo "configure:9332: checking whether the cpuid instruction is usable" >&5
+if eval "test \"`echo '$''{'tcl_cv_cpuid'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+
+ cat > conftest.$ac_ext <<EOF
+#line 9338 "configure"
+#include "confdefs.h"
+
+int main() {
+
+ int index,ax,bx,cx,dx;
+ __asm__ __volatile__ ("cpuid":\
+ "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (index));
+
+; return 0; }
+EOF
+if { (eval echo configure:9349: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+ rm -rf conftest*
+ tcl_cv_cpuid=yes
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ tcl_cv_cpuid=no
+fi
+rm -f conftest*
+fi
+
+echo "$ac_t""$tcl_cv_cpuid" 1>&6
+if test $tcl_cv_cpuid = yes; then
+ cat >> confdefs.h <<\EOF
+#define HAVE_CPUID 1
+EOF
+
+fi
+
+#--------------------------------------------------------------------
# The statements below define a collection of symbols related to
# building libtcl as a shared library instead of a static library.
#--------------------------------------------------------------------
@@ -9352,7 +9394,7 @@ if test "`uname -s`" = "Darwin" ; then
if test "`uname -s`" = "Darwin" ; then
echo $ac_n "checking how to package libraries""... $ac_c" 1>&6
-echo "configure:9356: checking how to package libraries" >&5
+echo "configure:9398: checking how to package libraries" >&5
# Check whether --enable-framework or --disable-framework was given.
if test "${enable_framework+set}" = set; then
enableval="$enable_framework"
diff --git a/unix/configure.in b/unix/configure.in
index fbf9f41..c04c735 100644
--- a/unix/configure.in
+++ b/unix/configure.in
@@ -566,6 +566,20 @@ fi
AC_MSG_RESULT([$tcl_ok])
#--------------------------------------------------------------------
+# The check below checks whether the cpuid instruction is usable.
+#--------------------------------------------------------------------
+
+AC_CACHE_CHECK([whether the cpuid instruction is usable], tcl_cv_cpuid, [
+ AC_TRY_LINK(, [
+ int index,ax,bx,cx,dx;
+ __asm__ __volatile__ ("cpuid":\
+ "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (index));
+ ], tcl_cv_cpuid=yes, tcl_cv_cpuid=no)])
+if test $tcl_cv_cpuid = yes; then
+ AC_DEFINE(HAVE_CPUID)
+fi
+
+#--------------------------------------------------------------------
# The statements below define a collection of symbols related to
# building libtcl as a shared library instead of a static library.
#--------------------------------------------------------------------
diff --git a/unix/tclUnixCompat.c b/unix/tclUnixCompat.c
index 16e7a61..aad3d76 100644
--- a/unix/tclUnixCompat.c
+++ b/unix/tclUnixCompat.c
@@ -692,8 +692,11 @@ TclWinCPUID(
{
int status = TCL_ERROR;
- /* There is no reason this couldn't be implemented on UNIX as well */
- return status;
+#ifdef HAVE_CPUID
+ __asm__ __volatile__ ("cpuid":\
+ "=a" (regsPtr[0]), "=b" (regsPtr[1]), "=c" (regsPtr[2]), "=d" (regsPtr[3]) : "a" (index));
+ status = TCL_OK;
+#endif return status;
}
/*
diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c
index 5eac978..4ba2e47 100644
--- a/unix/tclUnixFile.c
+++ b/unix/tclUnixFile.c
@@ -22,7 +22,8 @@ static int NativeMatchType(CONST char* nativeName, Tcl_GlobTypeData *types);
* TclpFindExecutable --
*
* This procedure computes the absolute path name of the current
- * application, given its argv[0] value.
+ * application, given its argv[0] value. For Cygwin, argv[0] is
+ * ignored and the path is determined the same as under win32.
*
* Results:
* A dirty UTF string that is the path to the executable. At this
@@ -45,18 +46,44 @@ TclpFindExecutable(argv0)
CONST char *argv0; /* The value of the application's argv[0]
* (native). */
{
+ int length;
+#ifdef __CYGWIN__
+ char buf[PATH_MAX * TCL_UTF_MAX + 1];
+ char name[PATH_MAX * TCL_UTF_MAX + 1];
+#else
CONST char *name, *p;
Tcl_StatBuf statBuf;
- int length;
Tcl_DString buffer, nameString;
+#endif
- if (argv0 == NULL) {
- return NULL;
- }
if (tclNativeExecutableName != NULL) {
return tclNativeExecutableName;
}
+#ifdef __CYGWIN__
+
+ /* Make some symbols available without including <windows.h> */
+# define CP_UTF8 65001
+ extern int cygwin_conv_to_full_posix_path(const char *, char *);
+ extern __stdcall int GetModuleFileNameW(void *, const char *, int);
+ extern __stdcall int WideCharToMultiByte(int, int, const char *, int,
+ const char *, int, const char *, const char *);
+
+ GetModuleFileNameW(NULL, name, PATH_MAX);
+ WideCharToMultiByte(CP_UTF8, 0, name, -1, buf, PATH_MAX, NULL, NULL);
+ cygwin_conv_to_full_posix_path(buf, name);
+ length = strlen(name);
+ if ((length > 4) && !strcasecmp(name + length - 4, ".exe")) {
+ /* Strip '.exe' part. */
+ length -= 4;
+ }
+ tclNativeExecutableName = (char *) ckalloc(length + 1);
+ memcpy(tclNativeExecutableName, name, length);
+ buf[length] = '\0';
+#else
+ if (argv0 == NULL) {
+ return NULL;
+ }
Tcl_DStringInit(&buffer);
name = argv0;
@@ -174,6 +201,7 @@ gotName:
done:
Tcl_DStringFree(&buffer);
+#endif
return tclNativeExecutableName;
}
diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h
index c0bf77d8..9426697 100644
--- a/unix/tclUnixPort.h
+++ b/unix/tclUnixPort.h
@@ -658,7 +658,6 @@ extern int copyfile(const char *from, const char *to, void *state,
* address platform-specific issues.
*/
-#define TclpGetPid(pid) ((unsigned long) (pid))
#define TclpReleaseFile(file) /* Nothing. */
/*
@@ -699,7 +698,6 @@ EXTERN struct tm * TclpLocaltime(TclpTime_t_CONST);
#ifndef TclpGmtime
EXTERN struct tm * TclpGmtime(TclpTime_t_CONST);
#endif
-EXTERN char * TclpInetNtoa(struct in_addr);
#define inet_ntoa(x) TclpInetNtoa(x)
#else
typedef int TclpMutex;