Hi all,

I had a look at chicken.h and I think we can get rid of some of the
complex nested #ifdef stuff by removing deprecated cruft and moving
some other stuff to platform-specific makefiles instead of trying
to rely on magic #ifdef stuff.

Attached is a series of patches that perform specific cleanup actions.

I have another proposal but that would be a bit more sweeping, so let's
get the small cruft out of the way first :)

Cheers,
Peter
From c0f60b582f70f339c8f342a71efaa323a8039d3b Mon Sep 17 00:00:00 2001
From: Peter Bex <pe...@more-magic.net>
Date: Sun, 29 Jan 2017 17:02:34 +0100
Subject: [PATCH 1/5] Move statement expression detection to existing
 language-specific block

---
 chicken.h | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/chicken.h b/chicken.h
index f3f16eb..fb3c6cd 100644
--- a/chicken.h
+++ b/chicken.h
@@ -219,16 +219,12 @@ void *alloca ();
 # endif
 #endif
 
-/* Language specifics: */
-#if defined(__GNUC__) || defined(__INTEL_COMPILER)
-#define HAVE_STATEMENT_EXPRESSIONS 1
-#endif
-
 #if !defined(__clang__) && !defined(__has_attribute)
 /* Define so it won't error on other compilers with keywords like "noreturn" */
 #define __has_attribute(x)        0
 #endif
 
+/* Language specifics: */
 #if defined(__GNUC__) || defined(__INTEL_COMPILER)
 # define C_unlikely(x)             __builtin_expect((x), 0)
 # define C_likely(x)               __builtin_expect((x), 1)
@@ -242,6 +238,10 @@ void *alloca ();
 #  endif
 #  define C_noret_decl(name)
 #  define C_aligned               __attribute__ ((aligned))
+/* Clang and G++ support statement expressions, but only in a limited way */
+#  if !defined(__clang__)
+#   define HAVE_STATEMENT_EXPRESSIONS 1
+#  endif
 # endif
 # if defined(__i386__) && !defined(__clang__)
 #  define C_regparm               __attribute__ ((regparm(3)))
@@ -878,8 +878,7 @@ typedef void (C_ccall *C_proc)(C_word, C_word *) C_noret;
 # define C_UWORD_MAX               UINT_MAX
 #endif
 
-/* Clang and G++ support statement expressions, but only in a limited way */
-#if DEBUGBUILD && HAVE_STATEMENT_EXPRESSIONS && !defined(__clang__) && !defined(__cplusplus)
+#if DEBUGBUILD && HAVE_STATEMENT_EXPRESSIONS
 /* These are wrappers around the following idiom:
  *    assert(SOME_PRED(obj));
  *    do_something_with(obj);
-- 
2.1.4

From 386a8a72054585e6d333748530ceeae2c81a60dd Mon Sep 17 00:00:00 2001
From: Peter Bex <pe...@more-magic.net>
Date: Sun, 29 Jan 2017 17:37:53 +0100
Subject: [PATCH 2/5] Remove unused C_c_regparm definition & fix typo

---
 chicken.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/chicken.h b/chicken.h
index fb3c6cd..f64c43e 100644
--- a/chicken.h
+++ b/chicken.h
@@ -274,15 +274,13 @@ void *alloca ();
 # define C_aligned
 #endif
 
-#define C_c_regparm
-
 #if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__cplusplus)
 # define C_inline                  inline static
 #else
 # define C_inline                  static
 #endif
 
-/* Thread Local Stoarage */
+/* Thread Local Storage */
 #ifdef C_ENABLE_TLS
 # if defined(__GNUC__)
 #  define C_TLS                    __thread
-- 
2.1.4

From 525e6f78a6330787af679093f6ea2e515af389e2 Mon Sep 17 00:00:00 2001
From: Peter Bex <pe...@more-magic.net>
Date: Sun, 29 Jan 2017 17:38:28 +0100
Subject: [PATCH 3/5] Simplify C_STACK_GROWS_DOWNWARD detection

Instead of first defining it to -1 if it's undefined and then checking
whether it has been defined as -1, we simply check if it's undefined.

There seems to be no good reason for the current behaviour.
---
 chicken.h | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/chicken.h b/chicken.h
index f64c43e..fa3c94b 100644
--- a/chicken.h
+++ b/chicken.h
@@ -293,12 +293,7 @@ void *alloca ();
 
 
 /* Stack growth direction; used to compute stack addresses */
-
 #ifndef C_STACK_GROWS_DOWNWARD
-# define C_STACK_GROWS_DOWNWARD    -1
-#endif
-
-#if C_STACK_GROWS_DOWNWARD == -1
 # ifdef __hppa__
 #  undef C_STACK_GROWS_DOWNWARD
 #  define C_STACK_GROWS_DOWNWARD 0
-- 
2.1.4

From 6fa039758a6487a312df327e338927571796218a Mon Sep 17 00:00:00 2001
From: Peter Bex <pe...@more-magic.net>
Date: Sun, 29 Jan 2017 17:40:15 +0100
Subject: [PATCH 4/5] Remove unused C_GENERIC_CONSOLE definition

---
 chicken.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/chicken.h b/chicken.h
index fa3c94b..da22b9e 100644
--- a/chicken.h
+++ b/chicken.h
@@ -312,8 +312,6 @@ void *alloca ();
 #   define WINAPI
 #  endif
 # endif
-#else
-# define C_GENERIC_CONSOLE
 #endif
 
 /**
-- 
2.1.4

From f4b8e76e64a8f0875170898c78de6d9c59afe3ae Mon Sep 17 00:00:00 2001
From: Peter Bex <pe...@more-magic.net>
Date: Sun, 29 Jan 2017 19:12:51 +0100
Subject: [PATCH 5/5] Move SEARCH_EXE_PATH macro magic to platform Makefiles

The macro #ifdef.. etc stuff got way too complex for no good reason.
Get rid of the detection logic and place #define SEARCH_EXE_PATH 1 in
the platform-specific Makefiles for platforms that don't have any more
specific search logic in C_resolve_executable_pathname().
---
 Makefile.aix     |  1 +
 Makefile.android |  1 +
 Makefile.bsd     |  1 +
 Makefile.cygwin  |  1 +
 Makefile.hurd    |  1 +
 Makefile.ios     |  2 ++
 chicken.h        | 26 ++++++++++----------------
 runtime.c        |  2 ++
 8 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/Makefile.aix b/Makefile.aix
index 2b0c521..3e66dda 100644
--- a/Makefile.aix
+++ b/Makefile.aix
@@ -93,6 +93,7 @@ chicken-config.h: chicken-defaults.h
 	echo "#define HAVE_ALLOCA_H 1" >>$@
 	echo "#define HAVE_ERRNO_H 1" >>$@
 	echo "#define HAVE_SYSEXITS_H 1" >>$@
+	echo "#define SEARCH_EXE_PATH 1" >>$@
 	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
 ifdef GCHOOKS
 	echo "#define C_GC_HOOKS" >>$@
diff --git a/Makefile.android b/Makefile.android
index c292a39..2f9c029 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -87,6 +87,7 @@ chicken-config.h: chicken-defaults.h
 	echo "#define HAVE_ALLOCA_H 1" >>$@
 	echo "#define HAVE_ERRNO_H 1" >>$@
 	echo "#define HAVE_MEMMOVE 1" >>$@
+	echo "#define SEARCH_EXE_PATH 1" >>$@
 	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
 ifdef GCHOOKS
 	echo "#define C_GC_HOOKS" >>$@
diff --git a/Makefile.bsd b/Makefile.bsd
index 6dd40f2..cb06944 100644
--- a/Makefile.bsd
+++ b/Makefile.bsd
@@ -93,6 +93,7 @@ chicken-config.h: chicken-defaults.h
 	echo "#define HAVE_ALLOCA 1" >>$@
 	echo "#define HAVE_ERRNO_H 1" >>$@
 	echo "#define HAVE_SYSEXITS_H 1" >>$@
+	echo "#define SEARCH_EXE_PATH 1" >>$@
 	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
 ifdef GCHOOKS
 	echo "#define C_GC_HOOKS" >>$@
diff --git a/Makefile.cygwin b/Makefile.cygwin
index 9867f8e..906fa1a 100644
--- a/Makefile.cygwin
+++ b/Makefile.cygwin
@@ -107,6 +107,7 @@ chicken-config.h: chicken-defaults.h
 	echo "#define HAVE_ERRNO_H 1" >>$@
 	echo "#define HAVE_SYSEXITS_H 1" >>$@
 	echo "#define HAVE_DLFCN_H 1" >>$@
+	echo "#define SEARCH_EXE_PATH 1" >>$@
 	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
 ifdef GCHOOKS
 	echo "#define C_GC_HOOKS" >>$@
diff --git a/Makefile.hurd b/Makefile.hurd
index bd95529..83402f5 100644
--- a/Makefile.hurd
+++ b/Makefile.hurd
@@ -88,6 +88,7 @@ chicken-config.h: chicken-defaults.h
 	echo "#define HAVE_ERRNO_H 1" >>$@
 	echo "#define HAVE_SYSEXITS_H 1" >>$@
 	echo "#define HAVE_MEMMOVE 1" >>$@
+	echo "#define SEARCH_EXE_PATH 1" >>$@
 	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
 ifdef GCHOOKS
 	echo "#define C_GC_HOOKS" >>$@
diff --git a/Makefile.ios b/Makefile.ios
index fb35ac3..64982ff 100644
--- a/Makefile.ios
+++ b/Makefile.ios
@@ -91,6 +91,8 @@ chicken-config.h: chicken-defaults.h
 	echo "#define HAVE_ALLOCA_H 1" >>$@
 	echo "#define HAVE_ERRNO_H 1" >>$@
 	echo "#define HAVE_SYSEXITS_H 1" >>$@
+# TODO: Use MacOS exe path mechanism?
+	echo "#define SEARCH_EXE_PATH 1" >>$@
 	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
 ifdef GCHOOKS
 	echo "#define C_GC_HOOKS" >>$@
diff --git a/chicken.h b/chicken.h
index da22b9e..1b18eda 100644
--- a/chicken.h
+++ b/chicken.h
@@ -314,22 +314,6 @@ void *alloca ();
 # endif
 #endif
 
-/**
- * HAVE_EXE_PATH is defined on platforms on which there's a simple way
- * to retrieve a path to the current executable (such as reading
- * "/proc/<pid>/exe" or some similar trick).
- *
- * SEARCH_EXE_PATH is defined on platforms on which we must search for
- * the current executable. Because this search is sensitive to things
- * like CWD, PATH, and so on, it's done once at startup and saved in
- * `C_main_exe`.
- */
-#if defined(__linux__) || defined(__sun) || defined(C_MACOSX) || defined(__HAIKU__) || (defined(_WIN32) && !defined(__CYGWIN__))
-# define HAVE_EXE_PATH
-#elif defined(__unix__) || defined(C_XXXBSD) || defined(_AIX)
-# define SEARCH_EXE_PATH
-#endif
-
 /* Needed for pre-emptive threading */
 
 #define C_TIMER_INTERRUPTS
@@ -1633,6 +1617,16 @@ typedef void (C_ccall *C_proc)(C_word, C_word *) C_noret;
 # define C_set_gui_mode
 #endif
 
+/**
+ * SEARCH_EXE_PATH is defined on platforms on which we must search for
+ * the current executable. Because this search is sensitive to things
+ * like CWD, PATH, and so on, it's done once at startup and saved in
+ * `C_main_exe`.
+ *
+ * On platforms where it's not defined, there's a simple way to
+ * retrieve a path to the current executable (such as reading
+ * "/proc/<pid>/exe" or some similar trick).
+ */
 #ifdef SEARCH_EXE_PATH
 # define C_set_main_exe(fname)          C_main_exe = C_resolve_executable_pathname(fname)
 #else
diff --git a/runtime.c b/runtime.c
index 5e0cc10..9ccce65 100644
--- a/runtime.c
+++ b/runtime.c
@@ -12903,6 +12903,8 @@ C_resolve_executable_pathname(C_char *fname)
 
   /* seek next entry, skip colon */
   } while (path += len, *path++);
+#else
+# error "Please either define SEARCH_EXE_PATH in Makefile.<platform> or implement C_resolve_executable_pathname for your platform!"
 #endif
 
 error:
-- 
2.1.4

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to