Skip to content

Commit 25dd99d

Browse files
committed
ParseXS: allow XS files with no XS again
GH #24016 ParseXS / xsubpp allowed .xs files to contain only C code; i.e. no XS code. A warning was issued about about a missing MODULE line, but the C contents of the file was emitted as-is. My recent refactoring broke this - it was now generating a C code file with zero lines. This was because ParseXS now splits the parsing and code-emitting into two separate phases, and this code during parsing: warn "Didn't find a 'MODULE ... PACKAGE ... PREFIX' line\n"; exit 0; # Not a fatal error for the caller process was now exiting before any lines had been emitted. The fix is to not suddenly exit, but instead continue with pared-down parsing and code emitting.
1 parent 348b9e8 commit 25dd99d

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,14 @@ sub parse {
603603

604604
my $C_part = ExtUtils::ParseXS::Node::C_part->new();
605605
$self->{C_part} = $C_part;
606-
$C_part->parse($pxs, $self)
607-
or return;
606+
my $c_part_result = $C_part->parse($pxs, $self);
608607
push @{$self->{kids}}, $C_part;
609608

609+
# A failure when parsing the C part means that there wasn't a MODULE
610+
# line. Don't try to parse the missing XS part, but still return
611+
# success, passing through the lines from the C part.
612+
return 1 unless $c_part_result;
613+
610614
# "Parse" the bit following any C code. Doesn't actually consume any
611615
# lines: just a placeholder for emitting postamble code.
612616

@@ -752,7 +756,7 @@ sub parse {
752756
}
753757

754758
warn "Didn't find a 'MODULE ... PACKAGE ... PREFIX' line\n";
755-
exit 0; # Not a fatal error for the caller process
759+
return;
756760
}
757761

758762

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5879,4 +5879,28 @@ EOF
58795879
test_many($preamble, undef, \@test_fns);
58805880
}
58815881

5882+
{
5883+
# An XS file without a MODULE line should warn, but
5884+
# still emit the C code in the C part of the file (the whole file
5885+
# contents in this case).
5886+
5887+
my $preamble = '';
5888+
5889+
my @test_fns = (
5890+
[
5891+
"No MODULE line",
5892+
[ Q(<<'EOF') ],
5893+
|foo
5894+
|bar
5895+
EOF
5896+
5897+
[ 0, 0, qr{#line 1 ".*"\nfoo\nbar\n#line 13 ".*"}, "all C present" ],
5898+
[ 1, 0, qr{Didn't find a 'MODULE ... PACKAGE ... PREFIX' line},
5899+
"got expected MODULE warning" ],
5900+
],
5901+
);
5902+
5903+
test_many($preamble, undef, \@test_fns);
5904+
}
5905+
58825906
done_testing;

0 commit comments

Comments
 (0)