This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Use template adapter to account for signal() prototype variations
- To: libstdc++ at gcc dot gnu dot org
- Subject: Use template adapter to account for signal() prototype variations
- From: Alexandre Oliva <aoliva at redhat dot com>
- Date: 22 Dec 2000 03:58:26 -0200
- Cc: gcc-patches at gcc dot gnu dot org
- Organization: GCC Team, Red Hat
On IRIX 5.2, the type of a signal handler is `void (*)(...)', so
compilation would fail. Ok to install?
Unfortunately, there still remains a execution error on IRIX 5.2: it
appears that each division by zero triggers *two* traps, the first of
which isn't caught by the SIGFPE handler. Within GDB, I get two
SIGFPEs, but execution of gen-num-limits results in:
Trace/BPT trap (core dumped)
when testing whether bool divide-by-zero traps. Can anybody explain
this, and suggest how to work around it?
Index: libstdc++-v3/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* src/gen-num-limits.cc (signal_adapter): New template function.
Index: libstdc++-v3/src/gen-num-limits.cc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/src/gen-num-limits.cc,v
retrieving revision 1.4
diff -u -p -r1.4 gen-num-limits.cc
--- libstdc++-v3/src/gen-num-limits.cc 2000/10/30 13:15:24 1.4
+++ libstdc++-v3/src/gen-num-limits.cc 2000/12/22 05:54:03
@@ -92,11 +92,23 @@ const int integer_base_rep = 2;
jmp_buf env;
+/* The prototype of signal() may vary. Accomodate variations such as
+ void(*)(int) and void(*)(...). */
+template <typename signal_handler_type, typename signal_number_type>
+inline void (*signal_adapter (signal_handler_type
+ (*signal_func)(signal_number_type,
+ signal_handler_type),
+ signal_number_type arg,
+ void (*handler)(int)))(int)
+{
+ return (void (*)(int))(*signal_func)(arg, (signal_handler_type)handler);
+}
+
void signal_handler(int sig)
{
#ifdef __CYGWIN__
static sigset_t x;
- signal (sig, signal_handler);
+ signal_adapter (signal, sig, signal_handler);
sigemptyset (&x);
sigprocmask(SIG_SETMASK, &x, NULL);
#endif /* __CYGWIN__ */
@@ -137,9 +149,9 @@ template<typename T> struct underflow {}
// traps
template<typename T> void traps()
{
- signal(SIGFPE, signal_handler);
+ signal_adapter (signal, SIGFPE, signal_handler);
bool trap_flag = trapping(division_by_zero<T>());
- signal(SIGFPE, signal_handler);
+ signal_adapter (signal, SIGFPE, signal_handler);
trap_flag = trap_flag && trapping(overflow<T>());
const char* p = bool_alpha[trap_flag];
printf("%s%s = %s;\n", tab2, "static const bool traps", p);
@@ -148,7 +160,7 @@ template<typename T> void traps()
#define SPECIALIZE_TRAPPING(T) \
template<> void traps< T >() \
{ \
- signal(SIGFPE, signal_handler); \
+ signal_adapter (signal, SIGFPE, signal_handler); \
const char* p = bool_alpha[trapping(division_by_zero<T>())]; \
printf("%s%s = %s;\n", tab2, "static const bool traps", p); \
}
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me