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

Ensure we're not UNPROTECT()ing 'x' in gsumm #6306

Merged
merged 3 commits into from
Jul 25, 2024
Merged

Conversation

MichaelChirico
Copy link
Member

rchk is still throwing issues around here:

Function gmean
  [UP] allocating function gather may destroy its unprotected argument (x <arg 1>), which is later used. /rchk/packages/build/CaNpi0PW/data.table/src/gsumm.c:600
  [UP] calling allocating function gather with a fresh pointer (x <arg 1>) /rchk/packages/build/CaNpi0PW/data.table/src/gsumm.c:600
  [UP] unprotected variable x while calling allocating function Rf_allocVector /rchk/packages/build/CaNpi0PW/data.table/src/gsumm.c:601

The only thing I can think of is that the UNPROTECT() is applying to x, not as:

The protection mechanism is stack-based, so UNPROTECT(n) unprotects the last n objects which were protected.

IINM that means we have to keep as protected as long as x is? Or we have to clutter the code to do UNPROTECT(2) (x, as), followed immediately by PROTECT(x) to get it back under protection? Not even sure that will work, and probably not worth the clutter.

Copy link

github-actions bot commented Jul 21, 2024

Comparison Plot

Generated via commit 5c7527f

Download link for the artifact containing the test results: ↓ atime-results.zip

Time taken to finish the standard R installation steps: 11 minutes and 33 seconds

Time taken to run atime::atime_pkg on the tests: 3 minutes and 45 seconds

@ben-schwen
Copy link
Member

IINM that means we have to keep as protected as long as x is? Or we have to clutter the code to do UNPROTECT(2) (x, as), followed immediately by PROTECT(x) to get it back under protection? Not even sure that will work, and probably not worth the clutter.

That should work and apparently some packages are doing it that way.

https://github.com/search?q=org%3Acran+%2FUNPROTECT%5C%28%5B2-9%5D%2B%5C%29%3B%5Cs*PROTECT%5C%28%5Cw%2B%5C%29%3B%2F&type=code

@MichaelChirico
Copy link
Member Author

That should work and apparently some packages are doing it that way.

Nice find! Great that GitHub regex search works across lines. Applied here now, with comment.

@ben-schwen ben-schwen merged commit 1600b51 into master Jul 25, 2024
4 of 5 checks passed
@ben-schwen ben-schwen deleted the rchk-protect-stack branch July 25, 2024 08:22
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