lucy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marvin Humphrey <>
Subject Re: [lucy-dev] Non-deterministic destruction in Perl 5.15
Date Sat, 12 Nov 2011 02:44:01 GMT

I'm going to reply to the stuff that I know best first, then go study and
reply to the rest later.

On Fri, Nov 11, 2011 at 02:51:26PM -0800, wrote:
> >   void
> >   IxSearcher_destroy(IndexSearcher *self) {
> >       DECREF(self->reader);
> This seems to answer my question in the negative.
> From reading this code superficially, it looks as though the Searcher object
> has an internal (non-Perl) reference count on the reader. The Perl object
> will also have a reference count on the reader. That should prevent the
> reader from being destroyed before the searcher is.

Lucy objects gain and cache a Perl object (in self->ref.host_obj) as soon as
they are accessed from Perl-space, or as soon as their refcount reaches 4.
Once that happens, the Lucy object and its cached Perl object are linked for
life, and the Lucy object defers to the Perl object's refcount from that point

So that it's entirely possible that DECREF(self->reader) will end up invoking
SvREFCNT_dec() on self->reader->ref.host_obj.

> But you do seem to be implying that VTables need to be present for anything
> to work.  

That's right. 

This code...


... means "If self->reader is not NULL, invoke its RefCount_Dec() method".

Since Lucy's method dispatch mechanism is vtable-based, it would be bad if
self->reader's VTable member (located at self->reader->vtable) gets destroyed
before we invoke RefCount_Dec() on self->reader.

But really, VTables should never be destroyed at all.  The VTable objects for
all compiled classes in Lucy are allocated from static memory at compile-time
-- you really don't want to free() them!  Hence this tripwire in VTable.c,
which is the superficial cause of all of our Perl 5.15 CPAN Testers failures:

    VTable_destroy(VTable *self) {
        THROW(ERR, "Insane attempt to destroy VTable for class '%o'", self->name);

Marvin Humphrey

[1] Refcounting in Lucy is method-based, so some classes override this.

View raw message