Skip to content

Commit a7c5807

Browse files
committed
ParseXS: refactor: alter Node:OUTPUT_line RETVAL
This is #7 of a small series of commits to refactor OUTPUT keyword handling. For OUTPUT_line, move, from the parse() method to the as_code() method, the bit which checks for RETVAL and causes its "push return value on stack" C code to be emitted later. Also, add a long comment explaining why this delay is required. The existing code in parse() worked purely by chance: it was just returning (without a value) if the parameter name was RETVAL. This was a hangover from moving the existing code from OUTPUT_handler() into a Node parse() method. By returning undef, it was signalling to the caller that the parse of the line failed, and so the subsequent call to as_code() was skipped. Instead, indicate that the parse was successful, and have as_code() skip RETVAL.
1 parent 9b3ee05 commit a7c5807

File tree

1 file changed

+33
-6
lines changed
  • dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS

1 file changed

+33
-6
lines changed

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,12 +3122,6 @@ sub parse {
31223122
: $pxs->{xsub_SETMAGIC_state};
31233123
$self->{code} = $param->{output_code} = $outcode if length $outcode;
31243124

3125-
if ($outarg eq 'RETVAL') {
3126-
# Postpone processing the RETVAL line to last (it's left to the
3127-
# caller to finish).
3128-
return;
3129-
}
3130-
31313125
1;
31323126
}
31333127

@@ -3136,8 +3130,41 @@ sub as_code {
31363130
my __PACKAGE__ $self = shift;
31373131
my ExtUtils::ParseXS $pxs = shift;
31383132

3133+
# An OUTPUT: line serves two logically distinct purposes. First, any
3134+
# parameters listed are updated; i.e. the perl equivalent of
3135+
#
3136+
# my $foo = $_[0];
3137+
# # maybe $foo's value gets changed here
3138+
# $_[0] = $foo; # update caller's arg with current value
3139+
#
3140+
# The code for updating such OUTPUT vars is emitted here, in the
3141+
# same order they appear in OUTPUT lines, and preserving the order
3142+
# of any intermixed POSTCALL etc blocks.
3143+
#
3144+
# Second, it can be used to indicate that an SV should be created,
3145+
# set to the current value of RETVAL, and pushed on the stack; i.e
3146+
# the perl equivalent of
3147+
#
3148+
# my $RETVAL;
3149+
# # maybe $RETVAL's value gets set here
3150+
# return $RETVAL;
3151+
#
3152+
# The code to return RETVAL is emitted later, after all other
3153+
# processing for XSUB is complete apart from any final CLEANUP block.
3154+
# It is done at the same time as any emitting for params declared as
3155+
# OUT or OUTLIST in the signature.
3156+
#
3157+
# There isn't any particularly strong reason to do things in this
3158+
# exact order; but the ordering was the result of how xsubpp was
3159+
# originally written and subsequently modified, and changing things
3160+
# now might break existing XS code which has come to rely on the
3161+
# ordering.
3162+
3163+
return if $self->{name} eq 'RETVAL';
3164+
31393165
my $param = $self->{param};
31403166
return unless $param; # might be an ENABLE line with no param to emit
3167+
31413168
$param->as_output_code($pxs);
31423169
}
31433170

0 commit comments

Comments
 (0)