Skip to content

Another rchk issue to look into #445

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

Open
DavisVaughan opened this issue Jan 21, 2025 · 2 comments
Open

Another rchk issue to look into #445

DavisVaughan opened this issue Jan 21, 2025 · 2 comments

Comments

@DavisVaughan
Copy link
Member

Function cpp11::writable::r_vector<SEXPREC*>::r_vector(std::initializer_list<cpp11::named_arg>)::{lambda()#1}::operator()() const
  [UP] unprotected variable names while calling allocating function Rf_mkCharCE cpp11/include/cpp11/list.hpp:91

Function cpp11::writable::r_vector<cpp11::r_bool>::r_vector(std::initializer_list<cpp11::named_arg>)::{lambda()#1}::operator()() const
  [UP] unprotected variable names while calling allocating function Rf_mkCharCE cpp11/include/cpp11/r_vector.hpp:890

https://raw.githubusercontent.com/kalibera/cran-checks/master/rchk/results/adfExplorer.out
https://raw.githubusercontent.com/kalibera/cran-checks/master/rchk/results/cpp11bigwig.out

I believe it is saying we have an unprotected SEXP called names at the point that we call Rf_mkCharCE(). This is surely a false alarm, because Rf_setAttrib() protects names by installed it as an attribute on data_, but I guess we can try to work around it.

template <>
inline r_vector<SEXP>::r_vector(std::initializer_list<named_arg> il)
    : cpp11::r_vector<SEXP>(safe[Rf_allocVector](VECSXP, il.size())),
      capacity_(il.size()) {
  unwind_protect([&] {
    SEXP names = Rf_allocVector(STRSXP, capacity_);
    Rf_setAttrib(data_, R_NamesSymbol, names);

    auto it = il.begin();

    for (R_xlen_t i = 0; i < capacity_; ++i, ++it) {
      SEXP elt = it->value();
      set_elt(data_, i, elt);

      SEXP name = Rf_mkCharCE(it->name(), CE_UTF8);
      SET_STRING_ELT(names, i, name);
    }
  });
}
@pachadotdev
Copy link
Contributor

@DavisVaughan how about #457 ?

@krlmlr
Copy link
Member

krlmlr commented Jun 8, 2025

@kalibera: I'm seeing this with RSQLite and other packages. Do you agree that the early Rf_setAttrib() calls in https://github.com/r-lib/cpp11/blob/main/inst/include/cpp11/list.hpp#L83 protects the names variable? The set_elt() call is a simple SET_VECTOR_ELT(), and nothing else affects data_ (the owner of the protection)? Can you change rchk to stop flagging this as an error, or is it easier to work around (the fix by Mauricio is easy enough)? What would it take for a fix to appear on CRAN? Thanks!

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

No branches or pull requests

3 participants