Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Copy strings before calling Rf_warningcall() to avoid weird unwind behavior #422

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions inst/include/cpp11/protect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename... Args>
void warning(const char* fmt_arg, Args&&... args) {
std::string msg = fmt::format(fmt_arg, std::forward<Args>(args)...);
safe[Rf_warningcall](R_NilValue, "%s", msg.c_str());
}
// Always making copy of string to avoid weird unwind behavior.

template <typename... Args>
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>(args)...);
safe[Rf_warningcall](R_NilValue, "%s", msg.c_str());
}
Expand All @@ -223,13 +219,10 @@ void stop [[noreturn]] (const std::string& fmt, Args... args) {
safe.noreturn(Rf_errorcall)(R_NilValue, fmt.c_str(), args...);
}

template <typename... Args>
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 <typename... Args>
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
Expand Down
Loading