diff --git a/include/boost/stacktrace/detail/addr2line_impls.hpp b/include/boost/stacktrace/detail/addr2line_impls.hpp index e314fe9..aae6422 100644 --- a/include/boost/stacktrace/detail/addr2line_impls.hpp +++ b/include/boost/stacktrace/detail/addr2line_impls.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -13,8 +13,9 @@ #endif #include +#include +#include #include -#include #include #include @@ -212,7 +213,7 @@ std::size_t frame::source_line() const { } res = res.substr(last + 1); - if (!boost::conversion::try_lexical_convert(res, line_num)) { + if (!boost::stacktrace::detail::try_dec_convert(res.c_str(), line_num)) { return 0; } diff --git a/include/boost/stacktrace/detail/collect_msvc.ipp b/include/boost/stacktrace/detail/collect_msvc.ipp index 37d3a29..ebe5904 100644 --- a/include/boost/stacktrace/detail/collect_msvc.ipp +++ b/include/boost/stacktrace/detail/collect_msvc.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/collect_noop.ipp b/include/boost/stacktrace/detail/collect_noop.ipp index bcfae4c..6c7867f 100644 --- a/include/boost/stacktrace/detail/collect_noop.ipp +++ b/include/boost/stacktrace/detail/collect_noop.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/collect_unwind.ipp b/include/boost/stacktrace/detail/collect_unwind.ipp index 98d8fcb..f7c1f82 100644 --- a/include/boost/stacktrace/detail/collect_unwind.ipp +++ b/include/boost/stacktrace/detail/collect_unwind.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/frame_decl.hpp b/include/boost/stacktrace/detail/frame_decl.hpp index 1919f6a..3e2cba3 100644 --- a/include/boost/stacktrace/detail/frame_decl.hpp +++ b/include/boost/stacktrace/detail/frame_decl.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/frame_msvc.ipp b/include/boost/stacktrace/detail/frame_msvc.ipp index 6e5eb49..13810a2 100644 --- a/include/boost/stacktrace/detail/frame_msvc.ipp +++ b/include/boost/stacktrace/detail/frame_msvc.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include #include "dbgeng.h" @@ -329,7 +329,7 @@ public: res += " at "; res += source_line.first; res += ':'; - res += boost::lexical_cast >(source_line.second).data(); + res += boost::stacktrace::detail::to_dec_array(source_line.second).data(); } else if (!module_name.empty()) { res += " in "; res += module_name; @@ -349,7 +349,7 @@ std::string to_string(const frame* frames, std::size_t size) { if (i < 10) { res += ' '; } - res += boost::lexical_cast >(i).data(); + res += boost::stacktrace::detail::to_dec_array(i).data(); res += '#'; res += ' '; idebug.to_string_impl(frames[i].address(), res); diff --git a/include/boost/stacktrace/detail/frame_noop.ipp b/include/boost/stacktrace/detail/frame_noop.ipp index b9b1b98..c33c351 100644 --- a/include/boost/stacktrace/detail/frame_noop.ipp +++ b/include/boost/stacktrace/detail/frame_noop.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/frame_unwind.ipp b/include/boost/stacktrace/detail/frame_unwind.ipp index d4e7973..44c982f 100644 --- a/include/boost/stacktrace/detail/frame_unwind.ipp +++ b/include/boost/stacktrace/detail/frame_unwind.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -16,8 +16,8 @@ #include #include +#include #include -#include #include @@ -67,7 +67,7 @@ std::string to_string(const frame* frames, std::size_t size) { if (i < 10) { res += ' '; } - res += boost::lexical_cast >(i).data(); + res += boost::stacktrace::detail::to_dec_array(i).data(); res += '#'; res += ' '; res += impl(frames[i].address()); diff --git a/include/boost/stacktrace/detail/libbacktrace_impls.hpp b/include/boost/stacktrace/detail/libbacktrace_impls.hpp index 121c41b..0c8d674 100644 --- a/include/boost/stacktrace/detail/libbacktrace_impls.hpp +++ b/include/boost/stacktrace/detail/libbacktrace_impls.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -13,9 +13,9 @@ #endif #include +#include #include #include -#include #include @@ -99,7 +99,7 @@ struct to_string_using_backtrace { res += " at "; res += filename; res += ':'; - res += boost::lexical_cast >(line).data(); + res += boost::stacktrace::detail::to_dec_array(line).data(); return true; } diff --git a/include/boost/stacktrace/detail/location_from_symbol.hpp b/include/boost/stacktrace/detail/location_from_symbol.hpp index 534ac91..322dcad 100644 --- a/include/boost/stacktrace/detail/location_from_symbol.hpp +++ b/include/boost/stacktrace/detail/location_from_symbol.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/pop_options.h b/include/boost/stacktrace/detail/pop_options.h index 8995b00..0faf6af 100644 --- a/include/boost/stacktrace/detail/pop_options.h +++ b/include/boost/stacktrace/detail/pop_options.h @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/push_options.h b/include/boost/stacktrace/detail/push_options.h index 3adb626..9be184f 100644 --- a/include/boost/stacktrace/detail/push_options.h +++ b/include/boost/stacktrace/detail/push_options.h @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/safe_dump_noop.ipp b/include/boost/stacktrace/detail/safe_dump_noop.ipp index 78fdc3a..aee378d 100644 --- a/include/boost/stacktrace/detail/safe_dump_noop.ipp +++ b/include/boost/stacktrace/detail/safe_dump_noop.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/safe_dump_posix.ipp b/include/boost/stacktrace/detail/safe_dump_posix.ipp index 97792c9..cfe3e41 100644 --- a/include/boost/stacktrace/detail/safe_dump_posix.ipp +++ b/include/boost/stacktrace/detail/safe_dump_posix.ipp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/to_dec_array.hpp b/include/boost/stacktrace/detail/to_dec_array.hpp new file mode 100644 index 0000000..5f02549 --- /dev/null +++ b/include/boost/stacktrace/detail/to_dec_array.hpp @@ -0,0 +1,46 @@ +// Copyright Antony Polukhin, 2016-2018. +// +// 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) + +#ifndef BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP +#define BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP + +#include +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + +#include + +namespace boost { namespace stacktrace { namespace detail { + +// We do not use boost::lexical_cast in this function to reduce module dependencies +inline boost::array to_dec_array(std::size_t value) BOOST_NOEXCEPT { + boost::array ret; + if (!value) { + ret[0] = '0'; + ret[1] = '\0'; + return ret; + } + + std::size_t digits = 0; + for (std::size_t value_copy = value; value_copy; value_copy /= 10) { + ++ digits; + } + + for (std::size_t i = 1; i <= digits; ++i) { + ret[digits - i] = '0' + (value % 10); + value /= 10; + } + + ret[digits] = '\0'; + + return ret; +} + + +}}} // namespace boost::stacktrace::detail + +#endif // BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP diff --git a/include/boost/stacktrace/detail/to_hex_array.hpp b/include/boost/stacktrace/detail/to_hex_array.hpp index dd55ded..20bba90 100644 --- a/include/boost/stacktrace/detail/to_hex_array.hpp +++ b/include/boost/stacktrace/detail/to_hex_array.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/try_dec_convert.hpp b/include/boost/stacktrace/detail/try_dec_convert.hpp new file mode 100644 index 0000000..af619bc --- /dev/null +++ b/include/boost/stacktrace/detail/try_dec_convert.hpp @@ -0,0 +1,29 @@ +// Copyright Antony Polukhin, 2016-2018. +// +// 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) + +#ifndef BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP +#define BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP + +#include +#ifdef BOOST_HAS_PRAGMA_ONCE +# pragma once +#endif + +#include + +namespace boost { namespace stacktrace { namespace detail { + +// We do not use boost::lexical_cast in this function to reduce module dependencies +inline bool try_dec_convert(const char* s, std::size_t& res) BOOST_NOEXCEPT { + char* end_ptr = 0; + res = std::strtoul(s, &end_ptr, 10); + return *end_ptr == '\0'; +} + + +}}} // namespace boost::stacktrace::detail + +#endif // BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP diff --git a/include/boost/stacktrace/detail/unwind_base_impls.hpp b/include/boost/stacktrace/detail/unwind_base_impls.hpp index 18a2378..2f72a15 100644 --- a/include/boost/stacktrace/detail/unwind_base_impls.hpp +++ b/include/boost/stacktrace/detail/unwind_base_impls.hpp @@ -1,4 +1,4 @@ -// Copyright Antony Polukhin, 2016-2017. +// Copyright Antony Polukhin, 2016-2018. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/stacktrace/detail/void_ptr_cast.hpp b/include/boost/stacktrace/detail/void_ptr_cast.hpp index f956f47..88e6916 100644 --- a/include/boost/stacktrace/detail/void_ptr_cast.hpp +++ b/include/boost/stacktrace/detail/void_ptr_cast.hpp @@ -1,5 +1,5 @@ // Copyright 2014 Renato Tegon Forti, Antony Polukhin. -// Copyright 2015-2017 Antony Polukhin. +// Copyright 2015-2018 Antony Polukhin. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 3c496bb..b3cb7d4 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -182,6 +182,7 @@ test-suite stacktrace_tests : windbg_cached_lib_threaded_com_st ] [ run test_void_ptr_cast.cpp ] + [ run test_num_conv.cpp ] ; # Assuring that examples compile and run. Adding sources from `examples` directory to the `type_index` test suite. diff --git a/test/test_num_conv.cpp b/test/test_num_conv.cpp new file mode 100644 index 0000000..d88e143 --- /dev/null +++ b/test/test_num_conv.cpp @@ -0,0 +1,69 @@ +// Copyright Antony Polukhin, 2016-2018. +// +// 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 +#include +#include + +#include + + +void test_to_hex_array() { + const void* ptr = 0; + BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("0x0") != std::string::npos); + + ptr = reinterpret_cast(0x10); + BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("10") != std::string::npos); + + ptr = reinterpret_cast(0x19); + BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("19") != std::string::npos); + + ptr = reinterpret_cast(0x999999); + BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("999999") != std::string::npos); +} + +void test_to_dec_array() { + BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(0).data()), std::string("0")); + BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(10).data()), std::string("10")); + BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(19).data()), std::string("19")); + BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(999999).data()), std::string("999999")); +} + +void test_try_dec_convert() { + std::size_t res = 0; + + BOOST_TEST(boost::stacktrace::detail::try_dec_convert("0", res)); + BOOST_TEST(res == 0); + + BOOST_TEST(boost::stacktrace::detail::try_dec_convert("+0", res)); + BOOST_TEST(res == 0); + + BOOST_TEST(boost::stacktrace::detail::try_dec_convert("10", res)); + BOOST_TEST(res == 10); + + BOOST_TEST(boost::stacktrace::detail::try_dec_convert("19", res)); + BOOST_TEST(res == 19); + + BOOST_TEST(boost::stacktrace::detail::try_dec_convert("+19", res)); + BOOST_TEST(res == 19); + + BOOST_TEST(boost::stacktrace::detail::try_dec_convert("9999", res)); + BOOST_TEST(res == 9999); + + BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("q", res)); + BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("0z", res)); + BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("0u", res)); + BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("+0u", res)); +} + + +int main() { + test_to_hex_array(); + test_to_dec_array(); + test_try_dec_convert(); + + return boost::report_errors(); +}