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/15 05:43:41 UTC

[lucy-commits] svn commit: r1070776 - in /incubator/lucy/trunk/clownfish: include/CFC.h lib/Clownfish.xs lib/Clownfish/CBlock.pm src/CFCCBlock.c src/CFCCBlock.h typemap

Author: marvin
Date: Tue Feb 15 04:43:41 2011
New Revision: 1070776

URL: http://svn.apache.org/viewvc?rev=1070776&view=rev
Log:
Port Clownfish::CBlock to C.

Added:
    incubator/lucy/trunk/clownfish/src/CFCCBlock.c
    incubator/lucy/trunk/clownfish/src/CFCCBlock.h
Modified:
    incubator/lucy/trunk/clownfish/include/CFC.h
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/CBlock.pm
    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=1070776&r1=1070775&r2=1070776&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/include/CFC.h (original)
+++ incubator/lucy/trunk/clownfish/include/CFC.h Tue Feb 15 04:43:41 2011
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include "CFCCBlock.h"
 #include "CFCClass.h"
 #include "CFCDocuComment.h"
 #include "CFCFunction.h"

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1070776&r1=1070775&r2=1070776&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Tue Feb 15 04:43:41 2011
@@ -48,6 +48,40 @@
         XSRETURN(0); \
     } 
 
+MODULE = Clownfish    PACKAGE = Clownfish::CBlock
+
+SV*
+_new(klass, contents)
+    const char *klass;
+    const char *contents;
+CODE:
+    CFCCBlock *self = CFCCBlock_new(contents);
+    RETVAL = newSV(0);
+	sv_setref_pv(RETVAL, klass, (void*)self);
+OUTPUT: RETVAL
+
+void
+DESTROY(self)
+    CFCCBlock *self;
+PPCODE:
+    CFCCBlock_destroy(self);
+
+void
+_set_or_get(self, ...)
+    CFCCBlock *self;
+ALIAS:
+    get_contents = 2
+PPCODE:
+{
+    START_SET_OR_GET_SWITCH
+        case 2: {
+                const char *contents = CFCCBlock_get_contents(self);
+                retval = newSVpvn(contents, strlen(contents));
+            }
+            break;
+    END_SET_OR_GET_SWITCH
+}
+
 MODULE = Clownfish    PACKAGE = Clownfish::Class
 
 SV*

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/CBlock.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/CBlock.pm?rev=1070776&r1=1070775&r2=1070776&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/CBlock.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/CBlock.pm Tue Feb 15 04:43:41 2011
@@ -23,17 +23,13 @@ use Carp;
 our %new_PARAMS = ( contents => undef, );
 
 sub new {
-    my $either = shift;
-    verify_args( \%new_PARAMS, @_ ) or confess $@;
-    my $self = bless { %new_PARAMS, @_ }, ref($either) || $either;
+    my ( $either, %args ) = @_;
+    verify_args( \%new_PARAMS, %args ) or confess $@;
     confess("Missing required param 'contents'")
-        unless defined $self->get_contents;
-    return $self;
+        unless defined $args{contents};
+    return $either->_new( $args{contents} );
 }
 
-# Accessors.
-sub get_contents { shift->{contents} }
-
 1;
 
 __END__

Added: incubator/lucy/trunk/clownfish/src/CFCCBlock.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCCBlock.c?rev=1070776&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCCBlock.c (added)
+++ incubator/lucy/trunk/clownfish/src/CFCCBlock.c Tue Feb 15 04:43:41 2011
@@ -0,0 +1,56 @@
+/* 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.
+ */
+
+#include <stdlib.h>
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#include "CFCCBlock.h"
+
+struct CFCCBlock {
+    const char *contents;
+};
+
+CFCCBlock*
+CFCCBlock_new(const char *contents)
+{
+    CFCCBlock *self = (CFCCBlock*)malloc(sizeof(CFCCBlock));
+    if (!self) { croak("malloc failed"); }
+    return CFCCBlock_init(self, contents);
+}
+
+CFCCBlock*
+CFCCBlock_init(CFCCBlock *self, const char *contents) 
+{
+    self->contents = savepv(contents);
+    return self;
+}
+
+void
+CFCCBlock_destroy(CFCCBlock *self)
+{
+    Safefree(self->contents);
+    free(self);
+}
+
+
+const char*
+CFCCBlock_get_contents(CFCCBlock *self)
+{
+    return self->contents;
+}
+

Added: incubator/lucy/trunk/clownfish/src/CFCCBlock.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCCBlock.h?rev=1070776&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCCBlock.h (added)
+++ incubator/lucy/trunk/clownfish/src/CFCCBlock.h Tue Feb 15 04:43:41 2011
@@ -0,0 +1,31 @@
+/* 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.
+ */
+
+typedef struct CFCCBlock CFCCBlock;
+
+CFCCBlock*
+CFCCBlock_new(const char *contents);
+
+CFCCBlock*
+CFCCBlock_init(CFCCBlock *self, const char *contents);
+
+void
+CFCCBlock_destroy(CFCCBlock *self);
+
+const char*
+CFCCBlock_get_contents(CFCCBlock *self);
+
+

Modified: incubator/lucy/trunk/clownfish/typemap
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/typemap?rev=1070776&r1=1070775&r2=1070776&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/typemap (original)
+++ incubator/lucy/trunk/clownfish/typemap Tue Feb 15 04:43:41 2011
@@ -14,6 +14,7 @@
 # limitations under the License.
 
 TYPEMAP
+CFCCBlock*	CLOWNFISH_TYPE
 CFCClass*	CLOWNFISH_TYPE
 CFCDocuComment*	CLOWNFISH_TYPE
 CFCFunction*	CLOWNFISH_TYPE