Optimization for error_info<throw_function>, error_info<throw_file>, error_info<throw_line>. Refactored exception_ptr to use shared_ptr.

[SVN r48521]
This commit is contained in:
Emil Dotchevski
2008-09-01 21:06:09 +00:00
parent 9a35c999a2
commit b84fb75a60
16 changed files with 418 additions and 455 deletions

View File

@ -23,7 +23,6 @@ run cloning_test.cpp ;
run copy_exception_test.cpp ;
run unknown_exception_test.cpp ;
run exception_test.cpp ;
run boost_error_info_test.cpp ;
run enable_error_info_test.cpp helper1.cpp ;
run throw_exception_test.cpp helper2.cpp ;
run errno_test.cpp ;

View File

@ -1,41 +0,0 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//Distributed under the Boost Software License, Version 1.0. (See accompanying
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <stdexcept>
namespace
test
{
class my_exception: public boost::exception { };
typedef boost::error_info<struct tag_my_info,int> my_info;
void
test_boost_error_info()
{
try
{
throw my_exception() << BOOST_ERROR_INFO << my_info(1);
}
catch(
my_exception & x )
{
BOOST_TEST(1==*boost::get_error_info<my_info>(x));
BOOST_TEST(boost::get_error_info<boost::throw_function>(x));
BOOST_TEST(boost::get_error_info<boost::throw_file>(x));
BOOST_TEST(boost::get_error_info<boost::throw_line>(x));
}
}
}
int
main()
{
test::test_boost_error_info();
return boost::report_errors();
}

View File

@ -11,7 +11,8 @@ typedef boost::error_info<struct test_tag,int> tag_int;
struct
error1:
public std::exception
public std::exception,
public boost::exception
{
char const *
what() const throw()
@ -22,18 +23,6 @@ error1:
struct
error2:
public std::exception,
public boost::exception
{
char const *
what() const throw()
{
return "error2";
}
};
struct
error3:
public boost::exception
{
};
@ -44,56 +33,17 @@ main()
using namespace boost;
try
{
error1 x;
error1 x; x << tag_int(42);
BOOST_TEST(x.what()==std::string("error1"));
throw x;
}
catch(
std::exception & x )
{
std::string di=boost::diagnostic_information(x);
BOOST_TEST(di.find("type:")!=std::string::npos);
BOOST_TEST(di.find("error1")!=std::string::npos);
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
error2 x; x << tag_int(42);
BOOST_TEST(x.what()==std::string("error2"));
throw x;
}
catch(
std::exception & x )
{
std::string di=boost::diagnostic_information(x);
BOOST_TEST(di.find("type:")!=std::string::npos);
BOOST_TEST(di.find("error2")!=std::string::npos);
#ifndef BOOST_NO_RTTI
BOOST_TEST(di.find("test_tag")!=std::string::npos);
#endif
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
error2 x; x << tag_int(42);
BOOST_TEST(x.what()==std::string("error2"));
throw x;
}
catch(
boost::exception & x )
{
std::string di=boost::diagnostic_information(x);
BOOST_TEST(di.find("type:")!=std::string::npos);
#ifndef BOOST_NO_RTTI
BOOST_TEST(di.find("error2")!=std::string::npos);
BOOST_TEST(di.find("type:")!=std::string::npos);
BOOST_TEST(di.find("error1")!=std::string::npos);
#endif
BOOST_TEST(di.find("test_tag")!=std::string::npos);
}
@ -104,7 +54,7 @@ main()
}
try
{
error3 x;
error2 x;
x << tag_int(1);
throw x;
}

View File

@ -22,19 +22,17 @@ test_type
count_=42;
}
friend
void
intrusive_ptr_add_ref( test_type const * c )
add_ref()
{
++c->count_;
++count_;
}
friend
void
intrusive_ptr_release( test_type const * c )
release()
{
if( !--c->count_ )
delete c;
if( !--count_ )
delete this;
}
private:

View File

@ -11,6 +11,66 @@
typedef boost::error_info<struct tag_test_int,int> test_data;
struct
exception1:
std::exception
{
};
struct
exception2:
std::exception,
boost::exception
{
};
void
boost_throw_exception_test()
{
try
{
BOOST_THROW_EXCEPTION(exception1());
BOOST_TEST(false);
}
catch(
boost::exception & x )
{
boost::shared_ptr<char const * const> file=boost::get_error_info<boost::throw_function>(x);
boost::shared_ptr<char const * const> function=boost::get_error_info<boost::throw_file>(x);
boost::shared_ptr<int const> line=boost::get_error_info<boost::throw_line>(x);
BOOST_TEST( file && *file );
BOOST_TEST( function && *function );
BOOST_TEST( line && *line==32 );
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
BOOST_THROW_EXCEPTION(exception2() << test_data(42));
BOOST_TEST(false);
}
catch(
boost::exception & x )
{
boost::shared_ptr<char const * const> file=boost::get_error_info<boost::throw_function>(x);
boost::shared_ptr<char const * const> function=boost::get_error_info<boost::throw_file>(x);
boost::shared_ptr<int const> line=boost::get_error_info<boost::throw_line>(x);
boost::shared_ptr<int const> data=boost::get_error_info<test_data>(x);
BOOST_TEST( file && *file );
BOOST_TEST( function && *function );
BOOST_TEST( line && *line==52 );
BOOST_TEST( data && *data==42 );
}
catch(
... )
{
BOOST_TEST(false);
}
}
void
throw_fwd( void (*thrower)(int) )
{
@ -80,6 +140,7 @@ tester()
int
main()
{
boost_throw_exception_test();
tester<boost::exception_test::derives_boost_exception>();
tester<boost::exception_test::derives_boost_exception_virtually>();
tester<boost::exception_test::derives_std_exception>();