Skip to content

Commit 5d4af97

Browse files
committed
ParseXS: clean up error messages and tests
Rationalise warning and error messages which appear in Node.pm: - always prefix with Warning: / Error: / Internal error: - lower-case the first letter following Error: etc - fix grammar - ensure full test coverage (except 'Internal error', which shouldn't be reproducible).
1 parent 19caf65 commit 5d4af97

File tree

2 files changed

+171
-77
lines changed

2 files changed

+171
-77
lines changed

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

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ sub parse {
333333
$pxs->blurt("Error: 'CASE:' after unconditional 'CASE:'")
334334
if $num > 1 && ! $case_had_cond;
335335
$case_had_cond = length $case->{cond};
336-
$pxs->blurt("Error: No 'CASE:' at top of function")
336+
$pxs->blurt("Error: no 'CASE:' at top of function")
337337
if $seen_bare_xbody;
338338
}
339339
else {
@@ -688,16 +688,16 @@ sub parse {
688688
# is for C++ functions.
689689

690690
my $func_header = shift(@{ $pxs->{line} });
691-
$pxs->blurt("Error: Cannot parse function definition from '$func_header'"), return
691+
$pxs->blurt("Error: cannot parse function definition from '$func_header'"), return
692692
unless $func_header =~ /^(?:([\w:]*)::)?(\w+)\s*\(\s*(.*?)\s*\)\s*(const)?\s*(;\s*)?$/s;
693693

694694
my ($class, $name, $params_text) = ($1, $2, $3);
695695
$class = "$4 $class" if $4;
696696

697697
if ($return_type->{static} and !defined $class)
698698
{
699-
$pxs->Warn( "Ignoring 'static' type modifier:"
700-
. " only valid with an XSUB name which includes a class");
699+
$pxs->Warn( "Warning: ignoring 'static' type modifier:"
700+
. " only valid with an XSUB name which includes a class");
701701
$return_type->{static} = 0;
702702
}
703703

@@ -824,7 +824,7 @@ sub parse {
824824

825825
# a function definition needs at least 2 lines
826826
unless (@{$pxs->{line}}) {
827-
$pxs->blurt("Error: Function definition too short '$line'");
827+
$pxs->blurt("Error: function definition too short '$line'");
828828
return;
829829
}
830830

@@ -939,7 +939,7 @@ sub parse {
939939
$self->{var} = 'SV *';
940940
return 1;
941941
}
942-
$pxs->blurt("Unparseable XSUB parameter: '$_'");
942+
$pxs->blurt("Error: unparseable XSUB parameter: '$_'");
943943
return;
944944
}
945945

@@ -984,7 +984,7 @@ sub parse {
984984
$out_type = $out_type eq 'IN' ? '' : $out_type;
985985
}
986986
else {
987-
$pxs->blurt("parameter IN/OUT modifier not allowed under -noinout");
987+
$pxs->blurt("Error: parameter IN/OUT modifier not allowed under -noinout");
988988
}
989989
}
990990
else {
@@ -994,7 +994,7 @@ sub parse {
994994
# Process optional type
995995

996996
if (defined($type) && !$pxs->{config_allow_argtypes}) {
997-
$pxs->blurt("parameter type not allowed under -noargtypes");
997+
$pxs->blurt("Error: parameter type not allowed under -noargtypes");
998998
undef $type;
999999
}
10001000

@@ -1008,12 +1008,12 @@ sub parse {
10081008
$len_name = $1;
10091009
$is_length = 1;
10101010
if (defined $default) {
1011-
$pxs->blurt("Default value not allowed on length() parameter '$len_name'");
1011+
$pxs->blurt("Error: default value not allowed on length() parameter '$len_name'");
10121012
undef $default;
10131013
}
10141014
}
10151015
else {
1016-
$pxs->blurt("length() pseudo-parameter not allowed under -noargtypes");
1016+
$pxs->blurt("Error: length() pseudo-parameter not allowed under -noargtypes");
10171017
}
10181018
}
10191019

@@ -1215,7 +1215,7 @@ sub lookup_input_typemap {
12151215
# e.g. 'SvPV_nolen($arg)'
12161216
my $inputmap = $typemaps->get_inputmap(xstype => $xstype);
12171217
if (not defined $inputmap) {
1218-
$pxs->blurt("Error: No INPUT definition for type '$type', typekind '$xstype' found");
1218+
$pxs->blurt("Error: no INPUT definition for type '$type', typekind '$xstype' found");
12191219
return;
12201220
}
12211221

@@ -1246,8 +1246,9 @@ sub lookup_input_typemap {
12461246
my $subinputmap =
12471247
$typemaps->get_inputmap(xstype => $subtypemap->xstype);
12481248
if (not $subinputmap) {
1249-
$pxs->blurt("Error: No INPUT definition for type '$subtype',
1250-
typekind '" . $subtypemap->xstype . "' found");
1249+
$pxs->blurt("Error: no INPUT definition for subtype "
1250+
. "'$subtype', typekind '"
1251+
. $subtypemap->xstype . "' found");
12511252
return;
12521253
}
12531254

@@ -1337,7 +1338,7 @@ sub lookup_output_typemap {
13371338
# values
13381339

13391340
unless (defined $type) {
1340-
$pxs->blurt("Can't determine output type for '$var'");
1341+
$pxs->blurt("Error: can't determine output type for '$var'");
13411342
return;
13421343
}
13431344

@@ -1393,7 +1394,7 @@ sub lookup_output_typemap {
13931394
if ($var ne 'RETVAL') {
13941395
# This special type is intended for use only as the return type of
13951396
# an XSUB
1396-
$pxs->blurt( "Can't use array(type,nitems) type for "
1397+
$pxs->blurt( "Error: can't use array(type,nitems) type for "
13971398
. (defined $out_num ? "OUTLIST" : "OUT")
13981399
. " parameter");
13991400
return;
@@ -1413,7 +1414,7 @@ sub lookup_output_typemap {
14131414

14141415
$outputmap = $typemaps->get_outputmap(xstype => $typemap->xstype);
14151416
if (not $outputmap) {
1416-
$pxs->blurt("Error: No OUTPUT definition for type '$type', typekind '"
1417+
$pxs->blurt("Error: no OUTPUT definition for type '$type', typekind '"
14171418
. $typemap->xstype . "' found");
14181419
return;
14191420
}
@@ -1462,7 +1463,7 @@ sub lookup_output_typemap {
14621463
# definitely would fail with OUT, which is supposed to be
14631464
# updating parameter SVs, not pushing anything on the stack.
14641465
# So forbid all except RETVAL.
1465-
$pxs->blurt("Can't use typemap containing DO_ARRAY_ELEM for "
1466+
$pxs->blurt("Error: can't use typemap containing DO_ARRAY_ELEM for "
14661467
. (defined $out_num ? "OUTLIST" : "OUT")
14671468
. " parameter");
14681469
return;
@@ -1477,7 +1478,7 @@ sub lookup_output_typemap {
14771478
my $suboutputmap =
14781479
$typemaps->get_outputmap(xstype => $subtypemap->xstype);
14791480
if (not $suboutputmap) {
1480-
$pxs->blurt("Error: No OUTPUT definition for type '$subtype', typekind '"
1481+
$pxs->blurt("Error: no OUTPUT definition for subtype '$subtype', typekind '"
14811482
. $subtypemap->xstype . "' found");
14821483
return;
14831484
}
@@ -1655,7 +1656,9 @@ sub as_input_code {
16551656
# been emitted, so remove it from the typemap before evalling it,
16561657

16571658
$init_code =~ s/^\s*\Q$var\E(\s*=\s*)/$1/
1658-
or $pxs->death("panic: typemap doesn't start with '\$var='\n");
1659+
# we just checked above that it starts with var=, so this
1660+
# should never happen
1661+
or $pxs->death("Internal error: typemap doesn't start with '\$var='\n");
16591662

16601663
printf "%s;\n", $init_code;
16611664
}
@@ -2284,7 +2287,7 @@ sub parse {
22842287

22852288
# Process ellipsis (...)
22862289

2287-
$pxs->blurt("further XSUB parameter seen after ellipsis (...)")
2290+
$pxs->blurt("Error: further XSUB parameter seen after ellipsis (...)")
22882291
if $self->{seen_ellipsis};
22892292

22902293
if ($param_text eq '...') {
@@ -2915,7 +2918,7 @@ sub as_code {
29152918
and not ($retval && $retval->{in_output})
29162919
and $xsub->{decl}{return_type}{type} ne 'void')
29172920
{
2918-
$pxs->Warn("Warning: Found a 'CODE' section which seems to be using 'RETVAL' but no 'OUTPUT' section.");
2921+
$pxs->Warn("Warning: found a 'CODE' section which seems to be using 'RETVAL' but no 'OUTPUT' section.");
29192922
}
29202923

29212924
# Process any OUT vars: i.e. vars that are declared OUT in
@@ -3318,7 +3321,7 @@ sub parse {
33183321

33193322
$self->SUPER::parse($pxs); # set file/line_no, self->{enable}
33203323

3321-
$pxs->blurt("Error: Only one SCOPE declaration allowed per XSUB")
3324+
$pxs->blurt("Error: only one SCOPE declaration allowed per XSUB")
33223325
if $xsub->{seen_SCOPE};
33233326
$xsub->{seen_SCOPE} = 1;
33243327

@@ -3629,7 +3632,7 @@ sub parse {
36293632

36303633
my $proto;
36313634

3632-
$pxs->death("Error: Only 1 PROTOTYPE definition allowed per xsub")
3635+
$pxs->death("Error: only one PROTOTYPE definition allowed per xsub")
36333636
if $xsub->{seen_PROTOTYPE};
36343637
$xsub->{seen_PROTOTYPE} = 1;
36353638

@@ -3645,7 +3648,7 @@ sub parse {
36453648
}
36463649
else {
36473650
s/\s+//g; # remove any whitespace
3648-
$pxs->death("Error: Invalid prototype '$_'")
3651+
$pxs->death("Error: invalid prototype '$_'")
36493652
unless ExtUtils::ParseXS::Utilities::valid_proto_string($_);
36503653
$proto = ExtUtils::ParseXS::Utilities::C_string($_);
36513654
}
@@ -3844,7 +3847,7 @@ sub parse {
38443847
$self->SUPER::parse($pxs); # set file/line_no/lines
38453848
$xsub->{seen_PPCODE} = 1;
38463849
# The only thing left should be the special "!End!\n\n" token.
3847-
$pxs->death("PPCODE must be last thing") if @{$pxs->{line}} > 1;
3850+
$pxs->death("Error: PPCODE must be the last thing") if @{$pxs->{line}} > 1;
38483851
1;
38493852
}
38503853

@@ -4075,7 +4078,7 @@ sub parse {
40754078
my ($alias, $is_symbolic, $value) = ($1, $2, $3);
40764079
my $orig_alias = $alias;
40774080

4078-
$pxs->blurt("Error: In alias definition for '$alias' the value may not"
4081+
$pxs->blurt("Error: in alias definition for '$alias' the value may not"
40794082
. " contain ':' unless it is symbolic.")
40804083
if !$is_symbolic and $value=~/:/;
40814084

@@ -4090,17 +4093,17 @@ sub parse {
40904093
} elsif ($value eq $fname) {
40914094
$value = 0;
40924095
} else {
4093-
$pxs->blurt("Error: Unknown alias '$value' in symbolic definition for '$orig_alias'");
4096+
$pxs->blurt("Error: unknown alias '$value' in symbolic definition for '$orig_alias'");
40944097
}
40954098
}
40964099

40974100
# check for duplicate alias name & duplicate value
40984101
my $prev_value = $xsub->{map_alias_name_to_value}{$alias};
40994102
if (defined $prev_value) {
41004103
if ($prev_value eq $value) {
4101-
$pxs->Warn("Warning: Ignoring duplicate alias '$orig_alias'")
4104+
$pxs->Warn("Warning: ignoring duplicate alias '$orig_alias'")
41024105
} else {
4103-
$pxs->Warn("Warning: Conflicting duplicate alias '$orig_alias'"
4106+
$pxs->Warn("Warning: conflicting duplicate alias '$orig_alias'"
41044107
. " changes definition from '$prev_value' to '$value'");
41054108
delete $xsub->
41064109
{map_alias_value_to_name_seen_hash}->
@@ -4130,7 +4133,7 @@ sub parse {
41304133
$copy
41314134
} @keys;
41324135
$pxs->WarnHint(
4133-
"Warning: Aliases '$orig_alias' and "
4136+
"Warning: aliases '$orig_alias' and "
41344137
. join(", ", @keys)
41354138
. " have identical values of $value"
41364139
. ( $value eq "0"
@@ -4149,7 +4152,7 @@ sub parse {
41494152
{$value}{$alias}++;
41504153
}
41514154

4152-
$pxs->blurt("Error: Cannot parse ALIAS definitions from '$orig'")
4155+
$pxs->blurt("Error: cannot parse ALIAS definitions from '$orig'")
41534156
if $line;
41544157

41554158
1;

0 commit comments

Comments
 (0)