Skip to content

Commit 59c7f4e

Browse files
committed
ParseXS - allow symbolic alias of default function
Also normalize warnings. It used to be if you created an alias of the root function (0) no warning would be produced. Now we will produce a warning, but we also allow symbolic references to defuse the warning.
1 parent 0b87cd9 commit 59c7f4e

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,9 @@ sub get_aliases {
13111311
my ($line) = @_;
13121312
my ($orig) = $line;
13131313

1314+
# we use this later for symbolic aliases
1315+
my $fname = $self->{Packprefix} . $self->{func_name};
1316+
13141317
# Parse alias definitions
13151318
# format is
13161319
# alias = value Pack::alias = value ...
@@ -1335,10 +1338,13 @@ sub get_aliases {
13351338
if ($is_symbolic) {
13361339
my $orig_value = $value;
13371340
$value = $self->{Packprefix} . $value if $value !~ /::/;
1338-
if (!defined $self->{XsubAliases}->{$value}) {
1341+
if (defined $self->{XsubAliases}->{$value}) {
1342+
$value = $self->{XsubAliases}->{$value};
1343+
} elsif ($value eq $fname) {
1344+
$value = 0;
1345+
} else {
13391346
blurt( $self, "Error: Unknown alias '$value' in symbolic definition for '$orig_alias'");
13401347
}
1341-
$value = $self->{XsubAliases}->{$value};
13421348
}
13431349

13441350
# check for duplicate alias name & duplicate value
@@ -1359,12 +1365,19 @@ sub get_aliases {
13591365
# it is NOT a mistake.
13601366
unless ($is_symbolic) {
13611367
my @keys= sort keys %{$self->{XsubAliasValues}->{$value}||{}};
1368+
# deal with an alias of 0, which might not be in the XsubAlias dataset
1369+
# yet as 0 is the default for the base function ($fname)
1370+
push @keys, $fname
1371+
if $value eq "0" and !defined $self->{XsubAlias}{$fname};
13621372
if (@keys) {
13631373
@keys= map { "'$_'" } map { s/^$self->{Packprefix}//r } @keys;
13641374
WarnHint( $self,
13651375
"Warning: Aliases '$orig_alias' and "
13661376
. join(", ", @keys)
1367-
. " have identical values",
1377+
. " have identical values of $value"
1378+
. ( $value eq "0"
1379+
? " - the base function"
1380+
: "" ),
13681381
!$self->{XsubAliasValueClashHinted}++
13691382
? "If this is deliberate use a symbolic alias instead."
13701383
: undef

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,14 @@ like $stderr, '/No INPUT definition/', "Exercise typemap error";
252252
$count++ while $content=~/^XS_EUPXS\(XS_My_do\)\n\{/mg;
253253
is $stderr,
254254
"Warning: Aliases 'pox' and 'dox', 'lox' have"
255-
. " identical values in XSAlias.xs, line 9\n"
255+
. " identical values of 1 in XSAlias.xs, line 9\n"
256256
. " (If this is deliberate use a symbolic alias instead.)\n"
257257
. "Warning: Conflicting duplicate alias 'pox' changes"
258258
. " definition from '1' to '2' in XSAlias.xs, line 10\n"
259259
. "Warning: Aliases 'docks' and 'dox', 'lox' have"
260-
. " identical values in XSAlias.xs, line 11\n",
260+
. " identical values of 1 in XSAlias.xs, line 11\n"
261+
. "Warning: Aliases 'xunx' and 'do' have identical values"
262+
. " of 0 - the base function in XSAlias.xs, line 13\n",
261263
"Saw expected warnings from XSAlias.xs";
262264

263265
my $expect = quotemeta(<<'EOF_CONTENT');
@@ -273,6 +275,10 @@ like $stderr, '/No INPUT definition/', "Exercise typemap error";
273275
XSANY.any_i32 = 1;
274276
cv = newXSproto_portable("My::pox", XS_My_do, file, "$");
275277
XSANY.any_i32 = 2;
278+
cv = newXSproto_portable("My::xukes", XS_My_do, file, "$");
279+
XSANY.any_i32 = 0;
280+
cv = newXSproto_portable("My::xunx", XS_My_do, file, "$");
281+
XSANY.any_i32 = 0;
276282
EOF_CONTENT
277283
$expect=~s/(?:\\[ ])+/\\s+/g;
278284
$expect=qr/$expect/;

dist/ExtUtils-ParseXS/t/XSAlias.xs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ ALIAS:
1010
pox = 2
1111
docks = 1
1212
dachs => lox
13+
xunx = 0
14+
xukes => do
1315
CODE:
1416
{
1517
int x;

0 commit comments

Comments
 (0)