From 54be500cfdc0966f9ede51155ac247e984da6512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 7 Dec 2024 20:45:20 +0100 Subject: [PATCH] fix: Copy strings before calling `Rf_warningcall()` to avoid weird unwind behavior --- inst/include/cpp11/protect.hpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/inst/include/cpp11/protect.hpp b/inst/include/cpp11/protect.hpp index 9cb4876a..401b394f 100644 --- a/inst/include/cpp11/protect.hpp +++ b/inst/include/cpp11/protect.hpp @@ -201,14 +201,10 @@ void stop [[noreturn]] (const std::string& fmt_arg, Args&&... args) { safe.noreturn(Rf_errorcall)(R_NilValue, "%s", msg.c_str()); } -template -void warning(const char* fmt_arg, Args&&... args) { - std::string msg = fmt::format(fmt_arg, std::forward(args)...); - safe[Rf_warningcall](R_NilValue, "%s", msg.c_str()); -} +// Always making copy of string to avoid weird unwind behavior. template -void warning(const std::string& fmt_arg, Args&&... args) { +void warning(const std::string fmt_arg, Args&&... args) { std::string msg = fmt::format(fmt_arg, std::forward(args)...); safe[Rf_warningcall](R_NilValue, "%s", msg.c_str()); } @@ -223,13 +219,10 @@ void stop [[noreturn]] (const std::string& fmt, Args... args) { safe.noreturn(Rf_errorcall)(R_NilValue, fmt.c_str(), args...); } -template -void warning(const char* fmt, Args... args) { - safe[Rf_warningcall](R_NilValue, fmt, args...); -} +// Always making copy of string to avoid weird unwind behavior. template -void warning(const std::string& fmt, Args... args) { +void warning(const std::string fmt, Args... args) { safe[Rf_warningcall](R_NilValue, fmt.c_str(), args...); } #endif