Skip to content
Prev 56704 / 63421 Next

Use of C++ in Packages

On 4/24/19 6:41 PM, Hugh Marera wrote:
I think the best way available now is manual inspection/review of the 
source code of the packages you are using for your critical work. Such 
review should cover more than just dangerous use of C++ - a lot of 
problems exist also in plain C code (using unexported API from R, 
violating value semantics of R, other kinds of PROTECT errors, memory 
leaks due to long jumps, etc). The review could be limited to the 
context of your pipeline, on how the package is used there and whether 
you have a reliable external process for validating the results.

Out of the problems I've mentioned in my blog, the worst for normal use 
of packages is probably a PROTECT error on the fast path due to 
allocation in a destructor or other function run automatically. Various 
memory leaks or correctness problems on error paths (long jumps) may not 
be a complete showstopper if you restart R often and if you have a 
reliable way of validating results, but such issues would still make it 
much harder to diagnose problems.

The simple steps may include looking at CRAN check results, if there 
were any errors, warnings, notes, reports from analyzers (valgrind, 
asan, ubsan, rchk). The analyzers _may_ be able to spot a PROTECT error 
due to allocation in a destructor if one is lucky (in the case I 
mentioned in the blog, there was an ASAN report), but I think manual 
inspection is needed, and it can also reveal other problems.

Tomas