Re: [RFC] Switch to make Test::Builder output even if $^C ( for B::C )
Now I understand I missed to tell you this fundamental detail before, sorry. > perlcc seems to be dropping BEGIN blocks entirely, that's the problem. No, that's correct. Explanation: if I have a module Foo package Foo; $x = 1; print "AAA"; sub a { $x } 1; and a main program foo.pl BEGIN { # think use Foo;, expanded for clarity require Foo; } print Foo::a(); perl -MO=C foo.pl calls B::C::compile _after_ it ran the BEGIN blocks; this means that the optree in Foo that initializes $x, and does "print AAA" has already been freed. So, even if B::C could save BEGIN blocks, this is not a good idea, for quite a lot of reasons. > # foo.plx > BEGIN { > print "foo\n"; > } > print "bar\n"; > > $ bleadperl foo.plx > foo > bar > $ perlcc foo.plx > $ ./a.out > bar > > The result from the compiled program should be the same as the > original. For some reason the BEGIN block is getting dropped when the > program is compiled. That's a bug. It is not a bug that the BEGIN blocks are dropped. It is a B::C bug induced by the perl design that it can't deal gracefully with code in BEGIN blocks that print()s, or does other things to the "environment" ( OS, screen, disks, %ENV ), or that initializes data structures outside the scope of perl ( this includes interpreter-local data using MY_CXT ( Opcode.pm ), or creating a SV holding a pointer to an external data structure, or dup()s filehandles ( Test::Builder ) [1] ). The only solution to these problems is something like B::Script ( mentioned in april-june on p5p ). Regards Mattia [1] try searching perlcc.PL for Test::Builder...
Re: [RFC] Switch to make Test::Builder output even if $^C ( for B::C )
On Sun, Jan 13, 2002 at 07:39:52PM +0100, Mattia Barbon wrote: > > perlcc seems to be dropping BEGIN blocks entirely, that's the problem. > > No, that's correct. Explanation: if I have a module Foo > > package Foo; > > $x = 1; > print "AAA"; > > sub a { $x } > > 1; > > and a main program foo.pl > > BEGIN { # think use Foo;, expanded for clarity > require Foo; > } > > print Foo::a(); > > perl -MO=C foo.pl > calls B::C::compile _after_ it ran the BEGIN blocks; this means that the > optree in Foo that initializes $x, and does "print AAA" has already been > freed. So, even if B::C could save BEGIN blocks, this is not a good > idea, for quite a lot of reasons. $ bleadperl -MO=-qq,Deparse foo.plx sub BEGIN { print "foo\n"; } print "bar\n"; If B::Deparse can save BEGIN blocks, B::C can. -- Michael G. Schwern <[EMAIL PROTECTED]>http://www.pobox.com/~schwern/ Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One I have this god-awful need to aquire useless crap!!!
Re: [RFC] Switch to make Test::Builder output even if $^C ( for B::C )
> On Sun, Jan 13, 2002 at 07:39:52PM +0100, Mattia Barbon wrote: > > > perlcc seems to be dropping BEGIN blocks entirely, that's the problem. > > > > No, that's correct. Explanation: if I have a module Foo > > > > package Foo; > > > > $x = 1; > > print "AAA"; > > > > sub a { $x } > > > > 1; > > > > and a main program foo.pl > > > > BEGIN { # think use Foo;, expanded for clarity > > require Foo; > > } > > > > print Foo::a(); > > > > perl -MO=C foo.pl > > calls B::C::compile _after_ it ran the BEGIN blocks; this means that the > > optree in Foo that initializes $x, and does "print AAA" has already been > > freed. So, even if B::C could save BEGIN blocks, this is not a good > > idea, for quite a lot of reasons. I didn't write what I meant, sorry, see below > $ bleadperl -MO=-qq,Deparse foo.plx > sub BEGIN { > print "foo\n"; > } > print "bar\n"; > > If B::Deparse can save BEGIN blocks, B::C can. I didn't mean that I can't write code to make B::C save BEGIN blocks ( it'd require <10 lines, probably ), I did mean that doing so would not be a god idea: _I am saving the state of the program after those blocks were ran_ and they will be run _another time_ at runtime, and this is not correct: ( for example use lib 'a'; would put 'a' into @INC twice, once ( correctly ) at compile time, and another time ( incorrectly ) at runtime ). In this case this is not harmful, but you get the idea. Regards Mattia
Compiled programs to keep BEGIN blocks? (was Re: [RFC] Switch to make Test::Builder output even if $^C ( for B::C ))
On Sun, Jan 13, 2002 at 10:04:58PM +0100, Mattia Barbon wrote: > > $ bleadperl -MO=-qq,Deparse foo.plx > > sub BEGIN { > > print "foo\n"; > > } > > print "bar\n"; > > > > If B::Deparse can save BEGIN blocks, B::C can. > > I didn't mean that I can't write code to make B::C save BEGIN blocks > ( it'd require <10 lines, probably ), I did mean that doing so would > not be a god idea: _I am > saving the state of the program after those blocks were ran_ and > they will be run _another time_ at runtime, and this is not correct: > ( for example use lib 'a'; would put 'a' into @INC twice, once > ( correctly ) at compile time, and another time ( incorrectly ) at > runtime ). In this > case this is not harmful, but you get the idea. I don't understand. The compiled program should do exactly what the original program did. Anything else, as difficult as it may be, is a bug. Lots of programs and modules do important load-time checks and logic inside BEGIN blocks. Why would this: BEGIN { push @INC, 'foo'; } put 'foo' into @INC twice if it were compiled? The compiled program should not be storing the post-BEGIN value of @INC, it should store the original value at startup. -- Michael G. Schwern <[EMAIL PROTECTED]>http://www.pobox.com/~schwern/ Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One Me? A robot? That's rediculous! For one thing, that doesn't compute at all!