From 711f7f38515074d96f9c306dc6558917c5f75f43 Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Thu, 17 Feb 2022 01:27:20 +0800 Subject: [PATCH] Avoid `std::terminate` for R package. (#7661) This is part of CRAN policies. --- include/xgboost/span.h | 20 +++++++++++++++++--- src/tree/hist/evaluate_splits.h | 3 --- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/xgboost/span.h b/include/xgboost/span.h index e2dff409d..4d61471bf 100644 --- a/include/xgboost/span.h +++ b/include/xgboost/span.h @@ -102,13 +102,27 @@ namespace common { #define SPAN_CHECK KERNEL_CHECK -#else // not CUDA +#else // ------------------------------ not CUDA ---------------------------- -#define KERNEL_CHECK(cond) \ - (XGBOOST_EXPECT((cond), true) ? static_cast(0) : std::terminate()) +#if defined(XGBOOST_STRICT_R_MODE) && XGBOOST_STRICT_R_MODE == 1 + +#define KERNEL_CHECK(cond) \ + do { \ + if (XGBOOST_EXPECT(!(cond), false)) { \ + printf("[xgboost] fatal error.\n"); \ + } \ + } while (0) #define SPAN_CHECK(cond) KERNEL_CHECK(cond) +#else + +#define KERNEL_CHECK(cond) (XGBOOST_EXPECT((cond), true) ? static_cast(0) : std::terminate()) + +#define SPAN_CHECK(cond) KERNEL_CHECK(cond) + +#endif // defined(XGBOOST_STRICT_R_MODE) + #endif // __CUDA_ARCH__ #if defined(__CUDA_ARCH__) diff --git a/src/tree/hist/evaluate_splits.h b/src/tree/hist/evaluate_splits.h index 9fd3ce5ca..ed3f14e60 100644 --- a/src/tree/hist/evaluate_splits.h +++ b/src/tree/hist/evaluate_splits.h @@ -114,9 +114,6 @@ template class HistEvaluator { left_sum.SetSubstract(parent.stats, right_sum); break; } - default: { - std::terminate(); - } } };