av_delete() didn't reify. I also updated its description
p4raw-id: //depot/perl@22624
=for apidoc av_delete
Deletes the element indexed by C<key> from the array. Returns the
-deleted element. C<flags> is currently ignored.
+deleted element. If C<flags> equals C<G_DISCARD>, the element is freed
+and null is returned.
=cut
*/
if (key > AvFILLp(av))
return Nullsv;
else {
+ if (!AvREAL(av) && AvREIFY(av))
+ av_reify(av);
sv = AvARRAY(av)[key];
if (key == AvFILLp(av)) {
AvARRAY(av)[key] = &PL_sv_undef;
}
require './test.pl';
-plan( tests => 20 );
+plan( tests => 23 );
# test various operations on @_
is(join('',bar('d')),'Dd');
is(join('',baz('e')),'eE');
}
+
+# [perl #28032] delete $_[0] was freeing things too early
+
+{
+ my $flag = 0;
+ sub X::DESTROY { $flag = 1 }
+ sub f {
+ delete $_[0];
+ ok(!$flag, 'delete $_[0] : in f');
+ }
+ {
+ my $x = bless [], 'X';
+ f($x);
+ ok(!$flag, 'delete $_[0] : after f');
+ }
+ ok($flag, 'delete $_[0] : outside block');
+}
+
+