From 8ff84fab4e56d996b2d4187bf1474c055d7d3c6c Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Tue, 2 Sep 2014 12:56:16 +0400 Subject: [PATCH 1/2] Allow instrumentation with RTTI-off and improve error reporting in RTTI-off env --- include/boost/math/constants/info.hpp | 2 +- .../distributions/detail/hypergeometric_pdf.hpp | 2 +- include/boost/math/policies/error_handling.hpp | 22 ++++------------------ include/boost/math/special_functions/erf.hpp | 16 ++++++++-------- include/boost/math/special_functions/gamma.hpp | 5 +++-- include/boost/math/tools/config.hpp | 2 +- test/Jamfile.v2 | 8 ++++++++ 7 files changed, 26 insertions(+), 31 deletions(-) diff --git a/include/boost/math/constants/info.hpp b/include/boost/math/constants/info.hpp index e3e6a517d..9c5277aef 100644 --- a/include/boost/math/constants/info.hpp +++ b/include/boost/math/constants/info.hpp @@ -22,7 +22,7 @@ namespace boost{ namespace math{ namespace constants{ template const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) { - return typeid(T).name(); + return typeindex::type_id().pretty_name(); } template <> const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(float)) diff --git a/include/boost/math/distributions/detail/hypergeometric_pdf.hpp b/include/boost/math/distributions/detail/hypergeometric_pdf.hpp index 1e6a5ca20..24da1c80f 100644 --- a/include/boost/math/distributions/detail/hypergeometric_pdf.hpp +++ b/include/boost/math/distributions/detail/hypergeometric_pdf.hpp @@ -58,7 +58,7 @@ T hypergeometric_pdf_lanczos_imp(T /*dummy*/, unsigned x, unsigned r, unsigned n BOOST_MATH_INSTRUMENT_VARIABLE(r); BOOST_MATH_INSTRUMENT_VARIABLE(n); BOOST_MATH_INSTRUMENT_VARIABLE(N); - BOOST_MATH_INSTRUMENT_VARIABLE(typeid(Lanczos).name()); + BOOST_MATH_INSTRUMENT_VARIABLE(typeindex::type_id().pretty_name()); T bases[9] = { T(n) + static_cast(Lanczos::g()) + 0.5f, diff --git a/include/boost/math/policies/error_handling.hpp b/include/boost/math/policies/error_handling.hpp index 674759006..1391820ea 100644 --- a/include/boost/math/policies/error_handling.hpp +++ b/include/boost/math/policies/error_handling.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef BOOST_MSVC # pragma warning(push) // Quiet warnings in boost/format.hpp # pragma warning(disable: 4996) // _SCL_SECURE_NO_DEPRECATE @@ -79,21 +80,14 @@ inline std::string do_format(Formatter f, const Group& g) } template -inline const char* name_of() +inline const std::string name_of() { -#ifndef BOOST_NO_RTTI - return typeid(T).name(); -#else - return "unknown"; -#endif + return typeindex::type_id().pretty_name(); } -template <> inline const char* name_of(){ return "float"; } -template <> inline const char* name_of(){ return "double"; } -template <> inline const char* name_of(){ return "long double"; } #ifdef BOOST_MATH_USE_FLOAT128 template <> -inline const char* name_of() +inline const std::string name_of() { return "__float128"; } @@ -108,11 +102,7 @@ void raise_error(const char* function, const char* message) message = "Cause unknown"; std::string msg("Error in function "); -#ifndef BOOST_NO_RTTI msg += (boost::format(function) % boost::math::policies::detail::name_of()).str(); -#else - msg += function; -#endif msg += ": "; msg += message; @@ -129,11 +119,7 @@ void raise_error(const char* function, const char* message, const T& val) message = "Cause unknown: error caused by bad argument with value %1%"; std::string msg("Error in function "); -#ifndef BOOST_NO_RTTI msg += (boost::format(function) % boost::math::policies::detail::name_of()).str(); -#else - msg += function; -#endif msg += ": "; msg += message; diff --git a/include/boost/math/special_functions/erf.hpp b/include/boost/math/special_functions/erf.hpp index f7f75b0bc..e4518b37b 100644 --- a/include/boost/math/special_functions/erf.hpp +++ b/include/boost/math/special_functions/erf.hpp @@ -1052,9 +1052,9 @@ inline typename tools::promote_args::type erf(T z, const Policy& /* pol */) policies::discrete_quantile<>, policies::assert_undefined<> >::type forwarding_policy; - BOOST_MATH_INSTRUMENT_CODE("result_type = " << typeid(result_type).name()); - BOOST_MATH_INSTRUMENT_CODE("value_type = " << typeid(value_type).name()); - BOOST_MATH_INSTRUMENT_CODE("precision_type = " << typeid(precision_type).name()); + BOOST_MATH_INSTRUMENT_CODE("result_type = " << typeindex::type_id().pretty_name()); + BOOST_MATH_INSTRUMENT_CODE("value_type = " << typeindex::type_id().pretty_name()); + BOOST_MATH_INSTRUMENT_CODE("precision_type = " << typeindex::type_id().pretty_name()); typedef typename mpl::if_< mpl::less_equal >, @@ -1074,7 +1074,7 @@ inline typename tools::promote_args::type erf(T z, const Policy& /* pol */) >::type >::type tag_type; - BOOST_MATH_INSTRUMENT_CODE("tag_type = " << typeid(tag_type).name()); + BOOST_MATH_INSTRUMENT_CODE("tag_type = " << typeindex::type_id().pretty_name()); detail::erf_initializer::force_instantiate(); // Force constants to be initialized before main @@ -1098,9 +1098,9 @@ inline typename tools::promote_args::type erfc(T z, const Policy& /* pol */) policies::discrete_quantile<>, policies::assert_undefined<> >::type forwarding_policy; - BOOST_MATH_INSTRUMENT_CODE("result_type = " << typeid(result_type).name()); - BOOST_MATH_INSTRUMENT_CODE("value_type = " << typeid(value_type).name()); - BOOST_MATH_INSTRUMENT_CODE("precision_type = " << typeid(precision_type).name()); + BOOST_MATH_INSTRUMENT_CODE("result_type = " << typeindex::type_id().pretty_name()); + BOOST_MATH_INSTRUMENT_CODE("value_type = " << typeindex::type_id().pretty_name()); + BOOST_MATH_INSTRUMENT_CODE("precision_type = " << typeindex::type_id().pretty_name()); typedef typename mpl::if_< mpl::less_equal >, @@ -1120,7 +1120,7 @@ inline typename tools::promote_args::type erfc(T z, const Policy& /* pol */) >::type >::type tag_type; - BOOST_MATH_INSTRUMENT_CODE("tag_type = " << typeid(tag_type).name()); + BOOST_MATH_INSTRUMENT_CODE("tag_type = " << typeindex::type_id().pretty_name()); detail::erf_initializer::force_instantiate(); // Force constants to be initialized before main diff --git a/include/boost/math/special_functions/gamma.hpp b/include/boost/math/special_functions/gamma.hpp index 07a0ba4f7..76a9babff 100644 --- a/include/boost/math/special_functions/gamma.hpp +++ b/include/boost/math/special_functions/gamma.hpp @@ -124,7 +124,8 @@ T gamma_imp(T z, const Policy& pol, const Lanczos& l) static bool b = false; if(!b) { - std::cout << "tgamma_imp called with " << typeid(z).name() << " " << typeid(l).name() << std::endl; + std::cout << "tgamma_imp called with " << typeindex::type_id().pretty_name() + << " " << typeindex::type_id().pretty_name() << std::endl; b = true; } #endif @@ -211,7 +212,7 @@ T lgamma_imp(T z, const Policy& pol, const Lanczos& l, int* sign = 0) static bool b = false; if(!b) { - std::cout << "lgamma_imp called with " << typeid(z).name() << " " << typeid(l).name() << std::endl; + std::cout << "lgamma_imp called with " << typeindex::type_id().pretty_name() << std::endl; b = true; } #endif diff --git a/include/boost/math/tools/config.hpp b/include/boost/math/tools/config.hpp index 4ec5768aa..f64e1a810 100644 --- a/include/boost/math/tools/config.hpp +++ b/include/boost/math/tools/config.hpp @@ -376,7 +376,7 @@ namespace boost{ namespace math{ # include # include -# include +# include # define BOOST_MATH_INSTRUMENT_CODE(x) \ std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index bdea3de57..54fd90ceb 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -186,6 +186,14 @@ run test_ellint_2.cpp test_instances//test_instances pch_light ../../test/build/ run test_ellint_3.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ; run test_erf.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ; run test_error_handling.cpp ../../test/build//boost_unit_test_framework ; +run test_error_handling.cpp ../../test/build//boost_unit_test_framework + : # command line + : # input files + : # requirements + off + BOOST_NO_RTTI + BOOST_NO_TYPEID + : test_error_handling_no_rtti ; run test_expint.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ; run test_exponential_dist.cpp ../../test/build//boost_unit_test_framework ; run test_extreme_value.cpp ../../test/build//boost_unit_test_framework ; From 18742bd5ec7aa31a82728224795475898ddc5bb5 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Tue, 2 Sep 2014 13:22:09 +0400 Subject: [PATCH 2/2] Fix a few typos from RTTI-off patches --- include/boost/math/constants/info.hpp | 18 +----------------- .../math/distributions/detail/hypergeometric_pdf.hpp | 4 ---- include/boost/math/special_functions/gamma.hpp | 3 ++- 3 files changed, 3 insertions(+), 22 deletions(-) diff --git a/include/boost/math/constants/info.hpp b/include/boost/math/constants/info.hpp index 9c5277aef..d86f673f0 100644 --- a/include/boost/math/constants/info.hpp +++ b/include/boost/math/constants/info.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include namespace boost{ namespace math{ namespace constants{ @@ -24,22 +24,6 @@ namespace boost{ namespace math{ namespace constants{ { return typeindex::type_id().pretty_name(); } - template <> - const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(float)) - { - return "float"; - } - template <> - const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(double)) - { - return "double"; - } - template <> - const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(long double)) - { - return "long double"; - } - } template diff --git a/include/boost/math/distributions/detail/hypergeometric_pdf.hpp b/include/boost/math/distributions/detail/hypergeometric_pdf.hpp index 24da1c80f..f53b71d96 100644 --- a/include/boost/math/distributions/detail/hypergeometric_pdf.hpp +++ b/include/boost/math/distributions/detail/hypergeometric_pdf.hpp @@ -16,10 +16,6 @@ #include #include -#ifdef BOOST_MATH_INSTRUMENT -#include -#endif - namespace boost{ namespace math{ namespace detail{ template diff --git a/include/boost/math/special_functions/gamma.hpp b/include/boost/math/special_functions/gamma.hpp index 76a9babff..26db1d7d8 100644 --- a/include/boost/math/special_functions/gamma.hpp +++ b/include/boost/math/special_functions/gamma.hpp @@ -212,7 +212,8 @@ T lgamma_imp(T z, const Policy& pol, const Lanczos& l, int* sign = 0) static bool b = false; if(!b) { - std::cout << "lgamma_imp called with " << typeindex::type_id().pretty_name() << std::endl; + std::cout << "lgamma_imp called with " << typeindex::type_id().pretty_name() + << " " << typeindex::type_id().pretty_name() << std::endl; b = true; } #endif