Skip to content

Commit 9c24c4e

Browse files
committed
ParseXS: refactor: rm {xsub_map_argname_to_type}
Eliminate the xsub_map_argname_to_type field of ExtUtils::ParseXS objects. Instead, now that they exist, get the type value from the relevant Node::Param object within the Node::Sig object.
1 parent f09d72c commit 9c24c4e

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,6 @@ BEGIN {
314314
'xsub_func_full_perl_name', # its full Perl function name eg. 'Foo::Bar::f'
315315
'xsub_func_full_C_name', # its full C function name eg 'Foo__Bar__f'
316316

317-
'xsub_map_argname_to_type', # Hash: map argument names to types, such as
318-
# 'int *'. Names include special ones like
319-
# 'RETVAL'.
320-
321317
'xsub_CASE_condition', # Most recent CASE string.
322318

323319
'xsub_CASE_condition_count', # number of CASE keywords encountered.
@@ -711,7 +707,7 @@ EOM
711707

712708
# Initialize some per-XSUB instance variables:
713709

714-
foreach my $member (qw(xsub_map_argname_to_type
710+
foreach my $member (qw(
715711
xsub_map_varname_to_seen_in_INPUT
716712
))
717713
{
@@ -1336,7 +1332,6 @@ EOF
13361332
# Emit the RETVAL variable declaration.
13371333
print "\t" . $self->map_type($self->{xsub_return_type}, 'RETVAL') . ";\n"
13381334
if !$self->{xsub_seen_RETVAL_in_INPUT};
1339-
$self->{xsub_map_argname_to_type}->{"RETVAL"} = $self->{xsub_return_type};
13401335

13411336
# If it looks like the output typemap code can be hacked to
13421337
# use a TARG to optimise returning the value (rather than
@@ -1539,7 +1534,6 @@ EOF
15391534
{
15401535
my $var = $param->{var};
15411536
$self->generate_output( {
1542-
type => $self->{xsub_map_argname_to_type}->{$var},
15431537
num => $param->{arg_num},
15441538
var => $var,
15451539
do_setmagic => $self->{xsub_SETMAGIC_state},
@@ -1639,7 +1633,6 @@ EOF
16391633
else {
16401634
# Emit a normal RETVAL
16411635
$self->generate_output( {
1642-
type => $self->{xsub_return_type},
16431636
num => 0,
16441637
var => 'RETVAL',
16451638
do_setmagic => 0, # RETVAL almost never needs SvSETMAGIC()
@@ -1662,7 +1655,6 @@ EOF
16621655
my $var = $param->{var};
16631656
$self->generate_output(
16641657
{
1665-
type => $self->{xsub_map_argname_to_type}->{$var},
16661658
num => $num++,
16671659
var => $var,
16681660
do_setmagic => 0,
@@ -2522,10 +2514,6 @@ sub OUTPUT_handler {
25222514
next;
25232515
}
25242516

2525-
$self->blurt("Error: No input definition for OUTPUT argument '$outarg' - ignored"), next
2526-
unless defined $self->{xsub_map_argname_to_type}->{$outarg};
2527-
2528-
25292517
# Emit the custom var-setter code if present; else use the one from
25302518
# the OUTPUT typemap.
25312519

@@ -2536,7 +2524,6 @@ sub OUTPUT_handler {
25362524
}
25372525
else {
25382526
$self->generate_output( {
2539-
type => $self->{xsub_map_argname_to_type}->{$outarg},
25402527
num => $var_num,
25412528
var => $outarg,
25422529
do_setmagic => $self->{xsub_SETMAGIC_state},
@@ -3473,7 +3460,6 @@ sub fetch_para {
34733460

34743461
# $self->generate_output({ key = value, ... })
34753462
#
3476-
# type 'char *' etc
34773463
# num the parameter number, corresponds to ST(num-1)
34783464
# var the parameter name, such as 'RETVAL'
34793465
# do_setmagic whether to call set magic after assignment
@@ -3517,8 +3503,28 @@ sub fetch_para {
35173503
sub generate_output {
35183504
my ExtUtils::ParseXS $self = shift;
35193505
my $argsref = shift;
3520-
my ($type, $num, $var, $do_setmagic, $do_push)
3521-
= @{$argsref}{qw(type num var do_setmagic do_push)};
3506+
my ($num, $var, $do_setmagic, $do_push)
3507+
= @{$argsref}{qw(num var do_setmagic do_push)};
3508+
3509+
# Determine type - this is usually from the 'type' field of the
3510+
# associated param object in the Sig object, but with special cases.
3511+
my $type;
3512+
if ($var eq 'RETVAL') {
3513+
$type = $self->{xsub_return_type};
3514+
}
3515+
else {
3516+
my $sig = $self->{xsub_sig};
3517+
my $param = $sig->{names}{$var};
3518+
if ($param) {
3519+
$type = $param->{type};
3520+
$type = $param->{soft_type} unless defined $type;
3521+
}
3522+
}
3523+
3524+
unless (defined $type) {
3525+
$self->blurt("Can't determine output type for '$var'");
3526+
next;
3527+
}
35223528

35233529
my $arg = $self->ST($num, 1);
35243530

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ sub check {
125125
my ExtUtils::ParseXS $pxs = shift;
126126

127127
my $type = defined $self->{type} ? $self->{type} : $self->{soft_type};
128-
$pxs->{xsub_map_argname_to_type}->{$self->{var}} = $type;
129128

130129
# Get the overridden prototype character, if any, associated with the
131130
# typemap entry for this var's type.
@@ -154,9 +153,7 @@ sub check {
154153
$self->{no_init} = 1;
155154
}
156155
# XXX also tmp copy some stuff back to the sig param
157-
$sigp->{type} = $self->{type}
158-
if defined $sigp->{soft_type} && !defined $sigp->{type};
159-
for(qw(is_addr in_out proto)) {
156+
for(qw(is_addr in_out proto type)) {
160157
$sigp->{$_} = $self->{$_} if exists $self->{$_};
161158
}
162159
}

0 commit comments

Comments
 (0)