lucy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marvin Humphrey <>
Subject [lucy-dev] Host overriding of all non-final methods
Date Thu, 03 Mar 2011 03:08:34 GMT

There's no good reason for it, but right now only methods which are tagged as
either "public" or "abstract" within Clownfish can be overridden from the host

This caused a problem in an application I was working on because we wanted to
override IndexSearcher's Top_Docs() method.  Since Top_Docs() is not yet 
public in Lucy, the attempt to override it from Perl fails silently: no
callback is installed.  Thus, when Searcher_Hits() invokes Top_Docs() from
C-space on our subclassed IndexSearcher, it gets the C function
IxSearcher_top_docs() rather than the Perl subroutine top_docs() from our 

The fix is to allow any non-final method to be overridden, regardless of its 
exposure.  Patch below.

For "final" methods, we have two options.  We can fail silently, as we do now.
In this case, there will be different behavior when a method is invoked from
the host (the illegal host override method fires) vs. when it is invoked from
within the Lucy core (the "final" method definition fires).

The other option is to throw an exception at runtime when an attempt to
override a final method is detected.  Dynamic VTable objects are built lazily,
so the error would occur the first time the constructor for the problematic
class gets invoked.

The rationale for this change is that method overrides should work the same way 
for both C-based classes and host-based classes: non-final methods should be
overridable from both C and the host.  There are no public API changes because
every public non-final method was already overridable; only non-public methods
will get a behavior change.  

Right this moment I'm feeling lazy, so inertia is favoring the first option for 
final methods, "fail silently." :)  Failing at runtime when illegal method
overriding from the host is detected isn't as friendly as failing at compile
time when an illegal override is found in a .cfh Clownfish header file, though.

Marvin Humphrey

Index: ../clownfish/lib/Clownfish/Binding/Core/
--- ../clownfish/lib/Clownfish/Binding/Core/    (revision 1075667)
+++ ../clownfish/lib/Clownfish/Binding/Core/    (working copy)
@@ -326,7 +326,7 @@
         # Define callbacks for methods that can be overridden via the 
         # host.
-        if ( $method->public or $method->abstract ) { 
+        if ( !$method->final ) { 
             my $callback_sym = $method->full_callback_sym;
             if ( $novel{ $method->micro_sym } ) { 

View raw message