summaryrefslogtreecommitdiff
path: root/ext/XS
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2007-09-19 10:53:01 +0000
committerNicholas Clark <nick@ccl4.org>2007-09-19 10:53:01 +0000
commit55289a74a75e6b09fb47c096d0658212f035d6bf (patch)
treeab21251a689519bb277719e264a10da9bd0c8b6b /ext/XS
parent80d693dde7675a7adf00a63b6fe47d20f709d2c1 (diff)
downloadperl-55289a74a75e6b09fb47c096d0658212f035d6bf.tar.gz
Call the key transformation function for hv_delete().
Honour the HV_DISABLE_UVAR_XKEY for hv_delete(). Test this. [Pass in 3 more parameters to S_hv_magic_uvar_xkey()] p4raw-id: //depot/perl@31905
Diffstat (limited to 'ext/XS')
-rw-r--r--ext/XS/APItest/APItest.xs22
-rw-r--r--ext/XS/APItest/Makefile.PL9
-rw-r--r--ext/XS/APItest/t/hash.t32
3 files changed, 59 insertions, 4 deletions
diff --git a/ext/XS/APItest/APItest.xs b/ext/XS/APItest/APItest.xs
index da865e693d..96efd9bf77 100644
--- a/ext/XS/APItest/APItest.xs
+++ b/ext/XS/APItest/APItest.xs
@@ -195,8 +195,12 @@ rot13_key(pTHX_ IV action, SV *field) {
return 0;
}
+#include "const-c.inc"
+
MODULE = XS::APItest:Hash PACKAGE = XS::APItest::Hash
+INCLUDE: const-xs.inc
+
void
rot13_hash(hash)
HV *hash
@@ -227,17 +231,31 @@ exists(hash, key_sv)
RETVAL
SV *
-delete(hash, key_sv)
+delete(hash, key_sv, flags = 0)
PREINIT:
STRLEN len;
const char *key;
INPUT:
HV *hash
SV *key_sv
+ I32 flags;
CODE:
key = SvPV(key_sv, len);
/* It's already mortal, so need to increase reference count. */
- RETVAL = SvREFCNT_inc(hv_delete(hash, key, UTF8KLEN(key_sv, len), 0));
+ RETVAL
+ = SvREFCNT_inc(hv_delete(hash, key, UTF8KLEN(key_sv, len), flags));
+ OUTPUT:
+ RETVAL
+
+SV *
+delete_ent(hash, key_sv, flags = 0)
+ INPUT:
+ HV *hash
+ SV *key_sv
+ I32 flags;
+ CODE:
+ /* It's already mortal, so need to increase reference count. */
+ RETVAL = SvREFCNT_inc(hv_delete_ent(hash, key_sv, flags, 0));
OUTPUT:
RETVAL
diff --git a/ext/XS/APItest/Makefile.PL b/ext/XS/APItest/Makefile.PL
index 76aa60ac35..05bcfb06dc 100644
--- a/ext/XS/APItest/Makefile.PL
+++ b/ext/XS/APItest/Makefile.PL
@@ -1,5 +1,6 @@
use 5.008;
use ExtUtils::MakeMaker;
+use ExtUtils::Constant 0.11 'WriteConstants';
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
@@ -17,6 +18,14 @@ WriteMakefile(
# Un-comment this if you add C files to link with later:
# 'OBJECT' => '$(O_FILES)', # link all the C files too
MAN3PODS => {}, # Pods will be built by installman.
+ realclean => {FILES => 'const-c.inc const-xs.inc'},
+);
+
+WriteConstants(
+ PROXYSUBS => 1,
+ NAME => 'XS::APItest',
+ NAMES => [qw(HV_DELETE HV_DISABLE_UVAR_XKEY G_DISCARD HV_FETCH_ISSTORE
+ HV_FETCH_ISEXISTS HV_FETCH_LVALUE HV_FETCH_JUST_SV)],
);
sub MY::install { "install ::\n" };
diff --git a/ext/XS/APItest/t/hash.t b/ext/XS/APItest/t/hash.t
index 4af7f88ad6..949f175e0a 100644
--- a/ext/XS/APItest/t/hash.t
+++ b/ext/XS/APItest/t/hash.t
@@ -18,7 +18,7 @@ use utf8;
use Tie::Hash;
use Test::More 'no_plan';
-use_ok('XS::APItest');
+BEGIN {use_ok('XS::APItest')};
sub preform_test;
sub test_present;
@@ -95,7 +95,7 @@ foreach my $in ("", "N", "a\0b") {
is ($got, $in, "test_share_unshare_pvn");
}
-{
+if ($] > 5.009) {
my %hash;
XS::APItest::Hash::rot13_hash(\%hash);
$hash{a}++; @hash{qw(p i e)} = (2, 4, 8);
@@ -105,6 +105,34 @@ foreach my $in ("", "N", "a\0b") {
"uvar magic called exactly once on store");
is($hash{i}, 4);
+
+ is(delete $hash{a}, 1);
+
+ is(keys %hash, 3);
+ @keys = sort keys %hash;
+ is("@keys", join(' ', sort(rot13(qw(p i e)))));
+
+ is (XS::APItest::Hash::delete_ent (\%hash, 'p',
+ XS::APItest::HV_DISABLE_UVAR_XKEY),
+ undef, "Deleting a known key with conversion disabled fails (ent)");
+ is(keys %hash, 3);
+
+ is (XS::APItest::Hash::delete_ent (\%hash, 'p', 0),
+ 2, "Deleting a known key with conversion enabled works (ent)");
+ is(keys %hash, 2);
+ @keys = sort keys %hash;
+ is("@keys", join(' ', sort(rot13(qw(i e)))));
+
+ is (XS::APItest::Hash::delete (\%hash, 'i',
+ XS::APItest::HV_DISABLE_UVAR_XKEY),
+ undef, "Deleting a known key with conversion disabled fails");
+ is(keys %hash, 2);
+
+ is (XS::APItest::Hash::delete (\%hash, 'i', 0),
+ 4, "Deleting a known key with conversion enabled works");
+ is(keys %hash, 1);
+ @keys = sort keys %hash;
+ is("@keys", join(' ', sort(rot13(qw(e)))));
}
exit;