From r|p|eybd @end|ng |rom |c|oud@com  Mon Feb  3 11:07:13 2025
From: r|p|eybd @end|ng |rom |c|oud@com (Prof Brian Ripley)
Date: Mon, 3 Feb 2025 10:07:13 +0000
Subject: [Rd] Suggestion to emphasize Rboolean is unrelated to LGLSXP in
 R-exts
In-Reply-To: <20250202185058.531317c2@Tarkus>
References: <CAPRVBcwA_j9=nPsjo272knqzK8Bdaoi6bgsGO+5YrKLhttHvDw@mail.gmail.com>
 <20250201123904.6fc253be@Tarkus> <20250202185058.531317c2@Tarkus>
Message-ID: <551e7875-03a3-4a94-99e5-751ac9c496f4@icloud.com>

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 at stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford



[Rd] Suggestion to emphasize Rboolean is unrelated to LGLSXP in R-exts
Prof Brian Ripley