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/01/23 21:38:20 UTC
[lucy-commits] svn commit: r1062523 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/Type.pm src/CFCType.c src/CFCType.h
Author: marvin
Date: Sun Jan 23 20:38:19 2011
New Revision: 1062523
URL: http://svn.apache.org/viewvc?rev=1062523&view=rev
Log:
Move the rest of Clownfish::Type's member variables to C.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm
incubator/lucy/trunk/clownfish/src/CFCType.c
incubator/lucy/trunk/clownfish/src/CFCType.h
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1062523&r1=1062522&r2=1062523&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Sun Jan 23 20:38:19 2011
@@ -51,24 +51,38 @@
MODULE = Clownfish PACKAGE = Clownfish::Type
SV*
-_new(klass, parcel, specifier, indirection, c_string)
+_new(klass, flags, parcel, specifier, indirection, c_string)
const char *klass;
+ int flags;
SV *parcel;
const char *specifier;
int indirection;
const char *c_string;
CODE:
- CFCType *self = CFCType_new(parcel, specifier, indirection, c_string);
+ CFCType *self = CFCType_new(flags, parcel, specifier, indirection,
+ c_string);
RETVAL = newSV(0);
sv_setref_pv(RETVAL, klass, (void*)self);
OUTPUT: RETVAL
void
-_destroy(self)
+DESTROY(self)
CFCType *self;
PPCODE:
CFCType_destroy(self);
+bool
+CONST(...)
+CODE:
+ RETVAL = CFCTYPE_CONST;
+OUTPUT: RETVAL
+
+bool
+NULLABLE(...)
+CODE:
+ RETVAL = CFCTYPE_NULLABLE;
+OUTPUT: RETVAL
+
void
_set_or_get(self, ...)
CFCType *self;
@@ -79,6 +93,9 @@ ALIAS:
get_indirection = 6
set_c_string = 7
to_c = 8
+ const = 10
+ set_nullable = 11
+ nullable = 12
PPCODE:
{
START_SET_OR_GET_SWITCH
@@ -103,6 +120,15 @@ PPCODE:
retval = newSVpvn(c_string, strlen(c_string));
}
break;
+ case 10:
+ retval = newSViv(CFCType_const(self));
+ break;
+ case 11:
+ CFCType_set_nullable(self, !!SvTRUE(ST(1)));
+ break;
+ case 12:
+ retval = newSViv(CFCType_nullable(self));
+ break;
END_SET_OR_GET_SWITCH
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm?rev=1062523&r1=1062522&r2=1062523&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm Sun Jan 23 20:38:19 2011
@@ -24,8 +24,6 @@ use Scalar::Util qw( blessed );
use Carp;
# Inside-out member vars.
-our %const;
-our %nullable;
our %new_PARAMS = (
const => undef,
@@ -42,6 +40,10 @@ sub new {
if $package eq __PACKAGE__;
verify_args( \%new_PARAMS, %args ) or confess $@;
+ my $flags = 0;
+ $flags |= CONST if $args{const};
+ $flags |= NULLABLE if $args{nullable};
+
my $parcel = $args{parcel};
if ( defined $parcel ) {
if ( !blessed($parcel) ) {
@@ -51,28 +53,14 @@ sub new {
unless $parcel->isa('Clownfish::Parcel');
}
- my $const = $args{const} || 0;
my $indirection = $args{indirection} || 0;
my $specifier = $args{specifier} || '';
my $c_string = $args{c_string} || '';
- my $self = $package->_new( $parcel, $specifier, $indirection, $c_string );
- $const{$self} = $const;
- return $self;
-}
-
-sub DESTROY {
- my $self = shift;
- delete $const{$self};
- delete $nullable{$self};
- _destroy($self);
+ return $package->_new( $flags, $parcel, $specifier, $indirection,
+ $c_string );
}
-sub const { $const{ +shift } }
-sub nullable { $nullable{ +shift } }
-
-sub set_nullable { $nullable{ $_[0] } = $_[1] }
-
sub is_object {0}
sub is_primitive {0}
sub is_integer {0}
Modified: incubator/lucy/trunk/clownfish/src/CFCType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.c?rev=1062523&r1=1062522&r2=1062523&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCType.c Sun Jan 23 20:38:19 2011
@@ -30,18 +30,20 @@ struct CFCType {
};
CFCType*
-CFCType_new(void *parcel, const char *specifier, int indirection,
+CFCType_new(int flags, void *parcel, const char *specifier, int indirection,
const char *c_string)
{
CFCType *self = (CFCType*)malloc(sizeof(CFCType));
if (!self) { croak("malloc failed"); }
- return CFCType_init(self, parcel, specifier, indirection, c_string);
+ return CFCType_init(self, flags, parcel, specifier, indirection,
+ c_string);
}
CFCType*
-CFCType_init(CFCType *self, void *parcel, const char *specifier,
+CFCType_init(CFCType *self, int flags, void *parcel, const char *specifier,
int indirection, const char *c_string)
{
+ self->flags = flags;
self->parcel = newSVsv((SV*)parcel);
self->specifier = savepv(specifier);
self->indirection = indirection;
@@ -96,3 +98,25 @@ CFCType_to_c(CFCType *self)
return self->c_string;
}
+int
+CFCType_const(CFCType *self)
+{
+ return !!(self->flags & CFCTYPE_CONST);
+}
+
+int
+CFCType_set_nullable(CFCType *self, int nullable)
+{
+ if (nullable) {
+ self->flags |= CFCTYPE_NULLABLE;
+ }
+ else {
+ self->flags &= ~CFCTYPE_NULLABLE;
+ }
+}
+
+int
+CFCType_nullable(CFCType *self)
+{
+ return !!(self->flags & CFCTYPE_NULLABLE);
+}
Modified: incubator/lucy/trunk/clownfish/src/CFCType.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.h?rev=1062523&r1=1062522&r2=1062523&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCType.h Sun Jan 23 20:38:19 2011
@@ -16,12 +16,15 @@
typedef struct CFCType CFCType;
+#define CFCTYPE_CONST 0x1
+#define CFCTYPE_NULLABLE 0x2
+
CFCType*
-CFCType_new(void *parcel, const char *specifier, int indirection,
+CFCType_new(int flags, void *parcel, const char *specifier, int indirection,
const char *c_string);
CFCType*
-CFCType_init(CFCType *self, void *parcel, const char *specifier,
+CFCType_init(CFCType *self, int flags, void *parcel, const char *specifier,
int indirection, const char *c_string);
void
@@ -45,3 +48,9 @@ CFCType_set_c_string(CFCType *self, cons
const char*
CFCType_to_c(CFCType *self);
+int
+CFCType_set_nullable(CFCType *self, int nullable);
+
+int
+CFCType_nullable(CFCType *self);
+