Change 16432 by jhi@alpha on 2002/05/06 13:29:22

        Add a test for #16431, and document Dave's campaign
        against localised hash element bugs.

Affected files ...

.... //depot/perl/pod/perldelta.pod#365 edit
.... //depot/perl/t/op/tie.t#17 edit

Differences ...

==== //depot/perl/pod/perldelta.pod#365 (text) ====
Index: perl/pod/perldelta.pod
--- perl/pod/perldelta.pod#364~16429~   Mon May  6 05:18:23 2002
+++ perl/pod/perldelta.pod      Mon May  6 06:29:22 2002
@@ -544,6 +544,11 @@
 
 =item *
 
+Tied hash interfaces are now required to have the EXISTS method
+(either own or inherited).
+
+=item *
+
 If tr/// is just counting characters, it doesn't attempt to
 modify its target.
 
@@ -1928,6 +1933,40 @@
 
 =item *
 
+Localised tied variables no more leak memory
+
+    use Tie::Hash;
+    tie my %tied_hash => 'Tie::StdHash';
+
+    ...
+
+    # Used to leak memory every time local() was called,
+    # in a loop this added up.
+    local($tied_hash{Foo}) = 1;
+
+=item *
+
+Localised hash elements are correctly unlocalised to not to exist,
+if that's what they where.
+
+
+    use Tie::Hash;
+    tie my %tied_hash => 'Tie::StdHash';
+
+    ...
+
+    # Nothing has set the FOO element so far
+
+    { local $tied_hash{FOO} = 'Bar' }
+    
+    # Here the FOO element would have been C<undef>,
+    # but no more so. 
+
+As a side effect of this fix, tied hash interfaces B<must> define
+the EXISTS method.
+
+=item *
+
 mkdir() now ignores trailing slashes in the directory name,
 as mandated by POSIX.
 
@@ -2845,18 +2884,6 @@
 =head2 XML::Parser not working
 
 Use XML::Parser 2.31 or later.
-
-=head2 Localising a Tied Variable Leaks Memory
-
-    use Tie::Hash;
-    tie my %tie_hash => 'Tie::StdHash';
-
-    ...
-
-    local($tie_hash{Foo}) = 1; # leaks
-
-Code like the above is known to leak memory every time the local()
-is executed.
 
 =head2 z/OS (OS/390)
 

==== //depot/perl/t/op/tie.t#17 (xtext) ====
Index: perl/t/op/tie.t
--- perl/t/op/tie.t#16~9955~    Wed May  2 06:05:38 2001
+++ perl/t/op/tie.t     Mon May  6 06:29:22 2002
@@ -202,3 +202,12 @@
 tie FH, 'main';
 EXPECT
 
+########
+# correct unlocalisation of tied hashes (patch #16431)
+use Tie::Hash ;
+tie %tied, Tie::StdHash;
+{ local $hash{'foo'} } print "exist1\n" if exists $hash{'foo'};
+{ local $tied{'foo'} } print "exist2\n" if exists $tied{'foo'};
+{ local $ENV{'foo'}  } print "exist3\n" if exists $ENV{'foo'};
+EXPECT
+
End of Patch.

Reply via email to