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
This commit is contained in:
Alexandre Oliva 2001-01-09 03:01:56 +00:00 committed by Alexandre Oliva
parent 9c8fad3381
commit 4a70b13a4c
2 changed files with 28 additions and 6 deletions

View File

@ -1,3 +1,10 @@
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

View File

@ -1,4 +1,4 @@
// 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;
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 {};
// 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()
#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); \
} }