From: Stepan Kasal Date: Thu, 9 Jul 2009 13:49:57 +0000 (+0200) Subject: h2ph: handle "#if defined SYMBOL" better X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3983eafb40341b21a64d20c0c4e7e618101ee6ce;p=p5sagit%2Fp5-mst-13.2.git h2ph: handle "#if defined SYMBOL" better expr() contains a code to handle "defined(SYM)" in #if directives. Unfortunately, this code is not executed for "defined SYM", without parentheses. This patch fixes it. --- diff --git a/t/lib/h2ph.pht b/t/lib/h2ph.pht index 3723fca..cda8d21 100644 --- a/t/lib/h2ph.pht +++ b/t/lib/h2ph.pht @@ -30,21 +30,21 @@ unless(defined(&_H2PH_H_)) { eval q((($a) < ($b) ? ($a) : ($b))); }' unless defined(&MIN); } - if(!(defined (defined(&__SOMETHING_MORE_IMPORTANT) ? &__SOMETHING_MORE_IMPORTANT : undef))) { + if(!(defined (&__SOMETHING_MORE_IMPORTANT))) { } - elsif(!(defined (defined(&__SOMETHING_REALLY_REALLY_IMPORTANT) ? &__SOMETHING_REALLY_REALLY_IMPORTANT : undef))) { + elsif(!(defined (&__SOMETHING_REALLY_REALLY_IMPORTANT))) { die("Nup, can't go on"); } else { eval 'sub EVERYTHING_IS_OK () {1;}' unless defined(&EVERYTHING_IS_OK); } undef(&WHATEVER) if defined(&WHATEVER); - if((!((defined (defined(&__SOMETHING_TRIVIAL) ? &__SOMETHING_TRIVIAL : undef) && defined (defined(&__SOMETHING_LESS_SO) ? &__SOMETHING_LESS_SO : undef))) || defined (defined(&__SOMETHING_OVERPOWERING) ? &__SOMETHING_OVERPOWERING : undef))) { + if((!((defined (&__SOMETHING_TRIVIAL) && defined (&__SOMETHING_LESS_SO))) || defined (&__SOMETHING_OVERPOWERING))) { eval 'sub WHATEVER () {6;}' unless defined(&WHATEVER); } - elsif(!(defined (defined(&__SOMETHING_TRIVIAL) ? &__SOMETHING_TRIVIAL : undef)) ) { + elsif(!(defined (&__SOMETHING_TRIVIAL)) ) { eval 'sub WHATEVER () {7;}' unless defined(&WHATEVER); } - elsif(!(defined (defined(&__SOMETHING_LESS_SO) ? &__SOMETHING_LESS_SO : undef)) ) { + elsif(!(defined (&__SOMETHING_LESS_SO)) ) { eval 'sub WHATEVER () {8;}' unless defined(&WHATEVER); } else { eval 'sub WHATEVER () {1000;}' unless defined(&WHATEVER); diff --git a/utils/h2ph.PL b/utils/h2ph.PL index cd4b5a0..ada226c 100644 --- a/utils/h2ph.PL +++ b/utils/h2ph.PL @@ -509,7 +509,8 @@ sub expr { s/^\s*\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/i; # cheat $new .= " &$id"; } elsif ($isatype{$id}) { - if ($new =~ /{\s*$/) { + if ($new =~ /{\s*$/ # } for vi + ) { $new .= "'$id'"; } elsif ($new =~ /\(\s*$/ && /^[\s*]*\)/) { $new =~ s/\(\s*$//; @@ -518,8 +519,14 @@ sub expr { $new .= q(').$id.q('); } } else { - if ($inif && $new !~ /defined\s*\($/) { - $new .= '(defined(&' . $id . ') ? &' . $id . ' : undef)'; + if ($inif) { + if ($new =~ /defined\s*$/) { + $new .= '(&' . $id . ')'; + } elsif ($new =~ /defined\s*\($/) { + $new .= '&' . $id; + } else { + $new .= '(defined(&' . $id . ') ? &' . $id . ' : undef)'; + } } elsif (/^\[/) { $new .= " \$$id"; } else {