Skip to content

Commit 54be500

Browse files
committed
fix: Copy strings before calling Rf_warningcall() to avoid weird unwind behavior
1 parent aeb1895 commit 54be500

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

inst/include/cpp11/protect.hpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,10 @@ void stop [[noreturn]] (const std::string& fmt_arg, Args&&... args) {
201201
safe.noreturn(Rf_errorcall)(R_NilValue, "%s", msg.c_str());
202202
}
203203

204-
template <typename... Args>
205-
void warning(const char* fmt_arg, Args&&... args) {
206-
std::string msg = fmt::format(fmt_arg, std::forward<Args>(args)...);
207-
safe[Rf_warningcall](R_NilValue, "%s", msg.c_str());
208-
}
204+
// Always making copy of string to avoid weird unwind behavior.
209205

210206
template <typename... Args>
211-
void warning(const std::string& fmt_arg, Args&&... args) {
207+
void warning(const std::string fmt_arg, Args&&... args) {
212208
std::string msg = fmt::format(fmt_arg, std::forward<Args>(args)...);
213209
safe[Rf_warningcall](R_NilValue, "%s", msg.c_str());
214210
}
@@ -223,13 +219,10 @@ void stop [[noreturn]] (const std::string& fmt, Args... args) {
223219
safe.noreturn(Rf_errorcall)(R_NilValue, fmt.c_str(), args...);
224220
}
225221

226-
template <typename... Args>
227-
void warning(const char* fmt, Args... args) {
228-
safe[Rf_warningcall](R_NilValue, fmt, args...);
229-
}
222+
// Always making copy of string to avoid weird unwind behavior.
230223

231224
template <typename... Args>
232-
void warning(const std::string& fmt, Args... args) {
225+
void warning(const std::string fmt, Args... args) {
233226
safe[Rf_warningcall](R_NilValue, fmt.c_str(), args...);
234227
}
235228
#endif

0 commit comments

Comments
 (0)