~ chicken-core (chicken-5) d2fa321f6ccc218c40d619cedbc37553e9eeb328
commit d2fa321f6ccc218c40d619cedbc37553e9eeb328
Author: Peter Bex <peter.bex@xs4all.nl>
AuthorDate: Sun Dec 1 18:01:19 2013 +0100
Commit: Christian Kellermann <ckeen@pestilenz.org>
CommitDate: Thu Dec 19 15:48:02 2013 +0100
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
Signed-off-by: Christian Kellermann <ckeen@pestilenz.org>
diff --git a/Makefile.cross-linux-mingw b/Makefile.cross-linux-mingw
index e1778cae..6a877f16 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 48b801df..c5373aad 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 74607aa2..885d9753 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 ede7e094..9bf0e3b8 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 <winsock2.h>
-# include <ws2tcpip.h>
-#else
-# include <winsock.h>
-#endif
-
-#include <signal.h>
+#include <direct.h>
#include <errno.h>
+#include <fcntl.h>
#include <io.h>
#include <process.h>
-#include <fcntl.h>
-#include <direct.h>
+#include <signal.h>
#include <utime.h>
+#include <winsock2.h>
#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 ed2a95ea..e91d4448 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 <winsock2.h>
# include <windows.h>
#endif
diff --git a/scheduler.scm b/scheduler.scm
index 12542da3..8cac5d1c 100644
--- a/scheduler.scm
+++ b/scheduler.scm
@@ -44,12 +44,8 @@
#endif
#ifdef _WIN32
-# if (defined(HAVE_WINSOCK2_H) && defined(HAVE_WS2TCPIP_H))
-# include <winsock2.h>
-# include <ws2tcpip.h>
-# else
-# include <winsock.h>
-# endif
+/* TODO: Winsock select() only works for sockets */
+# include <winsock2.h>
/* 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 40dcd8ec..766f7080 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 #<<EOF
#ifdef _WIN32
-# if (defined(HAVE_WINSOCK2_H) && defined(HAVE_WS2TCPIP_H))
-# include <winsock2.h>
-# include <ws2tcpip.h>
-# else
-# include <winsock.h>
-# endif
+# include <winsock2.h>
+# include <ws2tcpip.h>
/* Beware: winsock2.h must come BEFORE windows.h */
# define socklen_t int
static WSADATA wsa;
Trap