Skip to content

Commit fbfd5fb

Browse files
committed
ParseXS: process line continuations after TYPEMAP
(This is similar to the previous commit, which fixed the same bug for POD) Within fetch_para(), the at-end-of-TYPEMAP code and the main loop both had separate (but similar) chunks of code to read in the next line, with the latter one being more complete. In particular, the latter had logic to process '\' continuation lines, while the TYPEMAP one didn't. This meant that this gave a parse error: TYPEMAP: <<EOF ... EOF void foo(int i, \ int j) The fix is to make them both use the same code to read the next line. This bug was probably actually introduced by me during the refactoring in this branch. By using the same read-next-line code, it also means that an immediately following blank line is now stripped of whitespace. I'm not sure whether that actually affects anything in the real word. Also, any trailing lines in typemap are now stripped. Again, this shouldn't affect anything.
1 parent 27eb482 commit fbfd5fb

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -635,29 +635,29 @@ sub fetch_para {
635635
# Return what we have already and process this line on the
636636
# next call; that way something like a previous BOOT: won't
637637
# run on into the TYPEMAP: lines
638-
return 1 if @{$self->{line}};
638+
last if @{$self->{line}};
639639

640640
$self->{lastline} =~
641641
/^TYPEMAP\s*:\s*<<\s*(?:(["'])(.+?)\1|([^\s'"]+?))\s*;?\s*$/
642642
or $self->death("Error: unparseable TYPEMAP line: '$self->{lastline}'");
643643

644644
my $end_marker = quotemeta(defined($1) ? $2 : $3);
645645

646-
# Scan until we find $end_marker alone on a line.
647-
my $last;
648-
while (1) {
649-
unless ($last) {
650-
push @{$self->{line}}, $self->{lastline};
651-
push @{$self->{line_no}}, $.;
652-
}
653-
$self->{lastline} = readline($self->{in_fh});
654-
last if $last;
655-
$self->death("Error: Unterminated TYPEMAP section")
656-
unless defined $self->{lastline};
646+
# Add the 'TYPEMAP:' line
647+
push @{$self->{line}}, $self->{lastline};
648+
push @{$self->{line_no}}, $.;
649+
650+
# Accumulate lines until we find $end_marker alone on a line.
651+
while ($self->{lastline} = readline($self->{in_fh})) {
652+
last if $self->{lastline} =~ /^$end_marker\s*$/;
657653
chomp $self->{lastline};
658-
$last = $self->{lastline} =~ /^$end_marker\s*$/;
654+
push @{$self->{line}}, $self->{lastline};
655+
push @{$self->{line_no}}, $.;
659656
}
660-
return 1;
657+
$self->death("Error: Unterminated TYPEMAP section")
658+
unless defined $self->{lastline};
659+
$final = 1;
660+
goto read_next_line;
661661
}
662662

663663
if ($self->{lastline} =~ /^\s*#/

dist/ExtUtils-ParseXS/t/001-basic.t

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5793,6 +5793,20 @@ EOF
57935793
"got expected err msg"
57945794
],
57955795
],
5796+
[
5797+
"line continuation directly after TYPEMAP",
5798+
[ Q(<<'EOF') ],
5799+
|TYPEMAP: <<EOF
5800+
|
5801+
|foo_t T_FOO
5802+
|
5803+
|EOF
5804+
|void foo(int i, \
5805+
| int j)
5806+
EOF
5807+
5808+
[ 0, 0, qr{XS}, "no errs" ],
5809+
],
57965810
);
57975811

57985812
test_many($preamble, undef, \@test_fns);

0 commit comments

Comments
 (0)