Skip to content

Commit a9b73fc

Browse files
committed
ParseXS: refactor: simplify ST() method.
The $self->ST($num) method typically emits "ST(" . ($num-1) . ")" but it has special-case handling for $num being undef, or (in the case of output), being 0. The latter was a special-case for outputting RETVAL return code. Recent refactoring means that the ST() method is no longer called with $num == 0, so the method's code can be simplified (and the $is_output parameter eliminated). Should be no change in functionality.
1 parent bbb9904 commit a9b73fc

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,13 +1876,7 @@ sub CASE_handler {
18761876
#
18771877
# "ST(". $num - 1 . ")"
18781878
#
1879-
# but with subtleties when $num is 0 or undef.
1880-
# Gathering all such uses into one place helps in documenting the totality.
1881-
#
1882-
# Normally parameter names are mapped to index numbers 1,2,... . In
1883-
# addition, in *OUTPUT* processing only, 'RETVAL' is mapped to 0.
1884-
#
1885-
# Finally, in input processing it is legal to have a parameter with a
1879+
# except that in input processing it is legal to have a parameter with a
18861880
# typemap override, but where the parameter isn't in the signature. People
18871881
# misuse this to declare other variables which should really be in a
18881882
# PREINIT section:
@@ -1897,13 +1891,8 @@ sub CASE_handler {
18971891
# shouldn't emit a warning when generating "ST(N-1)".
18981892
#
18991893
sub ST {
1900-
my ($self, $num, $is_output) = @_;
1901-
1902-
if (defined $num) {
1903-
return "ST(0)" if $is_output && $num == 0;
1904-
return "ST(" . ($num-1) . ")" if $num >= 1;
1905-
$self->Warn("Internal error: unexpected zero num in ST()");
1906-
}
1894+
my ($self, $num) = @_;
1895+
return "ST(" . ($num-1) . ")" if defined $num;
19071896
return '/* not a parameter */';
19081897
}
19091898

@@ -3149,7 +3138,7 @@ sub generate_output {
31493138
return;
31503139
}
31513140

3152-
my $arg = $self->ST($num, 1);
3141+
my $arg = $self->ST($num);
31533142

31543143
my $typemaps = $self->{typemaps_object};
31553144

@@ -3490,7 +3479,7 @@ sub generate_output {
34903479
# Indicates that this is an OUTLIST value, so an SV with the value
34913480
# should be pushed onto the stack
34923481
print "\tPUSHs(sv_newmortal());\n";
3493-
$eval_vars->{arg} = $self->ST($out_num + 1, 1);
3482+
$eval_vars->{arg} = $self->ST($out_num + 1);
34943483
print $self->eval_output_typemap_code("qq\a$expr\a", $eval_vars);
34953484
}
34963485

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ sub as_code {
164164
my ($type, $arg_num, $var, $init, $no_init, $defer, $default)
165165
= @{$self}{qw(type arg_num var init no_init defer default)};
166166

167-
my $arg = $pxs->ST($arg_num, 0);
167+
my $arg = $pxs->ST($arg_num);
168168

169169
if ($self->{is_length}) {
170170
# Process length(foo) parameter.

0 commit comments

Comments
 (0)