[R] C API - no NULL pointer guarantee?

Ivan Krylov |kry|ov @end|ng |rom d|@root@org
Mon Jul 29 12:23:59 CEST 2024


В Sat, 27 Jul 2024 14:36:20 +0300
"Erez Shomron" <r-mails using erezsh.org> пишет:

> I'm working on bindings for the API (for zig), and was wondering if
> the R's C API guarantees it won't return null pointers? The only
> reference I found in the "Writing R Extensions" manual where this not
> the case is `R_tryEval` and `R_tryEvalSilent`.

Based on what I've been reading while working on (still very much
incomplete) <https://aitap.codeberg.page/R-api>, I think that these are
the only two cases where a SEXP can be null, precisely because a null
pointer is distinguished from every possible value that could be
returned by eval().

Some APIs may accept a null SEXP (with comments in the source code that
this is to support some legacy code, not the intended use), but when R
wants to return a value, it is always allocated through the memory
manager. A failing allocation will longjmp() away from the frame, not
return a null pointer.

It's hard to prove a negative, though.

-- 
Best regards,
Ivan



More information about the R-help mailing list