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/30 13:27:45 UTC
[06/12] lucy-clownfish git commit: Implement Vec_To_Host
Implement Vec_To_Host
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/c7176523
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/c7176523
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/c7176523
Branch: refs/heads/master
Commit: c7176523871d496d08e17de4d7822783c98426f3
Parents: dc82fc5
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri May 29 13:58:00 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri May 29 17:51:23 2015 +0200
----------------------------------------------------------------------
runtime/core/Clownfish/Vector.cfh | 3 ++
runtime/perl/xs/XSBind.c | 59 ++++++++++++++++------------------
2 files changed, 30 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c7176523/runtime/core/Clownfish/Vector.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Vector.cfh b/runtime/core/Clownfish/Vector.cfh
index 4034ebf..9271988 100644
--- a/runtime/core/Clownfish/Vector.cfh
+++ b/runtime/core/Clownfish/Vector.cfh
@@ -34,6 +34,9 @@ public final class Clownfish::Vector nickname Vec inherits Clownfish::Obj {
public inert Vector*
init(Vector *self, size_t capacity = 0);
+ void*
+ To_Host(Vector *self);
+
/** Push an item onto the end of a Vector.
*/
public void
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c7176523/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index 75d6941..0e8a579 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -49,11 +49,6 @@ S_perl_hash_to_cfish_hash(pTHX_ HV *phash);
static cfish_Vector*
S_perl_array_to_cfish_array(pTHX_ AV *parray);
-// Convert a Vector to a Perl array. Caller takes responsibility for a
-// refcount.
-static SV*
-S_cfish_array_to_perl_array(pTHX_ cfish_Vector *varray);
-
cfish_Obj*
XSBind_new_blank_obj(pTHX_ SV *either_sv) {
cfish_Class *klass;
@@ -155,9 +150,6 @@ XSBind_cfish_to_perl(pTHX_ cfish_Obj *obj) {
else if (cfish_Obj_is_a(obj, CFISH_BYTEBUF)) {
return XSBind_bb_to_sv(aTHX_ (cfish_ByteBuf*)obj);
}
- else if (cfish_Obj_is_a(obj, CFISH_VECTOR)) {
- return S_cfish_array_to_perl_array(aTHX_ (cfish_Vector*)obj);
- }
else {
return (SV*)CFISH_Obj_To_Host(obj);
}
@@ -303,30 +295,6 @@ S_perl_array_to_cfish_array(pTHX_ AV *parray) {
return retval;
}
-static SV*
-S_cfish_array_to_perl_array(pTHX_ cfish_Vector *varray) {
- AV *perl_array = newAV();
- uint32_t num_elems = CFISH_Vec_Get_Size(varray);
-
- // Iterate over array elems.
- if (num_elems) {
- av_fill(perl_array, num_elems - 1);
- for (uint32_t i = 0; i < num_elems; i++) {
- cfish_Obj *val = CFISH_Vec_Fetch(varray, i);
- if (val == NULL) {
- continue;
- }
- else {
- // Recurse for each value.
- SV *const val_sv = XSBind_cfish_to_perl(aTHX_ val);
- av_store(perl_array, i, val_sv);
- }
- }
- }
-
- return newRV_noinc((SV*)perl_array);
-}
-
struct trap_context {
SV *routine;
SV *context;
@@ -1001,6 +969,33 @@ cfish_Err_trap(CFISH_Err_Attempt_t routine, void *context) {
return error;
}
+/**************************** Clownfish::Vector *****************************/
+
+void*
+CFISH_Vec_To_Host_IMP(cfish_Vector *self) {
+ dTHX;
+ AV *perl_array = newAV();
+ uint32_t num_elems = CFISH_Vec_Get_Size(self);
+
+ // Iterate over array elems.
+ if (num_elems) {
+ av_fill(perl_array, num_elems - 1);
+ for (uint32_t i = 0; i < num_elems; i++) {
+ cfish_Obj *val = CFISH_Vec_Fetch(self, i);
+ if (val == NULL) {
+ continue;
+ }
+ else {
+ // Recurse for each value.
+ SV *const val_sv = XSBind_cfish_to_perl(aTHX_ val);
+ av_store(perl_array, i, val_sv);
+ }
+ }
+ }
+
+ return newRV_noinc((SV*)perl_array);
+}
+
/***************************** Clownfish::Hash ******************************/
void*