Commit e6ff97b1 by Rodney Brown Committed by Benjamin Kosnik

gen-num-limits.cc (traps): Add fflush prior to trapping signal (UnixWare 7 workaround).


2001-03-12  Rodney Brown  <RodneyBrown@mynd.com>

        * src/gen-num-limits.cc (traps) [SPECIALIZE_TRAPPING]: Add fflush
        prior to trapping signal (UnixWare 7 workaround).

From-SVN: r40422
parent 23712c11
2001-03-12 Rodney Brown <RodneyBrown@mynd.com>
* src/gen-num-limits.cc (traps) [SPECIALIZE_TRAPPING]: Add fflush
prior to trapping signal (UnixWare 7 workaround).
2001-03-12 Craig Rodrigues <rodrigc@mediaone.net> 2001-03-12 Craig Rodrigues <rodrigc@mediaone.net>
* include/backward/hashtable.h: Same. * include/backward/hashtable.h: Same.
......
...@@ -139,16 +139,20 @@ bool trapping(const Operation& op) ...@@ -139,16 +139,20 @@ bool trapping(const Operation& op)
return false; return false;
} }
template<typename T> struct division_by_zero { template<typename T>
struct division_by_zero
{
void operator() () const void operator() () const
{ {
volatile T zero = T(); volatile T zero = T();
volatile T one = T(1); volatile T one = T(1);
volatile T infinity = one / zero; volatile T infinity = one / zero;
} }
}; };
template<typename T> struct overflow { template<typename T>
struct overflow
{
void operator() () const void operator() () const
{ {
T i = T(1); T i = T(1);
...@@ -158,13 +162,14 @@ template<typename T> struct overflow { ...@@ -158,13 +162,14 @@ template<typename T> struct overflow {
i = i * 2 + 1; i = i * 2 + 1;
} }
} }
}; };
template<typename T> struct underflow {}; template<typename T> struct underflow { };
// traps // traps
template<typename T> void traps() template<typename T> void traps()
{ {
fflush(NULL);
signal_adapter (signal, SIGFPE, signal_handler); signal_adapter (signal, SIGFPE, signal_handler);
signal_adapter (signal, SIGTRAP, signal_handler); signal_adapter (signal, SIGTRAP, signal_handler);
bool trap_flag = trapping(division_by_zero<T>()); bool trap_flag = trapping(division_by_zero<T>());
...@@ -178,6 +183,7 @@ template<typename T> void traps() ...@@ -178,6 +183,7 @@ template<typename T> void traps()
#define SPECIALIZE_TRAPPING(T) \ #define SPECIALIZE_TRAPPING(T) \
template<> void traps< T >() \ template<> void traps< T >() \
{ \ { \
fflush(NULL); \
signal_adapter (signal, SIGFPE, signal_handler); \ signal_adapter (signal, SIGFPE, signal_handler); \
signal_adapter (signal, SIGTRAP, 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>())]; \
...@@ -194,10 +200,12 @@ SPECIALIZE_TRAPPING(unsigned long long); ...@@ -194,10 +200,12 @@ SPECIALIZE_TRAPPING(unsigned long long);
#undef SPECIALIZE_TRAPPING #undef SPECIALIZE_TRAPPING
template<typename T> struct type_name_trait { template<typename T>
struct type_name_trait
{
static const char type_name[]; static const char type_name[];
static const char trait_name[]; static const char trait_name[];
}; };
#define DEFINED_TYPE_NAME(T) \ #define DEFINED_TYPE_NAME(T) \
const char type_name_trait< T >::type_name[] = #T; \ const char type_name_trait< T >::type_name[] = #T; \
...@@ -225,25 +233,26 @@ DEFINED_TYPE_NAME(long double); ...@@ -225,25 +233,26 @@ DEFINED_TYPE_NAME(long double);
#undef DEFINED_TYPE_NAME #undef DEFINED_TYPE_NAME
// declarator // declarator
template<typename T> struct declarator : type_name_trait<T> { template<typename T>
struct declarator : type_name_trait<T>
{
typedef type_name_trait<T> base; typedef type_name_trait<T> base;
static void start() static void start()
{ {
printf("%s%s %s %s\n", tab, "template<> struct", printf("%s%s %s %s\n", tab, "template<> struct", base::trait_name, "{");
base::trait_name, "{");
} }
static void end() static void end()
{ { printf("%s};\n\n", tab); }
printf("%s};\n\n", tab); };
}
};
// //
// Predicates // Predicates
// //
template<typename T> struct predicate { template<typename T>
struct predicate
{
static const bool is_signed; static const bool is_signed;
static const bool is_integer; static const bool is_integer;
static const bool is_exact; static const bool is_exact;
...@@ -258,7 +267,7 @@ template<typename T> struct predicate { ...@@ -258,7 +267,7 @@ template<typename T> struct predicate {
static const bool is_bounded; static const bool is_bounded;
static const bool traps; static const bool traps;
}; };
template<typename T> template<typename T>
const bool predicate<T>::is_signed = T(-1) < 0; const bool predicate<T>::is_signed = T(-1) < 0;
...@@ -321,8 +330,9 @@ SPECIALIZE_IEC559(unsigned long long); ...@@ -321,8 +330,9 @@ SPECIALIZE_IEC559(unsigned long long);
// //
// Values // Values
// //
template<typename T>
template<typename T> struct value { struct value
{
static const char min[]; static const char min[];
static const char max[]; static const char max[];
...@@ -337,7 +347,7 @@ template<typename T> struct value { ...@@ -337,7 +347,7 @@ template<typename T> struct value {
static const int min_exponent10; static const int min_exponent10;
static const int max_exponent; static const int max_exponent;
static const int max_exponent10; static const int max_exponent10;
}; };
#define DEFINE_EXTREMA(T, m, M) DO_DEFINE_EXTREMA(T, m, M) #define DEFINE_EXTREMA(T, m, M) DO_DEFINE_EXTREMA(T, m, M)
#define DO_DEFINE_EXTREMA(T, m, M) \ #define DO_DEFINE_EXTREMA(T, m, M) \
...@@ -639,7 +649,9 @@ void has_denorm_loss() ...@@ -639,7 +649,9 @@ void has_denorm_loss()
bool_alpha[predicate<T>::has_denorm_loss]); bool_alpha[predicate<T>::has_denorm_loss]);
} }
template<typename T> struct infinity_trait { template<typename T>
struct infinity_trait
{
static void has_denorm() static void has_denorm()
{ {
printf("%s%s;\n", tab2, "static const float_denorm_style " printf("%s%s;\n", tab2, "static const float_denorm_style "
...@@ -649,9 +661,8 @@ template<typename T> struct infinity_trait { ...@@ -649,9 +661,8 @@ template<typename T> struct infinity_trait {
static void infinity() static void infinity()
{ {
printf("%s%s %s %s\n%s%s%s%s\n", tab2, "static", printf("%s%s %s %s\n%s%s%s%s\n", tab2, "static",
declarator<T>::type_name, "infinity() throw()", declarator<T>::type_name, "infinity() throw()", tab2,
tab2, "{ return static_cast<", declarator<T>::type_name, "{ return static_cast<", declarator<T>::type_name, ">(0); }");
">(0); }");
} }
static void quiet_NaN() static void quiet_NaN()
...@@ -677,7 +688,7 @@ template<typename T> struct infinity_trait { ...@@ -677,7 +688,7 @@ template<typename T> struct infinity_trait {
tab2, "{ return static_cast<", declarator<T>::type_name, tab2, "{ return static_cast<", declarator<T>::type_name,
">(0); }"); ">(0); }");
} }
}; };
template<typename T> template<typename T>
...@@ -705,8 +716,9 @@ void round_style() ...@@ -705,8 +716,9 @@ void round_style()
// type traits // type traits
template<typename T> struct type_trait { template<typename T>
struct type_trait
{
type_trait() type_trait()
{ {
declarator<T>::start(); declarator<T>::start();
...@@ -748,7 +760,7 @@ template<typename T> struct type_trait { ...@@ -748,7 +760,7 @@ template<typename T> struct type_trait {
round_style<T>(); round_style<T>();
declarator<T>::end(); declarator<T>::end();
} }
}; };
int main() int main()
{ {
......
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