New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
\delete $a{foo} #965
Comments
From @gisleShouldn't \$a{bar} and \delete $a{bar} give a reference to the same $a{bar} = 33; print "not " unless $b == $c; Perl Info
|
From @gsarOn 17 Dec 1999 14:36:17 GMT, gisle@aas.no wrote:
Here's a patch. Sarathy Inline Patch-----------------------------------8<-----------------------------------
Change 4694 by gsar@auger on 1999/12/17 18:09:08
delete() should return the value as is, not a copy thereof
Affected files ...
... //depot/perl/hv.c#51 edit
... //depot/perl/pod/perldelta.pod#120 edit
Differences ...
==== //depot/perl/hv.c#51 (text) ====
Index: perl/hv.c
--- perl/hv.c.~1~ Fri Dec 17 10:09:12 1999
+++ perl/hv.c Fri Dec 17 10:09:12 1999
@@ -502,8 +502,10 @@
xhv->xhv_fill--;
if (flags & G_DISCARD)
sv = Nullsv;
- else
- sv = sv_mortalcopy(HeVAL(entry));
+ else {
+ sv = HeVAL(entry);
+ HeVAL(entry) = &PL_sv_undef;
+ }
if (entry == xhv->xhv_eiter)
HvLAZYDEL_on(hv);
else
@@ -576,8 +578,10 @@
xhv->xhv_fill--;
if (flags & G_DISCARD)
sv = Nullsv;
- else
- sv = sv_mortalcopy(HeVAL(entry));
+ else {
+ sv = HeVAL(entry);
+ HeVAL(entry) = &PL_sv_undef;
+ }
if (entry == xhv->xhv_eiter)
HvLAZYDEL_on(hv);
else
==== //depot/perl/pod/perldelta.pod#120 (text) ====
Index: perl/pod/perldelta.pod
--- perl/pod/perldelta.pod.~1~ Fri Dec 17 10:09:12 1999
+++ perl/pod/perldelta.pod Fri Dec 17 10:09:12 1999
@@ -95,9 +95,9 @@
In Perl 5.6 and later, C<"$$1"> always means C<"${$1}">.
-=item values(%h) and C<\(%h)> operate on aliases to values, not copies
+=item delete(), values() and C<\(%h)> operate on aliases to values, not copies
-each(), values() and hashes in a list context return the actual
+delete(), each(), values() and hashes in a list context return the actual
values in the hash, instead of copies (as they used to in earlier
versions). Typical idioms for using these constructs copy the
returned values, but this can make a significant difference when
End of Patch.
Change 4695 by gsar@auger on 1999/12/17 18:14:11
test case for change#4694
Affected files ...
... //depot/perl/t/op/delete.t#7 edit
Differences ...
==== //depot/perl/t/op/delete.t#7 (xtext) ====
Index: perl/t/op/delete.t
--- perl/t/op/delete.t.~1~ Fri Dec 17 10:14:14 1999
+++ perl/t/op/delete.t Fri Dec 17 10:14:14 1999
@@ -1,9 +1,7 @@
#!./perl
-# $RCSfile: delete.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:44 $
-
-print "1..16\n";
+print "1..17\n";
$foo{1} = 'a';
$foo{2} = 'b';
$foo{3} = 'c';
@@ -49,3 +47,13 @@
@list = keys %{$refhash{"top"}};
print "@list" eq "foo" ? "ok 16\n" : "not ok 16 @list\n";
+
+{
+ my %a = ('bar', 33);
+ my($a) = \(values %a);
+ my $b = \$a{bar};
+ my $c = \delete $a{bar};
+
+ print "not " unless $a == $b && $b == $c;
+ print "ok 17\n";
+}
End of Patch. |
From @gisleGurusamy Sarathy <gsar@ActiveState.com> writes:
Wow! That was quick. Thank you! Regards, |
From @gsarOn 17 Dec 1999 19:48:29 +0100, Gisle Aas wrote:
Yeah, quick and buggy as hell. Thanks to Larry for spotting Sarathy Inline Patch-----------------------------------8<-----------------------------------
Change 4696 by gsar@auger on 1999/12/17 19:55:03
leak in change#4694 spotted by Larry
Affected files ...
... //depot/perl/hv.c#52 edit
Differences ...
==== //depot/perl/hv.c#52 (text) ====
Index: perl/hv.c
--- perl/hv.c.~1~ Fri Dec 17 11:55:09 1999
+++ perl/hv.c Fri Dec 17 11:55:09 1999
@@ -503,7 +503,7 @@
if (flags & G_DISCARD)
sv = Nullsv;
else {
- sv = HeVAL(entry);
+ sv = sv_2mortal(HeVAL(entry));
HeVAL(entry) = &PL_sv_undef;
}
if (entry == xhv->xhv_eiter)
@@ -579,7 +579,7 @@
if (flags & G_DISCARD)
sv = Nullsv;
else {
- sv = HeVAL(entry);
+ sv = sv_2mortal(HeVAL(entry));
HeVAL(entry) = &PL_sv_undef;
}
if (entry == xhv->xhv_eiter)
End of Patch. |
Migrated from rt.perl.org#1912 (status was 'resolved')
Searchable as RT1912$
The text was updated successfully, but these errors were encountered: