[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/5] Improve portability (particularly for Woe32)
From: |
Georgiy Tugai |
Subject: |
[PATCH 2/5] Improve portability (particularly for Woe32) |
Date: |
Thu, 25 Mar 2021 20:14:08 +0000 |
Test for siglongjmp, fcntl, GC_remove_roots; fallback to no-op.
2021-03-25 Georgiy Tugai <georgiy@crossings.link>
* bootstrap.conf: Add Gnulib modules arpa_inet, getsockname,
listen, netdb, netinet_in, regex, sigaction, signal-h, sys_select,
stpcpy
* configure.ac: Add checks for siglongjmp, GC_remove_roots and a
warning message for the latter
* libpoke/pvm-alloc.c: Skip GC_remove_roots calls if not available
* poke/pk-hserver.c: Include <sys/select.h>
* poke/pk-mi.c: Include <sys/select.h>
Skip fcntl calls if not available
* poke/pk-repl.c: Skip siglongjmp/sigsetjmp calls and sigjmp_buf
declaration if they are not available
---
ChangeLog | 14 ++++++++++++++
bootstrap.conf | 10 ++++++++++
configure.ac | 13 +++++++++++++
libpoke/pvm-alloc.c | 2 ++
poke/pk-hserver.c | 1 +
poke/pk-mi.c | 7 +++++++
poke/pk-repl.c | 6 ++++++
7 files changed, 53 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 626b8d0a..604ca010 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2021-03-25 Georgiy Tugai <georgiy@crossings.link>
+
+ * bootstrap.conf: Add Gnulib modules arpa_inet, getsockname,
+ listen, netdb, netinet_in, regex, sigaction, signal-h, sys_select,
+ stpcpy
+ * configure.ac: Add checks for siglongjmp, GC_remove_roots and a
+ warning message for the latter
+ * libpoke/pvm-alloc.c: Skip GC_remove_roots calls if not available
+ * poke/pk-hserver.c: Include <sys/select.h>
+ * poke/pk-mi.c: Include <sys/select.h>
+ Skip fcntl calls if not available
+ * poke/pk-repl.c: Skip siglongjmp/sigsetjmp calls and sigjmp_buf
+ declaration if they are not available
+
2021-03-25 Georgiy Tugai <georgiy@crossings.link>
* etc/poke.g4: Rename CHAR to CHARACTER
diff --git a/bootstrap.conf b/bootstrap.conf
index 3d217f46..43d24631 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -21,6 +21,7 @@
# gnulib modules used for this project.
gnulib_modules="
accept
+ arpa_inet
array-list
basename-lgpl
bind
@@ -31,23 +32,31 @@ gnulib_modules="
gethostname
getline
getopt-gnu
+ getsockname
glob
host-cpu-c-abi
isatty
libtextstyle-optional
+ listen
maintainer-makefile
mkstemp
+ netdb
+ netinet_in
parse-datetime
pmccabe2html
printf-posix
progname
pthread
readline
+ regex
+ sigaction
+ signal-h
socket
stdarg
stdbool
strchrnul
streq
+ sys_select
tmpdir
unlink
update-copyright
@@ -82,6 +91,7 @@ libpoke_modules="
stdarg
stdbool
stddef
+ stpcpy
strchrnul
streq
string-buffer
diff --git a/configure.ac b/configure.ac
index e40b3a4e..7ca26abb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,11 +98,20 @@ dnl emitted in case no proper AWK is present.
AX_CHECK_AWK_GENSUB([RAS_AWK=$AWK], [RAS_AWK=:])
AC_SUBST([RAS_AWK])
+dnl REPL
+
+AC_CHECK_FUNCS([siglongjmp], break)
+
dnl The Boehm-Weiser garbage collector
PKG_PROG_PKG_CONFIG
PKG_CHECK_MODULES(BDW_GC,[bdw-gc],[have_gc=yes],[have_gc=no])
+LIBS_BK="$LIBS"
+LIBS="$LIBS $BDW_GC_LIBS"
+AC_CHECK_FUNCS([GC_remove_roots],[HAVE_GC_REMOVE_ROOTS=yes])
+LIBS="$LIBS_BK"
+
dnl The JSON-C library for the machine-interface
AC_ARG_ENABLE([mi],
@@ -299,6 +308,10 @@ if test "x$have_gc" = "xno"; then
AC_MSG_ERROR([can't find the Boehm GC library. Please install it.])
fi
+if test "x$HAVE_GC_REMOVE_ROOTS" = "x"; then
+ AC_MSG_WARN([Boehm GC does not implement GC_remove_roots on your platform;
poke may leak roots, and thus memory.])
+fi
+
if test "x$gl_cv_lib_readline" = "xno"; then
AC_MSG_ERROR([can't find an usable libreadline. Please install one.])
fi
diff --git a/libpoke/pvm-alloc.c b/libpoke/pvm-alloc.c
index ab7bc9d3..5d121c6d 100644
--- a/libpoke/pvm-alloc.c
+++ b/libpoke/pvm-alloc.c
@@ -83,6 +83,8 @@ pvm_alloc_add_gc_roots (void *pointer, size_t nelems)
void
pvm_alloc_remove_gc_roots (void *pointer, size_t nelems)
{
+#if defined HAVE_GC_REMOVE_ROOTS
GC_remove_roots (pointer,
((char*) pointer) + sizeof (void*) * nelems);
+#endif
}
diff --git a/poke/pk-hserver.c b/poke/pk-hserver.c
index 873020f1..c1fca81f 100644
--- a/poke/pk-hserver.c
+++ b/poke/pk-hserver.c
@@ -27,6 +27,7 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
diff --git a/poke/pk-mi.c b/poke/pk-mi.c
index 64670f5c..81188d97 100644
--- a/poke/pk-mi.c
+++ b/poke/pk-mi.c
@@ -26,6 +26,7 @@
#include <assert.h>
#include <fcntl.h>
#include <errno.h>
+#include <sys/select.h>
#include "poke.h"
@@ -167,6 +168,7 @@ pk_mi_send_frame_msg (const char *payload)
/* Set fd to non-blocking and return old flags or -1 on error. */
static int pk_mi_fd_set_nonblocking (int fd)
{
+#if defined HAVE_FCNTL
int flags = fcntl (fd, F_GETFL, 0);
if (flags >= 0 && (flags & O_NONBLOCK) == 0)
@@ -179,16 +181,21 @@ static int pk_mi_fd_set_nonblocking (int fd)
perror ("fcntl");
return flags;
+#else
+ return 0;
+#endif
}
/* Restore flags to fd if it was set to blocking previously. */
static void pk_mi_fd_restore_blocking (int fd, int flags)
{
+#if defined HAVE_FCNTL
if (flags >= 0 && (flags & O_NONBLOCK) == 0)
{
if (fcntl (fd, F_SETFL, flags) < 0)
perror ("fcntl");
}
+#endif
}
/* This global is used to finalize the MI loop. */
diff --git a/poke/pk-repl.c b/poke/pk-repl.c
index f01b22f3..e1062c56 100644
--- a/poke/pk-repl.c
+++ b/poke/pk-repl.c
@@ -41,8 +41,10 @@
/* The thread that contains the non-local entry point for reentering
the REPL. */
static pthread_t volatile ctrlc_thread;
+#if HAVE_SIGLONGJMP
/* The non-local entry point for reentering the REPL. */
static sigjmp_buf /*volatile*/ ctrlc_buf;
+#endif
/* When nonzero, ctrlc_thread and ctrlc_buf contain valid values. */
static int volatile ctrlc_buf_valid;
@@ -237,7 +239,9 @@ poke_sigint_handler (int sig)
rl_cleanup_after_signal ();
rl_line_buffer[rl_point = rl_end = rl_mark = 0] = 0;
printf ("\n");
+#if HAVE_SIGLONGJMP
siglongjmp (ctrlc_buf, 1);
+#endif
}
}
else
@@ -348,7 +352,9 @@ pk_repl (void)
rl_filename_quoting_function = escape_metacharacters;
ctrlc_thread = pthread_self ();
+#if HAVE_SIGLONGJMP
sigsetjmp (ctrlc_buf, 1);
+#endif
ctrlc_buf_valid = 1;
while (!poke_exit_p)
--
2.26.2
- [PATCH 1/5] Rename CHAR, IN, VOID, ERROR to avoid collision, Georgiy Tugai, 2021/03/25
- [PATCH 2/5] Improve portability (particularly for Woe32),
Georgiy Tugai <=
- [PATCH 4/5] Disable the GC at exit if GC_remove_roots absent, Georgiy Tugai, 2021/03/25
- [PATCH 3/5] Allow Poke to be built relocatable, Georgiy Tugai, 2021/03/25
[PATCH 5/5] First version of REPL Ctrl-C trampoline for Woe32, Georgiy Tugai, 2021/03/25