[Rd] v3 serialization of compact_intseq altrep should write modified data

Michael Sannella m@@nnell @ending from tibco@com
Mon Oct 22 21:52:53 CEST 2018


Experimenting with altrep objects and v3 serialization, I discovered a
possible bug.  Calling DATAPTR on a compact_intseq object returns a
pointer to the expanded integer sequence in memory.  If you modify
this data, the object values appear to be changed.  However, if the
compact_intseq object is then serialized (with version=3), only the
original integer sequence info is written.

For example, suppose I have compiled and loaded the following C code:
  SEXP set_intseq_data(SEXP x)
  {
      void* ptr = DATAPTR(x);
      ((int*)ptr)[3] = 1234;
      return R_NilValue;
  }

I see the following behavior in R 3.5.1:
  > x <- 1:10
  > x
   [1]  1  2  3  4  5  6  7  8  9 10
  > .Call("set_intseq_data", x)
  NULL
  > x
   [1]    1    2    3 1234    5    6    7    8    9   10
  > save(x, file="temp.rda", version=3)
  > load(file="temp.rda")
  > x
   [1]  1  2  3  4  5  6  7  8  9 10
  >

I would have expected the modified vector data to be serialized to the
file, and be restored when it is loaded.

  ~~ Michael Sannella

	[[alternative HTML version deleted]]



More information about the R-devel mailing list