Commit 4a70b13a by Alexandre Oliva Committed by Alexandre Oliva

gen-num-limits.cc (signal_adapter): New template function.

* src/gen-num-limits.cc (signal_adapter): New template function.
(signal_handler): Use it, instead of signal.
(traps<T>): Likewise.  Install SIGTRAP handler too.  Don't
require both tests to trap to set trap_flag.

From-SVN: r38814
parent 9c8fad33
2001-01-09 Alexandre Oliva <aoliva@redhat.com>
* src/gen-num-limits.cc (signal_adapter): New template function.
(signal_handler): Use it, instead of signal.
(traps<T>): Likewise. Install SIGTRAP handler too. Don't
require both tests to trap to set trap_flag.
2001-01-08 Benjamin Kosnik <bkoz@redhat.com> 2001-01-08 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/fpos.h (fpos:::fpos(streamoff __pos)): Explicitly * include/bits/fpos.h (fpos:::fpos(streamoff __pos)): Explicitly
......
// Copyright (C) 1999, 2000 Free Software Foundation, Inc. // Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -92,11 +92,23 @@ const int integer_base_rep = 2; ...@@ -92,11 +92,23 @@ const int integer_base_rep = 2;
jmp_buf env; 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) void signal_handler(int sig)
{ {
#ifdef __CYGWIN__ #ifdef __CYGWIN__
static sigset_t x; static sigset_t x;
signal (sig, signal_handler); signal_adapter (signal, sig, signal_handler);
sigemptyset (&x); sigemptyset (&x);
sigprocmask(SIG_SETMASK, &x, NULL); sigprocmask(SIG_SETMASK, &x, NULL);
#endif /* __CYGWIN__ */ #endif /* __CYGWIN__ */
...@@ -137,10 +149,12 @@ template<typename T> struct underflow {}; ...@@ -137,10 +149,12 @@ template<typename T> struct underflow {};
// traps // traps
template<typename T> void traps() template<typename T> void traps()
{ {
signal(SIGFPE, signal_handler); signal_adapter (signal, SIGFPE, signal_handler);
signal_adapter (signal, SIGTRAP, signal_handler);
bool trap_flag = trapping(division_by_zero<T>()); 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>()); signal_adapter (signal, SIGTRAP, signal_handler);
trap_flag = trap_flag || trapping(overflow<T>());
const char* p = bool_alpha[trap_flag]; const char* p = bool_alpha[trap_flag];
printf("%s%s = %s;\n", tab2, "static const bool traps", p); printf("%s%s = %s;\n", tab2, "static const bool traps", p);
} }
...@@ -148,7 +162,8 @@ template<typename T> void traps() ...@@ -148,7 +162,8 @@ template<typename T> void traps()
#define SPECIALIZE_TRAPPING(T) \ #define SPECIALIZE_TRAPPING(T) \
template<> void traps< T >() \ template<> void traps< T >() \
{ \ { \
signal(SIGFPE, signal_handler); \ signal_adapter (signal, SIGFPE, signal_handler); \
signal_adapter (signal, SIGTRAP, signal_handler); \
const char* p = bool_alpha[trapping(division_by_zero<T>())]; \ const char* p = bool_alpha[trapping(division_by_zero<T>())]; \
printf("%s%s = %s;\n", tab2, "static const bool traps", p); \ printf("%s%s = %s;\n", tab2, "static const bool traps", p); \
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment