From 6d1b7cfa22910610a806afff2e3d3fb490f81489 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Mon, 7 Jul 2025 09:33:17 +0100 Subject: [PATCH] ParseXS: fix handling of empty C_ARGS etc GH#23407 My recent refactoring work on ParseXS made the parser go into an infinite loop on multiline_merged nodes such as C_ARGS when there was no text, e.g. void foo(int a) C_ARGS: --- dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm | 2 +- dist/ExtUtils-ParseXS/t/001-basic.t | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm b/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm index 8fa07a41aed4..245e6c01279e 100644 --- a/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm +++ b/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm @@ -3648,7 +3648,7 @@ sub parse { $self->SUPER::parse($pxs); # set file/line_no, read lines my @lines = @{$self->{lines}}; - shift @lines while $lines[0] !~ /\S/; + shift @lines while @lines && $lines[0] !~ /\S/; # XXX ParseXS originally didn't include a trailing \n, # so we carry on doing the same. $self->{text} = join "\n", @lines; diff --git a/dist/ExtUtils-ParseXS/t/001-basic.t b/dist/ExtUtils-ParseXS/t/001-basic.t index 9e7c3acaee29..5101a9d45959 100644 --- a/dist/ExtUtils-ParseXS/t/001-basic.t +++ b/dist/ExtUtils-ParseXS/t/001-basic.t @@ -1656,6 +1656,16 @@ EOF [ 0, 0, qr/\Qfoo(a, b , bar, c? c : "boo!")/, "" ], ], + [ + "autocall args empty C_ARGS", + [ Q(<<'EOF') ], + |void + |foo(int a) + | C_ARGS: +EOF + [ 0, 0, qr/\Qfoo()/, "" ], + ], + [ # Whether this is sensible or not is another matter. # For now, just check that it works as-is.