Who is unsetting this variable?

  • Thread starter Daniel Pfeiffer
  • Start date
D

Daniel Pfeiffer

In makepp http://makepp.sourceforge.net/ I noticed an unexplicable (to me)
evaporation of variable values.

In Makesubs.pm we have the following closure, where $_[1] is a Makefile object
and $CC is used nowhere else:

my $CC;
sub f_CC { $CC ||=
$_[1]->expand_expression('find_program gcc egcc pgcc c89 cc' .
:):is_windows?' cl bcc32':''), $_[2]) }

In Makefile.pm expand_variable line 426 in the inner else branch will call the
above function:

for( "$self->{PACKAGE}::f_$var" ) { # Name of the function with no arguments?
# Localizes $_; causes very weird errors if $_ is messed up.
my $orig = $_;
tr/-/_/; # Convert - to _ so it's more perl friendly.
s/\./_dot_/g;
$_ = *{$_}{CODE} || *{$orig}{CODE};
if( defined ) { # Defined in the makefile?
# if( $_ = defined &$_ ? \&$_ : defined &$orig && \&$orig ) { # same...
my $tmp = !$::environment_override && $self->{ENVIRONMENT}{$var};
if( $tmp && $_ == *{"Makesubs::f_$var"}{CODE} ) {
$result = $tmp;
} else {
local $::makefile = $self; # Pass the function a reference to the makefile.
$result = &$_( '', $self, $makefile_line ) and
$reexpand = 0; # It was a := variable.
print "$var:$result\n"; # this line added for debugging
}
}
}

Here $self->{PACKAGE} eq 'makefile_000', $var eq 'CC' and Makesubs::f_CC has
been imported into this package. Now, each time the makefile evaluates $(CC)
the function f_CC gets called.

At first I thought it might be a closure bug. But no matter whether I make
$CC a my or an our variable or a member of $_[1] the value toggles to and fro
between '' (in debugger is undef?) and 'gcc' (as found on my machine).
Calling Makesubs::f_CC or makefile_000::f_CC directly does not show this
behaviour. What is going on here???

A trivial makefile for watching this is:

x := $(CC) $(CC) $(CC)

DB<2> w $CC
DB<3> c
Watchpoint 0: $CC changed:
old value: ''
new value: 'gcc'
Makesubs::f_CC(/home/pfeiffer/makepp/cvs/Makesubs.pm:2066):
2066: sub f_CC { $CC ||=
2067: $_[1]->expand_expression('find_program gcc egcc pgcc c89 cc' .
:):is_windows?' cl bcc32':''), $_[2]) }
DB<3> c
Watchpoint 0: $CC changed:
old value: 'gcc'
new value: ''
Makefile::expand_variable(/home/pfeiffer/makepp/cvs/Makefile.pm:430):
430: print "$var:$result\n"; # this line added for debugging

coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
Daniel Pfeiffer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,829
Messages
2,569,737
Members
45,522
Latest member
CCPAnne66

Latest Threads

Top