On 10/14/06, Marvin Humphrey <[EMAIL PROTECTED]> wrote:

On Oct 13, 2006, at 6:42 AM, Peter Karman wrote:

> David Balmain scribbled on 10/13/06 1:21 AM:
>> I don't know how much of Ferret's binding code you've looked at but
>> you may have noticed a lot of my structs have a ref_cnt variable.
>> That
>> way, every time a struct gets wrapped in a ruby object, it's ref_cnt
>> is incremented. When the object goes out of scope and is garbage
>> collected the ref_cnt is decremented (and the object deleted if
>> ref_cnt = 0). I think as far as supporting multiple languages like we
>> are attempting to do with Lucy, this is the easiest way to go, since
>> it should work for all languages.

> fwiw, I have used the above approach in Perl myself. I just increm/
> decrem the refcnt in XS (Perl) space, in the DESTROY method.

I like this approach better, and I've now changed KinoSearch to use it.

One minor theoretical problem with subclassing.  Say you have a
struct that holds a TermDocs.

typedef struct lucy_SomeStruct {
     struct lucy_TermDocs *term_docs;
     /* ... */
} lucy_SomeStruct;

A Perl object created off of that has to take the class
"Lucy::Index::TermDocs", rather than "Lucy::Index::SegTermDocs" or
"Lucy::Index::MultiTermDocs".  That's not quite right.

/* This is an XS binding */
lucy_TermDocs*
get_term_docs(self)
     lucy_SomeStruct *self;
CODE:
     RETVAL = self->term_docs;
OUTPUT: RETVAL

However, you can only fake OOP so well with C, and this limitation
hasn't triggered any glitches yet.  We'll see what happens when I
port IndexReader, SegReader, and MultiReader to C -- they'll all
appear to be "IndexReader" from Perl-space.  Dunno if that will break
something.

It has worked fine for me. After all SegReader and MultiReader are
just implementations of IndexReader and the calling code shouldn't
ever need to know what it is calling as long as it implements the
IndexReader interface.

I also had to jettison a scheme I'd devised for generalizing object-
method callbacks to [your_language_here], but that might be for the
best. :)

That would be ambitious. :) I think we'll just have to define a list
of callbacks that each languages binding needs to implement.

Reply via email to