[Rd] Latent flaw in SEXPREC definition
peter dalgaard
pdalgd at gmail.com
Sun Aug 14 01:59:41 CEST 2011
On Aug 13, 2011, at 22:56 , Radford Neal wrote:
> There seems to be a latent flaw in the definition of struct SEXPREC
> in Rinternals.h, which likely doesn't cause problems now, but could
> if the relative sizes of data types changes.
>
> The SEXPREC structure contains a union that includes a primsxp,
> symsxp, etc, but not a vecsxp. However, in allocVector in memory.c,
> zero-length vectors are allocated using allocSExpNonCons, which
> appears to allocates a SEXPREC structure. This won't work if a vecsxp
> is larger than the other types that are in the union in the SEXPREC
> structure.
>
> Simply adding a vecsxp to the union would seem to fix this, as in
> the following patch:
But the whole point of separating VECTOR_SEXPREC from the other SEXPRECs is that they are _shorter_. A vecsxp is only going to be larger than (say) an envsxp if 2 R_len_t's are more than 3 pointers, which is quite unlikely since R_len_t variables holds things that one might add to pointers.
NOT having vecsxp in the SEXPREC union prevents programmers from mistakingly using SEXP* where VECSXP* should have been used. Since the distinction wasn't always there, I suspect that flagging usage of x->u.vecsxp.length by the compiler was rather important at some point in time.
>
> Index: src/include/Rinternals.h
> ===================================================================
> --- src/include/Rinternals.h (revision 56640)
> +++ src/include/Rinternals.h (working copy)
> @@ -219,6 +219,7 @@
> typedef struct SEXPREC {
> SEXPREC_HEADER;
> union {
> + struct vecsxp_struct vecsxp;
> struct primsxp_struct primsxp;
> struct symsxp_struct symsxp;
> struct listsxp_struct listsxp;
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
"Døden skal tape!" --- Nordahl Grieg
More information about the R-devel
mailing list