Skip to content

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

Open
krlmlr wants to merge 12 commits into
b-warning-copyfrom
claude/b-warning-copy-42ve6t
Open

fix: Copy strings before calling Rf_warningcall() to avoid weird unwind behavior#4
krlmlr wants to merge 12 commits into
b-warning-copyfrom
claude/b-warning-copy-42ve6t

Conversation

@krlmlr

@krlmlr krlmlr commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Patch b-warning-copy of the stack.

cpp11::warning() can unwind, and an R warning may be caught and turned into an error, so control need not return through the call. The overloads taking const char* and const std::string& both left the caller owning the storage the message was read from, which is not safe across that unwind.

Taking the format argument by value — const std::string rather than const std::string& — makes warning() hold its own copy. The const char* overloads go away; a string literal converts to std::string implicitly, so callers are unaffected.

Both the CPP11_USE_FMT and the plain branch are changed the same way.

Rebase note

This one conflicted on the rebase onto the current main, entirely because upstream reformatted the file with Air and moved these overloads. Reapplied by hand against the reformatted source; the change itself is unchanged from the original b-warning-copy.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K8MneV8KqHYUuC8fWV3X5Q


Generated by Claude Code

DavisVaughan and others added 12 commits April 3, 2026 13:09
* Don't rely on transitive include of `"fmt/core.h"`

We got it through `cpp11/protect.hpp`, but we should not rely on that

* Correctly use `fmt::runtime()` on runtime strings passed to `fmt::format()`

In fmt, there is a `FMT_CONSTEVAL` macro that resolves to `consteval` on "new enough" C++ (otherwise it doesn't do anything). For R 4.6+, the default C++ used is finally "new enough" (`__cplusplus > 201703L`).

This causes all `fmt::format()` calls to require a constant expression for `const char*` and `std::string&` input, which we are not currently doing via `fmt_arg`.

We have a runtime provided string, which must now be wrapped in `fmt::runtime()`, which is what we should have been doing all along.

* Add `r_ns_env()` and use in `get_namespace()`

Throwing an informative (and tested!) error when we can't find the package namespace

* Define `RCPP_NO_R_HEADERS_CHECK` before all `#include <Rcpp.h>` usage

`#include <cpp11/R.hpp>` sets everything up the right way, and otherwise we get a warning from Rcpp which doesn't seem to end up being relevant for this use case

* Use `r_env_has()` + `r_env_get()`

To avoid triggering a NOTE about usage of `Rf_findVarInFrame3()` on R 4.5, where technically we had the tools to avoid that
* Teach `cpp_source()` how to source multiple files

* NEWS bullet

* Link to PR
…violations (r-lib#493)

* Add failing test

* Use tag types to generate attribute specific internals

* NEWS bullet

* Formatting
* Update `cran-comments.md`

* Increment version number to 0.5.5
@krlmlr
krlmlr changed the base branch from main to claude/main-42ve6t August 17, 2026 21:12
@krlmlr
krlmlr changed the base branch from claude/main-42ve6t to b-warning-copy August 17, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants