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/26 00:05:18 UTC
[lucy-commits] svn commit: r1074741 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/Hierarchy.pm src/CFCHierarchy.c src/CFCHierarchy.h
Author: marvin
Date: Fri Feb 25 23:05:17 2011
New Revision: 1074741
URL: http://svn.apache.org/viewvc?rev=1074741&view=rev
Log:
Move 'source' and 'dest' members of CFCHierarchy to C.
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=1074741&r1=1074740&r2=1074741&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Fri Feb 25 23:05:17 2011
@@ -561,10 +561,12 @@ PPCODE:
MODULE = Clownfish PACKAGE = Clownfish::Hierarchy
SV*
-_new(klass)
+_new(klass, source, dest)
const char *klass;
+ const char *source;
+ const char *dest;
CODE:
- CFCHierarchy *self = CFCHierarchy_new();
+ CFCHierarchy *self = CFCHierarchy_new(source, dest);
RETVAL = newRV(CFCBase_get_perl_obj((CFCBase*)self));
CFCBase_decref((CFCBase*)self);
OUTPUT: RETVAL
@@ -575,6 +577,29 @@ _destroy(self)
PPCODE:
CFCHierarchy_destroy(self);
+void
+_set_or_get(self, ...)
+ CFCHierarchy *self;
+ALIAS:
+ get_source = 2
+ get_dest = 4
+PPCODE:
+{
+ START_SET_OR_GET_SWITCH
+ case 2: {
+ const char *value = CFCHierarchy_get_source(self);
+ retval = newSVpv(value, strlen(value));
+ }
+ break;
+ case 4: {
+ const char *value = CFCHierarchy_get_dest(self);
+ retval = newSVpv(value, strlen(value));
+ }
+ break;
+ END_SET_OR_GET_SWITCH
+}
+
+
MODULE = Clownfish PACKAGE = Clownfish::Method
SV*
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm?rev=1074741&r1=1074740&r2=1074741&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm Fri Feb 25 23:05:17 2011
@@ -28,8 +28,6 @@ use Clownfish::Class;
use Clownfish::Parser;
# Inside-out member vars.
-our %source;
-our %dest;
our %parser;
our %trees;
our %files;
@@ -42,13 +40,8 @@ our %new_PARAMS = (
sub new {
my ( $either, %args ) = @_;
verify_args( \%new_PARAMS, %args ) or confess $@;
- for (qw( source dest)) {
- confess("Missing required param '$_'") unless $args{$_};
- }
my $package = ref($either) || $either;
- my $self = $package->_new();
- $source{$self} = $args{source};
- $dest{$self} = $args{dest};
+ my $self = $package->_new( @args{qw( source dest )} );
$parser{$self} = Clownfish::Parser->new;
$trees{$self} = {};
$files{$self} = {};
@@ -60,14 +53,10 @@ sub DESTROY {
delete $parser{$self};
delete $trees{$self};
delete $files{$self};
- delete $source{$self};
- delete $dest{$self};
$self->_destroy;
}
# Accessors.
-sub get_source { $source{ +shift } }
-sub get_dest { $dest{ +shift } }
sub _get_trees { $trees{ +shift } }
sub _get_files { $files{ +shift } }
sub _get_parser { $parser{ +shift } }
Modified: incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.c?rev=1074741&r1=1074740&r2=1074741&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.c Fri Feb 25 23:05:17 2011
@@ -26,25 +26,46 @@
struct CFCHierarchy {
CFCBase base;
+ char *source;
+ char *dest;
};
CFCHierarchy*
-CFCHierarchy_new(void)
+CFCHierarchy_new(const char *source, const char *dest)
{
CFCHierarchy *self = (CFCHierarchy*)CFCBase_allocate(sizeof(CFCHierarchy),
"Clownfish::Hierarchy");
- return CFCHierarchy_init(self);
+ return CFCHierarchy_init(self, source, dest);
}
CFCHierarchy*
-CFCHierarchy_init(CFCHierarchy *self)
+CFCHierarchy_init(CFCHierarchy *self, const char *source, const char *dest)
{
+ if (!source || !strlen(source) || !dest || !strlen(dest)) {
+ croak("Both 'source' and 'dest' are required");
+ }
+ self->source = CFCUtil_strdup(source);
+ self->dest = CFCUtil_strdup(dest);
return self;
}
void
CFCHierarchy_destroy(CFCHierarchy *self)
{
+ FREEMEM(self->source);
+ FREEMEM(self->dest);
CFCBase_destroy((CFCBase*)self);
}
+const char*
+CFCHierarchy_get_source(CFCHierarchy *self)
+{
+ return self->source;
+}
+
+const char*
+CFCHierarchy_get_dest(CFCHierarchy *self)
+{
+ return self->dest;
+}
+
Modified: incubator/lucy/trunk/clownfish/src/CFCHierarchy.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.h?rev=1074741&r1=1074740&r2=1074741&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.h Fri Feb 25 23:05:17 2011
@@ -20,13 +20,19 @@
typedef struct CFCHierarchy CFCHierarchy;
CFCHierarchy*
-CFCHierarchy_new(void);
+CFCHierarchy_new(const char *source, const char *dest);
CFCHierarchy*
-CFCHierarchy_init(CFCHierarchy *self);
+CFCHierarchy_init(CFCHierarchy *self, const char *source, const char *dest);
void
CFCHierarchy_destroy(CFCHierarchy *self);
+const char*
+CFCHierarchy_get_source(CFCHierarchy *self);
+
+const char*
+CFCHierarchy_get_dest(CFCHierarchy *self);
+
#endif /* H_CFCHIERARCHY */