OUTPUT:
RETVAL
+bool
+exists_ent(hash, key_sv)
+ PREINIT:
+ INPUT:
+ HV *hash
+ SV *key_sv
+ CODE:
+ RETVAL = hv_exists_ent(hash, key_sv, 0);
+ OUTPUT:
+ RETVAL
+
SV *
delete(hash, key_sv, flags = 0)
PREINIT:
OUTPUT:
RETVAL
-
SV *
store(hash, key_sv, value)
PREINIT:
OUTPUT:
RETVAL
+SV *
+fetch_ent(hash, key_sv)
+ PREINIT:
+ HE *result;
+ INPUT:
+ HV *hash
+ SV *key_sv
+ CODE:
+ result = hv_fetch_ent(hash, key_sv, 0, 0);
+ if (!result) {
+ XSRETURN_EMPTY;
+ }
+ /* Force mg_get */
+ RETVAL = newSVsv(HeVAL(result));
+ OUTPUT:
+ RETVAL
SV *
fetch(hash, key_sv)
is(keys %hash, 1);
@keys = sort keys %hash;
is("@keys", join(' ', sort(rot13(qw(e)))));
+
+ $hash{f} = 9;
+ is(keys %hash, 2);
+ @keys = sort keys %hash;
+ is("@keys", join(' ', sort(rot13(qw(e f)))));
+
+ is (XS::APItest::Hash::store_ent(\%hash, 'g', 10), 10, "store_ent");
+ is(keys %hash, 3);
+ @keys = sort keys %hash;
+ is("@keys", join(' ', sort(rot13(qw(e f g)))));
+
+ is (XS::APItest::Hash::store(\%hash, 'h', 11), 11, "store");
+ is(keys %hash, 4);
+ @keys = sort keys %hash;
+ is("@keys", join(' ', sort(rot13(qw(e f g h)))));
+
+ is (XS::APItest::Hash::fetch_ent(\%hash, 'g'), 10, "fetch_ent");
+ is (XS::APItest::Hash::fetch_ent(\%hash, rot13('g')), undef,
+ "fetch_ent (missing)");
+
+ is (XS::APItest::Hash::fetch(\%hash, 'h'), 11, "fetch");
+ is (XS::APItest::Hash::fetch(\%hash, rot13('h')), undef,
+ "fetch (missing)");
+
+ ok (XS::APItest::Hash::exists_ent(\%hash, 'e'), "exists_ent");
+ ok (!XS::APItest::Hash::exists_ent(\%hash, rot13('e')),
+ "exists_ent (missing)");
+
+ ok (XS::APItest::Hash::exists(\%hash, 'f'), "exists");
+ ok (!XS::APItest::Hash::exists(\%hash, rot13('f')), "exists (missing)");
}
exit;
if (!hv)
return NULL;
+ if (SvSMAGICAL(hv) && SvGMAGICAL(hv) && !(action & HV_DISABLE_UVAR_XKEY)) {
+ keysv = hv_magic_uvar_xkey(hv, keysv, key, klen, flags, action);
+ /* If a fetch-as-store fails on the fetch, then the action is to
+ recurse once into "hv_store". If we didn't do this, then that
+ recursive call would call the key conversion routine again.
+ However, as we replace the original key with the converted
+ key, this would result in a double conversion, which would show
+ up as a bug if the conversion routine is not idempotent. */
+ }
if (keysv) {
- if (SvSMAGICAL(hv) && SvGMAGICAL(hv)
- && !(action & HV_DISABLE_UVAR_XKEY)) {
- keysv = hv_magic_uvar_xkey(hv, keysv, 0, 0, 0, action);
- /* If a fetch-as-store fails on the fetch, then the action is to
- recurse once into "hv_store". If we didn't do this, then that
- recursive call would call the key conversion routine again.
- However, as we replace the original key with the converted
- key, this would result in a double conversion, which would show
- up as a bug if the conversion routine is not idempotent. */
- }
if (flags & HVhek_FREEKEY)
Safefree(key);
key = SvPV_const(keysv, klen);