* Makefile: cosmetics
* socketmodule.c: get rid of makepair(); fix makesocketaddr to fix
  broken recvfrom()
* socketmodule: get rid of getStrarg()
* ceval.h: move eval_code() to new file eval.h, so compile.h is no
  longer needed.
* ceval.c: move thread comments to ceval.h; always make save/restore
  thread functions available (for dynloaded modules)
* cdmodule.c, listobject.c: don't include compile.h
* flmodule.c: include ceval.h
* import.c: include eval.h instead of ceval.h
* cgen.py: add forground(); noport(); winopen(""); to initgl().
* bltinmodule.c, socketmodule.c, fileobject.c, posixmodule.c,
  selectmodule.c:
  adapt to threads (add BGN/END SAVE macros)
* stdwinmodule.c: adapt to threads and use a special stdwin lock.
* pythonmain.c: don't include getpythonpath().
* pythonrun.c: use BGN/END SAVE instead of direct calls; also more
  BGN/END SAVE calls etc.
* thread.c: bigger stack size for sun; change exit() to _exit()
* threadmodule.c: use BGN/END SAVE macros where possible
* timemodule.c: adapt better to threads; use BGN/END SAVE; add
  longsleep internal function if BSD_TIME; cosmetics
diff --git a/Modules/cdmodule.c b/Modules/cdmodule.c
index 332b54b..04451a1 100644
--- a/Modules/cdmodule.c
+++ b/Modules/cdmodule.c
@@ -30,7 +30,6 @@
 #include "allobjects.h"
 #include "import.h"
 #include "modsupport.h"
-#include "compile.h"
 #include "ceval.h"
 
 #define NCALLBACKS	8
diff --git a/Modules/cgen.py b/Modules/cgen.py
index d6e9c96..2775d3d 100644
--- a/Modules/cgen.py
+++ b/Modules/cgen.py
@@ -459,4 +459,8 @@
 print 'initgl()'
 print '{'
 print '\tinitmodule("gl", gl_methods);'
+print '\t/* Initialize GL and don\'t go in the background */'
+print '\tforeground();'
+print '\tnoport();'
+print '\twinopen("");'
 print '}'
diff --git a/Modules/flmodule.c b/Modules/flmodule.c
index d8c423c..bd5ff56 100644
--- a/Modules/flmodule.c
+++ b/Modules/flmodule.c
@@ -35,9 +35,7 @@
 #include "import.h"
 #include "modsupport.h"
 #include "structmember.h"
-
-/* #include "ceval.h" */
-extern object *call_object(object *, object *);
+#include "ceval.h"
 
 /* Generic Forms Objects */
 
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 8ae1758..367e21c 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -73,6 +73,7 @@
 
 #include "allobjects.h"
 #include "modsupport.h"
+#include "ceval.h"
 
 extern char *strerror PROTO((int));
 
@@ -128,9 +129,13 @@
 	int (*func) FPROTO((const char *));
 {
 	char *path1;
+	int res;
 	if (!getstrarg(args, &path1))
 		return NULL;
-	if ((*func)(path1) < 0)
+	BGN_SAVE
+	res = (*func)(path1);
+	END_SAVE
+	if (res < 0)
 		return posix_error();
 	INCREF(None);
 	return None;
@@ -142,9 +147,13 @@
 	int (*func) FPROTO((const char *, const char *));
 {
 	char *path1, *path2;
+	int res;
 	if (!getstrstrarg(args, &path1, &path2))
 		return NULL;
-	if ((*func)(path1, path2) < 0)
+	BGN_SAVE
+	res = (*func)(path1, path2);
+	END_SAVE
+	if (res < 0)
 		return posix_error();
 	INCREF(None);
 	return None;
@@ -157,9 +166,13 @@
 {
 	char *path;
 	int i;
+	int res;
 	if (!getstrintarg(args, &path, &i))
 		return NULL;
-	if ((*func)(path, i) < 0)
+	BGN_SAVE
+	res = (*func)(path, i);
+	END_SAVE
+	if (res < 0)
 		return posix_error();
 	INCREF(None);
 	return None;
@@ -174,9 +187,13 @@
 	struct stat st;
 	char *path;
 	object *v;
+	int res;
 	if (!getstrarg(args, &path))
 		return NULL;
-	if ((*statfunc)(path, &st) != 0)
+	BGN_SAVE
+	res = (*statfunc)(path, &st);
+	END_SAVE
+	if (res != 0)
 		return posix_error();
 	v = newtupleobject(10);
 	if (v == NULL)
@@ -227,10 +244,14 @@
 	object *args;
 {
 	char buf[1026];
+	char *res;
 	extern char *getcwd PROTO((char *, int));
 	if (!getnoarg(args))
 		return NULL;
-	if (getcwd(buf, sizeof buf) == NULL)
+	BGN_SAVE
+	res = getcwd(buf, sizeof buf);
+	END_SAVE
+	if (res == NULL)
 		return posix_error();
 	return newstringobject(buf);
 }
@@ -284,10 +305,14 @@
 	struct direct *ep;
 	if (!getstrarg(args, &name))
 		return NULL;
-	if ((dirp = opendir(name)) == NULL)
+	BGN_SAVE
+	if ((dirp = opendir(name)) == NULL) {
+		RET_SAVE
 		return posix_error();
+	}
 	if ((d = newlistobject(0)) == NULL) {
 		closedir(dirp);
+		RET_SAVE
 		return NULL;
 	}
 	while ((ep = readdir(dirp)) != NULL) {
@@ -306,6 +331,7 @@
 		DECREF(v);
 	}
 	closedir(dirp);
+	END_SAVE
 #endif /* !MSDOS */
 
 	return d;
@@ -368,11 +394,13 @@
 	object *args;
 {
 	char *command;
-	int sts;
+	long sts;
 	if (!getstrarg(args, &command))
 		return NULL;
+	BGN_SAVE
 	sts = system(command);
-	return newintobject((long)sts);
+	END_SAVE
+	return newintobject(sts);
 }
 
 #ifndef MSDOS
@@ -411,9 +439,13 @@
 	extern int uname PROTO((struct utsname *));
 	struct utsname u;
 	object *v;
+	int res;
 	if (!getnoarg(args))
 		return NULL;
-	if (uname(&u) < 0)
+	BGN_SAVE
+	res = uname(&u);
+	END_SAVE
+	if (res < 0)
 		return posix_error();
 	v = newtupleobject(5);
 	if (v == NULL)
@@ -443,6 +475,7 @@
 	object *args;
 {
 	char *path;
+	int res;
 
 #ifdef UTIME_STRUCT
 	struct utimbuf buf;
@@ -459,7 +492,10 @@
 
 	if (!getargs(args, "(s(ll))", &path, &ATIME, &MTIME))
 		return NULL;
-	if (utime(path, UTIME_ARG) < 0)
+	BGN_SAVE
+	res = utime(path, UTIME_ARG);
+	END_SAVE
+	if (res < 0)
 		return posix_error();
 	INCREF(None);
 	return None;
@@ -648,7 +684,9 @@
 	FILE *fp;
 	if (!getargs(args, "(ss)", &name, &mode))
 		return NULL;
+	BGN_SAVE
 	fp = popen(name, mode);
+	END_SAVE
 	if (fp == NULL)
 		return posix_error();
 	/* From now on, ignore SIGPIPE and let the error checking
@@ -664,8 +702,11 @@
 {
 	object *v;
 	int pid, sts;
-	if (args == NULL)
+	if (args == NULL) {
+		BGN_SAVE
 		pid = wait(&sts);
+		END_SAVE
+	}
 	else {
 #ifdef NO_WAITPID
 		err_setstr(PosixError,
@@ -674,7 +715,9 @@
 		int options;
 		if (!getintintarg(args, &pid, &options))
 			return NULL;
+		BGN_SAVE
 		pid = waitpid(pid, &sts, options);
+		END_SAVE
 #endif
 	}
 	if (pid == -1)
@@ -719,7 +762,9 @@
 	int n;
 	if (!getstrarg(args, &path))
 		return NULL;
+	BGN_SAVE
 	n = readlink(path, buf, (int) sizeof buf);
+	END_SAVE
 	if (n < 0)
 		return posix_error();
 	return newsizedstringobject(buf, n);
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 8afd208..3a5644b 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -26,7 +26,6 @@
 
 #include "allobjects.h"
 #include "modsupport.h"
-#include "compile.h"
 #include "ceval.h"
 
 #include "myselect.h"
@@ -154,7 +153,9 @@
     if ( omax > max ) max = omax;
     if ( emax > max ) max = emax;
 
+    BGN_SAVE
     n = select(max, &ifdset, &ofdset, &efdset, tvp);
+    END_SAVE
 
     if ( n < 0 ) {
 	err_errno(SelectError);
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 839d46e..ab8c6b5 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -24,8 +24,6 @@
 
 /* Socket module */
 
-/* XXX Ought to fix getStr*arg calls to use getargs(args, "s#", ...) */
-
 /*
 This module provides an interface to Berkeley socket IPC.
 
@@ -72,6 +70,7 @@
 
 #include "allobjects.h"
 #include "modsupport.h"
+#include "ceval.h"
 
 #include "myselect.h" /* Implies <sys/types.h>, <sys/time.h>, <sys/param.h> */
 
@@ -171,7 +170,9 @@
 			((long) d3 << 8) | ((long) d4 << 0));
 		return 4;
 	}
+	BGN_SAVE
 	hp = gethostbyname(name);
+	END_SAVE
 	if (hp == NULL) {
 		err_setstr(SocketError, "host not found");
 		return -1;
@@ -256,16 +257,16 @@
 	case AF_UNIX:
 	{
 		static struct sockaddr_un addr;
-		object *path;
+		char *path;
 		int len;
-		if (!getStrarg(args, &path))
+		if (!getargs(args, "s#", &path, &len))
 			return 0;
-		if ((len = getstringsize(path)) > sizeof addr.sun_path) {
+		if (len > sizeof addr.sun_path) {
 			err_setstr(SocketError, "AF_UNIX path too long");
 			return 0;
 		}
 		addr.sun_family = AF_UNIX;
-		memcpy(addr.sun_path, getstringvalue(path), len);
+		memcpy(addr.sun_path, path, len);
 		*addr_ret = (struct sockaddr *) &addr;
 		*len_ret = len + sizeof addr.sun_family;
 		return 1;
@@ -274,11 +275,11 @@
 	case AF_INET:
 	{
 		static struct sockaddr_in addr;
-		object *host;
+		char *host;
 		int port;
-		if (!getStrintarg(args, &host, &port))
+		if (!getargs(args, "(si)", &host, &port))
 			return 0;
-		if (setipaddr(getstringvalue(host), &addr) < 0)
+		if (setipaddr(host, &addr) < 0)
 			return 0;
 		addr.sin_family = AF_INET;
 		addr.sin_port = htons(port);
@@ -344,7 +345,9 @@
 		return NULL;
 	if (!getsockaddrlen(s, &addrlen))
 		return NULL;
+	BGN_SAVE
 	newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
+	END_SAVE
 	if (newfd < 0)
 		return socket_error();
 	/* Create the new object with unspecified family,
@@ -370,7 +373,7 @@
 {
 	int flag;
 	int res;
-	if (!getintarg(args, &flag))
+	if (!getargs(args, "i", &flag))
 		return NULL;
 	res = setsockopt(s->sock_fd, SOL_SOCKET, SO_BROADCAST,
 			 &flag, sizeof flag);
@@ -461,9 +464,13 @@
 {
 	struct sockaddr *addr;
 	int addrlen;
+	int res;
 	if (!getsockaddrarg(s, args, &addr, &addrlen))
 		return NULL;
-	if (bind(s->sock_fd, addr, addrlen) < 0)
+	BGN_SAVE
+	res = bind(s->sock_fd, addr, addrlen);
+	END_SAVE
+	if (res < 0)
 		return socket_error();
 	INCREF(None);
 	return None;
@@ -481,7 +488,9 @@
 {
 	if (!getnoarg(args))
 		return NULL;
+	BGN_SAVE
 	(void) close(s->sock_fd);
+	END_SAVE
 	s->sock_fd = -1;
 	INCREF(None);
 	return None;
@@ -497,9 +506,13 @@
 {
 	struct sockaddr *addr;
 	int addrlen;
+	int res;
 	if (!getsockaddrarg(s, args, &addr, &addrlen))
 		return NULL;
-	if (connect(s->sock_fd, addr, addrlen) < 0)
+	BGN_SAVE
+	res = connect(s->sock_fd, addr, addrlen);
+	END_SAVE
+	if (res < 0)
 		return socket_error();
 	INCREF(None);
 	return None;
@@ -527,9 +540,13 @@
 	object *args;
 {
 	int backlog;
+	int res;
 	if (!getintarg(args, &backlog))
 		return NULL;
-	if (listen(s->sock_fd, backlog) < 0)
+	BGN_SAVE
+	res = listen(s->sock_fd, backlog);
+	END_SAVE
+	if (res < 0)
 		return socket_error();
 	INCREF(None);
 	return None;
@@ -549,15 +566,15 @@
 	object *args;
 {
 	extern int fclose PROTO((FILE *));
-	object *mode;
+	char *mode;
 	int fd;
 	FILE *fp;
-	if (!getStrarg(args, &mode))
+	if (!getargs(args, "s", &mode))
 		return NULL;
 	if ((fd = dup(s->sock_fd)) < 0 ||
-	    (fp = fdopen(fd, getstringvalue(mode))) == NULL)
+	    (fp = fdopen(fd, mode)) == NULL)
 		return socket_error();
-	return newopenfileobject(fp, "<socket>", getstringvalue(mode), fclose);
+	return newopenfileobject(fp, "<socket>", mode, fclose);
 }
 
 
@@ -579,7 +596,9 @@
 	buf = newsizedstringobject((char *) 0, len);
 	if (buf == NULL)
 		return NULL;
+	BGN_SAVE
 	n = recv(s->sock_fd, getstringvalue(buf), len, flags);
+	END_SAVE
 	if (n < 0)
 		return socket_error();
 	if (resizestring(&buf, n) < 0)
@@ -600,10 +619,13 @@
 	int addrlen, len, n;
 	if (!getintarg(args, &len))
 		return NULL;
+	if (!getsockaddrlen(s, &addrlen))
+		return NULL;
 	buf = newsizedstringobject((char *) 0, len);
-	addrlen = sizeof addrbuf;
+	BGN_SAVE
 	n = recvfrom(s->sock_fd, getstringvalue(buf), len, 0,
 		     addrbuf, &addrlen);
+	END_SAVE
 	if (n < 0)
 		return socket_error();
 	if (resizestring(&buf, n) < 0)
@@ -620,16 +642,17 @@
 	sockobject *s;
 	object *args;
 {
-	object *buf;
+	char *buf;
 	int len, n, flags;
-	if (!getStrintarg(args, &buf, &flags)) {
+	if (!getargs(args, "(s#i)", &buf, &len, &flags)) {
 		err_clear();
-		if (!getStrarg(args, &buf))
+		if (!getargs(args, "s#", &buf, &len))
 			return NULL;
 		flags = 0;
 	}
-	len = getstringsize(buf);
-	n = send(s->sock_fd, getstringvalue(buf), len, flags);
+	BGN_SAVE
+	n = send(s->sock_fd, buf, len, flags);
+	END_SAVE
 	if (n < 0)
 		return socket_error();
 	INCREF(None);
@@ -644,19 +667,20 @@
 	sockobject *s;
 	object *args;
 {
-	object *buf;
+	object *addro;
+	char *buf;
 	struct sockaddr *addr;
 	int addrlen, len, n;
 	if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) {
 		err_badarg();
 		return NULL;
 	}
-	if (!getStrarg(gettupleitem(args, 0), &buf) ||
-	    !getsockaddrarg(s, gettupleitem(args, 1), &addr, &addrlen))
+	if (!getargs(args, "(s#O)", &buf, &len, &addro) ||
+	    !getsockaddrarg(s, addro, &addr, &addrlen))
 		return NULL;
-	len = getstringsize(buf);
-	n = sendto(s->sock_fd, getstringvalue(buf), len, 0,
-		   addr, addrlen);
+	BGN_SAVE
+	n = sendto(s->sock_fd, buf, len, 0, addr, addrlen);
+	END_SAVE
 	if (n < 0)
 		return socket_error();
 	INCREF(None);
@@ -672,9 +696,13 @@
 	object *args;
 {
 	int how;
+	int res;
 	if (!getintarg(args, &how))
 		return NULL;
-	if (shutdown(s->sock_fd, how) < 0)
+	BGN_SAVE
+	res = shutdown(s->sock_fd, how);
+	END_SAVE
+	if (res < 0)
 		return socket_error();
 	INCREF(None);
 	return None;
@@ -758,13 +786,19 @@
 	object *args;
 {
 	char buf[1024];
+	int res;
 	if (!getnoarg(args))
 		return NULL;
-	if (gethostname(buf, (int) sizeof buf - 1) < 0)
+	BGN_SAVE
+	res = gethostname(buf, (int) sizeof buf - 1);
+	END_SAVE
+	if (res < 0)
 		return socket_error();
 	buf[sizeof buf - 1] = '\0';
 	return newstringobject(buf);
 }
+
+
 /* Python interface to gethostbyname(name). */
 
 /*ARGSUSED*/
@@ -775,9 +809,9 @@
 {
 	object *name;
 	struct sockaddr_in addrbuf;
-	if (!getStrarg(args, &name))
+	if (!getargs(args, "s", &name))
 		return NULL;
-	if (setipaddr(getstringvalue(name), &addrbuf) < 0)
+	if (setipaddr(name, &addrbuf) < 0)
 		return NULL;
 	return makeipaddr(&addrbuf);
 }
@@ -793,11 +827,13 @@
 	object *self;
 	object *args;
 {
-	object *name, *proto;
+	char *name, *proto;
 	struct servent *sp;
-	if (!getStrStrarg(args, &name, &proto))
+	if (!getargs(args, "(ss)", &name, &proto))
 		return NULL;
-	sp = getservbyname(getstringvalue(name), getstringvalue(proto));
+	BGN_SAVE
+	sp = getservbyname(name, proto);
+	END_SAVE
 	if (sp == NULL) {
 		err_setstr(SocketError, "service/proto not found");
 		return NULL;
@@ -827,7 +863,9 @@
 			return NULL;
 		proto = 0;
 	}
+	BGN_SAVE
 	fd = socket(family, type, proto);
+	END_SAVE
 	if (fd < 0)
 		return socket_error();
 	s = newsockobject(fd, family, type, proto);
diff --git a/Modules/stdwinmodule.c b/Modules/stdwinmodule.c
index 537777e..e33610d 100644
--- a/Modules/stdwinmodule.c
+++ b/Modules/stdwinmodule.c
@@ -63,11 +63,29 @@
 */
 
 #include "allobjects.h"
-
 #include "modsupport.h"
+#include "ceval.h"
 
 #include "stdwin.h"
 
+#ifdef USE_THREAD
+
+#include "thread.h"
+
+static type_lock StdwinLock; /* Lock held when interpreter not locked */
+
+#define BGN_STDWIN BGN_SAVE acquire_lock(StdwinLock, 1);
+#define RET_STDWIN release_lock(StdwinLock); RET_SAVE
+#define END_STDWIN release_lock(StdwinLock); END_SAVE
+
+#else
+
+#define BGN_STDWIN BGN_SAVE
+#define RET_STDWIN RET_SAVE
+#define END_STDWIN END_SAVE
+
+#endif
+
 static object *StdwinError; /* Exception stdwin.error */
 
 /* Window and menu object types declared here because of forward references */
@@ -1727,14 +1745,17 @@
 		return NULL;
 	}
  again:
+	BGN_STDWIN
 	if (poll) {
 		if (!wpollevent(&e)) {
+			RET_STDWIN
 			INCREF(None);
 			return None;
 		}
 	}
 	else
 		wgetevent(&e);
+	END_STDWIN
 	if (e.type == WE_COMMAND && e.u.command == WC_CANCEL) {
 		/* Turn keyboard interrupts into exceptions */
 		err_set(KeyboardInterrupt);
@@ -1919,7 +1940,9 @@
 		return NULL;
 	strncpy(buf, dflt, sizeof buf);
 	buf[sizeof buf - 1] = '\0';
+	BGN_STDWIN
 	ret = waskfile(prompt, buf, sizeof buf, new);
+	END_STDWIN
 	if (!ret) {
 		err_set(KeyboardInterrupt);
 		return NULL;
@@ -1936,7 +1959,9 @@
 	int new, ret;
 	if (!getstrintarg(args, &prompt, &new))
 		return NULL;
+	BGN_STDWIN
 	ret = waskync(prompt, new);
+	END_STDWIN
 	if (ret < 0) {
 		err_set(KeyboardInterrupt);
 		return NULL;
@@ -1956,7 +1981,9 @@
 		return NULL;
 	strncpy(buf, dflt, sizeof buf);
 	buf[sizeof buf - 1] = '\0';
+	BGN_STDWIN
 	ret = waskstr(prompt, buf, sizeof buf);
+	END_STDWIN
 	if (!ret) {
 		err_set(KeyboardInterrupt);
 		return NULL;
@@ -1972,7 +1999,9 @@
 	char *msg;
 	if (!getstrarg(args, &msg))
 		return NULL;
+	BGN_STDWIN
 	wmessage(msg);
+	END_STDWIN
 	INCREF(None);
 	return None;
 }
@@ -2185,4 +2214,9 @@
 	StdwinError = newstringobject("stdwin.error");
 	if (StdwinError == NULL || dictinsert(d, "error", StdwinError) != 0)
 		fatal("can't define stdwin.error");
+#ifdef USE_THREAD
+	StdwinLock = allocate_lock();
+	if (StdwinLock == NULL)
+		fatal("can't allocate stdwin lock");
+#endif
 }
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c
index c4de295..6ab7ea8 100644
--- a/Modules/threadmodule.c
+++ b/Modules/threadmodule.c
@@ -27,15 +27,10 @@
 
 #include "allobjects.h"
 #include "modsupport.h"
-#include "compile.h"
 #include "ceval.h"
 
 #include "thread.h"
 
-extern void init_save_thread PROTO((void));
-extern void* save_thread PROTO((void));
-extern void restore_thread PROTO((void *));
-
 object *ThreadError;
 
 
@@ -83,7 +78,6 @@
 	lockobject *self;
 	object *args;
 {
-	void *save;
 	int i;
 
 	if (args != NULL) {
@@ -93,11 +87,9 @@
 	else
 		i = 1;
 
-	save = save_thread();
-
+	BGN_SAVE
 	i = acquire_lock(self->lock_lock, i);
-
-	restore_thread(save);
+	END_SAVE
 
 	if (args == NULL) {
 		INCREF(None);
@@ -193,8 +185,6 @@
 	if (res == NULL) {
 		fprintf(stderr, "Unhandled exception in thread:\n");
 		print_error(); /* From pythonmain.c */
-		fprintf(stderr, "Exiting the entire program\n");
-		goaway(1);
 	}
 	(void) save_thread();
 	exit_thread();
@@ -251,7 +241,7 @@
 {
 	if (!getnoarg(args))
 		return NULL;
-	return newlockobject();
+	return (object *) newlockobject();
 }
 
 static struct methodlist thread_methods[] = {
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 5a278a9bd..4d13611 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -25,8 +25,8 @@
 /* Time module */
 
 #include "allobjects.h"
-
 #include "modsupport.h"
+#include "ceval.h"
 
 #include "sigtype.h"
 
@@ -104,14 +104,13 @@
 	object *self;
 	object *args;
 {
-	void *save, *save_thread(), restore_thread();
-	int secs;
+	long secs;
 	SIGTYPE (*sigsave)() = 0; /* Initialized to shut lint up */
-	if (!getintarg(args, &secs))
+	if (!getargs(args, "l", &secs))
 		return NULL;
-	save = save_thread();
+	BGN_SAVE
 	if (setjmp(sleep_intr)) {
-		restore_thread(save);
+		RET_SAVE
 		signal(SIGINT, sigsave);
 		err_set(KeyboardInterrupt);
 		return NULL;
@@ -119,8 +118,12 @@
 	sigsave = signal(SIGINT, SIG_IGN);
 	if (sigsave != (SIGTYPE (*)()) SIG_IGN)
 		signal(SIGINT, sleep_catcher);
-	sleep(secs);
-	restore_thread(save);
+#ifdef BSD_TIME
+	longsleep(secs);
+#else
+	sleep((int)secs);
+#endif
+	END_SAVE
 	signal(SIGINT, sigsave);
 	INCREF(None);
 	return None;
@@ -151,14 +154,13 @@
 	object *self;
 	object *args;
 {
-	void *save, *save_thread(), restore_thread();
 	long msecs;
 	SIGTYPE (*sigsave)();
 	if (!getlongarg(args, &msecs))
 		return NULL;
-	save = save_thread();
+	BGN_SAVE
 	if (setjmp(sleep_intr)) {
-		restore_thread(save);
+		RET_SAVE
 		signal(SIGINT, sigsave);
 		err_set(KeyboardInterrupt);
 		return NULL;
@@ -167,7 +169,7 @@
 	if (sigsave != (SIGTYPE (*)()) SIG_IGN)
 		signal(SIGINT, sleep_catcher);
 	millisleep(msecs);
-	restore_thread(save);
+	END_SAVE
 	signal(SIGINT, sigsave);
 	INCREF(None);
 	return None;
@@ -249,12 +251,12 @@
 #define MacTicks	(* (long *)0x16A)
 
 #ifdef THINK_C_3_0
-sleep(msecs)
-	int msecs;
+sleep(secs)
+	int secs;
 {
 	register long deadline;
 	
-	deadline = MacTicks + msecs * 60;
+	deadline = MacTicks + mecs * 60;
 	while (MacTicks < deadline) {
 		if (intrcheck())
 			sleep_catcher(SIGINT);
@@ -295,7 +297,6 @@
 	if (gettimeofday(&t, &tz) != 0)
 		return -1;
 	return t.tv_sec*1000 + t.tv_usec/1000;
-	
 }
 
 millisleep(msecs)
@@ -307,6 +308,15 @@
 	(void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
 }
 
+longsleep(secs)
+	long secs;
+{
+	struct timeval t;
+	t.tv_sec = secs;
+	t.tv_usec = 0;
+	(void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
+}
+
 #endif /* BSD_TIME */