Closed kevinushey closed 9 years ago
Hm, self reference in and of itself doesn't seem to cause R to crash. For example:
e <- new.env()
e$e <- e
object.size(e)
# 56 bytes
FWIW, pryr's version of object_size
works, and @hadley says it's more accurate than object.size
.
> pryr::object_size(np)
79.2 kB
I'll see if I can get a MRE without using R6.
Hm, it looks like the problem only happens when portable=FALSE
.
I think I've tracked down the problem - it's when an attribute refers to the original object. For example:
# This is OK
e <- new.env()
e$e <- e
object.size(e)
# 56 bytes
# Using attributes causes segfault
e <- new.env()
attr(e, "e") <- e
object.size(e)
# Segmentation fault
That was fast! Should we make a bug report / post on R-devel?
Sure, I can do it. Will you be able to work around this in RStudio? I believe the only attribute you need to watch out for in R6 objects is enclos_env
.
Yep, it should be possible to work around in RStudio.
If we really want to avoid bugs like this in RStudio, I think the IDE will need to switch to using lobstr...
@kevinushey Can we close this issue now?
Yes, I think so.
Sorry, I should add one more thing -- calling str(np)
itself also causes a recursion overflow; should R6 add a str.R6
method to avoid this?
If you want to use a buggy function (i.e. str()
), I think you have to live with the consequences (or report bugs upstream and hope they get fixed).
@kevinushey Good point. Although, even if I add a str.R6
method, this could still result in crashes in the case where someone uses class=FALSE
(where the environment doesn't have any classes attached to it). I'll see if I can do a different workaround so that the problem doesn't come up at all.
@kevinushey I decided to remove the attribute, because in the bug I filed, Luke Tierney said this: "Attributes on environments are always a bad idea. No matter how convenient they may seem, the implementation doesn't support them in a reasonable way."
So if you were thinking of adding a workaround to RStudio, it's not necessary anymore.
Repro:
gives a segfault from C stack overflow. Likely due to this being a self-referential object?
This is a problem for the IDE as we call
object.size()
when building the environment pane and so running the R6 examples crashes RStudio.