Skip to content

Commit 05c2d6d

Browse files
committed
parseXS: refactor: INPUT_handler() init parsing
Simplify a complex series of nested if/elses and update code comments. Should be no functional changes.
1 parent 2fbf369 commit 05c2d6d

File tree

1 file changed

+22
-38
lines changed

1 file changed

+22
-38
lines changed

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

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,59 +2404,43 @@ sub INPUT_handler {
24042404

24052405
my ($init, $no_init, $defer);
24062406

2407-
if ( defined $init_op
2408-
and $init_op =~ /^[=;]$/
2409-
and $var_init =~ /^NO_INIT\s*;?\s*$/
2410-
) {
2411-
# NO_INIT: skip initialisation
2412-
$no_init = 1;
2413-
}
2414-
2415-
elsif (defined $init_op) {
2407+
if (defined $init_op) {
24162408
# Emit the init code based on overridden $var_init, which was
24172409
# preceded by /[=;+]/ which has been extracted into $init_op
24182410

2419-
if ($init_op eq '=') {
2411+
if ( $init_op =~ /^[=;]$/
2412+
and $var_init =~ /^NO_INIT\s*;?\s*$/
2413+
) {
2414+
# NO_INIT: skip initialisation
2415+
$no_init = 1;
2416+
}
2417+
elsif ($init_op eq '=') {
24202418
# Overridden typemap, such as '= ($type)SvUV($arg)'
24212419
$var_init =~ s/;\s*$//;
2422-
24232420
$init = $var_init,
24242421
}
24252422
else {
24262423
# "; extra code" or "+ extra code" :
24272424
# append the extra code (after passing through eval) after all the
2428-
# INPUT and PREINIT blocks have been processed, using the
2429-
# $self->{xsub_deferred_code_lines} mechanism.
2430-
# In addition, for '+', also generate the normal initialisation code
2431-
# from the standard typemap - assuming that it's a real parameter
2432-
# that appears in the signature as well as the INPUT line.
2433-
2434-
# if '+' on a real var, generate init from typemap,
2435-
# else (';' or fake var), skip init.
2425+
# INPUT and PREINIT blocks have been processed, indirectly using
2426+
# the $self->{xsub_deferred_code_lines} mechanism.
2427+
# In addition, for '+', also generate the normal initialisation
2428+
# code from the standard typemap - assuming that it's a real
2429+
# parameter that appears in the signature as well as the INPUT
2430+
# line.
24362431
$no_init = !($init_op eq '+' && !$is_alien);
24372432
# But in either case, add the deferred code
2438-
$defer = $var_init,
2433+
$defer = $var_init;
24392434
}
24402435
}
2441-
2442-
elsif (!$is_alien) {
2443-
# Emit var and init code based on typemap entry
2444-
}
24452436
else {
2446-
# A parameter which has been declared (with no initialiser) in the
2447-
# INPUT section, but which hasn't also been declared in the XSUB's
2448-
# signature. Should be illegal, but people rely on it,
2449-
# For such a variable, don't use a typemap, because there's no value
2450-
# on the stack to be converted.
2451-
$no_init = 1;
2452-
}
2453-
2454-
if ( defined $param->{in_out}
2455-
and $param->{in_out} =~ /^OUT/
2456-
and !defined $init_op
2457-
) {
2458-
# OUT* class: skip initialisation
2459-
$no_init = 1;
2437+
# no initialiser: emit var and init code based on typemap entry,
2438+
# unless:
2439+
# - its alien (so no stack arg to bind to it), or
2440+
# - its an OUT-only var, so not initialised from the arg
2441+
$no_init = 1
2442+
if ( $is_alien
2443+
or defined $param->{in_out} and $param->{in_out} =~ /^OUT/)
24602444
}
24612445

24622446
%$param = (

0 commit comments

Comments
 (0)