develooper Front page | perl.perl5.porters | Postings from March 2006

Re: how should %^H work with lexical pramas

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
March 31, 2006 09:46
Subject:
Re: how should %^H work with lexical pramas
Message ID:
20060331174554.GV32132@plum.flirble.org
On Fri, Mar 31, 2006 at 02:57:44PM +0100, Nicholas Clark wrote:
> Current runtime behaviour of %^H is unchanged. I've not tested caller through
> evals yet - it may be broken. Others are welcome to write tests while I take
> a little break from all this. It may be possible to avoid Robin's trick of
> storing %^H away for eval, now that %^H can be recreated.

The appended patch seems to make caller work in evals. I'm not sure if it's
actually functionally correct, or if it's threadsafe.
Is PL_compiling.cop_hints shared across threads?

Nicholas Clark

==== //depot/perl/pp_ctl.c#537 - /home/nick/p4perl/perl/pp_ctl.c ====
--- /tmp/tmp.82617.0    Fri Mar 31 18:44:47 2006
+++ /home/nick/p4perl/perl/pp_ctl.c     Fri Mar 31 18:21:01 2006
@@ -3476,6 +3476,16 @@ PP(pp_entereval)
         PL_compiling.cop_io = newSVsv(PL_curcop->cop_io);
         SAVEFREESV(PL_compiling.cop_io);
     }
+    if (PL_compiling.cop_hints) {
+       PL_compiling.cop_hints->refcounted_he_refcnt--;
+    }
+    PL_compiling.cop_hints = PL_curcop->cop_hints;
+    /* FIXME - is this threadsafe?  Or is it manipulating a shared
+       resource?  */
+    if (PL_compiling.cop_hints) {
+       PL_compiling.cop_hints->refcounted_he_refcnt++;
+    }
+
     /* special case: an eval '' executed within the DB package gets lexically
      * placed in the first non-DB CV rather than the current CV - this
      * allows the debugger to execute code, find lexicals etc, in the
==== //depot/perl/t/op/caller.t#7 - /home/nick/p4perl/perl/t/op/caller.t ====
--- /tmp/tmp.82617.1    Fri Mar 31 18:44:47 2006
+++ /home/nick/p4perl/perl/t/op/caller.t        Fri Mar 31 18:24:48 2006
@@ -5,7 +5,7 @@ BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
     require './test.pl';
-    plan( tests => 56 );
+    plan( tests => 64 );
 }
 
 my @c;
@@ -200,4 +200,26 @@ sub dooot {
     }
     is(get_dooot(), 6 * 7);
     is(get_thikoosh(), "SKREECH");
+}
+
+{
+    BEGIN {
+       $^H{dooot} = 42;
+    }
+    is(get_dooot(), 6 * 7);
+    
+    eval "is(get_dooot(), 6 * 7); 1" or die $@;
+
+    eval <<'EOE' or die $@;
+    is(get_dooot(), 6 * 7);
+    eval "is(get_dooot(), 6 * 7); 1" or die $@;
+    BEGIN {
+       $^H{dooot} = 54;
+    }
+    is(get_dooot(), 54);
+    eval "is(get_dooot(), 54); 1" or die $@;
+    eval 'BEGIN { $^H{dooot} = -1; }; 1' or die $@;
+    is(get_dooot(), 54);
+    eval "is(get_dooot(), 54); 1" or die $@;
+EOE
 }

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About