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 2012/02/18 21:21:30 UTC

[lucy-commits] svn commit: r1290856 - in /incubator/lucy/trunk/clownfish: perl/lib/Clownfish/CFC.xs perl/lib/Clownfish/CFC/Binding/Perl.pm perl/typemap src/CFCPerl.c src/CFCPerl.h

Author: marvin
Date: Sat Feb 18 20:21:29 2012
New Revision: 1290856

URL: http://svn.apache.org/viewvc?rev=1290856&view=rev
Log:
Port CFCPerl constructor and member vars to C.

Modified:
    incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
    incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC/Binding/Perl.pm
    incubator/lucy/trunk/clownfish/perl/typemap
    incubator/lucy/trunk/clownfish/src/CFCPerl.c
    incubator/lucy/trunk/clownfish/src/CFCPerl.h

Modified: incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs?rev=1290856&r1=1290855&r2=1290856&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs (original)
+++ incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs Sat Feb 18 20:21:29 2012
@@ -1754,13 +1754,110 @@ PPCODE:
 MODULE = Clownfish   PACKAGE = Clownfish::CFC::Binding::Perl
 
 SV*
-_new()
+_new(parcel, hierarchy, lib_dir, boot_class, header, footer)
+    CFCParcel *parcel;
+    CFCHierarchy *hierarchy;
+    const char *lib_dir;
+    const char *boot_class;
+    const char *header;
+    const char *footer;
 CODE:
-    CFCPerl *self = CFCPerl_new();
+    CFCPerl *self = CFCPerl_new(parcel, hierarchy, lib_dir, boot_class,
+                                header, footer);
     RETVAL = S_cfcbase_to_perlref(self);
     CFCBase_decref((CFCBase*)self);
 OUTPUT: RETVAL
 
+
+void
+_set_or_get(self, ...)
+    CFCPerl *self;
+ALIAS:
+    _get_parcel      = 2
+    _get_hierarchy   = 4
+    _get_lib_dir     = 6
+    _get_boot_class  = 8
+    _get_header      = 10
+    _get_footer      = 12
+    _get_xs_path     = 14
+    _get_pm_path     = 16
+    _get_boot_h_file = 18
+    _get_boot_c_file = 20
+    _get_boot_h_path = 22
+    _get_boot_c_path = 24
+    _get_boot_func   = 26
+PPCODE:
+{
+    START_SET_OR_GET_SWITCH
+        case 2: {
+                CFCParcel *value = CFCPerl_get_parcel(self);
+                retval = S_cfcbase_to_perlref(value);
+            }
+            break;
+        case 4: {
+                CFCHierarchy *value = CFCPerl_get_hierarchy(self);
+                retval = S_cfcbase_to_perlref(value);
+            }
+            break;
+        case 6: {
+                const char *value = CFCPerl_get_lib_dir(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 8: {
+                const char *value = CFCPerl_get_boot_class(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 10: {
+                const char *value = CFCPerl_get_header(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 12: {
+                const char *value = CFCPerl_get_footer(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 14: {
+                const char *value = CFCPerl_get_xs_path(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 16: {
+                const char *value = CFCPerl_get_pm_path(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 18: {
+                const char *value = CFCPerl_get_boot_h_file(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 20: {
+                const char *value = CFCPerl_get_boot_c_file(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 22: {
+                const char *value = CFCPerl_get_boot_h_path(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 24: {
+                const char *value = CFCPerl_get_boot_c_path(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+        case 26: {
+                const char *value = CFCPerl_get_boot_func(self);
+                retval = newSVpvn(value, strlen(value));
+            }
+            break;
+    END_SET_OR_GET_SWITCH
+}
+
+
 MODULE = Clownfish   PACKAGE = Clownfish::CFC::Binding::Perl::Subroutine
 
 void

Modified: incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC/Binding/Perl.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC/Binding/Perl.pm?rev=1290856&r1=1290855&r2=1290856&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC/Binding/Perl.pm (original)
+++ incubator/lucy/trunk/clownfish/perl/lib/Clownfish/CFC/Binding/Perl.pm Sat Feb 18 20:21:29 2012
@@ -34,20 +34,6 @@ use Clownfish::CFC::Binding::Perl::Class
 use Clownfish::CFC::Binding::Perl::Method;
 use Clownfish::CFC::Binding::Perl::Constructor;
 
-our %parcel;
-our %hierarchy;
-our %lib_dir;
-our %boot_class;
-our %header;
-our %footer;
-our %xs_path;
-our %pm_path;
-our %boot_h_file;
-our %boot_c_file;
-our %boot_h_path;
-our %boot_c_path;
-our %boot_func;
-
 our %new_PARAMS = (
     parcel     => undef,
     hierarchy  => undef,
@@ -60,75 +46,14 @@ our %new_PARAMS = (
 sub new {
     my ( $either, %args ) = @_;
     verify_args( \%new_PARAMS, %args ) or confess $@;
-    my $self = _new();
     if ( !a_isa_b( $args{parcel}, 'Clownfish::CFC::Parcel' ) ) {
         $args{parcel}
             = Clownfish::CFC::Parcel->singleton( name => $args{parcel} );
     }
-    for ( keys %new_PARAMS ) {
-        confess("$_ is mandatory") unless defined $args{$_};
-    }
-    my $parcel = $parcel{$self} = $args{parcel};
-    $hierarchy{$self}  = $args{hierarchy};
-    $lib_dir{$self}    = $args{lib_dir};
-    $boot_class{$self} = $args{boot_class};
-    $header{$self}     = $args{header};
-    $footer{$self}     = $args{footer};
-
-    # Derive filenames.
-    my $lib                = $self->_get_lib_dir;
-    my $dest_dir           = $self->_get_hierarchy->get_dest;
-    my @file_components    = split( '::', $self->_get_boot_class );
-    my @xs_file_components = @file_components;
-    $xs_file_components[-1] .= '.xs';
-    $xs_path{$self} = catfile( $lib, @xs_file_components );
-
-    $pm_path{$self} = catfile( $lib, @file_components, 'Autobinding.pm' );
-    $boot_h_file{$self} = $parcel->get_prefix . "boot.h";
-    $boot_c_file{$self} = $parcel->get_prefix . "boot.c";
-    $boot_h_path{$self} = catfile( $dest_dir, $self->_get_boot_h_file );
-    $boot_c_path{$self} = catfile( $dest_dir, $self->_get_boot_c_file );
-
-    # Derive the name of the bootstrap function.
-    $boot_func{$self}
-        = $parcel->get_prefix . $self->_get_boot_class . '_bootstrap';
-    $boot_func{$self} =~ s/\W/_/g;
-
-    return $self;
+    return _new(
+        @args{qw( parcel hierarchy lib_dir boot_class header footer )} );
 }
 
-sub DESTROY {
-    my $self = shift;
-    delete $parcel{$self};
-    delete $hierarchy{$self};
-    delete $lib_dir{$self};
-    delete $boot_class{$self};
-    delete $header{$self};
-    delete $footer{$self};
-    delete $xs_path{$self};
-    delete $pm_path{$self};
-    delete $boot_h_file{$self};
-    delete $boot_c_file{$self};
-    delete $boot_h_path{$self};
-    delete $boot_c_path{$self};
-    delete $boot_func{$self};
-    $self->SUPER::DESTROY;
-}
-
-sub _get_parcel      { $parcel{ +shift } }
-sub _get_hierarchy   { $hierarchy{ +shift } }
-sub _get_lib_dir     { $lib_dir{ +shift } }
-sub _get_boot_class  { $boot_class{ +shift } }
-sub _get_header      { $header{ +shift } }
-sub _get_footer      { $footer{ +shift } }
-sub _get_xs_path     { $xs_path{ +shift } }
-sub _get_pm_path     { $pm_path{ +shift } }
-sub _get_boot_h_file { $boot_h_file{ +shift } }
-sub _get_boot_c_file { $boot_c_file{ +shift } }
-sub _get_boot_h_path { $boot_h_path{ +shift } }
-sub _get_boot_c_path { $boot_c_path{ +shift } }
-sub _get_boot_func   { $boot_func{ +shift } }
-
 sub write_bindings {
     my $self           = shift;
     my $ordered        = $self->_get_hierarchy->ordered_classes;

Modified: incubator/lucy/trunk/clownfish/perl/typemap
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/perl/typemap?rev=1290856&r1=1290855&r2=1290856&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/perl/typemap (original)
+++ incubator/lucy/trunk/clownfish/perl/typemap Sat Feb 18 20:21:29 2012
@@ -32,6 +32,7 @@ CFCType*	CLOWNFISH_TYPE
 CFCVariable*	CLOWNFISH_TYPE
 CFCBindCore*	CLOWNFISH_BINDING_CORE
 CFCBindClass*	CLOWNFISH_BINDING_CORE_TYPE
+CFCPerl*	CLOWNFISH_BINDING_PERL
 CFCPerlSub*	CLOWNFISH_BINDING_PERL_SUBROUTINE
 CFCPerlClass*	CLOWNFISH_BINDING_PERL_COMMON
 CFCPerlConstructor*	CLOWNFISH_BINDING_PERL_COMMON
@@ -76,6 +77,18 @@ CLOWNFISH_BINDING_CORE_TYPE
 		croak(\"Not a ${(my $t = $type) =~ s/CFCBind(\w+).*/Clownfish::CFC::Binding::Core::$1/;\$t}\");
 	}
 
+CLOWNFISH_BINDING_PERL
+	if (!SvOK($arg)) {
+        $var = NULL;
+    }
+	else if (sv_derived_from($arg, \"Clownfish::CFC::Binding::Perl\")) {
+		IV objint = SvIV((SV*)SvRV($arg));
+		$var = INT2PTR($type, objint);
+	}
+    else {
+		croak(\"Not a Clownfish::CFC::Binding::Perl\");
+	}
+
 CLOWNFISH_BINDING_PERL_COMMON
 	if (!SvOK($arg)) {
         $var = NULL;
@@ -125,6 +138,9 @@ CLOWNFISH_BINDING_CORE
 CLOWNFISH_BINDING_CORE_TYPE
 	sv_setref_pv($arg, \"${(my $t = $type) =~ s/CFCBind(\w+).*/Clownfish::CFC::Binding::Core::$1/;\$t}\", (void*)$var);
 
+CLOWNFISH_BINDING_PERL
+	sv_setref_pv($arg, \"Clownfish::CFC::Binding::Perl\", (void*)$var);
+
 CLOWNFISH_BINDING_PERL_COMMON
 	sv_setref_pv($arg, \"${(my $t = $type) =~ s/CFCPerl(\w+).*/Clownfish::CFC::Binding::Perl::$1/;\$t}\", (void*)$var);
 

Modified: incubator/lucy/trunk/clownfish/src/CFCPerl.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerl.c?rev=1290856&r1=1290855&r2=1290856&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerl.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCPerl.c Sat Feb 18 20:21:29 2012
@@ -14,12 +14,30 @@
  * limitations under the License.
  */
 
+#include <string.h>
+#include <ctype.h>
 #define CFC_NEED_BASE_STRUCT_DEF
 #include "CFCBase.h"
 #include "CFCPerl.h"
+#include "CFCParcel.h"
+#include "CFCHierarchy.h"
+#include "CFCUtil.h"
 
 struct CFCPerl {
     CFCBase base;
+    CFCParcel *parcel;
+    CFCHierarchy *hierarchy;
+    char *lib_dir;
+    char *boot_class;
+    char *header;
+    char *footer;
+    char *xs_path;
+    char *pm_path;
+    char *boot_h_file;
+    char *boot_c_file;
+    char *boot_h_path;
+    char *boot_c_path;
+    char *boot_func;
 };
 
 const static CFCMeta CFCPERL_META = {
@@ -29,18 +47,158 @@ const static CFCMeta CFCPERL_META = {
 };
 
 CFCPerl*
-CFCPerl_new(void) {
+CFCPerl_new(CFCParcel *parcel, CFCHierarchy *hierarchy, const char *lib_dir,
+            const char *boot_class, const char *header, const char *footer) {
     CFCPerl *self = (CFCPerl*)CFCBase_allocate(&CFCPERL_META);
-    return CFCPerl_init(self);
+    return CFCPerl_init(self, parcel, hierarchy, lib_dir, boot_class, header,
+                        footer);
 }
 
 CFCPerl*
-CFCPerl_init(CFCPerl *self) {
+CFCPerl_init(CFCPerl *self, CFCParcel *parcel, CFCHierarchy *hierarchy,
+             const char *lib_dir, const char *boot_class, const char *header,
+             const char *footer) {
+    CFCUTIL_NULL_CHECK(parcel);
+    CFCUTIL_NULL_CHECK(hierarchy);
+    CFCUTIL_NULL_CHECK(lib_dir);
+    CFCUTIL_NULL_CHECK(boot_class);
+    CFCUTIL_NULL_CHECK(header);
+    CFCUTIL_NULL_CHECK(footer);
+    self->parcel     = (CFCParcel*)CFCBase_incref((CFCBase*)parcel);
+    self->hierarchy  = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy);
+    self->lib_dir    = CFCUtil_strdup(lib_dir);
+    self->boot_class = CFCUtil_strdup(boot_class);
+    self->header     = CFCUtil_strdup(header);
+    self->footer     = CFCUtil_strdup(footer);
+
+    // Derive path to generated .xs file.
+    self->xs_path = CFCUtil_cat(CFCUtil_strdup(""), lib_dir, CFCUTIL_PATH_SEP,
+                                boot_class, ".xs", NULL);
+    size_t pos = 0;
+    for (char *ptr = self->xs_path; *ptr != '\0'; ptr++) {
+        if (strcmp(ptr, "::") == 0) {
+            self->xs_path[pos++] = CFCUTIL_PATH_SEP_CHAR;
+            ptr++;
+        }
+        else {
+            self->xs_path[pos++] = *ptr;
+        }
+    }
+    self->xs_path[pos] = '\0';
+
+    // Derive path to generated .pm file.
+    self->pm_path = CFCUtil_strdup(self->xs_path);
+    self->pm_path[strlen(self->pm_path) - strlen(".xs")] = '\0';
+    self->pm_path = CFCUtil_cat(self->pm_path, CFCUTIL_PATH_SEP,
+                                "Autobinding.pm", NULL);
+
+    // Derive the name of the files containing bootstrapping code.
+    const char *prefix   = CFCParcel_get_prefix(parcel);
+    const char *dest_dir = CFCHierarchy_get_dest(hierarchy);
+    self->boot_h_file = CFCUtil_cat(CFCUtil_strdup(""), prefix, "boot.h",
+                                    NULL);
+    self->boot_c_file = CFCUtil_cat(CFCUtil_strdup(""), prefix, "boot.c",
+                                    NULL);
+    self->boot_h_path = CFCUtil_cat(CFCUtil_strdup(""), dest_dir,
+                                    CFCUTIL_PATH_SEP, self->boot_h_file,
+                                    NULL);
+    self->boot_c_path = CFCUtil_cat(CFCUtil_strdup(""), dest_dir,
+                                    CFCUTIL_PATH_SEP, self->boot_c_file,
+                                    NULL);
+
+    // Derive the name of the bootstrap function.
+    self->boot_func
+        = CFCUtil_cat(CFCUtil_strdup(""), CFCParcel_get_prefix(parcel),
+                      boot_class, "_bootstrap", NULL);
+    for (int i = 0; self->boot_func[i] != 0; i++) {
+        if (!isalnum(self->boot_func[i])) {
+            self->boot_func[i] = '_';
+        }
+    }
+
     return self;
 }
 
 void
 CFCPerl_destroy(CFCPerl *self) {
+    CFCBase_decref((CFCBase*)self->parcel);
+    CFCBase_decref((CFCBase*)self->hierarchy);
+    FREEMEM(self->lib_dir);
+    FREEMEM(self->boot_class);
+    FREEMEM(self->header);
+    FREEMEM(self->footer);
+    FREEMEM(self->xs_path);
+    FREEMEM(self->pm_path);
+    FREEMEM(self->boot_h_file);
+    FREEMEM(self->boot_c_file);
+    FREEMEM(self->boot_h_path);
+    FREEMEM(self->boot_c_path);
+    FREEMEM(self->boot_func);
     CFCBase_destroy((CFCBase*)self);
 }
 
+CFCParcel*
+CFCPerl_get_parcel(CFCPerl *self) {
+    return self->parcel;
+}
+
+CFCHierarchy*
+CFCPerl_get_hierarchy(CFCPerl *self) {
+    return self->hierarchy;
+}
+
+const char*
+CFCPerl_get_lib_dir(CFCPerl *self) {
+    return self->lib_dir;
+}
+
+const char*
+CFCPerl_get_boot_class(CFCPerl *self) {
+    return self->boot_class;
+}
+
+const char*
+CFCPerl_get_header(CFCPerl *self) {
+    return self->header;
+}
+
+const char*
+CFCPerl_get_footer(CFCPerl *self) {
+    return self->footer;
+}
+
+const char*
+CFCPerl_get_xs_path(CFCPerl *self) {
+    return self->xs_path;
+}
+
+const char*
+CFCPerl_get_pm_path(CFCPerl *self) {
+    return self->pm_path;
+}
+
+const char*
+CFCPerl_get_boot_h_file(CFCPerl *self) {
+    return self->boot_h_file;
+}
+
+const char*
+CFCPerl_get_boot_c_file(CFCPerl *self) {
+    return self->boot_c_file;
+}
+
+const char*
+CFCPerl_get_boot_h_path(CFCPerl *self) {
+    return self->boot_h_path;
+}
+
+const char*
+CFCPerl_get_boot_c_path(CFCPerl *self) {
+    return self->boot_c_path;
+}
+
+const char*
+CFCPerl_get_boot_func(CFCPerl *self) {
+    return self->boot_func;
+}
+

Modified: incubator/lucy/trunk/clownfish/src/CFCPerl.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerl.h?rev=1290856&r1=1290855&r2=1290856&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerl.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCPerl.h Sat Feb 18 20:21:29 2012
@@ -22,16 +22,61 @@ extern "C" {
 #endif
 
 typedef struct CFCPerl CFCPerl;
+struct CFCParcel;
+struct CFCHierarchy;
 
 CFCPerl*
-CFCPerl_new(void);
+CFCPerl_new(struct CFCParcel *parcel, struct CFCHierarchy *hierarchy,
+            const char *lib_dir, const char *boot_class, const char *header,
+            const char *footer);
 
 CFCPerl*
-CFCPerl_init(CFCPerl *self);
+CFCPerl_init(CFCPerl *self, struct CFCParcel *parcel,
+             struct CFCHierarchy *hierarchy, const char *lib_dir,
+             const char *boot_class, const char *header, const char *footer);
 
 void
 CFCPerl_destroy(CFCPerl *self);
 
+struct CFCParcel*
+CFCPerl_get_parcel(CFCPerl *self);
+
+struct CFCHierarchy*
+CFCPerl_get_hierarchy(CFCPerl *self);
+
+const char*
+CFCPerl_get_lib_dir(CFCPerl *self);
+
+const char*
+CFCPerl_get_boot_class(CFCPerl *self);
+
+const char*
+CFCPerl_get_header(CFCPerl *self);
+
+const char*
+CFCPerl_get_footer(CFCPerl *self);
+
+const char*
+CFCPerl_get_xs_path(CFCPerl *self);
+
+const char*
+CFCPerl_get_pm_path(CFCPerl *self);
+
+const char*
+CFCPerl_get_boot_h_file(CFCPerl *self);
+
+const char*
+CFCPerl_get_boot_c_file(CFCPerl *self);
+
+const char*
+CFCPerl_get_boot_h_path(CFCPerl *self);
+
+const char*
+CFCPerl_get_boot_c_path(CFCPerl *self);
+
+const char*
+CFCPerl_get_boot_func(CFCPerl *self);
+
 #ifdef __cplusplus
 }
 #endif