You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/05/05 11:39:03 UTC
[3/5] lucy-clownfish git commit: Perl bindings for Blob
Perl bindings for Blob
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/911bcb75
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/911bcb75
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/911bcb75
Branch: refs/heads/master
Commit: 911bcb75d7972cfd7c8a5c86a89e6c4d4279ed9c
Parents: 1b1789a
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon May 4 15:34:52 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue May 5 11:15:12 2015 +0200
----------------------------------------------------------------------
.../perl/buildlib/Clownfish/Build/Binding.pm | 31 ++++++++++++++++++++
runtime/perl/lib/Clownfish/Blob.pm | 25 ++++++++++++++++
runtime/perl/t/018-host.t | 2 +-
runtime/perl/xs/XSBind.c | 10 +++++++
runtime/perl/xs/XSBind.h | 12 ++++++--
5 files changed, 77 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/911bcb75/runtime/perl/buildlib/Clownfish/Build/Binding.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
index 6d8be97..c70d528 100644
--- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm
+++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
@@ -24,6 +24,7 @@ sub bind_all {
$class->bind_clownfish;
$class->bind_test;
$class->bind_test_alias_obj;
+ $class->bind_blob;
$class->bind_bytebuf;
$class->bind_string;
$class->bind_err;
@@ -140,6 +141,36 @@ sub bind_test_alias_obj {
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
+sub bind_blob {
+ my $xs_code = <<'END_XS_CODE';
+MODULE = Clownfish PACKAGE = Clownfish::Blob
+
+SV*
+new(either_sv, sv)
+ SV *either_sv;
+ SV *sv;
+CODE:
+{
+ STRLEN size;
+ char *ptr = SvPV(sv, size);
+ cfish_Blob *self
+ = (cfish_Blob*)XSBind_new_blank_obj(aTHX_ either_sv);
+ cfish_Blob_init(self, ptr, size);
+ RETVAL = CFISH_OBJ_TO_SV_NOINC(self);
+}
+OUTPUT: RETVAL
+END_XS_CODE
+
+ my $binding = Clownfish::CFC::Binding::Perl::Class->new(
+ parcel => "Clownfish",
+ class_name => "Clownfish::Blob",
+ );
+ $binding->append_xs($xs_code);
+ $binding->exclude_constructor;
+
+ Clownfish::CFC::Binding::Perl::Class->register($binding);
+}
+
sub bind_bytebuf {
my $xs_code = <<'END_XS_CODE';
MODULE = Clownfish PACKAGE = Clownfish::ByteBuf
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/911bcb75/runtime/perl/lib/Clownfish/Blob.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/lib/Clownfish/Blob.pm b/runtime/perl/lib/Clownfish/Blob.pm
new file mode 100644
index 0000000..b944259
--- /dev/null
+++ b/runtime/perl/lib/Clownfish/Blob.pm
@@ -0,0 +1,25 @@
+# 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.
+
+package Clownfish::Blob;
+use Clownfish;
+our $VERSION = '0.004000';
+$VERSION = eval $VERSION;
+
+1;
+
+__END__
+
+
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/911bcb75/runtime/perl/t/018-host.t
----------------------------------------------------------------------
diff --git a/runtime/perl/t/018-host.t b/runtime/perl/t/018-host.t
index 5a79eff..050a010 100644
--- a/runtime/perl/t/018-host.t
+++ b/runtime/perl/t/018-host.t
@@ -30,7 +30,7 @@ is_deeply( $transformed, \%complex_data_structure,
"transform from Perl to Clownfish data structures and back" );
my $bread_and_butter = Clownfish::Hash->new;
-$bread_and_butter->store( 'bread', Clownfish::ByteBuf->new('butter') );
+$bread_and_butter->store( 'bread', Clownfish::Blob->new('butter') );
my $salt_and_pepper = Clownfish::Hash->new;
$salt_and_pepper->store( 'salt', Clownfish::ByteBuf->new('pepper') );
$complex_data_structure{c} = $bread_and_butter;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/911bcb75/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index df069c9..fd5fd09 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -150,6 +150,9 @@ XSBind_cfish_to_perl(pTHX_ cfish_Obj *obj) {
else if (CFISH_Obj_Is_A(obj, CFISH_STRING)) {
return XSBind_str_to_sv(aTHX_ (cfish_String*)obj);
}
+ else if (CFISH_Obj_Is_A(obj, CFISH_BLOB)) {
+ return XSBind_blob_to_sv(aTHX_ (cfish_Blob*)obj);
+ }
else if (CFISH_Obj_Is_A(obj, CFISH_BYTEBUF)) {
return XSBind_bb_to_sv(aTHX_ (cfish_ByteBuf*)obj);
}
@@ -232,6 +235,13 @@ XSBind_perl_to_cfish(pTHX_ SV *sv) {
}
SV*
+XSBind_blob_to_sv(pTHX_ cfish_Blob *blob) {
+ return blob
+ ? newSVpvn(CFISH_Blob_Get_Buf(blob), CFISH_Blob_Get_Size(blob))
+ : newSV(0);
+}
+
+SV*
XSBind_bb_to_sv(pTHX_ cfish_ByteBuf *bb) {
return bb
? newSVpvn(CFISH_BB_Get_Buf(bb), CFISH_BB_Get_Size(bb))
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/911bcb75/runtime/perl/xs/XSBind.h
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.h b/runtime/perl/xs/XSBind.h
index b1c7b22..4b48167 100644
--- a/runtime/perl/xs/XSBind.h
+++ b/runtime/perl/xs/XSBind.h
@@ -21,6 +21,7 @@
#define H_CFISH_XSBIND 1
#include "Clownfish/Obj.h"
+#include "Clownfish/Blob.h"
#include "Clownfish/ByteBuf.h"
#include "Clownfish/String.h"
#include "Clownfish/Err.h"
@@ -117,8 +118,9 @@ cfish_XSBind_cfish_obj_to_sv_noinc(pTHX_ cfish_Obj *obj) {
cfish_XSBind_cfish_obj_to_sv_noinc(aTHX_ (cfish_Obj*)_obj)
/** Deep conversion of Clownfish objects to Perl objects -- Strings to UTF-8
- * SVs, ByteBufs to SVs, Vectors to Perl array refs, Hashes to Perl hashrefs,
- * and any other object to a Perl object wrapping the Clownfish Obj.
+ * SVs, Blobs to SVs, ByteBufs to SVs, Vectors to Perl array refs, Hashes to
+ * Perl hashrefs, and any other object to a Perl object wrapping the Clownfish
+ * Obj.
*/
CFISH_VISIBLE SV*
cfish_XSBind_cfish_to_perl(pTHX_ cfish_Obj *obj);
@@ -130,6 +132,11 @@ cfish_XSBind_cfish_to_perl(pTHX_ cfish_Obj *obj);
CFISH_VISIBLE cfish_Obj*
cfish_XSBind_perl_to_cfish(pTHX_ SV *sv);
+/** Convert a Blob into a new string SV.
+ */
+CFISH_VISIBLE SV*
+cfish_XSBind_blob_to_sv(pTHX_ cfish_Blob *blob);
+
/** Convert a ByteBuf into a new string SV.
*/
CFISH_VISIBLE SV*
@@ -317,6 +324,7 @@ cfish_XSBind_allot_params(pTHX_ SV** stack, int32_t start,
#define XSBind_cfish_obj_to_sv_noinc cfish_XSBind_cfish_obj_to_sv_noinc
#define XSBind_cfish_to_perl cfish_XSBind_cfish_to_perl
#define XSBind_perl_to_cfish cfish_XSBind_perl_to_cfish
+#define XSBind_blob_to_sv cfish_XSBind_blob_to_sv
#define XSBind_bb_to_sv cfish_XSBind_bb_to_sv
#define XSBind_str_to_sv cfish_XSBind_str_to_sv
#define XSBind_trap cfish_XSBind_trap