Commit 949d9ae1 by Benjamin Kosnik Committed by Benjamin Kosnik

throw_allocator.h: Fixes for -fno-exceptions.

2007-06-26  Benjamin Kosnik  <bkoz@redhat.com>

	* include/ext/throw_allocator.h: Fixes for -fno-exceptions.
	* testsuite/util/testsuite_shared.cc: Same.
	* testsuite/util/io/illegal_input_error.hpp: Same.
	* testsuite/util/io/verified_cmd_line_input.cc: Same.

	* libsupc++/typeinfo (type_info): Correct comment formatting,
	clarify member access and public interface.
	* libsupc++/exception: Less compressed comments.
	* libsupc++/new: Same.

From-SVN: r126016
parent 12c7b51e
2007-06-26 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/throw_allocator.h: Fixes for -fno-exceptions.
* testsuite/util/testsuite_shared.cc: Same.
* testsuite/util/io/illegal_input_error.hpp: Same.
* testsuite/util/io/verified_cmd_line_input.cc: Same.
* libsupc++/typeinfo (type_info): Correct comment formatting,
clarify member access and public interface.
* libsupc++/exception: Less compressed comments.
* libsupc++/new: Same.
2007-06-18 Paolo Carlini <pcarlini@suse.de> 2007-06-18 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_list.h: Rename guard macro consistently with * include/bits/stl_list.h: Rename guard macro consistently with
......
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
#include <stdexcept> #include <stdexcept>
#include <utility> #include <utility>
#include <tr1/random> #include <tr1/random>
#include <bits/functexcept.h>
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
...@@ -82,10 +83,20 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ...@@ -82,10 +83,20 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
std::tr1::mt19937 _M_generator; std::tr1::mt19937 _M_generator;
}; };
struct forced_exception_error : public std::exception struct forced_exception_error : public std::exception
{ }; { };
// Substitute for concurrence_error object in the case of -fno-exceptions.
inline void
__throw_forced_exception_error()
{
#if __EXCEPTIONS
throw forced_exception_error();
#else
__builtin_abort();
#endif
}
class throw_allocator_base class throw_allocator_base
{ {
public: public:
...@@ -329,7 +340,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ...@@ -329,7 +340,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
error += '\n'; error += '\n';
print_to_string(error, make_entry(p, size)); print_to_string(error, make_entry(p, size));
print_to_string(error, *found_it); print_to_string(error, *found_it);
throw std::logic_error(error); std::__throw_logic_error(error.c_str());
} }
_S_map.insert(make_entry(p, size)); _S_map.insert(make_entry(p, size));
} }
...@@ -355,7 +366,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ...@@ -355,7 +366,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
error += "null erase!"; error += "null erase!";
error += '\n'; error += '\n';
print_to_string(error, make_entry(p, size)); print_to_string(error, make_entry(p, size));
throw std::logic_error(error); std::__throw_logic_error(error.c_str());
} }
if (found_it->second.second != size) if (found_it->second.second != size)
...@@ -365,7 +376,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ...@@ -365,7 +376,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
error += '\n'; error += '\n';
print_to_string(error, make_entry(p, size)); print_to_string(error, make_entry(p, size));
print_to_string(error, *found_it); print_to_string(error, *found_it);
throw std::logic_error(error); std::__throw_logic_error(error.c_str());
} }
} }
...@@ -386,7 +397,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ...@@ -386,7 +397,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
std::string error("throw_allocator_base::check_allocated by label "); std::string error("throw_allocator_base::check_allocated by label ");
error += '\n'; error += '\n';
error += found; error += found;
throw std::logic_error(error); std::__throw_logic_error(error.c_str());
} }
} }
...@@ -394,7 +405,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ...@@ -394,7 +405,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
throw_allocator_base::throw_conditionally() throw_allocator_base::throw_conditionally()
{ {
if (_S_g.get_prob() < _S_throw_prob) if (_S_g.get_prob() < _S_throw_prob)
throw forced_exception_error(); __throw_forced_exception_error();
} }
void void
......
...@@ -58,6 +58,7 @@ namespace std ...@@ -58,6 +58,7 @@ namespace std
public: public:
exception() throw() { } exception() throw() { }
virtual ~exception() throw(); virtual ~exception() throw();
/** Returns a C-style character string describing the general cause /** Returns a C-style character string describing the general cause
* of the current error. */ * of the current error. */
virtual const char* what() const throw(); virtual const char* what() const throw();
...@@ -69,26 +70,31 @@ namespace std ...@@ -69,26 +70,31 @@ namespace std
{ {
public: public:
bad_exception() throw() { } bad_exception() throw() { }
// This declaration is not useless: // This declaration is not useless:
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
virtual ~bad_exception() throw(); virtual ~bad_exception() throw();
// See comment in eh_exception.cc. // See comment in eh_exception.cc.
virtual const char* what() const throw(); virtual const char* what() const throw();
}; };
/// If you write a replacement %terminate handler, it must be of this type. /// If you write a replacement %terminate handler, it must be of this type.
typedef void (*terminate_handler) (); typedef void (*terminate_handler) ();
/// If you write a replacement %unexpected handler, it must be of this type. /// If you write a replacement %unexpected handler, it must be of this type.
typedef void (*unexpected_handler) (); typedef void (*unexpected_handler) ();
/// Takes a new handler function as an argument, returns the old function. /// Takes a new handler function as an argument, returns the old function.
terminate_handler set_terminate(terminate_handler) throw(); terminate_handler set_terminate(terminate_handler) throw();
/** The runtime will call this function if %exception handling must be /** The runtime will call this function if %exception handling must be
* abandoned for any reason. It can also be called by the user. */ * abandoned for any reason. It can also be called by the user. */
void terminate() __attribute__ ((__noreturn__)); void terminate() __attribute__ ((__noreturn__));
/// Takes a new handler function as an argument, returns the old function. /// Takes a new handler function as an argument, returns the old function.
unexpected_handler set_unexpected(unexpected_handler) throw(); unexpected_handler set_unexpected(unexpected_handler) throw();
/** The runtime will call this function if an %exception is thrown which /** The runtime will call this function if an %exception is thrown which
* violates the function's %exception specification. */ * violates the function's %exception specification. */
void unexpected() __attribute__ ((__noreturn__)); void unexpected() __attribute__ ((__noreturn__));
......
...@@ -59,19 +59,25 @@ namespace std ...@@ -59,19 +59,25 @@ namespace std
{ {
public: public:
bad_alloc() throw() { } bad_alloc() throw() { }
// This declaration is not useless: // This declaration is not useless:
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
virtual ~bad_alloc() throw(); virtual ~bad_alloc() throw();
// See comment in eh_exception.cc. // See comment in eh_exception.cc.
virtual const char* what() const throw(); virtual const char* what() const throw();
}; };
struct nothrow_t { }; struct nothrow_t { };
extern const nothrow_t nothrow; extern const nothrow_t nothrow;
/** If you write your own error handler to be called by @c new, it must /** If you write your own error handler to be called by @c new, it must
* be of this type. */ * be of this type. */
typedef void (*new_handler)(); typedef void (*new_handler)();
/// Takes a replacement handler as the argument, returns the previous handler.
/// Takes a replacement handler as the argument, returns the
/// previous handler.
new_handler set_new_handler(new_handler) throw(); new_handler set_new_handler(new_handler) throw();
} // namespace std } // namespace std
......
...@@ -93,25 +93,12 @@ namespace std ...@@ -93,25 +93,12 @@ namespace std
class type_info class type_info
{ {
public: public:
/** Destructor. Being the first non-inline virtual function, this /** Destructor first. Being the first non-inline virtual function, this
* controls in which translation unit the vtable is emitted. The * controls in which translation unit the vtable is emitted. The
* compiler makes use of that information to know where to emit * compiler makes use of that information to know where to emit
* the runtime-mandated type_info structures in the new-abi. */ * the runtime-mandated type_info structures in the new-abi. */
virtual ~type_info(); virtual ~type_info();
private:
/// Assigning type_info is not supported. Made private.
type_info& operator=(const type_info&);
type_info(const type_info&);
protected:
const char *__name;
protected:
explicit type_info(const char *__n): __name(__n) { }
public:
// the public interface
/** Returns an @e implementation-defined byte string; this is not /** Returns an @e implementation-defined byte string; this is not
* portable between compilers! */ * portable between compilers! */
const char* name() const const char* name() const
...@@ -119,6 +106,7 @@ namespace std ...@@ -119,6 +106,7 @@ namespace std
#if !__GXX_TYPEINFO_EQUALITY_INLINE #if !__GXX_TYPEINFO_EQUALITY_INLINE
bool before(const type_info& __arg) const; bool before(const type_info& __arg) const;
// In old abi, or when weak symbols are not supported, there can // In old abi, or when weak symbols are not supported, there can
// be multiple instances of a type_info object for one // be multiple instances of a type_info object for one
// type. Uniqueness must use the _name value, not object address. // type. Uniqueness must use the _name value, not object address.
...@@ -133,19 +121,13 @@ namespace std ...@@ -133,19 +121,13 @@ namespace std
// and therefore address comparisons are sufficient. // and therefore address comparisons are sufficient.
bool before(const type_info& __arg) const bool before(const type_info& __arg) const
{ return __name < __arg.__name; } { return __name < __arg.__name; }
bool operator==(const type_info& __arg) const bool operator==(const type_info& __arg) const
{ return __name == __arg.__name; } { return __name == __arg.__name; }
#endif #endif
bool operator!=(const type_info& __arg) const bool operator!=(const type_info& __arg) const
{ return !operator==(__arg); } { return !operator==(__arg); }
// the internal interface
public:
// return true if this is a pointer type of some kind
virtual bool __is_pointer_p() const;
// return true if this is a function type
virtual bool __is_function_p() const;
// Try and catch a thrown type. Store an adjusted pointer to the // Try and catch a thrown type. Store an adjusted pointer to the
// caught type in THR_OBJ. If THR_TYPE is not a pointer type, then // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
// THR_OBJ points to the thrown object. If THR_TYPE is a pointer // THR_OBJ points to the thrown object. If THR_TYPE is a pointer
...@@ -155,9 +137,25 @@ namespace std ...@@ -155,9 +137,25 @@ namespace std
virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj, virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
unsigned __outer) const; unsigned __outer) const;
// internally used during catch matching // Internally used during catch matching
virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target, virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
void **__obj_ptr) const; void **__obj_ptr) const;
// Return true if this is a pointer type of some kind
virtual bool __is_pointer_p() const;
// Return true if this is a function type
virtual bool __is_function_p() const;
protected:
const char *__name;
explicit type_info(const char *__n): __name(__n) { }
private:
/// Assigning type_info is not supported.
type_info& operator=(const type_info&);
type_info(const type_info&);
}; };
/** /**
...@@ -169,9 +167,11 @@ namespace std ...@@ -169,9 +167,11 @@ namespace std
{ {
public: public:
bad_cast() throw() { } bad_cast() throw() { }
// This declaration is not useless: // This declaration is not useless:
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
virtual ~bad_cast() throw(); virtual ~bad_cast() throw();
// See comment in eh_exception.cc. // See comment in eh_exception.cc.
virtual const char* what() const throw(); virtual const char* what() const throw();
}; };
...@@ -181,9 +181,11 @@ namespace std ...@@ -181,9 +181,11 @@ namespace std
{ {
public: public:
bad_typeid () throw() { } bad_typeid () throw() { }
// This declaration is not useless: // This declaration is not useless:
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
virtual ~bad_typeid() throw(); virtual ~bad_typeid() throw();
// See comment in eh_exception.cc. // See comment in eh_exception.cc.
virtual const char* what() const throw(); virtual const char* what() const throw();
}; };
......
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2005, 2006 Free Software Foundation, Inc. // Copyright (C) 2005, 2006, 2007 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 terms // software; you can redistribute it and/or modify it under the terms
...@@ -47,17 +47,26 @@ ...@@ -47,17 +47,26 @@
#ifndef PB_DS_ILLEGAL_INPUT_EX_HPP #ifndef PB_DS_ILLEGAL_INPUT_EX_HPP
#define PB_DS_ILLEGAL_INPUT_EX_HPP #define PB_DS_ILLEGAL_INPUT_EX_HPP
#include <exception>
namespace pb_ds namespace pb_ds
{ {
namespace test namespace test
{ {
class illegal_input_error : public std::exception
class illegal_input_error
{ }; { };
// Substitute for concurrence_error object in the case of -fno-exceptions.
inline void
__throw_illegal_input_error()
{
#if __EXCEPTIONS
throw illegal_input_error();
#else
__builtin_abort();
#endif
}
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
#endif // #ifndef PB_DS_ILLEGAL_INPUT_EX_HPP #endif // #ifndef PB_DS_ILLEGAL_INPUT_EX_HPP
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2005, 2006 Free Software Foundation, Inc. // Copyright (C) 2005, 2006, 2007 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 terms // software; you can redistribute it and/or modify it under the terms
...@@ -48,84 +48,69 @@ ...@@ -48,84 +48,69 @@
#include <limits.h> #include <limits.h>
#include <utility> #include <utility>
#include <stdlib.h> #include <stdlib.h>
#include <bits/functexcept.h>
namespace pb_ds namespace pb_ds
{ {
namespace test namespace test
{ {
void void
verify_argc(size_t given, size_t required) verify_argc(size_t given, size_t required)
{ {
if (given != required) if (given != required)
throw illegal_input_error(); __throw_illegal_input_error();
} }
void void
verify_prob(double prob) verify_prob(double prob)
{ {
if (prob < 0 || prob > 1) if (prob < 0 || prob > 1)
throw illegal_input_error(); __throw_illegal_input_error();
} }
std::string std::string
get_cmd_line_str(int argc, char* a_p_argv[], int argn) get_cmd_line_str(int argc, char* a_p_argv[], int argn)
{ {
if (argc <= argn) if (argc <= argn)
throw illegal_input_error(); __throw_illegal_input_error();
const std::string ret(a_p_argv[argn]); const std::string ret(a_p_argv[argn]);
return ret;
return (ret);
} }
double double
get_cmd_line_prob(int argc, char* a_p_argv[], int argn) get_cmd_line_prob(int argc, char* a_p_argv[], int argn)
{ {
if (argc <= argn) if (argc <= argn)
throw illegal_input_error(); __throw_illegal_input_error();
const double ret = ::atof(a_p_argv[argn]); const double ret = ::atof(a_p_argv[argn]);
verify_prob(ret); verify_prob(ret);
return ret;
return (ret);
} }
size_t size_t
get_cmd_line_size(int argc, char* a_p_argv[], int argn) get_cmd_line_size(int argc, char* a_p_argv[], int argn)
{ {
if (argc <= argn) if (argc <= argn)
throw illegal_input_error(); __throw_illegal_input_error();
const size_t ret = static_cast<size_t>(::atoi(a_p_argv[argn])); const size_t ret = static_cast<size_t>(::atoi(a_p_argv[argn]));
return ret;
return (ret);
} }
bool bool
get_cmd_line_bool(int argc, char* a_p_argv[], int argn) get_cmd_line_bool(int argc, char* a_p_argv[], int argn)
{ {
if (argc <= argn) if (argc <= argn)
throw illegal_input_error(); __throw_illegal_input_error();
const std::string opt(a_p_argv[argn]); const std::string opt(a_p_argv[argn]);
if (opt.size() != 1) if (opt.size() != 1)
throw illegal_input_error(); __throw_illegal_input_error();
if (opt[0] == 't') if (opt[0] == 't')
return (true); return true;
if (opt[0] == 'f') if (opt[0] == 'f')
return (false); return false;
__throw_illegal_input_error();
throw illegal_input_error(); return false;
return (false);
} }
} // namespace test } // namespace test
} // namespace pb_ds } // namespace pb_ds
// Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. // Copyright (C) 2004, 2005, 2006, 2007 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
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <ext/mt_allocator.h> #include <ext/mt_allocator.h>
#include <bits/functexcept.h>
// libstdc++/22309 // libstdc++/22309
extern "C" void extern "C" void
...@@ -43,7 +44,7 @@ try_throw_exception() ...@@ -43,7 +44,7 @@ try_throw_exception()
{ {
try try
{ {
throw std::bad_exception(); std::__throw_bad_exception();
} }
catch (const std::exception& e) catch (const std::exception& e)
{ } { }
...@@ -68,5 +69,5 @@ try_function_random_fail() ...@@ -68,5 +69,5 @@ try_function_random_fail()
} }
// Randomly throw. See if other threads cleanup. // Randomly throw. See if other threads cleanup.
throw std::bad_exception(); std::__throw_bad_exception();
} }
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