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

rchk error #408

Closed
NicChr opened this issue Dec 2, 2024 · 9 comments · Fixed by #409
Closed

rchk error #408

NicChr opened this issue Dec 2, 2024 · 9 comments · Fixed by #409

Comments

@NicChr
Copy link

NicChr commented Dec 2, 2024

Hi, I'm getting an rchk error and not sure if it relates to my code directly or something I can't fix on my side.
https://raw.githubusercontent.com/kalibera/cran-checks/master/rchk/results/fastplyr.out

Many thanks!

The error:

Function cpp11::writable::r_vector<SEXPREC*>::reserve_data(SEXPREC*, bool, long)
  [UP] calling allocating function cpp11::writable::r_vector<SEXPREC*>::resize_names(SEXPREC*, long) with a fresh pointer (names <arg 1>) cpp11/include/cpp11/r_vector.hpp:1329
@DavisVaughan
Copy link
Member

We've also seen this in one other package so I'll see what I can do
r-lib/archive@d1fca9d#diff-d0bd7e3af6adbdcc064b3bc426e211cc595cbe2c9627d2cf5f66a505c63c4ea7R1330-R1332

Nothing for you to do on your end, but thanks for reporting!

@pepijn-devries
Copy link

Hi there,

Has it been confirmed that this commit fixed the issue reported here? This commit is included in the latest release (0.5.1) which is also on CRAN. However, I'm still receiving similar rchk reports as reported here. See for instance:

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

Are these issues indeed related? Should this have been fixed by #409? Or is this something I need to fix myself?

@jayhesselberth
Copy link

#409 doesn't appear to have fixed the rchk issue, still being flagged in several packages:

https://cloud.r-project.org/web/checks/check_results_cpp11bigwig.html
https://cran.r-project.org/web/checks/check_results_tweenr.html

@jayhesselberth
Copy link

I wonder if it should be something like:

if (Rf_xlength(names) != size) {
  SEXP resized_names = PROTECT(resize_names(names, size));
  Rf_setAttrib(out, R_NamesSymbol, resized_names);
  UNPROTECT(1);
}

@jwood000
Copy link

I too am getting rchk issues:

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

I haven't submitted an update to my package yet, but I suspect they won't accept an update until this has been addressed.

I have addressed the rchk issue in my package (the 'Suspicious Call').

Thanks

@pepijn-devries
Copy link

@r-lib @DavisVaughan It looks like this issue needs to be reopened?

@jwood000
Copy link

I think the error message from rchk is pretty telling:

Function ... reserve_data ... calling allocating function ... resize_names

If we look at the current definition of reserve_data found here:

inline SEXP r_vector<T>::reserve_data(SEXP x, bool is_altrep, R_xlen_t size) {

We see the following code:

.
.
.
  // Resize names, if required
  // Protection seems needed to make rchk happy
  SEXP names = PROTECT(Rf_getAttrib(x, R_NamesSymbol));
  if (names != R_NilValue) {
    if (Rf_xlength(names) != size) {
      names = resize_names(names, size);
    }
    Rf_setAttrib(out, R_NamesSymbol, names);
  }
.
.
.

The problem line is names = resize_names(names, size);. We can rewrite the above as:

.
.
.
  // Resize names, if required
  // Protection seems needed to make rchk happy
  SEXP names = PROTECT(Rf_getAttrib(x, R_NamesSymbol));
  if (names != R_NilValue) {
    if (Rf_xlength(names) != size) {
      SEXP names_resized = PROTECT(resize_names(names, size));
      Rf_setAttrib(out, R_NamesSymbol, names_resized);
      UNPROTECT(1);
    } else {
      Rf_setAttrib(out, R_NamesSymbol, names);
    }
  }
.
.
.

@DavisVaughan
Copy link
Member

From what I can tell, every listed package did the rchk run on 2024-11-21

The cpp11 release was on 2024-12-04

The full message is

Function cpp11::writable::r_vector<SEXPREC*>::reserve_data(SEXPREC*, bool, long)
  [UP] calling allocating function cpp11::writable::r_vector<SEXPREC*>::resize_names(SEXPREC*, long) with a fresh pointer (names <arg 1>) cpp11/include/cpp11/r_vector.hpp:1329

The main problem being

with a fresh pointer (names <arg 1>)

Which is why the fix protects names.
https://github.com/r-lib/cpp11/pull/409/files

If anyone can reproduce with CRAN cpp11 and provide an easy way for me to reproduce as well, then we can reopen. But I think CRAN just hasn't rerun rchk on these packages.

@DavisVaughan
Copy link
Member

An exception is cpp11bigwig, run on 2025-01-09
https://raw.githubusercontent.com/kalibera/cran-checks/master/rchk/results/cpp11bigwig.out

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

That is a different issue from the one I tried to fix. I will open a different issue for that.

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 a pull request may close this issue.

5 participants