On 04/08/2014 18:09, Marvin Humphrey wrote:
Using a special value in `ref.count` such as -1 prevents us from caching a
host object in `ref.host_obj` and thus has the consequence that a Clownfish
object may be associated with multiple Perl objects during the course of its
lifetime. That means we need to account for the fact that the Perl-space
DESTROY may be called an arbitrary number of times for a given Clownfish
object.
[...]
So what I'm left with is the unsatisfying suggestion that Obj_make_immortal()
be implemented in Perl by caching a host object and setting its refcount to
half of the maximum. In the absence of additional refcounting bugs, that
yields immortality in practice. But if there are refcounting bugs, the
failure mode is bad: only long-running processes would be affected, making it
hard to reproduce.
Yes, the special refcount value would be lost as soon as a host object is
created. But we could use the second least significant bit of cfish_ref_t for
the immortal flag, regardless of whether it contains a refcount or a host
object. This would mean to mask the flag to zero whenever the host object is
accessed but that's a small price to pay.
Then we could check the flag in Obj#Destroy and throw an exception if it's set.
Nick