develooper Front page | perl.perl5.porters | Postings from April 2003

[PATCH] B::Deparse: sv_no != 0

Thread Next
From:
Stephen McCamant
Date:
April 6, 2003 14:00
Subject:
[PATCH] B::Deparse: sv_no != 0
Message ID:
16016.38272.921140.343901@syllepsis.MIT.EDU
The false value returned by boolean operators like '==' is a special
immortal SV named sv_no, whose numeric value is 0 and whose string
value is the empty string. In the past, B::Deparse printed this value
as "0", which is correct for arithmetic but incorrect for string
operations like 'print'; compare:

% perl -e 'print "<", (1 == 0), ">\n"'
<>
% perl5.8.0 -MO=Deparse -e 'print "<", (1 == 0), ">\n"'
print '<', 0, ">\n";
% perl5.8.0 -MO=Deparse -e 'print "<", (1 == 0), ">\n"' | perl
<0>

The empty string is a value whose numeric value is 0 and whose string
value is the empty string, but the conversion of the empty string to a
number generates a warning under -w, while using sv_no as a number
doesn't. The following patch therefore changes B::Deparse to print
sv_no as a small piece of code that evaluates to false.

 -- Stephen

--- ext/B/B/Deparse.pm.orig	2003-04-06 16:47:03.000000000 -0400
+++ ext/B/B/Deparse.pm	2003-04-06 16:47:16.000000000 -0400
@@ -3184,7 +3184,7 @@
 sub const {
     my $sv = shift;
     if (class($sv) eq "SPECIAL") {
-	return ('undef', '1', '0')[$$sv-1]; # sv_undef, sv_yes, sv_no
+	return ('undef', '1', '(!1)')[$$sv-1]; # sv_undef, sv_yes, sv_no
     } elsif (class($sv) eq "NULL") {
        return 'undef';
     } elsif ($sv->FLAGS & SVf_IOK) {

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About