Justin Talbot
2013-Jan-09 04:44 UTC
[Rd] Bug in list subset assignment due to NAMED optimization
In R version 2.15.2 (2012-10-26) i386-apple-darwin9.8.0/i386 (32-bit) I get the following:> a <- list(1) > (a[[1]] <- a)[[1]] [[1]][[1]] [1] 1 but> a <- list(1) > b <- a > (a[[1]] <- a)[[1]] [1] 1 And similarly:> a <- list(x=1) > (a$x <- a)$x $x$x [1] 1 but> a <- list(x=1) > b <- a > (a$x <- a)$x [1] 1 In both cases the result of the first sequence is wrong. It's returning the updated `a` rather than the RHS of the assignment. The second sequence in both cases is correct; the assignment to `b` increments the NAMED value causing the necessary copy to be made so the RHS is returned from the assignment. Would it be sufficient to add a check to do_subassign2_dflt and do_subassign3_dflt that creates a duplicate of the LHS if the LHS & RHS are the same object? Justin [[alternative HTML version deleted]]
luke-tierney at uiowa.edu
2013-Jan-09 15:16 UTC
[Rd] Bug in list subset assignment due to NAMED optimization
On Tue, 8 Jan 2013, Justin Talbot wrote:> In R version 2.15.2 (2012-10-26) i386-apple-darwin9.8.0/i386 (32-bit) I get > the following: > >> a <- list(1) >> (a[[1]] <- a) > [[1]] > [[1]][[1]] > [1] 1 > > but > >> a <- list(1) >> b <- a >> (a[[1]] <- a) > [[1]] > [1] 1 > > And similarly: > >> a <- list(x=1) >> (a$x <- a) > $x > $x$x > [1] 1 > > but > >> a <- list(x=1) >> b <- a >> (a$x <- a) > $x > [1] 1 > > In both cases the result of the first sequence is wrong. It's returning the > updated `a` rather than the RHS of the assignment. The second sequence in > both cases is correct; the assignment to `b` increments the NAMED value > causing the necessary copy to be made so the RHS is returned from the > assignment. > > Would it be sufficient to add a check to do_subassign2_dflt > and do_subassign3_dflt that creates a duplicate of the LHS if the LHS & RHS > are the same object?Thanks -- that's probably the best fix but I want to think it thorugh a bit more before committing. Best, luke> > Justin > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics and Fax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: luke-tierney at uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
luke-tierney at uiowa.edu
2013-Jan-17 19:26 UTC
[Rd] Bug in list subset assignment due to NAMED optimization
Thanks for the report. This is now fixed in R-devel and R-patched by increasing NAMED on the RHS value to 2 when it is not 0. Best, luke On Tue, 8 Jan 2013, Justin Talbot wrote:> In R version 2.15.2 (2012-10-26) i386-apple-darwin9.8.0/i386 (32-bit) I get > the following: > >> a <- list(1) >> (a[[1]] <- a) > [[1]] > [[1]][[1]] > [1] 1 > > but > >> a <- list(1) >> b <- a >> (a[[1]] <- a) > [[1]] > [1] 1 > > And similarly: > >> a <- list(x=1) >> (a$x <- a) > $x > $x$x > [1] 1 > > but > >> a <- list(x=1) >> b <- a >> (a$x <- a) > $x > [1] 1 > > In both cases the result of the first sequence is wrong. It's returning the > updated `a` rather than the RHS of the assignment. The second sequence in > both cases is correct; the assignment to `b` increments the NAMED value > causing the necessary copy to be made so the RHS is returned from the > assignment. > > Would it be sufficient to add a check to do_subassign2_dflt > and do_subassign3_dflt that creates a duplicate of the LHS if the LHS & RHS > are the same object? > > Justin > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics and Fax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: luke-tierney at uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
Reasonably Related Threads
- Bug in out-of-bounds assignment of list object to expression() vector
- [External] Re: Bug in out-of-bounds assignment of list object to expression() vector
- Recycling memory with a small free list
- Bug in out-of-bounds assignment of list object to expression() vector
- Recycling memory with a small free list