Skip to content

Commit 8d66b3f

Browse files
Robin Barkerrgs
Robin Barker
authored andcommitted
Fix h2ph and test
1 parent 9500e8e commit 8d66b3f

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

lib/h2ph.t

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (!(-e $extracted_program)) {
1818
exit 0;
1919
}
2020

21-
plan(4);
21+
plan(5);
2222

2323
# quickly compare two text files
2424
sub txt_compare {
@@ -41,8 +41,16 @@ $result = runperl( progfile => 'lib/h2ph.pht',
4141
stderr => 1 );
4242
like( $result, qr/syntax OK$/, "output compiles");
4343

44+
$result = runperl( progfile => '_h2ph_pre.ph',
45+
switches => ['-c'],
46+
stderr => 1 );
47+
like( $result, qr/syntax OK$/, "preamble compiles");
48+
4449
$result = runperl( switches => ["-w"],
45-
prog => '$SIG{__WARN__} = sub { die $_[0] }; require q(lib/h2ph.pht);');
50+
stderr => 1,
51+
prog => <<'PROG' );
52+
$SIG{__WARN__} = sub { die $_[0] }; require q(lib/h2ph.pht);
53+
PROG
4654
is( $result, '', "output free of warnings" );
4755

4856
# cleanup

utils/h2ph.PL

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,10 @@ if ($opt_e && (scalar(keys %bad_file) > 0)) {
401401
exit $Exit;
402402
403403
sub expr {
404-
$new = '"(assembly code)"' and return if /\b__asm__\b/; # freak out.
404+
if (/\b__asm__\b/) { # freak out
405+
$new = '"(assembly code)"';
406+
return
407+
}
405408
my $joined_args;
406409
if(keys(%curargs)) {
407410
$joined_args = join('|', keys(%curargs));
@@ -770,7 +773,7 @@ sub inc_dirs
770773
sub build_preamble_if_necessary
771774
{
772775
# Increment $VERSION every time this function is modified:
773-
my $VERSION = 2;
776+
my $VERSION = 3;
774777
my $preamble = "$Dest_dir/_h2ph_pre.ph";
775778
776779
# Can we skip building the preamble file?
@@ -798,7 +801,16 @@ sub build_preamble_if_necessary
798801
# parenthesized value: d=(v)
799802
$define{$_} = $1;
800803
}
801-
if ($define{$_} =~ /^([+-]?(\d+)?\.\d+([eE][+-]?\d+)?)[FL]?$/) {
804+
if (/^(\w+)\((\w)\)$/) {
805+
my($macro, $arg) = ($1, $2);
806+
my $def = $define{$_};
807+
$def =~ s/$arg/\$\{$arg\}/g;
808+
print PREAMBLE <<DEFINE;
809+
unless (defined &$macro) { sub $macro(\$) { my (\$$arg) = \@_; \"$def\" } }
810+
811+
DEFINE
812+
} elsif
813+
($define{$_} =~ /^([+-]?(\d+)?\.\d+([eE][+-]?\d+)?)[FL]?$/) {
802814
# float:
803815
print PREAMBLE
804816
"unless (defined &$_) { sub $_() { $1 } }\n\n";
@@ -807,8 +819,14 @@ sub build_preamble_if_necessary
807819
print PREAMBLE
808820
"unless (defined &$_) { sub $_() { $1 } }\n\n";
809821
} elsif ($define{$_} =~ /^\w+$/) {
810-
print PREAMBLE
811-
"unless (defined &$_) { sub $_() { &$define{$_} } }\n\n";
822+
my $def = $define{$_};
823+
if ($isatype{$def}) {
824+
print PREAMBLE
825+
"unless (defined &$_) { sub $_() { \"$def\" } }\n\n";
826+
} else {
827+
print PREAMBLE
828+
"unless (defined &$_) { sub $_() { &$def } }\n\n";
829+
}
812830
} else {
813831
print PREAMBLE
814832
"unless (defined &$_) { sub $_() { \"",

0 commit comments

Comments
 (0)