~ chicken-core (chicken-5) 133dc1c7654eca1d92bde078996e085355551a0e
commit 133dc1c7654eca1d92bde078996e085355551a0e
Author: Peter Bex <peter.bex@xs4all.nl>
AuthorDate: Sun Nov 24 15:16:16 2013 +0100
Commit: Evan Hanson <evhan@foldling.org>
CommitDate: Mon Nov 25 18:58:44 2013 +1300
Simplify handling of header file inclusion:
- Remove headers from specific files if already included by chicken.h
- While we're at it, reorder headers in chicken.h so they're included in alphabetic order so it's easier to find a header in the list.
- unistd.h was unconditionally included in files.scm, so it's safe to include it unconditionally in chicken.h even if running under Windows
- sys/types.h was unconditionally included in posix-common.scm, so safe to use in chicken.h
- stdint.h is included by inttypes.h, so remove the conditional inclusion of stdint.h when not under SunOS.
- inttypes.h was already included by the above check, even on Windows, so it's safe to remove the conditional around that.
- Just to be on the safe side, include stddef.h; we use NULL and size_t, which are supposed to be defined by it
- On haiku, only include kernel/image.h when C_PRIVATE_REPOSITORY is defined, as it's needed only for the path_to_executable hack.
- Don't include signal.h twice in runtime.c
Signed-off-by: Evan Hanson <evhan@foldling.org>
diff --git a/chicken.h b/chicken.h
index 6265940d..c018f13c 100644
--- a/chicken.h
+++ b/chicken.h
@@ -96,26 +96,19 @@
/* Headers */
+#include <ctype.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <math.h>
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdarg.h>
-#include <ctype.h>
#include <string.h>
-#include <setjmp.h>
-#include <limits.h>
#include <time.h>
-#include <math.h>
-
-/* This check is exceedingly strange */
-#if !defined(C_NONUNIX) || defined(__MINGW32__) || defined(__WATCOMC__)
-# include <unistd.h>
-# include <inttypes.h>
-# include <sys/types.h>
-#endif
-
-#if defined(__HAIKU__)
-# include <kernel/image.h>
-#endif
+#include <unistd.h>
+#include <sys/types.h>
/* Byteorder in machine word */
@@ -536,13 +529,6 @@ static inline int isinf_ld (long double x)
#define C_uword unsigned C_word
#define C_header C_uword
-#if defined(__sun) && !defined(__SVR4)
-/* SunOS is supposed not to have stdint.h */
-# include <inttypes.h>
-#else
-# include <stdint.h>
-#endif
-
/* if all else fails, use these:
#define UINT64_MAX (18446744073709551615ULL)
#define INT64_MAX (9223372036854775807LL)
@@ -2908,7 +2894,10 @@ C_inline C_word C_a_i_record8(C_word **ptr, int n, C_word x1, C_word x2, C_word
#ifdef C_PRIVATE_REPOSITORY
# if defined(C_MACOSX) && defined(C_GUI)
# include <CoreFoundation/CoreFoundation.h>
+# elif defined(__HAIKU__)
+# include <kernel/image.h>
# endif
+
C_inline C_char *
C_path_to_executable(C_char *fname)
{
diff --git a/files.scm b/files.scm
index 8c8f1fa3..69829a06 100644
--- a/files.scm
+++ b/files.scm
@@ -41,7 +41,6 @@
(hide chop-pds absolute-pathname-root root-origin root-directory split-directory)
(disable-interrupts)
(foreign-declare #<<EOF
-#include <unistd.h>
#include <errno.h>
#ifndef _WIN32
diff --git a/library.scm b/library.scm
index 6756b323..2a926b68 100644
--- a/library.scm
+++ b/library.scm
@@ -40,18 +40,13 @@
##sys#default-read-info-hook ##sys#infix-list-hook ##sys#sharp-number-hook
##sys#user-print-hook ##sys#user-interrupt-hook ##sys#step-hook)
(foreign-declare #<<EOF
-#include <string.h>
-#include <ctype.h>
#include <errno.h>
-#include <time.h>
#include <float.h>
#ifdef HAVE_SYSEXITS_H
# include <sysexits.h>
#endif
-#include <unistd.h>
-
#ifndef EX_SOFTWARE
# define EX_SOFTWARE 70
#endif
diff --git a/lolevel.scm b/lolevel.scm
index 1adba1ea..4387141b 100644
--- a/lolevel.scm
+++ b/lolevel.scm
@@ -36,9 +36,6 @@
pv-buf-ref pv-buf-set!)
(not inline ipc-hook-0 ##sys#invalid-procedure-call-hook)
(foreign-declare #<<EOF
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
-# include <sys/types.h>
-#endif
#ifndef C_NONUNIX
# include <sys/mman.h>
#endif
diff --git a/posix-common.scm b/posix-common.scm
index 3ed0f30d..6c0ff7e4 100644
--- a/posix-common.scm
+++ b/posix-common.scm
@@ -30,9 +30,7 @@
#include <signal.h>
#include <errno.h>
-#include <math.h>
-#include <sys/types.h>
#include <sys/stat.h>
static int C_not_implemented(void);
diff --git a/posixunix.scm b/posixunix.scm
index 7f6d739e..8f678486 100644
--- a/posixunix.scm
+++ b/posixunix.scm
@@ -48,7 +48,6 @@
(foreign-declare #<<EOF
static C_TLS int C_wait_status;
-#include <unistd.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/utsname.h>
@@ -69,7 +68,6 @@ static C_TLS int C_wait_status;
#include <sys/mman.h>
#include <sys/poll.h>
-#include <time.h>
#ifndef O_FSYNC
# define O_FSYNC O_SYNC
diff --git a/posixwin.scm b/posixwin.scm
index c5091a50..b8ae2da0 100644
--- a/posixwin.scm
+++ b/posixwin.scm
@@ -83,12 +83,10 @@
#include <signal.h>
#include <errno.h>
#include <io.h>
-#include <stdio.h>
#include <process.h>
#include <fcntl.h>
#include <direct.h>
#include <utime.h>
-#include <time.h>
#define ARG_MAX 256
#define PIPE_BUF 512
diff --git a/profiler.scm b/profiler.scm
index d1b2b153..359be644 100644
--- a/profiler.scm
+++ b/profiler.scm
@@ -31,11 +31,6 @@
(unsafe)
(disable-interrupts))
-(foreign-declare #<<EOF
-#include <unistd.h>
-EOF
-)
-
(include "common-declarations.scm")
(define-foreign-variable profile-id int "C_getpid()")
diff --git a/runtime.c b/runtime.c
index bd676d16..555c76bb 100644
--- a/runtime.c
+++ b/runtime.c
@@ -27,13 +27,11 @@
#include "chicken.h"
-#include <errno.h>
-#include <signal.h>
#include <assert.h>
-#include <limits.h>
+#include <errno.h>
#include <float.h>
-#include <math.h>
#include <signal.h>
+#include <sys/stat.h>
#ifdef HAVE_SYSEXITS_H
# include <sysexits.h>
@@ -68,17 +66,12 @@
#if !defined(C_NONUNIX)
-# include <sys/types.h>
-# include <sys/stat.h>
# include <sys/time.h>
# include <sys/resource.h>
# include <sys/wait.h>
#else
-# include <sys/types.h>
-# include <sys/stat.h>
-
#ifdef ECOS
#include <cyg/kernel/kapi.h>
static C_TLS int timezone;
diff --git a/scheduler.scm b/scheduler.scm
index f337dcf6..12542da3 100644
--- a/scheduler.scm
+++ b/scheduler.scm
@@ -53,10 +53,7 @@
/* Beware: winsock2.h must come BEFORE windows.h */
# define C_msleep(n) (Sleep(C_unfix(n)), C_SCHEME_TRUE)
#else
-# include <unistd.h>
-# include <sys/types.h>
# include <sys/time.h>
-# include <time.h>
static C_word C_msleep(C_word ms);
C_word C_msleep(C_word ms) {
#ifdef __CYGWIN__
diff --git a/tcp.scm b/tcp.scm
index c3689ae9..bba60c42 100644
--- a/tcp.scm
+++ b/tcp.scm
@@ -57,11 +57,9 @@ static WSADATA wsa;
getsockopt(socket, level, optname, (char *)optval, optlen)
#else
# include <fcntl.h>
-# include <sys/types.h>
# include <sys/socket.h>
# include <sys/time.h>
# include <netinet/in.h>
-# include <unistd.h>
# include <netdb.h>
# include <signal.h>
# define closesocket close
Trap