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/08/06 18:22:18 UTC

[2/5] lucy git commit: Fix hv_fetch with UTF-8 keys

Fix hv_fetch with UTF-8 keys


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/35b4c52e
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/35b4c52e
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/35b4c52e

Branch: refs/heads/master
Commit: 35b4c52ebaf789920276154a150615896e8edc47
Parents: 199561e
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Aug 1 17:19:13 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 4 21:57:40 2015 +0200

----------------------------------------------------------------------
 perl/xs/Lucy/Document/Doc.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/35b4c52e/perl/xs/Lucy/Document/Doc.c
----------------------------------------------------------------------
diff --git a/perl/xs/Lucy/Document/Doc.c b/perl/xs/Lucy/Document/Doc.c
index 2f54da7..fff4e62 100644
--- a/perl/xs/Lucy/Document/Doc.c
+++ b/perl/xs/Lucy/Document/Doc.c
@@ -150,7 +150,7 @@ LUCY_Doc_Extract_IMP(lucy_Doc *self, cfish_String *field) {
     lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
     cfish_Obj *retval = NULL;
     SV **sv_ptr = hv_fetch((HV*)ivars->fields, CFISH_Str_Get_Ptr8(field),
-                           CFISH_Str_Get_Size(field), 0);
+                           -CFISH_Str_Get_Size(field), 0);
 
     if (sv_ptr) {
         retval = XSBind_perl_to_cfish(aTHX_ *sv_ptr);
@@ -218,8 +218,20 @@ LUCY_Doc_Equals_IMP(lucy_Doc *self, cfish_Obj *other) {
     while (num_fields--) {
         HE *my_entry = hv_iternext(my_fields);
         SV *my_val_sv = HeVAL(my_entry);
-        STRLEN key_len = HeKLEN(my_entry);
-        char *key = HeKEY(my_entry);
+        STRLEN key_len;
+        char *key;
+
+        if (HeKLEN(my_entry) == HEf_SVKEY) {
+            SV *key_sv = HeKEY_sv(my_entry);
+            key = SvPV(key_sv, key_len);
+            if (SvUTF8(key_sv)) { key_len = -key_len; }
+        }
+        else {
+            key_len = HeKLEN(my_entry);
+            key = key_len ? HeKEY(my_entry) : Nullch;
+            if (HeKUTF8(my_entry)) { key_len = -key_len; }
+        }
+
         SV **const other_val = hv_fetch(other_fields, key, key_len, 0);
         if (!other_val) { return false; }
         if (!sv_eq(my_val_sv, *other_val)) { return false; }