Skip to content

Suggestion to emphasize Rboolean is unrelated to LGLSXP in R-exts

1 message · Michael Chirico

#
Hello all,

The recent change (r87656) to make Rboolean map to type 'bool', not
'int', broke some tests & made me realize I've had totally the wrong
impression about what Rboolean actually is, and I suspect I'm not
alone.

Till now, I've assumed that like Rbyte --> RAWSXP, Rboolean is the
_correct_ storage type for LGLSXP, while idioms like int *ip =
LOGICAL(...) only "happened to work" because Rboolean masks int, which
could change at any time.

Actually, it turns out Rboolean only "happened to be int" because of
the use of 'enum', which is changing in now-and-future C standards!

We made that mistake in 9 places [1], though only one happened to
break tests. There are at least dozens of other cases on CRAN [2],[3].

Here's the current exposition on Rboolean in R-exts [4]:
I suggest embellishing this, perhaps like so:
It would also be nice if this mistake could be caught by the compiler,
but that's another issue.

Michael Chirico

[1] https://github.com/Rdatatable/data.table/pull/6782/files
[2] https://github.com/search?q=org%3Acran+%2FRboolean.*%5CbLOGICAL%2F&type=code
[3] https://github.com/search?q=org%3Acran+%2FLOGICAL.*sizeof%5B%28%5DRboolean%2F&type=code
[4] https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Mathematical-constants