Skip to content

Commit 264963f

Browse files
committed
ParseXS: spot TYPEMAP: line syntax errors
Previously, a line which was not a completely syntactically correct TYPEMAP: line was not treated as a TYPEMAP line; instead it got passed on uninterpreted until likely causing an error further along in parsing. This commit changes things so that anything starting with /^TYPEMAP\s*:/ is treated as a TYPEMAP line, and is *only then* examined for full syntactic correctness, giving an error if not ok. This is similar to two commits ago which did the same for the MODULE keyword.
1 parent 969eb6c commit 264963f

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,13 @@ sub _maybe_parse_typemap_block {
533533

534534
# This is special cased from the usual paragraph-handler logic
535535
# due to the HEREdoc-ish syntax.
536-
if ($self->{lastline} =~ /^TYPEMAP\s*:\s*<<\s*(?:(["'])(.+?)\1|([^\s'"]+?))\s*;?\s*$/)
537-
{
536+
return unless $self->{lastline} =~ /^TYPEMAP\s*:/;
537+
538+
$self->{lastline} =~ /^TYPEMAP\s*:\s*<<\s*(?:(["'])(.+?)\1|([^\s'"]+?))\s*;?\s*$/
539+
or $self->death("Error: unparseable TYPEMAP line: '$self->{lastline}'");
540+
541+
542+
538543
my $end_marker = quotemeta(defined($1) ? $2 : $3);
539544

540545
# Scan until we find $end_marker alone on a line.
@@ -554,7 +559,6 @@ sub _maybe_parse_typemap_block {
554559
$self->{typemaps_object}->merge(typemap => $tmap, replace => 1);
555560

556561
$self->{lastline} = "";
557-
}
558562
}
559563

560564

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5767,4 +5767,32 @@ EOF
57675767
test_many($preamble, undef, \@test_fns);
57685768
}
57695769

5770+
5771+
{
5772+
# Test reporting of bad syntax on TYPEMAP lines.
5773+
5774+
my $preamble = Q(<<'EOF');
5775+
|MODULE = Foo PACKAGE = Foo
5776+
|
5777+
|PROTOTYPES: DISABLE
5778+
|
5779+
EOF
5780+
5781+
my @test_fns = (
5782+
[
5783+
'TYPEMAP syntax err',
5784+
[ Q(<<'EOF') ],
5785+
|TYPEMAP: <EOF
5786+
|
5787+
EOF
5788+
5789+
[ 1, 0, qr{Error: unparseable TYPEMAP line: 'TYPEMAP: <EOF'},
5790+
"got expected err msg"
5791+
],
5792+
],
5793+
);
5794+
5795+
test_many($preamble, undef, \@test_fns);
5796+
}
5797+
57705798
done_testing;

0 commit comments

Comments
 (0)