Skip to content

Conversation

@jangorecki
Copy link
Member

@jangorecki jangorecki commented Feb 4, 2019

#3301, some obvious DATAPTR to remove
@mattdowle check one inline comment

@mattdowle mattdowle mentioned this pull request Feb 4, 2019
12 tasks
@jangorecki jangorecki added this to the 1.12.2 milestone Feb 4, 2019
@jangorecki jangorecki requested a review from mattdowle February 4, 2019 12:08
Copy link
Member

@mattdowle mattdowle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHAR() is to access the char * part of CHARSXP. So it's inappropriate here. It may well just call DATAPTR and currently work, but without USE_RINTERNALS defined, R might check that it is only passed a CHARSXP. If not now, then probably in the future. And under stress-test conditions it could easily break (that test isn't enough of a stress test).
I've started to use STRING_PTR for this, when it's absolutely guaranteed that we are reading only. However, Luke warns that it's not strictly part of the API either. I've long understood that the issue is writing to the memory returned by STRING_PTR is strictly prohibited (that's behind the write-barrier). We must write using SET_STRING_ELT which looks after the increment and decrement references the strings in the global cache. For reading-only, Luke told me that in future STRING_PTR might be made available with a const return but even that could be abused by casting.
As the lines in this file show, it's very hard to get right and guarantee.
This usage of memcpy here to write to the STRSXP is definitely unsafe. According the comment looks like it came from memrecycle which I recently tidied up. I'll tidy it.

@mattdowle mattdowle changed the title remove DATAPTR, #3301 remove some DATAPTR Feb 4, 2019
@mattdowle mattdowle merged commit 110f76d into master Feb 4, 2019
@mattdowle mattdowle deleted the rbindlist-dataptr branch February 4, 2019 23:00
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