Re: [Rd] Latent flaw in SEXPREC definition

From: peter dalgaard <pdalgd_at_gmail.com>
Date: Sun, 14 Aug 2011 01:59:41 +0200

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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sun 14 Aug 2011 - 00:57:56 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 14 Aug 2011 - 16:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive