You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ensure that HeldClass bound methods don't hit released memory.
HeldClass instances have a different lifetime than regular classes - things like
bound methods on them store a reference to them via pointer. This allows us to do things like
l = ListOf(SomeHeldClass)([...])
l[10].f()
and allow 'f' to modify the contents of the list in interepreted as well as compiled code,
even though the list is holding H as packed memory.
This is, of course, very dangerous! Such a reference will be invalidated by resizing the list,
for instance (really, anything that moves the memory), following the standard semantics of
C++.
However, we also had a bug where you could just write
SomeHeldClass().f()
and crash, because the intermediate 'f' was not holding SomeHeldClass() alive.
This change fixes this by doing two things:
(1) we ensure that bound methods keep the object being bound alive for the
duration of the instruction in the parent frame. This follows the same
semantic model we have for temporary 'refTo' instances
(2) we cause 'f' to keep the temporary alive, and then throw an exception if
we are the last refcount to the object alive.
0 commit comments