From 74b899ae3030e8dddc4750668c41c5be0a84e832 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Tue, 30 Dec 2014 14:09:40 -0700 Subject: lib/B/Deparse.pm: Output WARNING_BITS in binary This binary value was being output as just another string, which would cause the bit patterns that coincidentally coincided with letters to be output as those. This is not portable to EBCDIC, but outputting it as \xXX is, which this commit does. I chose to output in hex instead of octal, as I think that is the more modern thing to do, and it's easier for me to grok the larger values when they are in hex. --- lib/B/Deparse.pm | 4 +++- lib/B/Deparse.t | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/B') diff --git a/lib/B/Deparse.pm b/lib/B/Deparse.pm index 7b4ae77a4d..90793b6634 100644 --- a/lib/B/Deparse.pm +++ b/lib/B/Deparse.pm @@ -2026,7 +2026,9 @@ sub declare_warnings { elsif (($to & WARN_MASK) eq ("\0"x length($to) & WARN_MASK)) { return $self->keyword("no") . " warnings;\n"; } - return "BEGIN {\${^WARNING_BITS} = ".perlstring($to)."}\n\cK"; + return "BEGIN {\${^WARNING_BITS} = \"" + . join("", map { sprintf("\\x%02x", ord $_) } split "", $to) + . "\"}\n\cK"; } sub declare_hints { diff --git a/lib/B/Deparse.t b/lib/B/Deparse.t index 74f37a747e..d7b19c1773 100644 --- a/lib/B/Deparse.t +++ b/lib/B/Deparse.t @@ -1857,12 +1857,12 @@ my sub f {} print f(); >>>> use feature 'lexical_subs'; -BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUT\005U\001"} +BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x55\x01"} my sub f { - BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUT\005\001"} + BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x01"} } -BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUT\005\001"} +BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x01"} print f(); #### # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version" @@ -1873,13 +1873,13 @@ state sub f {} print f(); >>>> use feature 'lexical_subs'; -BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUT\005U\001"} +BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x55\x01"} CORE::state sub f { - BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUT\005\001"} + BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x01"} use feature 'state'; } -BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUT\005\001"} +BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x01"} use feature 'state'; print f(); #### -- cgit v1.2.1