From lucyshannonhutchinson@example.org Thu May 01 05:59:00 2008
Return-Path: <lucyshannonhutchinson@example.org>
Delivered-To: shannonhutchinson@example.org
Received: (qmail 62937 invoked from network); 1 May 2008 05:58:57 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155)
  by minotaur.apache.org with SMTP; 1 May 2008 05:58:57 -0000
Received: (qmail 92000 invoked by uid 500); 1 May 2008 05:58:58 -0000
Delivered-To: shannonhutchinson@example.org
Received: (qmail 91985 invoked by uid 500); 1 May 2008 05:58:58 -0000
Mailing-List: contact shannonhutchinson@example.org; run by ezmlm
Precedence: bulk
List-Help: <mailto:shannonhutchinson@example.org>
List-Unsubscribe: <mailto:shannonhutchinson@example.org>
List-Post: <mailto:shannonhutchinson@example.org>
List-Id: <lucy-dev.lucene.apache.org>
Reply-To: shannonhutchinson@example.org
Delivered-To: mailing list shannonhutchinson@example.org
Received: (qmail 91974 invoked by uid 99); 1 May 2008 05:58:58 -0000
Received: from nike.apache.org (HELO nike.apache.org) (83.161.120.155)
    by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Apr 2008 22:58:58 -0700
X-ASF-Spam-Status: No, hits=-0.0 required=10.0
	tests=SPF_PASS
X-Spam-Check-By: apache.org
Received-SPF: pass (nike.apache.org: local policy)
Received: from [83.161.120.155] (HELO rectangular.com) (83.161.120.155)
    by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 May 2008 05:58:04 +0000
Received: from c-76-115-21-31.hsd1.or.comcast.net ([83.161.120.155] helo=[83.161.120.155])
	by rectangular.com with esmtpa (Exim 4.44)
	id 1JrRxg-000Kec-JL
	for shannonhutchinson@example.org; Wed, 30 Apr 2008 23:08:08 -0700
Message-Id: <shannonhutchinson@example.org>
From: Marvin Humphrey <shannonhutchinson@example.org>
To: shannonhutchinson@example.org
In-Reply-To: <shannonhutchinson@example.org>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (Apple Message framework v919.2)
Subject: Re: Native callbacks
Date: Wed, 30 Apr 2008 22:58:22 -0700
References: <shannonhutchinson@example.org> <shannonhutchinson@example.org> <shannonhutchinson@example.org>
X-Mailer: Apple Mail (2.919.2)
X-Virus-Checked: Checked by ClamAV on apache.org


On Apr 26, 2008, at 12:55 PM, Marvin Humphrey wrote:

> This isn't a truly hard problem. There are definitely many ways to  
> make this introspection data available using C.   But all the ways  
> I've thought of so far are ugly.

I've gotten this working.  On its own, it's mildly ugly -- not too bad.

Things are improving step by step. At first, you couldn't override  
anything.  Then you could implement abstract methods using the host  
language.  Now you can override public methods.

There's one significant problem left that I'm aware of: Perl's SUPER  
mechanism is broken with the vtable override.

Say you use the host language to override a method which was  
implemented in C.  The original binding invoked the implementing  
function via the vtable.  The override has now changed that vtable  
pointer to be a callback.  If you invoke SUPER from the subclass, it  
invokes the callback, which invokes the native method again, and you  
end up in an infinite loop.

   sub serialize {
      my ( $self, $outstream ) = @_;
      $self->SUPER888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4serialize($outstream); # BOOM! Infinite recursion.
      ...
   }

The solution, I believe, is to have the XS bindings not invoke via the  
vtable, but instead invoke the implementing function directly.   
Unfortunately, that means a lot more binding code, because each  
override requires its own binding.

Now:

    MODULE = KinoSearch   PACKAGE = KinoSearch888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4Index888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4PostingList

    chy_u32_t
    get_doc_num(self)
       kino_PostingList *self;
    CODE:
       RETVAL = Kino_PList_Get_Doc_Num(self);
    OUTPUT: RETVAL

Fixed:

    MODULE = KinoSearch   PACKAGE = KinoSearch888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4Index888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4PostingList

    chy_u32_t
    get_doc_num(self)
       kino_PostingList *self;
    CODE:
       RETVAL = kino_PList_get_doc_num(self);
    OUTPUT: RETVAL

    MODULE = KinoSearch   PACKAGE = KinoSearch888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4Index888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4SegPostingList

    chy_u32_t
    get_doc_num(self)
       kino_SegPostingList *self;
    CODE:
       RETVAL = kino_SegPList_get_doc_num(self);
    OUTPUT: RETVAL

    MODULE = KinoSearch   PACKAGE = KinoSearch888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4Index888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4MultiPostingList

    chy_u32_t
    get_doc_num(self)
       kino_MultiPostingList *self;
    CODE:
       RETVAL = kino_MultiPList_get_doc_num(self);
    OUTPUT: RETVAL

Fortunately, most of the binding code gets auto-generated these days,  
so once the auto-generation code gets patched the suffering will  
primarily take the form of slower compiles rather than increased  
maintenance costs.

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/



{'source': 'Apache Software Foundation Public Mail Archives'}