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/07/10 06:14:49 UTC

[lucy-commits] svn commit: r1144771 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs lib/Clownfish/Binding/Core.pm src/CFCBindCore.c src/CFCBindCore.h

Author: marvin
Date: Sun Jul 10 04:14:49 2011
New Revision: 1144771

URL: http://svn.apache.org/viewvc?rev=1144771&view=rev
Log:
Move member vars for CFCBindCore from Perl to C.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core.pm
    incubator/lucy/trunk/clownfish/src/CFCBindCore.c
    incubator/lucy/trunk/clownfish/src/CFCBindCore.h

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1144771&r1=1144770&r2=1144771&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Sun Jul 10 04:14:49 2011
@@ -1707,19 +1707,57 @@ PPCODE:
 MODULE = Clownfish   PACKAGE = Clownfish::Binding::Core
 
 SV*
-_new()
+_new(hierarchy, dest, header, footer)
+    CFCHierarchy *hierarchy;
+    const char   *dest;
+    const char   *header;
+    const char   *footer;
 CODE:
-    CFCBindCore *self = CFCBindCore_new();
+    CFCBindCore *self = CFCBindCore_new(hierarchy, dest, header, footer);
     RETVAL = S_cfcbase_to_perlref(self);
     CFCBase_decref((CFCBase*)self);
 OUTPUT: RETVAL
 
 void
-_destroy(self);
+DESTROY(self);
     CFCBindCore *self;
 PPCODE:
     CFCBindCore_destroy(self);
 
+void
+_set_or_get(self, ...)
+    CFCBindCore *self;
+ALIAS:
+    _get_hierarchy    = 2
+    _get_dest         = 4
+    _get_header       = 6
+    _get_footer       = 8
+PPCODE:
+{
+    START_SET_OR_GET_SWITCH
+        case 2: {
+                CFCHierarchy *hierarchy = CFCBindCore_get_hierarchy(self);
+                retval = S_cfcbase_to_perlref(hierarchy);
+            }
+            break;
+        case 4: {
+                const char *value = CFCBindCore_get_dest(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 6: {
+                const char *value = CFCBindCore_get_header(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 8: {
+                const char *value = CFCBindCore_get_footer(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+    END_SET_OR_GET_SWITCH
+}
+
 
 MODULE = Clownfish   PACKAGE = Clownfish::Binding::Core::Function
 

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core.pm?rev=1144771&r1=1144770&r2=1144771&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core.pm Sun Jul 10 04:14:49 2011
@@ -17,7 +17,7 @@ use strict;
 use warnings;
 
 package Clownfish::Binding::Core;
-use Clownfish::Util qw( a_isa_b verify_args );
+use Clownfish::Util qw( verify_args );
 use Clownfish::Binding::Core::Function;
 use Clownfish::Binding::Core::Method;
 use Clownfish::Binding::Core::Class;
@@ -42,35 +42,9 @@ our %footer;
 sub new {
     my ( $either, %args ) = @_;
     verify_args( \%new_PARAMS, %args ) or confess $@;
-    for ( keys %new_PARAMS ) {
-        confess("Missing required param '$_'") unless defined $args{$_};
-    }
-    confess("Not a Hierarchy")
-        unless a_isa_b( $args{hierarchy}, "Clownfish::Hierarchy" );
-
-    my $self = _new();
-    $hierarchy{$self} = $args{hierarchy};
-    $dest{$self}      = $args{dest};
-    $header{$self}    = $args{header};
-    $footer{$self}    = $args{footer};
-
-    return $self;
+    return _new( @args{qw( hierarchy dest header footer )} );
 }
 
-sub DESTROY {
-    my $self = shift;
-    delete $hierarchy{$self};
-    delete $dest{$self};
-    delete $header{$self};
-    delete $footer{$self};
-    _destroy($self);
-}
-
-sub _get_hierarchy { $hierarchy{ +shift } }
-sub _get_dest      { $dest{ +shift } }
-sub _get_header    { $header{ +shift } }
-sub _get_footer    { $footer{ +shift } }
-
 sub write_all_modified {
     my ( $self, $modified ) = @_;
     my $hierarchy = $self->_get_hierarchy;

Modified: incubator/lucy/trunk/clownfish/src/CFCBindCore.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCBindCore.c?rev=1144771&r1=1144770&r2=1144771&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCBindCore.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCBindCore.c Sun Jul 10 04:14:49 2011
@@ -17,27 +17,66 @@
 #define CFC_NEED_BASE_STRUCT_DEF
 #include "CFCBase.h"
 #include "CFCBindCore.h"
+#include "CFCHierarchy.h"
 #include "CFCUtil.h"
 
 struct CFCBindCore {
     CFCBase base;
+    CFCHierarchy *hierarchy;
+    char         *dest;
+    char         *header;
+    char         *footer;
 };
 
 CFCBindCore*
-CFCBindCore_new(void) {
+CFCBindCore_new(CFCHierarchy *hierarchy, const char *dest, const char *header, 
+                const char *footer) {
     CFCBindCore *self
         = (CFCBindCore*)CFCBase_allocate(sizeof(CFCBindCore),
                                          "Clownfish::Binding::Core");
-    return CFCBindCore_init(self);
+    return CFCBindCore_init(self, hierarchy, dest, header, footer);
 }
 
 CFCBindCore*
-CFCBindCore_init(CFCBindCore *self) {
+CFCBindCore_init(CFCBindCore *self, CFCHierarchy *hierarchy, const char *dest,
+                 const char *header, const char *footer) {
+    CFCUTIL_NULL_CHECK(hierarchy);
+    CFCUTIL_NULL_CHECK(dest);
+    CFCUTIL_NULL_CHECK(header);
+    CFCUTIL_NULL_CHECK(footer);
+    self->hierarchy = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy);
+    self->dest      = CFCUtil_strdup(dest);
+    self->header    = CFCUtil_strdup(header);
+    self->footer    = CFCUtil_strdup(footer);
     return self;
 }
 
 void
 CFCBindCore_destroy(CFCBindCore *self) {
+    CFCBase_decref((CFCBase*)self->hierarchy);
+    FREEMEM(self->dest);
+    FREEMEM(self->header);
+    FREEMEM(self->footer);
     CFCBase_destroy((CFCBase*)self);
 }
 
+CFCHierarchy*
+CFCBindCore_get_hierarchy(CFCBindCore *self) {
+    return self->hierarchy;
+}
+
+const char*
+CFCBindCore_get_dest(CFCBindCore *self) {
+    return self->dest;
+}
+
+const char*
+CFCBindCore_get_header(CFCBindCore *self) {
+    return self->header;
+}
+
+const char*
+CFCBindCore_get_footer(CFCBindCore *self) {
+    return self->footer;
+}
+

Modified: incubator/lucy/trunk/clownfish/src/CFCBindCore.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCBindCore.h?rev=1144771&r1=1144770&r2=1144771&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCBindCore.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCBindCore.h Sun Jul 10 04:14:49 2011
@@ -22,16 +22,31 @@ extern "C" {
 #endif
 
 typedef struct CFCBindCore CFCBindCore;
+struct CFCHierarchy;
 
 CFCBindCore*
-CFCBindCore_new(void);
+CFCBindCore_new(struct CFCHierarchy *hierarchy, const char *dest,
+                 const char *header, const char *footer);
 
 CFCBindCore*
-CFCBindCore_init(CFCBindCore *self);
+CFCBindCore_init(CFCBindCore *self, struct CFCHierarchy *hierarchy,
+                 const char *dest, const char *header, const char *footer);
 
 void
 CFCBindCore_destroy(CFCBindCore *self);
 
+struct CFCHierarchy*
+CFCBindCore_get_hierarchy(CFCBindCore *self);
+
+const char*
+CFCBindCore_get_dest(CFCBindCore *self);
+
+const char*
+CFCBindCore_get_header(CFCBindCore *self);
+
+const char*
+CFCBindCore_get_footer(CFCBindCore *self);
+
 #ifdef __cplusplus
 }
 #endif