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:41 UTC
[02/12] lucy-clownfish git commit: Implement Hash_To_Host
Implement Hash_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/dc82fc54
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/dc82fc54
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/dc82fc54
Branch: refs/heads/master
Commit: dc82fc54c3faf929b271fca886feab9fb02e06da
Parents: 7bceed1
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri May 29 13:53:05 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri May 29 17:44:47 2015 +0200
----------------------------------------------------------------------
runtime/core/Clownfish/Hash.cfh | 3 ++
runtime/perl/xs/XSBind.c | 58 +++++++++++++++++-------------------
2 files changed, 30 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dc82fc54/runtime/core/Clownfish/Hash.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Hash.cfh b/runtime/core/Clownfish/Hash.cfh
index 6217415..95f4779 100644
--- a/runtime/core/Clownfish/Hash.cfh
+++ b/runtime/core/Clownfish/Hash.cfh
@@ -44,6 +44,9 @@ public final class Clownfish::Hash inherits Clownfish::Obj {
inert String*
get_tombstone();
+ void*
+ To_Host(Hash *self);
+
/** Empty the hash of all key-value pairs.
*/
public void
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dc82fc54/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index 72c4337..75d6941 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -54,10 +54,6 @@ S_perl_array_to_cfish_array(pTHX_ AV *parray);
static SV*
S_cfish_array_to_perl_array(pTHX_ cfish_Vector *varray);
-// Convert a Hash to a Perl hash. Caller takes responsibility for a refcount.
-static SV*
-S_cfish_hash_to_perl_hash(pTHX_ cfish_Hash *hash);
-
cfish_Obj*
XSBind_new_blank_obj(pTHX_ SV *either_sv) {
cfish_Class *klass;
@@ -162,9 +158,6 @@ XSBind_cfish_to_perl(pTHX_ cfish_Obj *obj) {
else if (cfish_Obj_is_a(obj, CFISH_VECTOR)) {
return S_cfish_array_to_perl_array(aTHX_ (cfish_Vector*)obj);
}
- else if (cfish_Obj_is_a(obj, CFISH_HASH)) {
- return S_cfish_hash_to_perl_hash(aTHX_ (cfish_Hash*)obj);
- }
else {
return (SV*)CFISH_Obj_To_Host(obj);
}
@@ -334,30 +327,6 @@ S_cfish_array_to_perl_array(pTHX_ cfish_Vector *varray) {
return newRV_noinc((SV*)perl_array);
}
-static SV*
-S_cfish_hash_to_perl_hash(pTHX_ cfish_Hash *hash) {
- HV *perl_hash = newHV();
- cfish_HashIterator *iter = cfish_HashIter_new(hash);
-
- // Iterate over key-value pairs.
- while (CFISH_HashIter_Next(iter)) {
- cfish_String *key = CFISH_HashIter_Get_Key(iter);
- const char *key_ptr = CFISH_Str_Get_Ptr8(key);
- I32 key_size = CFISH_Str_Get_Size(key);
-
- // Recurse for each value.
- cfish_Obj *val = CFISH_HashIter_Get_Value(iter);
- SV *val_sv = XSBind_cfish_to_perl(aTHX_ val);
-
- // Using a negative `klen` argument to signal UTF-8 is undocumented
- // in older Perl versions but works since 5.8.0.
- hv_store(perl_hash, key_ptr, -key_size, val_sv, 0);
- }
-
- CFISH_DECREF(iter);
- return newRV_noinc((SV*)perl_hash);
-}
-
struct trap_context {
SV *routine;
SV *context;
@@ -1032,6 +1001,33 @@ cfish_Err_trap(CFISH_Err_Attempt_t routine, void *context) {
return error;
}
+/***************************** Clownfish::Hash ******************************/
+
+void*
+CFISH_Hash_To_Host_IMP(cfish_Hash *self) {
+ dTHX;
+ HV *perl_hash = newHV();
+ cfish_HashIterator *iter = cfish_HashIter_new(self);
+
+ // Iterate over key-value pairs.
+ while (CFISH_HashIter_Next(iter)) {
+ cfish_String *key = CFISH_HashIter_Get_Key(iter);
+ const char *key_ptr = CFISH_Str_Get_Ptr8(key);
+ I32 key_size = CFISH_Str_Get_Size(key);
+
+ // Recurse for each value.
+ cfish_Obj *val = CFISH_HashIter_Get_Value(iter);
+ SV *val_sv = XSBind_cfish_to_perl(aTHX_ val);
+
+ // Using a negative `klen` argument to signal UTF-8 is undocumented
+ // in older Perl versions but works since 5.8.0.
+ hv_store(perl_hash, key_ptr, -key_size, val_sv, 0);
+ }
+
+ CFISH_DECREF(iter);
+ return newRV_noinc((SV*)perl_hash);
+}
+
/****************************** Clownfish::Num ******************************/
void*