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 2009/12/24 16:28:37 UTC
svn commit: r893780 - in /lucene/lucy/trunk/perl: t/binding/017-hash.t
xs/XSBind.c
Author: marvin
Date: Thu Dec 24 15:28:35 2009
New Revision: 893780
URL: http://svn.apache.org/viewvc?rev=893780&view=rev
Log:
Fix a bug in the Perl bindings where the UTF-8-ness of hash keys was not
preserved on the transition for a Lucy Hash with CharBuf keys to a Perl hash.
Modified:
lucene/lucy/trunk/perl/t/binding/017-hash.t
lucene/lucy/trunk/perl/xs/XSBind.c
Modified: lucene/lucy/trunk/perl/t/binding/017-hash.t
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/t/binding/017-hash.t?rev=893780&r1=893779&r2=893780&view=diff
==============================================================================
--- lucene/lucy/trunk/perl/t/binding/017-hash.t (original)
+++ lucene/lucy/trunk/perl/t/binding/017-hash.t Thu Dec 24 15:28:35 2009
@@ -1,9 +1,10 @@
use strict;
use warnings;
-use Test::More tests => 2;
+use Test::More tests => 3;
use Storable qw( nfreeze thaw );
use Lucy::Test;
+use Lucy::Util::ToolSet qw( to_perl to_lucy );
my $hash = Lucy::Object::Hash->new( capacity => 10 );
$hash->store( "foo", Lucy::Object::CharBuf->new("bar") );
@@ -23,3 +24,7 @@
my $deserialized = $hash->deserialize($instream);
is_deeply( $hash->to_perl, $deserialized->to_perl, "serialize/deserialize" );
+my %hash_with_utf8_keys = ( "\x{263a}" => "foo" );
+my $round_tripped = to_perl( to_lucy( \%hash_with_utf8_keys ) );
+is_deeply( $round_tripped, \%hash_with_utf8_keys,
+ "Round trip conversion of hash with UTF-8 keys" );
Modified: lucene/lucy/trunk/perl/xs/XSBind.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/xs/XSBind.c?rev=893780&r1=893779&r2=893780&view=diff
==============================================================================
--- lucene/lucy/trunk/perl/xs/XSBind.c (original)
+++ lucene/lucy/trunk/perl/xs/XSBind.c Thu Dec 24 15:28:35 2009
@@ -299,9 +299,14 @@
S_lucy_hash_to_perl_hash(lucy_Hash *hash)
{
HV *perl_hash = newHV();
+ SV *key_sv = newSV(1);
lucy_CharBuf *key;
lucy_Obj *val;
+ /* Prepare the SV key. */
+ SvPOK_on(key_sv);
+ SvUTF8_on(key_sv);
+
/* Iterate over key-value pairs. */
Lucy_Hash_Iter_Init(hash);
while (Lucy_Hash_Iter_Next(hash, (lucy_Obj**)&key, &val)) {
@@ -312,9 +317,16 @@
"Can't convert a key of class %o to a Perl hash key",
Lucy_Obj_Get_Class_Name(key));
}
- hv_store(perl_hash, (char*)Lucy_CB_Get_Ptr8(key),
- Lucy_CB_Get_Size(key), val_sv, 0);
+ else {
+ STRLEN key_size = Lucy_CB_Get_Size(key);
+ char *key_sv_ptr = SvGROW(key_sv, key_size + 1);
+ memcpy(key_sv_ptr, Lucy_CB_Get_Ptr8(key), key_size);
+ SvCUR_set(key_sv, key_size);
+ *SvEND(key_sv) = '\0';
+ hv_store_ent(perl_hash, key_sv, val_sv, 0);
+ }
}
+ SvREFCNT_dec(key_sv);
return newRV_noinc((SV*)perl_hash);
}