Skip to content
Prev 56970 / 63424 Next

[External] undefined symbol errors when compiling package using ALTREP API

Hi Mark,

So depending pretty strongly on what you mean by "ALTREP aware", packages
aren't necessarily supposed to be ALTREP aware. What I mean by this is that
as of right now, ALTREP objects are designed to be interacted with by
non-ALTREP-implementing package code, *more-or-less *exactly as standard
(non-AR) SEXPs are: via the published C API. The more or less comes from
the fact that in some cases, doing things that are good ideas on standard
SEXPS will work, but may not be a good idea for ALTREPs.

The most "low-hanging-fruit" example of something that was best practice
for standard vectors but is not a good idea for ALTREP vectors is grabbing
a DATAPTR and iterating over the values without modification in a tight
loop.  This will work (absent allocation  failure or, I suppose, the ALTREP
being specifically designed to refuse to give you a full DATAPTR), but with
ALTREP in place its no longer what you want to do.

That said, you don't want to check whether something is an ALTREP yourself
and branch your code, what you want to do is use the ITERATE_BY_REGION
macro in R_ext/Itermacros.h for ALL SEXPs, which will be nearly as for
standard vectors and work safely for ALTREP vectors.

Basically any time you find yourself wanting to check if something is an
ALTREP and if so, call a specific ALT*_BLAH method, the intention is that
there should be a universal API point you can call which will work for both
types.

This is true, e.g., of INTEGER_IS_SORTED (which will always work and just
returns UNKNOWN_SORTEDNESS, ie INT_MIN, ie NA_INTEGER for non-ALTREPs).,
for REAL_GET_REGION, (which populates a double* with the requested values
for both standard and ALTREP REALSXPs), etc.

Does the above make sense?

If you feel a universal API point is missing, you can raise that here,
though I can't promise that will ultimately result in the method being
added.

Best,
~G
On Tue, Jun 4, 2019 at 2:22 PM Mark Klik <markklik at gmail.com> wrote: