This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Use template adapter to account for signal() prototype variations
On Dec 22, 2000, Alexandre Oliva <aoliva@redhat.com> wrote:
> On Dec 22, 2000, Alexandre Oliva <aoliva@redhat.com> wrote:
>> Trace/BPT trap (core dumped)
>> when testing whether bool divide-by-zero traps. Can anybody explain
>> this, and suggest how to work around it?
> Well, adding signal handlers for SIGTRAP fixes the problem.
> However, the results appear wrong to me. If division by zero traps,
> should traps be true, even if overflow doesn't trap? traps() computes
> a `&&' of the two conditions, whereas I'd expect a `||' here, but I
> can't tell which is correct, based on the Standard.
Here's a revised patch that addresses both issues. Ok to install?
Index: libstdc++-v3/ChangeLog
from 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.
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/25 21:02:44
@@ -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,10 +149,12 @@ template<typename T> struct underflow {}
// 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>());
- signal(SIGFPE, signal_handler);
- trap_flag = trap_flag && trapping(overflow<T>());
+ signal_adapter (signal, SIGFPE, signal_handler);
+ signal_adapter (signal, SIGTRAP, 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 +162,8 @@ template<typename T> void traps()
#define SPECIALIZE_TRAPPING(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>())]; \
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