You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2009/12/27 03:22:12 UTC

svn commit: r894043 - in /lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Core: Class.pm Method.pm

Author: marvin
Date: Sun Dec 27 02:22:11 2009
New Revision: 894043

URL: http://svn.apache.org/viewvc?rev=894043&view=rev
Log:
 Change Clownfish's method invocation syntax to require specific types as
 invocants instead of casting to "const void*" -- so that the C compiler will
 complain about pointer type mismatches.  (tighten_types.diff from LUCY-89)

Modified:
    lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Class.pm
    lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Method.pm

Modified: lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Class.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Class.pm?rev=894043&r1=894042&r2=894043&view=diff
==============================================================================
--- lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Class.pm (original)
+++ lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Class.pm Sun Dec 27 02:22:11 2009
@@ -182,7 +182,7 @@
     for my $method (@methods) {
         $method_defs .= Clownfish::Binding::Core::Method->method_def(
             method => $method,
-            cnick  => $cnick,
+            class  => $self->{client},
         ) . "\n";
     }
 

Modified: lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Method.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Method.pm?rev=894043&r1=894042&r2=894043&view=diff
==============================================================================
--- lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Method.pm (original)
+++ lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Method.pm Sun Dec 27 02:22:11 2009
@@ -7,21 +7,25 @@
 
 sub method_def {
     my ( undef,   %args )  = @_;
-    my ( $method, $cnick ) = @args{qw( method cnick )};
+    my ( $method, $class ) = @args{qw( method class )};
     confess("Not a Method")
         unless a_isa_b( $method, "Clownfish::Method" );
+    confess("Not a Class")
+        unless a_isa_b( $class, "Clownfish::Class" );
     if ( $method->final ) {
-        return _final_method_def( $method, $cnick );
+        return _final_method_def( $method, $class );
     }
     else {
-        return _virtual_method_def( $method, $cnick );
+        return _virtual_method_def( $method, $class );
     }
 }
 
 sub _virtual_method_def {
-    my ( $method, $cnick ) = @_;
+    my ( $method, $class ) = @_;
+    my $cnick           = $class->get_cnick;
     my $param_list      = $method->get_param_list;
-    my $struct_sym      = $method->self_type->get_specifier;
+    my $invoker_struct  = $class->full_struct_sym;
+    my $common_struct   = $method->self_type->get_specifier;
     my $full_method_sym = $method->full_method_sym($cnick);
     my $full_offset_sym = $method->full_offset_sym($cnick);
     my $typedef         = $method->full_typedef;
@@ -31,7 +35,7 @@
 
     # Prepare the parameter list for the inline function.
     my $params = $param_list->to_c;
-    $params =~ s/^.*?\*\s*\w+/const void *vself/
+    $params =~ s/^.*?\*\s*\w+/const $invoker_struct *self/
         or confess("no match: $params");
 
     # Prepare a return statement... or not.
@@ -43,10 +47,9 @@
 static CHY_INLINE $return_type
 $full_method_sym($params)
 {
-    $struct_sym *const self = ($struct_sym*)vself;
     char *const method_address = *(char**)self + $full_offset_sym;
     const $typedef method = *(($typedef*)method_address);
-    ${maybe_return}method($arg_names);
+    ${maybe_return}method(($common_struct*)$arg_names);
 }
 END_STUFF
 }
@@ -54,7 +57,8 @@
 # Create a macro definition that aliases to a function name directly, since
 # this method may not be overridden.
 sub _final_method_def {
-    my ( $method, $cnick ) = @_;
+    my ( $method, $class ) = @_;
+    my $cnick           = $class->get_cnick;
     my $macro_sym       = $method->get_macro_sym;
     my $self_type       = $method->self_type->to_c;
     my $full_method_sym = $method->full_method_sym($cnick);
@@ -294,7 +298,7 @@
 $return_type_str
 $full_func_sym($params)
 {
-    lucy_CharBuf *klass = self ? Lucy_Obj_Get_Class_Name(self) : $vtable->name;$unused
+    lucy_CharBuf *klass = self ? Lucy_Obj_Get_Class_Name((lucy_Obj*)self) : $vtable->name;$unused
     LUCY_THROW(LUCY_ERR, "Abstract method '$macro_sym' not defined by %o", klass);$ret_statement
 }
 END_ABSTRACT_DEF
@@ -321,7 +325,7 @@
 
     my $c_code = Clownfish::Binding::Core::Method->method_def(
         method => $method,
-        cnick  => 'LobClaw',
+        $class => $class,
     );
 
 Return C code for the static inline vtable method invocation function.  
@@ -330,9 +334,9 @@
 
 =item * B<method> - A L<Clownfish::Method>.
 
-=item * B<cnick> - The cnick for the class which will be invoking the method -
-i.e. LobsterClaw needs its own method invocation function even if the method
-was defined in Claw.
+=item * B<class> - The L<Clownfish::Class> which will be invoking the method -
+LobsterClaw needs its own method invocation function even if the method was
+defined in Claw.
 
 =back