From fe615c4aee1a34eb567dd8ab80bab7bc41171ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 26 Jun 2024 11:45:08 +0200 Subject: [PATCH] Revert "Revert a011d425" This reverts commit aafd64e602d793810bbcf623ff68fb725796bb31. --- inst/include/cpp11/declarations.hpp | 5 +++-- inst/include/cpp11/protect.hpp | 15 ++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/inst/include/cpp11/declarations.hpp b/inst/include/cpp11/declarations.hpp index f749729af..d94afa39d 100644 --- a/inst/include/cpp11/declarations.hpp +++ b/inst/include/cpp11/declarations.hpp @@ -46,7 +46,7 @@ T& unmove(T&& t) { SEXP err = R_NilValue; \ char buf[CPP11_ERROR_BUFSIZE] = ""; \ try { -#define END_CPP11 \ +#define END_CPP11_EX(RET) \ } \ catch (cpp11::unwind_exception & e) { \ err = e.token; \ @@ -62,4 +62,5 @@ T& unmove(T&& t) { } else if (err != R_NilValue) { \ CPP11_UNWIND \ } \ - return R_NilValue; + return RET; +#define END_CPP11 END_CPP11_EX(R_NilValue) diff --git a/inst/include/cpp11/protect.hpp b/inst/include/cpp11/protect.hpp index 508210c0d..2d6093b0c 100644 --- a/inst/include/cpp11/protect.hpp +++ b/inst/include/cpp11/protect.hpp @@ -214,14 +214,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()); } @@ -236,13 +232,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