boost_exception.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. From 8f57d59bfbc978673a2493a90b4f3e7e54ddbf18 Mon Sep 17 00:00:00 2001
  2. From: Antony Polukhin <antoshkka@gmail.com>
  3. Date: Thu, 20 Feb 2014 18:30:11 +0400
  4. Subject: [PATCH] Boost.Exception now uses TypeIndex to reduce duplicate code
  5. and simplify name demanglings
  6. ---
  7. include/boost/exception/detail/type_info.hpp | 43 +++-------------------
  8. include/boost/exception/diagnostic_information.hpp | 2 +-
  9. include/boost/exception/exception.hpp | 3 +-
  10. include/boost/exception/info.hpp | 2 +-
  11. test/Jamfile.v2 | 2 +
  12. 5 files changed, 12 insertions(+), 40 deletions(-)
  13. diff --git a/include/boost/exception/detail/type_info.hpp b/include/boost/exception/detail/type_info.hpp
  14. index 6e5942d..a247b71 100644
  15. --- a/include/boost/exception/detail/type_info.hpp
  16. +++ b/include/boost/exception/detail/type_info.hpp
  17. @@ -12,13 +12,7 @@
  18. #pragma warning(push,1)
  19. #endif
  20. -#include <boost/detail/sp_typeinfo.hpp>
  21. -#include <boost/current_function.hpp>
  22. -#include <boost/config.hpp>
  23. -//#ifndef BOOST_NO_TYPEID
  24. -//#include <boost/units/detail/utility.hpp>
  25. -//#endif
  26. -#include <string>
  27. +#include <boost/type_index.hpp>
  28. namespace
  29. boost
  30. @@ -28,11 +22,7 @@ boost
  31. std::string
  32. tag_type_name()
  33. {
  34. -#ifdef BOOST_NO_TYPEID
  35. - return BOOST_CURRENT_FUNCTION;
  36. -#else
  37. - return /*units::detail::demangle*/(typeid(T*).name());
  38. -#endif
  39. + return boost::typeind::type_id<T*>().pretty_name();
  40. }
  41. template <class T>
  42. @@ -40,41 +30,20 @@ boost
  43. std::string
  44. type_name()
  45. {
  46. -#ifdef BOOST_NO_TYPEID
  47. - return BOOST_CURRENT_FUNCTION;
  48. -#else
  49. - return /*units::detail::demangle*/(typeid(T).name());
  50. -#endif
  51. + return boost::typeind::type_id<T>().pretty_name();
  52. }
  53. namespace
  54. exception_detail
  55. {
  56. - struct
  57. - type_info_
  58. - {
  59. - detail::sp_typeinfo const * type_;
  60. -
  61. - explicit
  62. - type_info_( detail::sp_typeinfo const & type ):
  63. - type_(&type)
  64. - {
  65. - }
  66. -
  67. - friend
  68. - bool
  69. - operator<( type_info_ const & a, type_info_ const & b )
  70. - {
  71. - return 0!=(a.type_->before(*b.type_));
  72. - }
  73. - };
  74. + typedef boost::typeind::type_index type_info_;
  75. }
  76. }
  77. -#define BOOST_EXCEPTION_STATIC_TYPEID(T) ::boost::exception_detail::type_info_(BOOST_SP_TYPEID(T))
  78. +#define BOOST_EXCEPTION_STATIC_TYPEID(T) ::boost::typeind::type_id<T>()
  79. #ifndef BOOST_NO_RTTI
  80. -#define BOOST_EXCEPTION_DYNAMIC_TYPEID(x) ::boost::exception_detail::type_info_(typeid(x))
  81. +#define BOOST_EXCEPTION_DYNAMIC_TYPEID(x) ::boost::typeind::type_id_runtime(x)
  82. #endif
  83. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  84. diff --git a/include/boost/exception/diagnostic_information.hpp b/include/boost/exception/diagnostic_information.hpp
  85. index 2f5cb88..0f8b5e8 100644
  86. --- a/include/boost/exception/diagnostic_information.hpp
  87. +++ b/include/boost/exception/diagnostic_information.hpp
  88. @@ -151,7 +151,7 @@ boost
  89. #ifndef BOOST_NO_RTTI
  90. if ( verbose )
  91. tmp << std::string("Dynamic exception type: ") <<
  92. - /*units::detail::demangle*/((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_->name()) << '\n';
  93. + /*units::detail::demangle*/((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)))) << '\n';
  94. #endif
  95. if( with_what && se && verbose )
  96. tmp << "std::exception::what: " << wh << '\n';
  97. diff --git a/include/boost/exception/exception.hpp b/include/boost/exception/exception.hpp
  98. index 9f20a04..53c341f 100644
  99. --- a/include/boost/exception/exception.hpp
  100. +++ b/include/boost/exception/exception.hpp
  101. @@ -12,6 +12,8 @@
  102. #pragma warning(push,1)
  103. #endif
  104. +#include <boost/exception/detail/type_info.hpp>
  105. +
  106. namespace
  107. boost
  108. {
  109. @@ -151,7 +153,6 @@ boost
  110. exception_detail
  111. {
  112. class error_info_base;
  113. - struct type_info_;
  114. struct
  115. error_info_container
  116. diff --git a/include/boost/exception/info.hpp b/include/boost/exception/info.hpp
  117. index edbf058..e0f4950 100644
  118. --- a/include/boost/exception/info.hpp
  119. +++ b/include/boost/exception/info.hpp
  120. @@ -96,7 +96,7 @@ boost
  121. {
  122. shared_ptr<error_info_base> const & p = i->second;
  123. #ifndef BOOST_NO_RTTI
  124. - BOOST_ASSERT( *BOOST_EXCEPTION_DYNAMIC_TYPEID(*p).type_==*ti.type_ );
  125. + BOOST_ASSERT(BOOST_EXCEPTION_DYNAMIC_TYPEID(*p)==ti );
  126. #endif
  127. return p;
  128. }
  129. diff --git a/test/Jamfile.v2 b/test/Jamfile.v2
  130. index d2dfcd6..5bd076d 100644
  131. --- a/test/Jamfile.v2
  132. +++ b/test/Jamfile.v2
  133. @@ -35,7 +35,9 @@ run enable_error_info_test.cpp helper1.cpp ;
  134. run throw_exception_test.cpp helper2.cpp ;
  135. run errno_test.cpp ;
  136. run error_info_test.cpp ;
  137. +run error_info_test.cpp : : : <rtti>off : error_info_test_rtti ;
  138. run diagnostic_information_test.cpp ;
  139. +run diagnostic_information_test.cpp : : : <rtti>off : diagnostic_information_test_rtti ;
  140. run refcount_ptr_test.cpp ;
  141. run current_exception_cast_test.cpp ;
  142. run no_exceptions_test.cpp : : : <exception-handling>off ;
  143. --
  144. 1.8.5.3