Skip to content
Prev 63017 / 63424 Next

R should add an API routine for safe use of memcpy(), memset() for use with 0-length SEXP

On 4/24/25 18:35, Michael Chirico wrote:
I would say not necessarily, and certainly no such decision has been 
made. Another option would be that it would eventually return a null 
pointer (as a data pointer to an empty vector), and holding such pointer 
is fine. One just cannot dereference it.
As above - it may not become an error at all. Also - this would be hard 
doing in isolation. Say that you as a package maintainer wanted to make 
sure that you never grab a data pointer to an empty vector. So you 
enable such a theoretical option. But your package has dependencies 
which may not necessarily want to be that strict, and may not work with 
such strict checking.

If you are decided you would never want to grab a data pointer to an 
empty vector in your package, you could create custom wrappers of the 
corresponding macros / functions that get the data pointer. But I 
wouldn't do even that, I think that wrappers of the R API make the code 
harder to read. One could still do it somehow only for testing. And 
certainly one could make sure that package tests also use extreme 
inputs, such as empty vectors. That would have the benefit of testing 
also other code, not just non-referencing of such pointers.

Best
Tomas