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/23 01:27:23 UTC

[lucy-commits] svn commit: r1149762 - in /incubator/lucy/trunk/clownfish: include/CFC.h lib/Clownfish.xs lib/Clownfish/Binding/Perl/Method.pm src/CFCPerlMethod.c src/CFCPerlMethod.h src/CFCPerlSub.c src/CFCPerlSub.h typemap

Author: marvin
Date: Fri Jul 22 23:27:21 2011
New Revision: 1149762

URL: http://svn.apache.org/viewvc?rev=1149762&view=rev
Log:
Start porting CFCPerlMethod to C.

Added:
    incubator/lucy/trunk/clownfish/src/CFCPerlMethod.c   (with props)
    incubator/lucy/trunk/clownfish/src/CFCPerlMethod.h   (with props)
Modified:
    incubator/lucy/trunk/clownfish/include/CFC.h
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm
    incubator/lucy/trunk/clownfish/src/CFCPerlSub.c
    incubator/lucy/trunk/clownfish/src/CFCPerlSub.h
    incubator/lucy/trunk/clownfish/typemap

Modified: incubator/lucy/trunk/clownfish/include/CFC.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/include/CFC.h?rev=1149762&r1=1149761&r2=1149762&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/include/CFC.h (original)
+++ incubator/lucy/trunk/clownfish/include/CFC.h Fri Jul 22 23:27:21 2011
@@ -38,5 +38,6 @@
 #include "CFCBindMethod.h"
 
 #include "CFCPerlSub.h"
+#include "CFCPerlMethod.h"
 #include "CFCPerlClass.h"
 

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1149762&r1=1149761&r2=1149762&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Fri Jul 22 23:27:21 2011
@@ -1928,6 +1928,40 @@ CODE:
     RETVAL = S_sv_eat_c_string(CFCPerlSub_build_allot_params(self));
 OUTPUT: RETVAL
 
+MODULE = Clownfish   PACKAGE = Clownfish::Binding::Perl::Method
+
+SV*
+_new(method, alias)
+    CFCMethod *method;
+    const char *alias;
+CODE:
+    CFCPerlMethod *self = CFCPerlMethod_new(method, alias);
+    RETVAL = S_cfcbase_to_perlref(self);
+    CFCBase_decref((CFCBase*)self);
+OUTPUT: RETVAL
+
+void
+DESTROY(self)
+    CFCPerlMethod *self;
+PPCODE:
+    CFCPerlMethod_destroy(self);
+
+void
+_set_or_get(self, ...)
+    CFCPerlMethod *self;
+ALIAS:
+    _get_method        = 2
+PPCODE:
+{
+    START_SET_OR_GET_SWITCH
+        case 2: {
+                CFCMethod *value = CFCPerlMethod_get_method(self);
+                retval = S_cfcbase_to_perlref(value);
+            }
+            break;
+    END_SET_OR_GET_SWITCH
+}
+
 
 MODULE = Clownfish   PACKAGE = Clownfish::Binding::Perl::Class
 

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm?rev=1149762&r1=1149761&r2=1149762&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm Fri Jul 22 23:27:21 2011
@@ -27,37 +27,12 @@ our %new_PARAMS = (
     alias  => undef,
 );
 
-our %method;
-
 sub new {
     my ( $either, %args ) = @_;
     confess $@ unless verify_args( \%new_PARAMS, %args );
-
-    # Derive arguments to SUPER constructor from supplied Method.
-    my $method = delete $args{method};
-    $args{param_list}  ||= $method->get_param_list;
-    $args{alias}       ||= $method->micro_sym;
-    $args{class_name}  ||= $method->get_class_name;
-    if ( !defined $args{use_labeled_params} ) {
-        $args{use_labeled_params}
-            = $method->get_param_list->num_vars > 2
-            ? 1
-            : 0;
-    }
-    my $self = $either->SUPER::new(%args);
-    $method{$self} = $method;
-
-    return $self;
+    return _new( @args{qw( method alias )} );
 }
 
-sub DESTROY {
-    my $self = shift;
-    delete $method{$self};
-    $self->SUPER::DESTROY;
-}
-
-sub _get_method { $method{ +shift } }
-
 sub xsub_def {
     my $self = shift;
     if ( $self->use_labeled_params ) {

Added: incubator/lucy/trunk/clownfish/src/CFCPerlMethod.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlMethod.c?rev=1149762&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlMethod.c (added)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlMethod.c Fri Jul 22 23:27:21 2011
@@ -0,0 +1,63 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define CFC_NEED_PERLSUB_STRUCT_DEF 1
+#include "CFCPerlSub.h"
+#include "CFCPerlMethod.h"
+#include "CFCUtil.h"
+#include "CFCMethod.h"
+#include "CFCParamList.h"
+
+struct CFCPerlMethod {
+    CFCPerlSub  sub;
+    CFCMethod  *method;
+};
+
+CFCPerlMethod*
+CFCPerlMethod_new(CFCMethod *method, const char *alias) {
+    CFCPerlMethod *self
+        = (CFCPerlMethod*)CFCBase_allocate(sizeof(CFCPerlMethod),
+                                          "Clownfish::Binding::Perl::Method");
+    return CFCPerlMethod_init(self, method, alias);
+}
+
+CFCPerlMethod*
+CFCPerlMethod_init(CFCPerlMethod *self, CFCMethod *method,
+                   const char *alias) {
+    CFCParamList *param_list = CFCMethod_get_param_list(method);
+    const char *class_name = CFCMethod_get_class_name(method);
+    int use_labeled_params = CFCParamList_num_vars(param_list) > 2
+                             ? 1 : 0;
+    if (!alias) {
+        alias = CFCMethod_micro_sym(method);
+    }
+    CFCPerlSub_init((CFCPerlSub*)self, param_list, class_name, alias,
+                    use_labeled_params);
+    self->method = (CFCMethod*)CFCBase_incref((CFCBase*)method);
+    return self;
+}
+
+void
+CFCPerlMethod_destroy(CFCPerlMethod *self) {
+    CFCBase_decref((CFCBase*)self->method);
+    CFCPerlSub_destroy((CFCPerlSub*)self);
+}
+
+CFCMethod*
+CFCPerlMethod_get_method(CFCPerlMethod *self) {
+    return self->method;
+}
+

Propchange: incubator/lucy/trunk/clownfish/src/CFCPerlMethod.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/lucy/trunk/clownfish/src/CFCPerlMethod.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlMethod.h?rev=1149762&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlMethod.h (added)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlMethod.h Fri Jul 22 23:27:21 2011
@@ -0,0 +1,45 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef H_CFCPERLMETHOD
+#define H_CFCPERLMETHOD
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct CFCPerlMethod CFCPerlMethod;
+struct CFCMethod;
+
+CFCPerlMethod*
+CFCPerlMethod_new(struct CFCMethod *method, const char *alias);
+
+CFCPerlMethod*
+CFCPerlMethod_init(CFCPerlMethod *self, struct CFCMethod *method,
+                   const char *alias);
+
+void
+CFCPerlMethod_destroy(CFCPerlMethod *self);
+
+struct CFCMethod*
+CFCPerlMethod_get_method(CFCPerlMethod *self);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_CFCPERLMETHOD */
+

Propchange: incubator/lucy/trunk/clownfish/src/CFCPerlMethod.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/lucy/trunk/clownfish/src/CFCPerlSub.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlSub.c?rev=1149762&r1=1149761&r2=1149762&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlSub.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlSub.c Fri Jul 22 23:27:21 2011
@@ -17,8 +17,9 @@
 #include <string.h>
 #include <stdio.h>
 #define CFC_NEED_BASE_STRUCT_DEF
-#include "CFCBase.h"
+#define CFC_NEED_PERLSUB_STRUCT_DEF
 #include "CFCPerlSub.h"
+#include "CFCBase.h"
 #include "CFCUtil.h"
 #include "CFCParamList.h"
 #include "CFCVariable.h"
@@ -29,16 +30,6 @@
     #define false 0
 #endif
 
-struct CFCPerlSub {
-    CFCBase base;
-    CFCParamList *param_list;
-    char *class_name;
-    char *alias;
-    int use_labeled_params;
-    char *perl_name;
-    char *c_name;
-};
-
 CFCPerlSub*
 CFCPerlSub_new(const char *klass, CFCParamList *param_list,
                const char *class_name, const char *alias,

Modified: incubator/lucy/trunk/clownfish/src/CFCPerlSub.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlSub.h?rev=1149762&r1=1149761&r2=1149762&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlSub.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlSub.h Fri Jul 22 23:27:21 2011
@@ -25,6 +25,20 @@ typedef struct CFCPerlSub CFCPerlSub;
 struct CFCParamList;
 struct CFCType;
 
+#ifdef CFC_NEED_PERLSUB_STRUCT_DEF
+#define CFC_NEED_BASE_STRUCT_DEF
+#include "CFCBase.h"
+struct CFCPerlSub {
+    CFCBase base;
+    struct CFCParamList *param_list;
+    char *class_name;
+    char *alias;
+    int use_labeled_params;
+    char *perl_name;
+    char *c_name;
+};
+#endif
+
 CFCPerlSub*
 CFCPerlSub_new(const char *klass, struct CFCParamList *param_list,
                const char *class_name, const char *alias,

Modified: incubator/lucy/trunk/clownfish/typemap
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/typemap?rev=1149762&r1=1149761&r2=1149762&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/typemap (original)
+++ incubator/lucy/trunk/clownfish/typemap Fri Jul 22 23:27:21 2011
@@ -32,6 +32,7 @@ CFCBindCore*	CLOWNFISH_BINDING_CORE
 CFCBindClass*	CLOWNFISH_BINDING_CORE_TYPE
 CFCPerlSub*	CLOWNFISH_BINDING_PERL_SUBROUTINE
 CFCPerlClass*	CLOWNFISH_BINDING_PERL_COMMON
+CFCPerlMethod*	CLOWNFISH_BINDING_PERL_COMMON
 
 INPUT