>From ca305745040cab8676256125834064dc6a0ef374 Mon Sep 17 00:00:00 2001
From: Peter Bex
Date: Sun, 1 Dec 2013 18:01:19 +0100
Subject: [PATCH 2/2] Get rid of all fallback winsock.h code and simplify a
few more Windows things.
- Winsock 1 probably doesn't work anymore anyway, and Winsock 2 is supported
on all target Windows versions. All of our Windows Makefiles define
HAVE_WINSOCK2 so it was dead, untested code.
- Remove unused strange HAVE_... feature definitions
- Remove unused get_netinfo() function
- Remove a whole bunch of unused process/pipe/IO redirection functions and macros
---
Makefile.cross-linux-mingw | 4 -
Makefile.mingw | 4 -
Makefile.mingw-msys | 4 -
posixwin.scm | 196 ++------------------------------------------
runtime.c | 4 +-
scheduler.scm | 8 +-
tcp.scm | 8 +-
7 files changed, 12 insertions(+), 216 deletions(-)
diff --git a/Makefile.cross-linux-mingw b/Makefile.cross-linux-mingw
index e1778ca..6a877f1 100644
--- a/Makefile.cross-linux-mingw
+++ b/Makefile.cross-linux-mingw
@@ -110,16 +110,12 @@ chicken-config.h: chicken-defaults.h
echo "#define HAVE_SYS_TYPES_H 1" >>$@
echo "#define HAVE_UNISTD_H 1" >>$@
echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
- echo "#define HAVE_WINDOWS_H 1" >>$@
- echo "#define HAVE__STRTOI64 1" >>$@
echo "#define STDC_HEADERS 1" >>$@
echo "#define HAVE_ALLOCA_H 1" >>$@
echo "#define HAVE_DIRECT_H 1" >>$@
echo "#define HAVE_ERRNO_H 1" >>$@
echo "#define HAVE_LOADLIBRARY 1" >>$@
echo "#define HAVE_GETPROCADDRESS 1" >>$@
- echo "#define HAVE_WINSOCK2_H 1" >>$@
- echo "#define HAVE_WS2TCPIP_H 1" >>$@
echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
ifdef GCHOOKS
echo "#define C_GC_HOOKS" >>$@
diff --git a/Makefile.mingw b/Makefile.mingw
index 48b801d..c5373aa 100644
--- a/Makefile.mingw
+++ b/Makefile.mingw
@@ -105,15 +105,11 @@ chicken-config.h: chicken-defaults.h
echo #define HAVE_SYS_TYPES_H 1 >>$@
echo #define HAVE_UNISTD_H 1 >>$@
echo #define HAVE_UNSIGNED_LONG_LONG 1 >>$@
- echo #define HAVE_WINDOWS_H 1 >>$@
- echo #define HAVE__STRTOI64 1 >>$@
echo #define STDC_HEADERS 1 >>$@
echo #define HAVE_DIRECT_H 1 >>$@
echo #define HAVE_ERRNO_H 1 >>$@
echo #define HAVE_LOADLIBRARY 1 >>$@
echo #define HAVE_GETPROCADDRESS 1 >>$@
- echo #define HAVE_WINSOCK2_H 1 >>$@
- echo #define HAVE_WS2TCPIP_H 1 >>$@
echo #define C_STACK_GROWS_DOWNWARD 1 >>$@
ifdef GCHOOKS
echo #define C_GC_HOOKS >>$@
diff --git a/Makefile.mingw-msys b/Makefile.mingw-msys
index 74607aa..885d975 100644
--- a/Makefile.mingw-msys
+++ b/Makefile.mingw-msys
@@ -104,15 +104,11 @@ chicken-config.h: chicken-defaults.h
echo "#define HAVE_SYS_TYPES_H 1" >>$@
echo "#define HAVE_UNISTD_H 1" >>$@
echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
- echo "#define HAVE_WINDOWS_H 1" >>$@
- echo "#define HAVE__STRTOI64 1" >>$@
echo "#define STDC_HEADERS 1" >>$@
echo "#define HAVE_DIRECT_H 1" >>$@
echo "#define HAVE_ERRNO_H 1" >>$@
echo "#define HAVE_LOADLIBRARY 1" >>$@
echo "#define HAVE_GETPROCADDRESS 1" >>$@
- echo "#define HAVE_WINSOCK2_H 1" >>$@
- echo "#define HAVE_WS2TCPIP_H 1" >>$@
echo "#define C_WINDOWS_SHELL 1" >>$@
echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
ifdef GCHOOKS
diff --git a/posixwin.scm b/posixwin.scm
index ede7e09..9bf0e3b 100644
--- a/posixwin.scm
+++ b/posixwin.scm
@@ -73,20 +73,14 @@
# define WIN32_LEAN_AND_MEAN
#endif
-#if (defined(HAVE_WINSOCK2_H) && defined(HAVE_WS2TCPIP_H))
-# include
-# include
-#else
-# include
-#endif
-
-#include
+#include
#include
+#include
#include
#include
-#include
-#include
+#include
#include
+#include
#define ARG_MAX 256
#define PIPE_BUF 512
@@ -386,161 +380,6 @@ set_last_errno()
return 0;
}
-/* Functions for creating process with redirected I/O */
-
-static int C_fcall
-zero_handles()
-{
- C_rd0 = C_wr0 = C_wr0_ = INVALID_HANDLE_VALUE;
- C_rd1 = C_wr1 = C_rd1_ = INVALID_HANDLE_VALUE;
- C_save0 = C_save1 = INVALID_HANDLE_VALUE;
- return 1;
-}
-
-static int C_fcall
-close_handles()
-{
- if (C_rd0 != INVALID_HANDLE_VALUE)
- CloseHandle(C_rd0);
- if (C_rd1 != INVALID_HANDLE_VALUE)
- CloseHandle(C_rd1);
- if (C_wr0 != INVALID_HANDLE_VALUE)
- CloseHandle(C_wr0);
- if (C_wr1 != INVALID_HANDLE_VALUE)
- CloseHandle(C_wr1);
- if (C_rd1_ != INVALID_HANDLE_VALUE)
- CloseHandle(C_rd1_);
- if (C_wr0_ != INVALID_HANDLE_VALUE)
- CloseHandle(C_wr0_);
- if (C_save0 != INVALID_HANDLE_VALUE)
- {
- SetStdHandle(STD_INPUT_HANDLE, C_save0);
- CloseHandle(C_save0);
- }
- if (C_save1 != INVALID_HANDLE_VALUE)
- {
- SetStdHandle(STD_OUTPUT_HANDLE, C_save1);
- CloseHandle(C_save1);
- }
- return zero_handles();
-}
-
-static int C_fcall
-redir_io()
-{
- SECURITY_ATTRIBUTES sa;
- sa.nLength = sizeof(SECURITY_ATTRIBUTES);
- sa.bInheritHandle = TRUE;
- sa.lpSecurityDescriptor = NULL;
-
- zero_handles();
-
- C_save0 = GetStdHandle(STD_INPUT_HANDLE);
- C_save1 = GetStdHandle(STD_OUTPUT_HANDLE);
- if (!CreatePipe(&C_rd0, &C_wr0, &sa, 0)
- || !SetStdHandle(STD_INPUT_HANDLE, C_rd0)
- || !DuplicateHandle(GetCurrentProcess(), C_wr0, GetCurrentProcess(),
- &C_wr0_, 0, FALSE, DUPLICATE_SAME_ACCESS)
- || !CreatePipe(&C_rd1, &C_wr1, &sa, 0)
- || !SetStdHandle(STD_OUTPUT_HANDLE, C_wr1)
- || !DuplicateHandle(GetCurrentProcess(), C_rd1, GetCurrentProcess(),
- &C_rd1_, 0, FALSE, DUPLICATE_SAME_ACCESS))
- {
- set_last_errno();
- close_handles();
- return 0;
- }
-
- CloseHandle(C_wr0);
- C_wr0 = INVALID_HANDLE_VALUE;
- CloseHandle(C_rd1);
- C_rd1 = INVALID_HANDLE_VALUE;
- return 1;
-}
-
-static C_word C_fcall
-run_process(char *cmdline)
-{
- PROCESS_INFORMATION pi;
- STARTUPINFO si;
-
- ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
- ZeroMemory(&si, sizeof(STARTUPINFO));
- si.cb = sizeof(STARTUPINFO);
-
- C_wr0_ = C_rd1_ = INVALID_HANDLE_VALUE; /* these handles are saved */
-
- if (CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0, NULL,
- NULL, &si, &pi))
- {
- CloseHandle(pi.hThread);
-
- SetStdHandle(STD_INPUT_HANDLE, C_save0);
- SetStdHandle(STD_OUTPUT_HANDLE, C_save1);
- C_save0 = C_save1 = INVALID_HANDLE_VALUE;
-
- CloseHandle(C_rd0);
- CloseHandle(C_wr1);
- C_rd0 = C_wr1 = INVALID_HANDLE_VALUE;
- return (C_word)pi.hProcess;
- }
- else
- return set_last_errno();
-}
-
-static C_word C_fcall
-pipe_write(C_word hpipe, void* buf, int count)
-{
- DWORD done = 0;
- if (WriteFile((HANDLE)hpipe, buf, count, &done, NULL))
- return 1;
- else
- return set_last_errno();
-}
-
-static C_word C_fcall
-pipe_read(C_word hpipe)
-{
- DWORD done = 0;
- /* TODO:
- if (!pipe_ready(hpipe))
- go_to_sleep;
- */
- if (ReadFile((HANDLE)hpipe, &C_rdbuf, 1, &done, NULL))
- {
- if (done > 0) /* not EOF yet */
- return 1;
- else
- return -1;
- }
- return set_last_errno();
-}
-
-static int C_fcall
-pipe_ready(C_word hpipe)
-{
- DWORD avail = 0;
- if (PeekNamedPipe((HANDLE)hpipe, NULL, 0, NULL, &avail, NULL) && avail)
- return 1;
- else
- {
- Sleep(0); /* give pipe a chance */
- if (PeekNamedPipe((HANDLE)hpipe, NULL, 0, NULL, &avail, NULL))
- return (avail > 0);
- else
- return 0;
- }
-}
-
-#define C_zero_handles() C_fix(zero_handles())
-#define C_close_handles() C_fix(close_handles())
-#define C_redir_io() (redir_io() ? C_SCHEME_TRUE : C_SCHEME_FALSE)
-#define C_run_process(cmdline) C_fix(run_process(C_c_string(cmdline)))
-#define C_pipe_write(h, b, n) (pipe_write(C_unfix(h), C_c_string(b), C_unfix(n)) ? C_SCHEME_TRUE : C_SCHEME_FALSE)
-#define C_pipe_read(h) C_fix(pipe_read(C_unfix(h)))
-#define C_pipe_ready(h) (pipe_ready(C_unfix(h)) ? C_SCHEME_TRUE : C_SCHEME_FALSE)
-#define close_handle(h) CloseHandle((HANDLE)h)
-
static int C_fcall
process_wait(C_word h, C_word t)
{
@@ -665,7 +504,7 @@ get_shlcmd()
/* Do we need to build the shell command pathname? */
if (!strlen(C_shlcmd))
{
- if (sysinfo())
+ if (sysinfo()) /* for C_isNT */
{
char *cmdnam = C_isNT ? "\\cmd.exe" : "\\command.com";
UINT len = GetSystemDirectory(C_shlcmd, sizeof(C_shlcmd) - strlen(cmdnam));
@@ -700,31 +539,6 @@ get_user_name()
#define C_get_user_name() (get_user_name() ? C_SCHEME_TRUE : C_SCHEME_FALSE)
-/* User Information */
-
-#if 0
-static int C_fcall
-get_netinfo()
-{
- HINSTANCE hNet = 0,
- hLoc = 0;
-
- if (isNT)
- hNet = LoadLibrary("netapi32.dll");
- else
- {
- hLoc = LoadLibrary("rlocal32.dll");
- hNet = LoadLibrary("radmin32.dll");
- //hNet = LoadLibrary("netapi.dll");
- }
-
- if (!hNet)
- return 0;
-
-
-}
-#endif
-
/*
Spawn a process directly.
Params:
diff --git a/runtime.c b/runtime.c
index 93463c2..16b6299 100644
--- a/runtime.c
+++ b/runtime.c
@@ -96,7 +96,9 @@ static C_TLS int timezone;
# define RTLD_LAZY 0
#endif
-#if defined(HAVE_WINDOWS_H) || (defined(_WIN32) && !defined(__CYGWIN__))
+#if defined(_WIN32) && !defined(__CYGWIN__)
+/* Include winsock2 to get select() for check_fd_ready() */
+# include
# include
#endif
diff --git a/scheduler.scm b/scheduler.scm
index 12542da..8cac5d1 100644
--- a/scheduler.scm
+++ b/scheduler.scm
@@ -44,12 +44,8 @@
#endif
#ifdef _WIN32
-# if (defined(HAVE_WINSOCK2_H) && defined(HAVE_WS2TCPIP_H))
-# include
-# include
-# else
-# include
-# endif
+/* TODO: Winsock select() only works for sockets */
+# include
/* Beware: winsock2.h must come BEFORE windows.h */
# define C_msleep(n) (Sleep(C_unfix(n)), C_SCHEME_TRUE)
#else
diff --git a/tcp.scm b/tcp.scm
index 7bf49a5..282ff73 100644
--- a/tcp.scm
+++ b/tcp.scm
@@ -34,12 +34,8 @@
tcp-read-timeout tcp-write-timeout tcp-accept-timeout tcp-connect-timeout)
(foreign-declare #<
-# include
-# else
-# include
-# endif
+# include
+# include
/* Beware: winsock2.h must come BEFORE windows.h */
# define socklen_t int
static WSADATA wsa;
--
1.7.10.4