Skip to content

Commit 7559ea2

Browse files
committed
ParseXS: refactor: rm various xsub_*alias* fields
Remove the following fields from the ExtUtils::ParseXS class: xsub_map_alias_name_to_value xsub_map_alias_value_to_name_seen_hash xsub_alias_clash_hinted and replace them with these new fields in the ExtUtils::ParseXS::Node::xsub class: map_alias_name_to_value map_alias_value_to_name_seen_hash alias_clash_hinted
1 parent f775bec commit 7559ea2

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,6 @@ BEGIN {
262262
# (possibly multiple space-separated
263263
# keywords per string).
264264

265-
'xsub_map_alias_name_to_value', # Hash: maps ALIAS name to value.
266-
267-
'xsub_map_alias_value_to_name_seen_hash', # Hash of hash of bools:
268-
# indicates which alias names have been
269-
# used for each value.
270-
271-
'xsub_alias_clash_hinted', # Bool: an ALIAS warning-hint has been emitted.
272-
273-
274265
# Per-XSUB OUTPUT section parsing state:
275266

276267
'xsub_SETMAGIC_state', # Bool: most recent value of SETMAGIC in an
@@ -673,8 +664,6 @@ EOM
673664

674665
# Initialise more per-XSUB state
675666

676-
delete $self->{xsub_map_alias_name_to_value}; # ALIAS: ...
677-
delete $self->{xsub_map_alias_value_to_name_seen_hash};
678667
%{ $self->{xsub_map_interface_name_short_to_original} } = ();
679668
@{ $self->{xsub_attributes} } = (); # ATTRS: lvalue method
680669
$self->{xsub_SETMAGIC_state} = 1; # SETMAGIC: ENABLE

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

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ BEGIN { $build_subclass->('', # parent
219219
'CODE_sets_ST0', # Bool
220220
'XSRETURN_count_basic', # Int
221221
'XSRETURN_count_extra', # Int
222+
223+
# these maintain the alias parsing state across potentially multiple
224+
# ALIAS keywords and or lines:
225+
226+
'map_alias_name_to_value', # Hash: maps seen alias names to their value
227+
228+
# Hash of hash of bools:
229+
# indicates which alias names have been
230+
# used for each value.
231+
'map_alias_value_to_name_seen_hash',
232+
233+
'alias_clash_hinted', # Bool: an ALIAS warn-hint has been emitted.
234+
235+
222236
)};
223237

224238

@@ -503,18 +517,20 @@ sub boot_code {
503517
my $pname = $pxs->{cur_xsub}{decl}{full_perl_name};
504518
my $cname = $pxs->{cur_xsub}{decl}{full_C_name};
505519

506-
if ( $pxs->{xsub_map_alias_name_to_value}
507-
and keys %{ $pxs->{xsub_map_alias_name_to_value} })
520+
if ( $pxs->{cur_xsub}{map_alias_name_to_value}
521+
and keys %{ $pxs->{cur_xsub}{map_alias_name_to_value} })
508522
{
509523
# For the main XSUB and for each alias name, generate a newXS() call
510524
# and 'XSANY.any_i32 = ix' line.
511525

512526
# Make the main name one of the aliases if it isn't already
513-
$pxs->{xsub_map_alias_name_to_value}->{$pname} = 0
514-
unless defined $pxs->{xsub_map_alias_name_to_value}->{$pname};
527+
$pxs->{cur_xsub}{map_alias_name_to_value}->{$pname} = 0
528+
unless defined $pxs->{cur_xsub}{map_alias_name_to_value}{$pname};
515529

516-
foreach my $xname (sort keys %{ $pxs->{xsub_map_alias_name_to_value} }) {
517-
my $value = $pxs->{xsub_map_alias_name_to_value}{$xname};
530+
foreach my $xname (sort keys
531+
%{ $pxs->{cur_xsub}{map_alias_name_to_value} })
532+
{
533+
my $value = $pxs->{cur_xsub}{map_alias_name_to_value}{$xname};
518534
push(@code, ExtUtils::ParseXS::Q(<<"EOF"));
519535
| cv = $newXS(\"$xname\", XS_$cname$file_arg$proto_arg);
520536
| XSANY.any_i32 = $value;
@@ -3657,8 +3673,9 @@ BEGIN { $build_subclass->('keyline', # parent
36573673
#
36583674
# Updates:
36593675
# $parent->{aliases}{$alias} = $value;
3660-
# $pxs->{xsub_map_alias_name_to_value}->{$alias} = $value;
3661-
# $pxs->{xsub_map_alias_value_to_name_seen_hash}->{$value}{$alias}++;
3676+
# $xsub->{map_alias_name_to_value}{$alias} = $value;
3677+
# $xsub->{map_alias_value_to_name_seen_hash}{$value}{$alias}++;
3678+
36623679

36633680
sub parse {
36643681
my __PACKAGE__ $self = shift;
@@ -3695,8 +3712,8 @@ sub parse {
36953712
if ($is_symbolic) {
36963713
my $orig_value = $value;
36973714
$value = $pxs->{PACKAGE_class} . $value if $value !~ /::/;
3698-
if (defined $pxs->{xsub_map_alias_name_to_value}->{$value}) {
3699-
$value = $pxs->{xsub_map_alias_name_to_value}->{$value};
3715+
if (defined $pxs->{cur_xsub}{map_alias_name_to_value}{$value}) {
3716+
$value = $pxs->{cur_xsub}{map_alias_name_to_value}{$value};
37003717
} elsif ($value eq $fname) {
37013718
$value = 0;
37023719
} else {
@@ -3705,14 +3722,16 @@ sub parse {
37053722
}
37063723

37073724
# check for duplicate alias name & duplicate value
3708-
my $prev_value = $pxs->{xsub_map_alias_name_to_value}->{$alias};
3725+
my $prev_value = $pxs->{cur_xsub}{map_alias_name_to_value}{$alias};
37093726
if (defined $prev_value) {
37103727
if ($prev_value eq $value) {
37113728
$pxs->Warn("Warning: Ignoring duplicate alias '$orig_alias'")
37123729
} else {
37133730
$pxs->Warn("Warning: Conflicting duplicate alias '$orig_alias'"
37143731
. " changes definition from '$prev_value' to '$value'");
3715-
delete $pxs->{xsub_map_alias_value_to_name_seen_hash}->{$prev_value}{$alias};
3732+
delete $pxs->{cur_xsub}->
3733+
{map_alias_value_to_name_seen_hash}->
3734+
{$prev_value}{$alias};
37163735
}
37173736
}
37183737

@@ -3721,11 +3740,13 @@ sub parse {
37213740
# symbolic definitions is to say we want to duplicate the value and
37223741
# it is NOT a mistake.
37233742
unless ($is_symbolic) {
3724-
my @keys= sort keys %{$pxs->{xsub_map_alias_value_to_name_seen_hash}->{$value}||{}};
3743+
my @keys= sort keys %{$pxs->{cur_xsub}->
3744+
{map_alias_value_to_name_seen_hash}->{$value}||{}};
37253745
# deal with an alias of 0, which might not be in the aliases
37263746
# dataset yet as 0 is the default for the base function ($fname)
37273747
push @keys, $fname
3728-
if $value eq "0" and !defined $pxs->{xsub_map_alias_name_to_value}{$fname};
3748+
if $value eq "0" and
3749+
!defined $pxs->{cur_xsub}{map_alias_name_to_value}{$fname};
37293750
if (@keys and $pxs->{config_author_warnings}) {
37303751
# We do not warn about value collisions unless author_warnings
37313752
# are enabled. They aren't helpful to a module consumer, only
@@ -3742,16 +3763,17 @@ sub parse {
37423763
. ( $value eq "0"
37433764
? " - the base function"
37443765
: "" ),
3745-
!$pxs->{xsub_alias_clash_hinted}++
3766+
!$pxs->{cur_xsub}{alias_clash_hinted}++
37463767
? "If this is deliberate use a symbolic alias instead."
37473768
: undef
37483769
);
37493770
}
37503771
}
37513772

37523773
$parent->{aliases}{$alias} = $value;
3753-
$pxs->{xsub_map_alias_name_to_value}->{$alias} = $value;
3754-
$pxs->{xsub_map_alias_value_to_name_seen_hash}->{$value}{$alias}++;
3774+
$pxs->{cur_xsub}{map_alias_name_to_value}->{$alias} = $value;
3775+
$pxs->{cur_xsub}{map_alias_value_to_name_seen_hash}->
3776+
{$value}{$alias}++;
37553777
}
37563778

37573779
$pxs->blurt("Error: Cannot parse ALIAS definitions from '$orig'")

0 commit comments

Comments
 (0)