[Rd] Suggestion to emphasize Rboolean is unrelated to LGLSXP in R-exts
Prof Brian Ripley
r|p|eybd @end|ng |rom |c|oud@com
Mon Feb 3 11:07:13 CET 2025
On 02/02/2025 15:50, Ivan Krylov via R-devel wrote:
> The good news is that without a C23-enabled compiler, the problem will
> only happen to source files that #include <stdbool.h>. The bad news is
> that such a source file will technically disagree with the rest of R
> about the type of Rboolean, including the prototypes of the API
> functions that accept Rboolean:
>
> #include <stdbool.h>
> #include <Rinternals.h>
> typedef void (*pordervector1)(int *, int, SEXP, Rboolean, Rboolean);
> // ...
> pordervector1 f = R_orderVector1;
> f(pindx, length(indx), arg, nalast, decreasing);
>
> foo.c:27:17: runtime error: call to function R_orderVector1 through
> pointer to incorrect function type 'void (*)(int *, int, struct SEXPREC
> *, bool, bool)'
> /tmp/R-devel/src/main/sort.c:1135: note: R_orderVector1 defined here
> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior foo.c:27:17
>
> With sanitizers disabled, this doesn't seem to cause any real problems
> thanks to the calling convention, where both 'enum's and 'bool's are
> passed and returned in a register.
This is work in progress, and it was not intended to apply to R-devel
unless configured with --with-C23 or using a compiler (such as GCC
pre-15) that defaults to C23. We will back that out pending further
testing.
--
Brian D. Ripley, ripley using stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
More information about the R-devel
mailing list