Merge branch 'master' of https://github.com/fasiondog/hikyuu into analysis

This commit is contained in:
fasiondog 2023-10-15 00:32:25 +08:00
commit 95a8ee5fd7
6 changed files with 100 additions and 19 deletions

View File

@ -30,6 +30,10 @@
#include <fmt/format.h>
#include <fmt/chrono.h>
#ifdef HKU_ENABLE_STACK_TRACE
#include <boost/stacktrace.hpp>
#endif
#ifndef HKU_API
#define HKU_API
#endif
@ -212,6 +216,7 @@ std::string HKU_API getLocalTime();
#define HKU_FUNCTION __FUNCTION__
#endif
#ifndef HKU_ENABLE_STACK_TRACE
/**
* false hku::exception ,
* @note
@ -220,7 +225,7 @@ std::string HKU_API getLocalTime();
do { \
if (!(expr)) { \
throw hku::exception(fmt::format("CHECK({}) {} [{}] ({}:{})", #expr, \
fmt::format(__VA_ARGS__), __FUNCTION__, __FILE__, \
fmt::format(__VA_ARGS__), HKU_FUNCTION, __FILE__, \
__LINE__)); \
} \
} while (0)
@ -233,27 +238,74 @@ std::string HKU_API getLocalTime();
do { \
if (!(expr)) { \
throw except(fmt::format("CHECK({}) {} [{}] ({}:{})", #expr, fmt::format(__VA_ARGS__), \
__FUNCTION__, __FILE__, __LINE__)); \
HKU_FUNCTION, __FILE__, __LINE__)); \
} \
} while (0)
#else
#define HKU_CHECK(expr, ...) \
do { \
if (!(expr)) { \
std::string errmsg = fmt::format(__VA_ARGS__); \
errmsg = fmt::format("{}\n {}", errmsg, to_string(boost::stacktrace::stacktrace())); \
throw hku::exception(fmt::format("CHECK({}) {} [{}] ({}:{})", #expr, errmsg, \
HKU_FUNCTION, __FILE__, __LINE__)); \
} \
} while (0)
#define HKU_CHECK_THROW(expr, except, ...) \
do { \
if (!(expr)) { \
std::string errmsg = fmt::format(__VA_ARGS__); \
errmsg = fmt::format("{}\n {}", errmsg, to_string(boost::stacktrace::stacktrace())); \
throw except(fmt::format("CHECK({}) {} [{}] ({}:{})", #expr, errmsg, HKU_FUNCTION, \
__FILE__, __LINE__)); \
} \
} while (0)
#endif // #ifndef HKU_ENABLE_STACK_TRACE
#if HKU_DISABLE_ASSERT
#define HKU_ASSERT(expr)
#define HKU_ASSERT_M(expr, ...)
#else /* #if HKU_DISABLE_ASSERT */
#ifdef HKU_ENABLE_STACK_TRACE
/**
* false hku::exception
* @note HKU_DISABLE_ASSERT
*/
#define HKU_ASSERT(expr) \
do { \
if (!(expr)) { \
std::string err_msg( \
fmt::format("ASSERT({})\n{}", #expr, to_string(boost::stacktrace::stacktrace()))); \
throw hku::exception( \
fmt::format("{} [{}] ({}:{})", err_msg, HKU_FUNCTION, __FILE__, __LINE__)); \
} \
} while (0)
/**
* false hku::exception ,
* @note HKU_DISABLE_ASSERT
*/
#define HKU_ASSERT_M(expr, ...) \
do { \
if (!(expr)) { \
std::string err_msg(fmt::format("ASSERT({}) {}\n{}", #expr, fmt::format(__VA_ARGS__), \
to_string(boost::stacktrace::stacktrace()))); \
throw hku::exception( \
fmt::format("{} [{}] ({}:{})", err_msg, HKU_FUNCTION, __FILE__, __LINE__)); \
} \
} while (0)
#else
#define HKU_ASSERT(expr) \
do { \
if (!(expr)) { \
std::string err_msg(fmt::format("ASSERT({})", #expr)); \
HKU_ERROR(err_msg); \
throw hku::exception( \
fmt::format("{} [{}] ({}:{})", err_msg, __FUNCTION__, __FILE__, __LINE__)); \
fmt::format("{} [{}] ({}:{})", err_msg, HKU_FUNCTION, __FILE__, __LINE__)); \
} \
} while (0)
@ -265,28 +317,46 @@ std::string HKU_API getLocalTime();
do { \
if (!(expr)) { \
std::string err_msg(fmt::format("ASSERT({}) {}", #expr, fmt::format(__VA_ARGS__))); \
HKU_ERROR(err_msg); \
throw hku::exception( \
fmt::format("{} [{}] ({}:{})", err_msg, __FUNCTION__, __FILE__, __LINE__)); \
fmt::format("{} [{}] ({}:{})", err_msg, HKU_FUNCTION, __FILE__, __LINE__)); \
} \
} while (0)
#endif // #ifndef HKU_ENABLE_STACK_TRACE
#endif /* #if HKU_DISABLE_ASSERT */
#endif /* #if HKU_DISABLE_ASSERT */
#ifndef HKU_ENABLE_STACK_TRACE
/** 抛出 hku::exception 及传入信息 */
#define HKU_THROW(...) \
do { \
throw hku::exception(fmt::format("EXCEPTION: {} [{}] ({}:{})", fmt::format(__VA_ARGS__), \
__FUNCTION__, __FILE__, __LINE__)); \
HKU_FUNCTION, __FILE__, __LINE__)); \
} while (0)
/** 抛出指定异常及传入信息 */
#define HKU_THROW_EXCEPTION(except, ...) \
do { \
throw except(fmt::format("EXCEPTION: {} [{}] ({}:{})", fmt::format(__VA_ARGS__), \
__FUNCTION__, __FILE__, __LINE__)); \
HKU_FUNCTION, __FILE__, __LINE__)); \
} while (0)
#else
#define HKU_THROW(...) \
do { \
std::string errmsg(fmt::format("{}\n {}", fmt::format(__VA_ARGS__), \
to_string(boost::stacktrace::stacktrace()))); \
throw hku::exception( \
fmt::format("EXCEPTION: {} [{}] ({}:{})", errmsg, HKU_FUNCTION, __FILE__, __LINE__)); \
} while (0)
#define HKU_THROW_EXCEPTION(except, ...) \
do { \
std::string errmsg(fmt::format("{}\n {}", fmt::format(__VA_ARGS__), \
to_string(boost::stacktrace::stacktrace()))); \
throw except( \
fmt::format("EXCEPTION: {} [{}] ({}:{})", errmsg, HKU_FUNCTION, __FILE__, __LINE__)); \
} while (0)
#endif // #ifndef HKU_ENABLE_STACK_TRACE
/**
* TRACE
* @param expr

View File

@ -43,7 +43,8 @@ void ISum::_calculate(const Indicator& ind) {
m_discard = ind.discard();
price_t sum = 0.0;
for (size_t i = m_discard; i < m_discard + n; i++) {
for (size_t i = m_discard, len = (m_discard + n) >= total ? total : m_discard + n; i < len;
i++) {
sum += ind[i];
_set(sum, i);
}

View File

@ -6,7 +6,7 @@ target("hikyuu")
set_kind("shared")
end
add_options("hdf5", "mysql", "sqlite", "tdx", "feedback")
add_options("hdf5", "mysql", "sqlite", "tdx", "feedback", "stackstrace")
add_packages("boost", "fmt", "spdlog", "flatbuffers", "nng", "nlohmann_json", "cpp-httplib")
if is_plat("windows", "linux", "cross") then

View File

@ -266,7 +266,7 @@ inline void set_logger_level(const std::string& name, int level) {
do { \
if (!(expr)) { \
throw hku::exception(fmt::format("CHECK({}) {} [{}] ({}:{})", #expr, \
fmt::format(__VA_ARGS__), __FUNCTION__, __FILE__, \
fmt::format(__VA_ARGS__), HKU_FUNCTION, __FILE__, \
__LINE__)); \
} \
} while (0)
@ -279,7 +279,7 @@ inline void set_logger_level(const std::string& name, int level) {
do { \
if (!(expr)) { \
throw except(fmt::format("CHECK({}) {} [{}] ({}:{})", #expr, fmt::format(__VA_ARGS__), \
__FUNCTION__, __FILE__, __LINE__)); \
HKU_FUNCTION, __FILE__, __LINE__)); \
} \
} while (0)
@ -299,7 +299,7 @@ inline void set_logger_level(const std::string& name, int level) {
std::string err_msg(fmt::format("ASSERT({})", #expr)); \
HKU_ERROR(err_msg); \
throw hku::exception( \
fmt::format("{} [{}] ({}:{})", err_msg, __FUNCTION__, __FILE__, __LINE__)); \
fmt::format("{} [{}] ({}:{})", err_msg, HKU_FUNCTION, __FILE__, __LINE__)); \
} \
} while (0)
@ -313,7 +313,7 @@ inline void set_logger_level(const std::string& name, int level) {
std::string err_msg(fmt::format("ASSERT({}) {}", #expr, fmt::format(__VA_ARGS__))); \
HKU_ERROR(err_msg); \
throw hku::exception( \
fmt::format("{} [{}] ({}:{})", err_msg, __FUNCTION__, __FILE__, __LINE__)); \
fmt::format("{} [{}] ({}:{})", err_msg, HKU_FUNCTION, __FILE__, __LINE__)); \
} \
} while (0)
@ -323,14 +323,14 @@ inline void set_logger_level(const std::string& name, int level) {
#define APP_THROW(...) \
do { \
throw hku::exception(fmt::format("EXCEPTION: {} [{}] ({}:{})", fmt::format(__VA_ARGS__), \
__FUNCTION__, __FILE__, __LINE__)); \
HKU_FUNCTION, __FILE__, __LINE__)); \
} while (0)
/** 抛出指定异常及传入信息 */
#define APP_THROW_EXCEPTION(except, ...) \
do { \
throw except(fmt::format("EXCEPTION: {} [{}] ({}:{})", fmt::format(__VA_ARGS__), \
__FUNCTION__, __FILE__, __LINE__)); \
HKU_FUNCTION, __FILE__, __LINE__)); \
} while (0)
//--------------------------------------------------------------

View File

@ -12,6 +12,8 @@ target("core")
--set_enable(false) --set_enable(false)会彻底禁用这个target连target的meta也不会被加载vcproj不会保留它
end
add_options("stackstrace")
add_deps("hikyuu")
add_packages("boost", "fmt", "spdlog", "flatbuffers", "cpp-httplib")
if is_plat("windows") then

View File

@ -50,10 +50,18 @@ option("tdx")
set_description("Enable tdx kdata engine.")
option_end()
option("feedback")
option("stacktrace")
set_default(true)
set_showmenu(true)
set_category("hikyuu")
set_description("Enable check/assert with stack trace info.")
add_defines("HKU_ENABLE_STACK_TRACE")
option_end()
option("feedback")
set_default(false)
set_showmenu(true)
set_category("hikyuu")
set_description("Enable send feedback.")
option_end()