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/02/19 22:52:01 UTC

[lucy-commits] svn commit: r1072450 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs lib/Clownfish/File.pm src/CFCFile.c src/CFCFile.h

Author: marvin
Date: Sat Feb 19 21:52:00 2011
New Revision: 1072450

URL: http://svn.apache.org/viewvc?rev=1072450&view=rev
Log:
Move 'source_class' and 'modified' members of CFCFile from Perl to C.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm
    incubator/lucy/trunk/clownfish/src/CFCFile.c
    incubator/lucy/trunk/clownfish/src/CFCFile.h

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1072450&r1=1072449&r2=1072450&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Sat Feb 19 21:52:00 2011
@@ -194,10 +194,11 @@ PPCODE:
 MODULE = Clownfish    PACKAGE = Clownfish::File
 
 SV*
-_new(klass)
+_new(klass, source_class)
     const char *klass;
+    const char *source_class;
 CODE:
-    CFCFile *self = CFCFile_new();
+    CFCFile *self = CFCFile_new(source_class);
     RETVAL = newRV(CFCBase_get_perl_obj((CFCBase*)self));
     CFCBase_decref((CFCBase*)self);
 OUTPUT: RETVAL
@@ -208,6 +209,29 @@ _destroy(self)
 PPCODE:
     CFCFile_destroy(self);
 
+void
+_set_or_get(self, ...)
+    CFCFile *self;
+ALIAS:
+    set_modified       = 1
+    get_modified       = 2
+    get_source_class   = 4
+PPCODE:
+{
+    START_SET_OR_GET_SWITCH
+        case 1: 
+            CFCFile_set_modified(self, !!SvTRUE(ST(1)));
+            break;
+        case 2: 
+            retval = newSViv(CFCFile_get_modified(self));
+            break;
+        case 4: {
+                const char *value = CFCFile_get_source_class(self);
+                retval = newSVpv(value, strlen(value));
+            }
+            break;
+    END_SET_OR_GET_SWITCH
+}
 
 MODULE = Clownfish    PACKAGE = Clownfish::Function
 

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm?rev=1072450&r1=1072449&r2=1072450&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm Sat Feb 19 21:52:00 2011
@@ -25,8 +25,6 @@ use Carp;
 
 # Inside out member vars.
 our %blocks;
-our %source_class;
-our %modified;
 
 our %new_PARAMS = (
     source_class => undef,
@@ -36,20 +34,14 @@ sub new {
     my ( $either, %args ) = @_;
     verify_args( \%new_PARAMS, %args ) or confess $@;
     my $package = ref($either) || $either;
-    my $self = $either->_new();
+    my $self = $either->_new($args{source_class});
     $blocks{$self} = [];
-    $source_class{$self} = $args{source_class};
-    $modified{$self} = 0;
-    confess("Missing required param 'source_class'")
-        unless $self->get_source_class;
     return $self;
 }
 
 sub DESTROY {
     my $self = shift;
     delete $blocks{$self};
-    delete $source_class{$self};
-    delete $modified{$self};
     $self->_destroy;
 }
 
@@ -67,10 +59,6 @@ sub add_block {
     push @{ $blocks{$self} }, $block;
 }
 
-sub get_modified     { $modified{ +shift } }
-sub set_modified     { $modified{ $_[0] } = $_[1] }
-sub get_source_class { $source_class{ +shift } }
-
 sub blocks { $blocks{ +shift } }
 
 sub classes {

Modified: incubator/lucy/trunk/clownfish/src/CFCFile.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCFile.c?rev=1072450&r1=1072449&r2=1072450&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCFile.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCFile.c Sat Feb 19 21:52:00 2011
@@ -19,6 +19,11 @@
 #include "perl.h"
 #include "XSUB.h"
 
+#ifndef true
+    #define true 1
+    #define false 0
+#endif
+
 #define CFC_NEED_BASE_STRUCT_DEF
 #include "CFCBase.h"
 #include "CFCFile.h"
@@ -26,25 +31,50 @@
 
 struct CFCFile {
     CFCBase base;
+    int modified;
+    char *source_class;
 };
 
 CFCFile*
-CFCFile_new(void)
+CFCFile_new(const char *source_class)
 {
+
     CFCFile *self = (CFCFile*)CFCBase_allocate(sizeof(CFCFile),
         "Clownfish::File");
-    return CFCFile_init(self);
+    return CFCFile_init(self, source_class);
 }
 
 CFCFile*
-CFCFile_init(CFCFile *self) 
+CFCFile_init(CFCFile *self, const char *source_class) 
 {
+    CFCUTIL_NULL_CHECK(source_class);
+    self->modified = false;
+    self->source_class = CFCUtil_strdup(source_class);
     return self;
 }
 
 void
 CFCFile_destroy(CFCFile *self)
 {
+    free(self->source_class);
     CFCBase_destroy((CFCBase*)self);
 }
 
+void
+CFCFile_set_modified(CFCFile *self, int modified)
+{
+    self->modified = !!modified;
+}
+
+int
+CFCFile_get_modified(CFCFile *self)
+{
+    return self->modified;
+}
+
+const char*
+CFCFile_get_source_class(CFCFile *self)
+{
+    return self->source_class;
+}
+

Modified: incubator/lucy/trunk/clownfish/src/CFCFile.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCFile.h?rev=1072450&r1=1072449&r2=1072450&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCFile.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCFile.h Sat Feb 19 21:52:00 2011
@@ -20,13 +20,22 @@
 typedef struct CFCFile CFCFile;
 
 CFCFile*
-CFCFile_new(void);
+CFCFile_new(const char *source_class);
 
 CFCFile*
-CFCFile_init(CFCFile *self);
+CFCFile_init(CFCFile *self, const char *source_class);
 
 void
 CFCFile_destroy(CFCFile *self);
 
+void
+CFCFile_set_modified(CFCFile *self, int modified);
+
+int
+CFCFile_get_modified(CFCFile *self);
+
+const char*
+CFCFile_get_source_class(CFCFile *self);
+
 #endif /* H_CFCFILE */