[m-rev.] for review: Delete unnecessary test for sa_sigaction field.
Peter Wang
novalazy at gmail.com
Tue Oct 13 13:33:23 AEDT 2020
configure.ac:
Delete check for sa_sigaction field. If a call to sigaction()
has the SA_SIGINFO flag set then the handler must be specified in
the sa_sigaction field, not the sa_handler field.
runtime/mercury_conf.h.in:
Delete MR_SIGACTION_FIELD macro.
runtime/mercury_signal.c:
Don't use MR_SIGACTION_FIELD macro.
Don't define dummy value for SA_SIGINFO.
tools/configure_mingw_cross:
Don't set now-unused variable.
---
configure.ac | 70 ++++++-------------------------------
runtime/mercury_conf.h.in | 6 ----
runtime/mercury_signal.c | 20 ++++++-----
tools/configure_mingw_cross | 1 -
4 files changed, 22 insertions(+), 75 deletions(-)
diff --git a/configure.ac b/configure.ac
index f84d87158..78567aac9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# vim: ts=4 sw=4 expandtab
#-----------------------------------------------------------------------------#
# Copyright (C) 1995-2012 The University of Melbourne.
-# Copyright (C) 2013-2018 The Mercury team.
+# Copyright (C) 2013-2020 The Mercury team.
# This file may only be copied under the terms of the GNU General
# Public Licence - see the file COPYING in the Mercury distribution.
#-----------------------------------------------------------------------------#
@@ -1529,63 +1529,12 @@ AC_SUBST(HAVE_GETOPT)
#-----------------------------------------------------------------------------#
#
-# Check the basics of sigaction
+# Check the basics of SA_SIGINFO and siginfo_t
#
if test "$ac_cv_func_sigaction" = yes; then
- AC_MSG_CHECKING(for \`sigaction' field name)
- AC_CACHE_VAL(mercury_cv_sigaction_field,
- AC_TRY_RUN(
- [
- #include <signal.h>
- #include <stdlib.h>
-
- #define FAULT_ADDRESS ((int *)112)
-
- extern void handler(int signum, siginfo_t *info, void *context);
-
- int main() {
- struct sigaction act;
- act.sa_flags = SA_SIGINFO;
- act.sa_sigaction = handler;
- if (sigemptyset(&act.sa_mask) != 0)
- exit(1);
- if (sigaction(SIGSEGV, &act, NULL) != 0)
- exit(1);
- /* provoke a SIGSEGV */
- (*FAULT_ADDRESS)++;
- exit(1);
- }
-
- void handler(int signum, siginfo_t *info, void *context) {
- if (signum == SIGSEGV &&
- info->si_signo == SIGSEGV &&
- info->si_code > 0 &&
- (int *)info->si_addr == FAULT_ADDRESS)
- {
- exit(0);
- } else {
- exit(1);
- }
- }
- ],
- [mercury_cv_sigaction_field=sa_sigaction],
- [mercury_cv_sigaction_field=sa_handler]))
- AC_MSG_RESULT($mercury_cv_sigaction_field)
- AC_DEFINE_UNQUOTED(MR_SIGACTION_FIELD,$mercury_cv_sigaction_field)
- if test "$mercury_cv_sigaction_field" = sa_sigaction; then
- AC_DEFINE([MR_HAVE_SIGINFO])
- fi
-fi
-
-#-----------------------------------------------------------------------------#
-#
-# Check the basics of siginfo_t
-#
-
-AC_MSG_CHECKING(for \`siginfo_t')
+AC_MSG_CHECKING(for SA_SIGINFO and siginfo_t)
AC_CACHE_VAL(mercury_cv_siginfo_t,
-mercury_cv_siginfo_t=no
AC_TRY_RUN(
[
#include <stdio.h>
@@ -1609,7 +1558,7 @@ AC_TRY_RUN(
int main() {
struct sigaction act;
act.sa_flags = SA_SIGINFO;
- act.$mercury_cv_sigaction_field = handler;
+ act.sa_sigaction = handler;
if (sigemptyset(&act.sa_mask) != 0)
exit(1);
if (sigaction(SIGSEGV, &act, NULL) != 0)
@@ -1626,8 +1575,11 @@ AC_TRY_RUN(
}
],
[mercury_cv_siginfo_t=yes],
- [true]))
+ [mercury_cv_siginfo_t=no]))
AC_MSG_RESULT($mercury_cv_siginfo_t)
+else
+ mercury_cv_siginfo_t=no
+fi
if test "$mercury_cv_siginfo_t" = yes; then
AC_DEFINE(MR_HAVE_SIGINFO_T)
AC_DEFINE(MR_HAVE_SIGINFO)
@@ -1654,7 +1606,7 @@ if test "$mercury_cv_siginfo_t" = yes; then
int main() {
struct sigaction act;
act.sa_flags = SA_SIGINFO;
- act.$mercury_cv_sigaction_field = handler;
+ act.sa_sigaction = handler;
if (sigemptyset(&act.sa_mask) != 0)
exit(1);
if (sigaction(SIGSEGV, &act, NULL) != 0)
@@ -1695,7 +1647,7 @@ if test "$mercury_cv_siginfo_t" = yes; then
int main() {
struct sigaction act;
act.sa_flags = SA_SIGINFO;
- act.$mercury_cv_sigaction_field = handler;
+ act.sa_sigaction = handler;
if (sigemptyset(&act.sa_mask) != 0)
exit(1);
if (sigaction(SIGSEGV, &act, NULL) != 0)
@@ -1734,7 +1686,7 @@ if test "$mercury_cv_siginfo_t" = yes; then
int main() {
struct sigaction act;
act.sa_flags = SA_SIGINFO;
- act.$mercury_cv_sigaction_field = handler;
+ act.sa_sigaction = handler;
if (sigemptyset(&act.sa_mask) != 0)
exit(1);
if (sigaction(SIGSEGV, &act, NULL) != 0)
diff --git a/runtime/mercury_conf.h.in b/runtime/mercury_conf.h.in
index 7ee4dd1da..400c5e62a 100644
--- a/runtime/mercury_conf.h.in
+++ b/runtime/mercury_conf.h.in
@@ -410,12 +410,6 @@
#undef MR_PC_ACCESS
#undef MR_PC_ACCESS_GREG
-// MR_SIGACTION_FIELD: the name of the field in the sigaction struct
-// (either sa_handler or sa_sigaction). Defined only if MR_HAVE_SIGACTION
-// is defined.
-
-#undef MR_SIGACTION_FIELD
-
// Configuration parameters for multithreaded execution support.
//
// MR_THREAD_LOCAL_STORAGE is defined if the thread-local storage extension
diff --git a/runtime/mercury_signal.c b/runtime/mercury_signal.c
index 91266100c..f6d528ff0 100644
--- a/runtime/mercury_signal.c
+++ b/runtime/mercury_signal.c
@@ -39,18 +39,13 @@
////////////////////////////////////////////////////////////////////////////
-// If we don't have SA_RESTART or SA_SIGINFO, defined them as 0.
-// It would be nice to have them, but it is still better to use
-// sigaction without SA_RESTART or SA_SIGINFO than to use signal.
+// If we don't have SA_RESTART define it as 0. It is still better to use
+// sigaction without SA_RESTART than to use signal.
#if !defined(SA_RESTART)
#define SA_RESTART 0
#endif
-#if !defined(SA_SIGINFO)
- #define SA_SIGINFO 0
-#endif
-
static void MR_do_setup_signal(int sig, MR_Code *handler, MR_bool need_info,
MR_bool restart, const char *error_message);
@@ -109,7 +104,16 @@ MR_init_signal_action(MR_signal_action *act, MR_Code *handler,
if (need_info) {
#ifdef MR_HAVE_SIGINFO_T
act->sa_flags |= SA_SIGINFO;
+ act->sa_sigaction = handler;
+ #else
+ // This branch should be unreachable in practice.
+ // The caller must check that MR_HAVE_SIGINFO_T is defined
+ // before calling this function with need_info=TRUE,
+ // otherwise the handler will have the wrong type.
+ act->sa_handler = handler;
#endif
+ } else {
+ act->sa_handler = handler;
}
if (sigemptyset(&(act->sa_mask)) != 0) {
@@ -118,8 +122,6 @@ MR_init_signal_action(MR_signal_action *act, MR_Code *handler,
}
errno = 0;
- act->MR_SIGACTION_FIELD = handler;
-
#else // not MR_HAVE_SIGACTION
*act = handler;
diff --git a/tools/configure_mingw_cross b/tools/configure_mingw_cross
index eec14d05e..b3235e1d4 100755
--- a/tools/configure_mingw_cross
+++ b/tools/configure_mingw_cross
@@ -66,7 +66,6 @@ fi
# Taken from the config.cache file after running configure -C in msys.
mercury_cv_cc_type=gcc \
-mercury_cv_sigaction_field=no \
mercury_cv_siginfo_t=no \
mercury_cv_is_bigender=no \
mercury_cv_is_littleender=yes \
--
2.28.0
More information about the reviews
mailing list