develooper Front page | perl.perl5.porters | Postings from September 2000

Re: [ID 20000828.017] bytecode fails with use subs;

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
September 28, 2000 03:52
Subject:
Re: [ID 20000828.017] bytecode fails with use subs;
Message ID:
20000928115224.D7924@plum.flirble.org
On Tue, Aug 29, 2000 at 04:57:46PM +0100, Nicholas Clark wrote:
> On Tue, Aug 29, 2000 at 07:18:40AM -0700, Benjamin Stuhl wrote:
> > I'm not entirely sure where to go. One option (read:
> > (possibly evil) hack) is to have subs.pm store a list
> > (perhaps @B::Bytecode::Savelist) of what it's creating and
> > have B::Bytecode look at that to see what subs that it
> > would normally ignore should actually should be saved.
> 
> This seems both evil and slow :-(
> My understanding is that  Evil is allowed if it has the saving grace

Simon Cozens and I had a chat at YAPC::Europe, and concluded that the correct
solution was to turn off the GvIMPORTED_CV flag on a gv when the subroutine
was defined. Hopefully this patch is the correct implementation of this.]

This works for the common case of:

use subs qw(foo);
foo;
sub foo {
  print "This is foo\n";
}

(which didn't before)

However, 

&bar;
sub bar {
  print "This is bar\n";
}
use subs qw(bar);

still doesn't work. I guess it still needs sv.c not to set the GvIMPORTED_CV
flag if you're importing from yourself to yourself.
(simply to propagate any flag you find)

However, with the patch one can now byte-compile the use subs; in perlcc

Nicholas Clark

--- op.c.orig   Thu Sep 14 15:44:20 2000
+++ op.c        Wed Sep 27 21:51:04 2000
@@ -4561,6 +4561,9 @@
     CvGV(cv) = (GV*)SvREFCNT_inc(gv);
     CvFILE(cv) = CopFILE(PL_curcop);
     CvSTASH(cv) = PL_curstash;
+    /* use subs; etc may have turned this on
+       As we're (re)defining the sub here it's definately not imported */
+    GvIMPORTED_CV_off(gv);
 #ifdef USE_THREADS
     CvOWNER(cv) = 0;
     if (!CvMUTEXP(cv)) {


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