From: Stephen McCamant Date: Wed, 9 Jan 2002 23:04:01 +0000 (-0800) Subject: Magic numbers in B::Concise X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=213a1a263469325697166cf306c9ca76600e54dd;p=p5sagit%2Fp5-mst-13.2.git Magic numbers in B::Concise Message-ID: <15421.15585.813580.211907@soda.csua.berkeley.edu> p4raw-id: //depot/perl@14162 --- diff --git a/ext/B/B/Concise.pm b/ext/B/B/Concise.pm index ccf326c..46a8cfe 100644 --- a/ext/B/B/Concise.pm +++ b/ext/B/B/Concise.pm @@ -499,10 +499,40 @@ sub tree { map(" " x (length($name)+$size) . $_, @lines)); } -# This is a bit of a hack; the 2 and 15 were determined empirically. -# These need to stay the last things in the module. -$cop_seq_base = svref_2object(eval 'sub{0;}')->START->cop_seq + 2; -$seq_base = svref_2object(eval 'sub{}')->START->seq + 15; +# *** Warning: fragile kludge ahead *** +# Because the B::* modules run in the same interpreter as the code +# they're compiling, their presence tends to distort the view we have +# of the code we're looking at. In particular, perl gives sequence +# numbers to both OPs in general and COPs in particular. If the +# program we're looking at were run on its own, these numbers would +# start at 1. Because all of B::Concise and all the modules it uses +# are compiled first, though, by the time we get to the user's program +# the sequence numbers are alreay at pretty high numbers, which would +# be distracting if you're trying to tell OPs apart. Therefore we'd +# like to subtract an offset from all the sequence numbers we display, +# to restore the simpler view of the world. The trick is to know what +# that offset will be, when we're still compiling B::Concise! If we +# hardcoded a value, it would have to change every time B::Concise or +# other modules we use do. To help a little, what we do here is +# compile a little code at the end of the module, and compute the base +# sequence number for the user's program as being a small offset +# later, so all we have to worry about are changes in the offset. + +# When you say "perl -MO=Concise -e '$a'", the output should look like: + +# 4 <@> leave[t1] vKP/REFC ->(end) +# 1 <0> enter ->2 + #^ smallest OP sequence number should be 1 +# 2 <;> nextstate(main 1 -e:1) v ->3 + # ^ smallest COP sequence number should be 1 +# - <1> ex-rv2sv vK/1 ->4 +# 3 <$> gvsv(*a) s ->4 + +# If either of the marked numbers there aren't 1, it means you need to +# update the corresponding magic number in the next two lines. +# Reember, these need to stay the last things in the module. +$cop_seq_base = svref_2object(eval 'sub{0;}')->START->cop_seq + 11; +$seq_base = svref_2object(eval 'sub{}')->START->seq + 84; 1; diff --git a/ext/B/O.pm b/ext/B/O.pm index af9885b..0cdf436 100644 --- a/ext/B/O.pm +++ b/ext/B/O.pm @@ -3,7 +3,7 @@ package O; our $VERSION = '1.00'; use B qw(minus_c save_BEGINs); -use Carp; +use Carp; sub import { my ($class, @options) = @_; @@ -31,6 +31,11 @@ sub import { open (STDOUT, ">&SAVEOUT"); close SAVEOUT; } + + # Note: if you change the code after this 'use', please + # change the fudge factors in B::Concise (grep for + # "fragile kludge") so that its output still looks + # nice. Thanks. --smcc use B::].$backend.q[ (); if ($@) { croak "use of backend $backend failed: $@";