Repository: lucy-clownfish Updated Branches: refs/heads/master 5343ab61c -> aec7214de
Hash_Store should accept nullable values. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/11fdf7fe Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/11fdf7fe Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/11fdf7fe Branch: refs/heads/master Commit: 11fdf7fecb21102337fe713c35995b7898076143 Parents: 8655f18 Author: Marvin Humphrey <[email protected]> Authored: Tue Aug 4 18:43:40 2015 -0700 Committer: Marvin Humphrey <[email protected]> Committed: Wed Aug 5 15:23:11 2015 -0700 ---------------------------------------------------------------------- runtime/core/Clownfish/Hash.cfh | 4 ++-- runtime/core/Clownfish/Test/TestHash.c | 10 +++++++++- runtime/perl/buildlib/Clownfish/Build/Binding.pm | 9 ++++++--- runtime/perl/t/binding/017-hash.t | 7 ++++++- 4 files changed, 23 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11fdf7fe/runtime/core/Clownfish/Hash.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Hash.cfh b/runtime/core/Clownfish/Hash.cfh index 95f4779..33d4cfd 100644 --- a/runtime/core/Clownfish/Hash.cfh +++ b/runtime/core/Clownfish/Hash.cfh @@ -55,11 +55,11 @@ public final class Clownfish::Hash inherits Clownfish::Obj { /** Store a key-value pair. */ public void - Store(Hash *self, String *key, decremented Obj *value); + Store(Hash *self, String *key, decremented nullable Obj *value); public void Store_Utf8(Hash *self, const char *str, size_t len, - decremented Obj *value); + decremented nullable Obj *value); /** Fetch the value associated with `key`. * http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11fdf7fe/runtime/core/Clownfish/Test/TestHash.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestHash.c b/runtime/core/Clownfish/Test/TestHash.c index 2fe1be3..2c5e27f 100644 --- a/runtime/core/Clownfish/Test/TestHash.c +++ b/runtime/core/Clownfish/Test/TestHash.c @@ -122,6 +122,14 @@ test_Store_and_Fetch(TestBatchRunner *runner) { TEST_TRUE(runner, Hash_Fetch(hash, twenty) == NULL, "Clear"); TEST_TRUE(runner, Hash_Get_Size(hash) == 0, "size is 0 after Clear"); + Hash_Clear(hash); + Hash_Store(hash, forty, NULL); + TEST_TRUE(runner, Hash_Fetch(hash, forty) == NULL, "Store NULL"); + TEST_TRUE(runner, Hash_Get_Size(hash) == 1, "Size after Store NULL"); + TEST_TRUE(runner, Hash_Delete(hash, forty) == NULL, "Delete NULL value"); + TEST_TRUE(runner, Hash_Get_Size(hash) == 0, + "Size after Deleting NULL val"); + DECREF(hash); DECREF(dupe); DECREF(got); @@ -239,7 +247,7 @@ test_store_skips_tombstone(TestBatchRunner *runner) { void TestHash_Run_IMP(TestHash *self, TestBatchRunner *runner) { - TestBatchRunner_Plan(runner, (TestBatch*)self, 26); + TestBatchRunner_Plan(runner, (TestBatch*)self, 30); srand((unsigned int)time((time_t*)NULL)); test_Equals(runner); test_Store_and_Fetch(runner); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11fdf7fe/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 b6fe63a..2cbf62f 100644 --- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm +++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm @@ -302,13 +302,16 @@ CODE: OUTPUT: RETVAL void -store(self, key, value); +store(self, key, value_sv); cfish_Hash *self; cfish_String *key; - cfish_Obj *value; + SV *value_sv; PPCODE: { - if (value) { CFISH_INCREF(value); } + cfish_Obj *value + = (cfish_Obj*)XSBind_maybe_sv_to_cfish_obj(aTHX_ value_sv, CFISH_OBJ, + CFISH_ALLOCA_OBJ(CFISH_STRING)); + if (value) { value = CFISH_INCREF(value); } CFISH_Hash_Store_IMP(self, key, value); } END_XS_CODE http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11fdf7fe/runtime/perl/t/binding/017-hash.t ---------------------------------------------------------------------- diff --git a/runtime/perl/t/binding/017-hash.t b/runtime/perl/t/binding/017-hash.t index 1843198..8844255 100644 --- a/runtime/perl/t/binding/017-hash.t +++ b/runtime/perl/t/binding/017-hash.t @@ -16,7 +16,7 @@ use strict; use warnings; -use Test::More tests => 2; +use Test::More tests => 4; use Clownfish qw( to_perl to_clownfish ); my $hash = Clownfish::Hash->new( capacity => 10 ); @@ -26,6 +26,11 @@ $hash->store( "baz", Clownfish::String->new("banana") ); ok( !defined( $hash->fetch("blah") ), "fetch for a non-existent key returns undef" ); +$hash->clear(); +$hash->store( "nada", undef ); +ok( !defined($hash->fetch("nada")), "store/fetch undef value" ); +is( $hash->get_size, 1, "size after storing undef value" ); + my %hash_with_utf8_keys = ( "\x{263a}" => "foo" ); my $round_tripped = to_perl( to_clownfish( \%hash_with_utf8_keys ) ); is_deeply( $round_tripped, \%hash_with_utf8_keys,
