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 04:56:58 UTC

[lucy-commits] svn commit: r1062317 - in /incubator/lucy/trunk/clownfish: Build.PL include/CFC.h lib/Clownfish.pm lib/Clownfish.xs lib/Clownfish/Type.pm src/CFCType.c src/CFCType.h typemap

Author: marvin
Date: Sun Jan 23 03:56:58 2011
New Revision: 1062317

URL: http://svn.apache.org/viewvc?rev=1062317&view=rev
Log:
Make Clownfish::Type an XS class and introduce stub C files.

Added:
    incubator/lucy/trunk/clownfish/include/CFC.h
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/src/CFCType.c
    incubator/lucy/trunk/clownfish/src/CFCType.h
    incubator/lucy/trunk/clownfish/typemap
Modified:
    incubator/lucy/trunk/clownfish/Build.PL
    incubator/lucy/trunk/clownfish/lib/Clownfish.pm
    incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm

Modified: incubator/lucy/trunk/clownfish/Build.PL
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/Build.PL?rev=1062317&r1=1062316&r2=1062317&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/Build.PL (original)
+++ incubator/lucy/trunk/clownfish/Build.PL Sun Jan 23 03:56:58 2011
@@ -23,13 +23,15 @@ my $builder = Module::Build->new(
     license     => 'apache',
     dist_author =>
         'The Apache Lucy Project <lucy-dev at incubator dot apache dot org>',
-    dist_version   => '0.001',
+    dist_version_from => 'lib/Clownfish.pm',
     requires       => { 'Parse::RecDescent' => 0, },
     build_requires => {
         'ExtUtils::CBuilder' => 0.18,
         'ExtUtils::ParseXS'  => 2.16,
         'Devel::PPPort'      => 3.13,
     },
+    include_dirs   => 'include',
+    c_source       => 'src',
     add_to_cleanup => [
         qw(
             MANIFEST.bak

Added: incubator/lucy/trunk/clownfish/include/CFC.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/include/CFC.h?rev=1062317&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/include/CFC.h (added)
+++ incubator/lucy/trunk/clownfish/include/CFC.h Sun Jan 23 03:56:58 2011
@@ -0,0 +1,2 @@
+#include "CFCType.h"
+

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.pm?rev=1062317&r1=1062316&r2=1062317&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.pm Sun Jan 23 03:56:58 2011
@@ -19,6 +19,9 @@ use warnings;
 package Clownfish;
 our $VERSION = '0.01';
 
+use XSLoader;
+BEGIN { XSLoader::load( 'Clownfish', '0.01' ) } 
+
 1;
 
 =head1 NAME

Added: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1062317&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (added)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Sun Jan 23 03:56:58 2011
@@ -0,0 +1,23 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#include "CFC.h"
+
+MODULE = Clownfish    PACKAGE = Clownfish::Type
+
+SV*
+_new(klass)
+    const char *klass;
+CODE:
+    CFCType *self = CFCType_new();
+    RETVAL = newSV(0);
+	sv_setref_pv(RETVAL, klass, (void*)self);
+OUTPUT: RETVAL
+
+void
+_destroy(self)
+    CFCType *self;
+PPCODE:
+    CFCType_destroy(self);
+

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm?rev=1062317&r1=1062316&r2=1062317&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm Sun Jan 23 03:56:58 2011
@@ -17,6 +17,7 @@ use strict;
 use warnings;
 
 package Clownfish::Type;
+use Clownfish;
 use Clownfish::Parcel;
 use Clownfish::Util qw( verify_args );
 use Scalar::Util qw( blessed );
@@ -44,8 +45,7 @@ sub new {
     confess( __PACKAGE__ . "is an abstract class" )
         if $package eq __PACKAGE__;
     verify_args( \%new_PARAMS, %args ) or confess $@;
-    my $blank = '';
-    my $self = bless \$blank, $package;
+    my $self = $package->_new();
 
     my $parcel = $args{parcel};
     if ( defined $parcel ) {
@@ -73,6 +73,7 @@ sub DESTROY {
     delete $indirection{$self};
     delete $c_string{$self};
     delete $nullable{$self};
+    _destroy($self);
 }
 
 sub get_specifier   { $specifier{ +shift } }

Added: incubator/lucy/trunk/clownfish/src/CFCType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.c?rev=1062317&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.c (added)
+++ incubator/lucy/trunk/clownfish/src/CFCType.c Sun Jan 23 03:56:58 2011
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+
+#include "CFCType.h"
+
+struct CFCType {
+    int   flags;
+};
+
+CFCType*
+CFCType_new()
+{
+    CFCType *self = (CFCType*)malloc(sizeof(CFCType));
+    if (!self) { croak("malloc failed"); }
+    return self;
+}
+
+void
+CFCType_destroy(CFCType *self)
+{
+    free(self);
+}
+
+

Added: incubator/lucy/trunk/clownfish/src/CFCType.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.h?rev=1062317&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.h (added)
+++ incubator/lucy/trunk/clownfish/src/CFCType.h Sun Jan 23 03:56:58 2011
@@ -0,0 +1,8 @@
+typedef struct CFCType CFCType;
+
+CFCType*
+CFCType_new();
+
+void
+CFCType_destroy(CFCType *self);
+

Added: incubator/lucy/trunk/clownfish/typemap
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/typemap?rev=1062317&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/typemap (added)
+++ incubator/lucy/trunk/clownfish/typemap Sun Jan 23 03:56:58 2011
@@ -0,0 +1,19 @@
+TYPEMAP
+CFCType*	CLOWNFISH_TYPE
+
+INPUT
+
+CLOWNFISH_TYPE
+	if (sv_derived_from($arg, \"${(my $t = $type) =~ s/CFC(\w+).*/Clownfish::$1/;\$t}\")) {
+		IV objint = SvIV((SV*)SvRV($arg));
+		$var = INT2PTR($type, objint);
+	}
+	else {
+		croak(\"Not a ${(my $t = $type) =~ s/CFC(\w+).*/Clownfish::$1/;\$t}\");
+	}
+
+OUTPUT
+
+CLOWNFISH_TYPE
+	sv_setref_pv($arg, \"${(my $t = $type) =~ s/CFC(\w+).*/Clownfish::$1/;\$t}\", (void*)$var);
+