Skip to content

Commit

Permalink
adjust CC to svop_pv, merge .perldb and t/testc.sh 74, XXX protect fr…
Browse files Browse the repository at this point in the history
…om failing $$sv
  • Loading branch information
Reini Urban committed Feb 19, 2012
1 parent 8b07854 commit f1df04a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions .perldb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$DB::deep=500;
20 changes: 11 additions & 9 deletions lib/B/C.pm
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,12 @@ sub cache_svop_pkg {
} elsif ($svop->name eq 'gv') {
$sv = $svop->gv;
}
if (@_) { # set
$newpkg{$$sv} = shift;
} else { # get
return $newpkg{$$sv};
if ($sv and $$sv) {
if (@_) { # set
$newpkg{$$sv} = shift;
} else { # get
return $newpkg{$$sv};
}
}
}

Expand Down Expand Up @@ -551,7 +553,7 @@ sub svop_pv {
} else {
$sv = $op->sv;
}
if ($$sv) {
if ($sv and $$sv) {
return $sv->PV if $sv->can("PV");
} else {
my $pv = padop_name($op);
Expand Down Expand Up @@ -848,7 +850,8 @@ sub check_entersub {
# Foo->bar() compile-time lookup, 64 = BARE in all versions
(($op->first->next->name eq 'const' and $op->first->next->flags == 64)
# or $foo->bar() run-time lookup
or $op->first->next->name eq 'padsv')) { # note that padsv is called gvsv in Concise
or $op->first->next->name eq 'padsv')) # note that padsv is called gvsv in Concise
{
my $pkgop = $op->first->next; # padsv for objects or const for classes
my $methop = $pkgop; # walk args until method or sub end. This ends
do { $methop = $methop->next; } while $methop->name !~ /^method_named|method|gv$/;
Expand Down Expand Up @@ -1248,8 +1251,7 @@ sub method_named {
# warn $name;
# return $name;
#}
my $method;
my @candidates;
my ($method, @candidates);
for my $p ( $package_pv, @package_pv, 'main',
grep{$include_package{$_}} keys %include_package,
map{packname_inc($_)} keys %savINC ) {
Expand Down Expand Up @@ -1279,7 +1281,7 @@ sub method_named {
}
}
}
warn "WARNING: method \"$package_pv\::$name\" found in no packages ",join(" "),@candidates,".\n" if $verbose;
warn "WARNING: method \"$package_pv\::$name\" found in no packages ",join(" ",@candidates),".\n" if $verbose;
warn "Probably need to define the right package with -uPackage, or maybe the method is never called.\n"
if $verbose and !$method_named_warn++;
$method = $package_pv.'::'.$name;
Expand Down
8 changes: 4 additions & 4 deletions lib/B/CC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ use B qw(main_start main_root class comppadlist peekop svref_2object
#CXt_NULL CXt_SUB CXt_EVAL CXt_SUBST CXt_BLOCK
use B::C qw(save_unused_subs objsym init_sections mark_unused mark_skip
output_all output_boilerplate output_main output_main_rest fixup_ppaddr save_sig
svop_or_padop_pv inc_cleanup);
svop_pv inc_cleanup);
use B::Bblock qw(find_leaders);
use B::Stackobj qw(:types :flags);
use B::C::Flags;
Expand Down Expand Up @@ -1348,12 +1348,12 @@ sub pp_const {
else {
$obj = $pad[ $op->targ ];
}
# XXX looks like method_named has only const as prev op
# XXX looks like method_named has only const as prev op. TODO use the better B::C checks at entersub
if ($op->next
and $op->next->can('name')
and $op->next->name eq 'method_named'
) {
$package_pv = svop_or_padop_pv($op);
$package_pv = svop_pv($op);
debug "save package_pv \"$package_pv\" for method_name\n" if $debug{op};
}
push( @stack, $obj );
Expand Down Expand Up @@ -1468,7 +1468,7 @@ sub bad_pp_anoncode {
# XXX TODO get prev op. For now saved in pp_const.
sub pp_method_named {
my ( $op ) = @_;
my $name = svop_or_padop_pv($op);
my $name = svop_pv($op);
# The pkg PV is at [PL_stack_base+TOPMARK+1], the previous op->sv->PV.
my $stash = $package_pv ? $package_pv."::" : "main::";
$name = $stash . $name;
Expand Down
7 changes: 6 additions & 1 deletion t/testc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function init {
BASE=`basename $0`
# if $] < 5.9 you may want to remove -Mblib for testing the core lib. -o
#Mblib="`$PERL -e'print (($] < 5.009005) ? q() : q(-Mblib))'`"
Mblib=${Mblib:--Mblib} # B::C is now fully 5.6+5.8 backwards compatible
Mblib=${Mblib:--Iblib/arch -Iblib/lib} # B::C is now fully 5.6+5.8 backwards compatible
v513="`$PERL -e'print (($] < 5.013005) ? q() : q(-fno-fold,-fno-warnings,))'`"
# OCMD=${OCMD}${v513}
if [ -z $Mblib ]; then
Expand Down Expand Up @@ -338,6 +338,11 @@ result[72]='ok'
# object call: dynamic method_named with args.
tests[73]='package dummy;sub meth{print "ok"};package main;my $meth="meth";my $o = bless {},"dummy"; $o->$meth("const")'
result[73]='ok'
tests[74]='package dummy;
my $invoked_as_script = !caller();
__PACKAGE__->script(@ARGV) if $invoked_as_script;
sub script {my($package,@args)=@_;print "ok"}'
result[74]='ok'
# issue71
tests[71]='
package my;
Expand Down

0 comments on commit f1df04a

Please sign in to comment.