Skip to content
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

Closed
p5pRT opened this issue Dec 17, 1999 · 4 comments
Closed

\delete $a{foo} #965

p5pRT opened this issue Dec 17, 1999 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 17, 1999

Migrated from rt.perl.org#1912 (status was 'resolved')

Searchable as RT1912$

@p5pRT
Copy link
Author

p5pRT commented Dec 17, 1999

From @gisle

Shouldn't \$a{bar} and \delete $a{bar} give a reference to the same
thing? It looks like with delete you get a reference to a copy of the
value that was present in the hash.

$a{bar} = 33;
$b = \$a{bar};
$c = \delete $a{bar};

print "not " unless $b == $c;
print "ok 1\n";

Perl Info


Site configuration information for perl 5.00503:

Configured by gisle at Wed Sep  8 11:27:53 CEST 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.2.10, archname=i686-linux
    uname='linux eik 2.2.10 #1 tue jul 20 16:32:24 mest 1999 i686 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
    cppflags='-Dbool=char -DHAS_BOOL'
    ccflags ='-Dbool=char -DHAS_BOOL'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =''
    libpth=/shlib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared'

Locally applied patches:
    


@INC for perl 5.00503:
    /local/perl/5.005/lib/5.00503/i686-linux
    /local/perl/5.005/lib/5.00503
    /local/perl/5.005/lib/site_perl/5.005/i686-linux
    /local/perl/5.005/lib/site_perl/5.005
    .


Environment for perl 5.00503:
    HOME=/home/gisle
    LANG=POSIX
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/gisle/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/openwin/bin:/usr/lib/java/bin:/var/lib/dosemu:/usr/games/bin:/usr/games:/opt/gnome/bin:/opt/kde/bin:.:/local/perl/bin:/usr/lib/pgsql/bin:/opt/pilotsdk/bin:/var/qmail/bin:/local/ssh/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 17, 1999

From @gsar

On 17 Dec 1999 14​:36​:17 GMT, gisle@​aas.no wrote​:

Shouldn't \$a{bar} and \delete $a{bar} give a reference to the same
thing? It looks like with delete you get a reference to a copy of the
value that was present in the hash.

$a{bar} = 33;
$b = \$a{bar};
$c = \delete $a{bar};

print "not " unless $b == $c;
print "ok 1\n";

Here's a patch.

Sarathy
gsar@​ActiveState.com

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.

@p5pRT
Copy link
Author

p5pRT commented Dec 17, 1999

From @gisle

Gurusamy Sarathy <gsar@​ActiveState.com> writes​:

On 17 Dec 1999 14​:36​:17 GMT, gisle@​aas.no wrote​:

Shouldn't \$a{bar} and \delete $a{bar} give a reference to the same
thing? It looks like with delete you get a reference to a copy of the
value that was present in the hash.

$a{bar} = 33;
$b = \$a{bar};
$c = \delete $a{bar};

print "not " unless $b == $c;
print "ok 1\n";

Here's a patch.

Wow! That was quick. Thank you!

Regards,
Gisle

@p5pRT
Copy link
Author

p5pRT commented Dec 17, 1999

From @gsar

On 17 Dec 1999 19​:48​:29 +0100, Gisle Aas wrote​:

Wow! That was quick. Thank you!

Yeah, quick and buggy as hell. Thanks to Larry for spotting
the leak.

Sarathy
gsar@​ActiveState.com

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant