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 2011/03/05 22:47:41 UTC

[lucy-commits] svn commit: r1078368 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs lib/Clownfish/Hierarchy.pm src/CFCHierarchy.c src/CFCHierarchy.h

Author: marvin
Date: Sat Mar  5 21:47:40 2011
New Revision: 1078368

URL: http://svn.apache.org/viewvc?rev=1078368&view=rev
Log:
Move parser storage within Clownfish::Hierarchy from inside-out Perl to C
struct member.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
    incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
    incubator/lucy/trunk/clownfish/src/CFCHierarchy.h

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1078368&r1=1078367&r2=1078368&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Sat Mar  5 21:47:40 2011
@@ -709,18 +709,19 @@ PPCODE:
 MODULE = Clownfish    PACKAGE = Clownfish::Hierarchy
 
 SV*
-_new(klass, source, dest)
+_new(klass, source, dest, parser)
     const char *klass;
     const char *source;
     const char *dest;
+    SV *parser;
 CODE:
-    CFCHierarchy *self = CFCHierarchy_new(source, dest);
+    CFCHierarchy *self = CFCHierarchy_new(source, dest, parser);
     RETVAL = S_cfcbase_to_perlref(self);
     CFCBase_decref((CFCBase*)self);
 OUTPUT: RETVAL
 
 void
-_destroy(self)
+DESTROY(self)
     CFCHierarchy *self;
 PPCODE:
     CFCHierarchy_destroy(self);
@@ -734,14 +735,12 @@ CODE:
 OUTPUT: RETVAL
 
 SV*
-_parse_file(self, parser, content, source_class)
+_parse_file(self, content, source_class)
     CFCHierarchy *self;
-    SV *parser;
     const char *content;
     const char *source_class;
 CODE:
-    CFCFile *file = CFCHierarchy_parse_file(self, parser, content,
-        source_class);
+    CFCFile *file = CFCHierarchy_parse_file(self, content, source_class);
     RETVAL = S_cfcbase_to_perlref(file);
 OUTPUT: RETVAL
 

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm?rev=1078368&r1=1078367&r2=1078368&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm Sat Mar  5 21:47:40 2011
@@ -27,9 +27,6 @@ use Clownfish::Util qw( slurp_file curre
 use Clownfish::Class;
 use Clownfish::Parser;
 
-# Inside-out member vars.
-our %parser;
-
 our %new_PARAMS = (
     source => undef,
     dest   => undef,
@@ -39,20 +36,10 @@ sub new {
     my ( $either, %args ) = @_;
     verify_args( \%new_PARAMS, %args ) or confess $@;
     my $package = ref($either) || $either;
-    my $self = $package->_new( @args{qw( source dest )} );
-    $parser{$self} = Clownfish::Parser->new;
-    return $self;
+    my $parser = Clownfish::Parser->new;
+    return $package->_new( @args{qw( source dest )}, $parser );
 }
 
-sub DESTROY {
-    my $self = shift;
-    delete $parser{$self};
-    $self->_destroy;
-}
-
-# Accessors.
-sub _get_parser { $parser{ +shift } }
-
 # Slurp all Clownfish header files.
 # Arrange the class objects into inheritance trees.
 sub build {
@@ -98,8 +85,7 @@ sub _parse_cf_files {
 
         # Slurp, parse, add parsed file to pool.
         my $content = slurp_file($source_path);
-        my $file = $self->_parse_file( $self->_get_parser, $content,
-            $source_class );
+        my $file = $self->_parse_file( $content, $source_class );
         confess("parse error for $source_path")
             unless a_isa_b( $file, "Clownfish::File" );
         $self->_add_file($file);

Modified: incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.c?rev=1078368&r1=1078367&r2=1078368&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.c Sat Mar  5 21:47:40 2011
@@ -36,6 +36,7 @@ struct CFCHierarchy {
     CFCBase base;
     char *source;
     char *dest;
+    void *parser;
     CFCClass **trees;
     size_t num_trees;
     CFCFile **files;
@@ -47,15 +48,16 @@ int
 S_do_propagate_modified(CFCHierarchy *self, CFCClass *klass, int modified);
 
 CFCHierarchy*
-CFCHierarchy_new(const char *source, const char *dest)
+CFCHierarchy_new(const char *source, const char *dest, void *parser)
 {
     CFCHierarchy *self = (CFCHierarchy*)CFCBase_allocate(sizeof(CFCHierarchy),
         "Clownfish::Hierarchy");
-    return CFCHierarchy_init(self, source, dest);
+    return CFCHierarchy_init(self, source, dest, parser);
 }
 
 CFCHierarchy*
-CFCHierarchy_init(CFCHierarchy *self, const char *source, const char *dest) 
+CFCHierarchy_init(CFCHierarchy *self, const char *source, const char *dest,
+                  void *parser) 
 {
     if (!source || !strlen(source) || !dest || !strlen(dest)) {
         croak("Both 'source' and 'dest' are required");
@@ -66,6 +68,7 @@ CFCHierarchy_init(CFCHierarchy *self, co
     self->num_trees = 0;
     self->files     = (CFCFile**)CALLOCATE(1, sizeof(CFCFile*));
     self->num_files = 0;
+    self->parser    = newSVsv((SV*)parser);
     return self;
 }
 
@@ -83,18 +86,19 @@ CFCHierarchy_destroy(CFCHierarchy *self)
     FREEMEM(self->files);
     FREEMEM(self->source);
     FREEMEM(self->dest);
+    SvREFCNT_dec((SV*)self->parser);
     CFCBase_destroy((CFCBase*)self);
 }
 
 CFCFile*
-CFCHierarchy_parse_file(CFCHierarchy *self, void *parser, 
-                        const char *content, const char *source_class)
+CFCHierarchy_parse_file(CFCHierarchy *self, const char *content, 
+                        const char *source_class)
 {
     dSP;
     ENTER;
     SAVETMPS;
     PUSHMARK(SP);
-    XPUSHs(sv_2mortal(newSVsv((SV*)parser)));
+    XPUSHs(sv_2mortal(newSVsv((SV*)self->parser)));
     XPUSHs(sv_2mortal(newSVpvn(content, strlen(content))));
     XPUSHs(sv_2mortal(newSVpvn(source_class, strlen(source_class))));
     PUTBACK;

Modified: incubator/lucy/trunk/clownfish/src/CFCHierarchy.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.h?rev=1078368&r1=1078367&r2=1078368&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.h Sat Mar  5 21:47:40 2011
@@ -26,17 +26,18 @@ struct CFCClass;
 struct CFCFile;
 
 CFCHierarchy*
-CFCHierarchy_new(const char *source, const char *dest);
+CFCHierarchy_new(const char *source, const char *dest, void *parser);
 
 CFCHierarchy*
-CFCHierarchy_init(CFCHierarchy *self, const char *source, const char *dest);
+CFCHierarchy_init(CFCHierarchy *self, const char *source, const char *dest, 
+                  void *parser);
 
 void
 CFCHierarchy_destroy(CFCHierarchy *self);
 
 struct CFCFile*
-CFCHierarchy_parse_file(CFCHierarchy *self, void *parser, 
-                        const char *content, const char *source_class);
+CFCHierarchy_parse_file(CFCHierarchy *self, const char *content, 
+                        const char *source_class);
 
 int
 CFCHierarchy_propagate_modified(CFCHierarchy *self, int modified);