@@ -915,7 +915,7 @@ sub as_code {
915
915
916
916
print " \t STRLEN\t STRLEN_length_of_$name ;\n " ;
917
917
# defer this line until after all the other declarations
918
- $pxs -> {xsub_deferred_code_lines } .=
918
+ $pxs -> {cur_xbody }{ input_part }{ deferred_code_lines } .=
919
919
" \n\t XSauto_length_of_$name = STRLEN_length_of_$name ;\n " ;
920
920
921
921
# this var will be declared using the normal typemap mechanism below
@@ -1125,7 +1125,7 @@ sub as_code {
1125
1125
if ($default eq ' NO_INIT' ) {
1126
1126
# for foo(a, b = NO_INIT), add code to initialise later only if
1127
1127
# an arg was supplied.
1128
- $pxs -> {xsub_deferred_code_lines }
1128
+ $pxs -> {cur_xbody }{ input_part }{ deferred_code_lines }
1129
1129
.= sprintf " \n\t if (items >= %d ) {\n %s ;\n\t }\n " ,
1130
1130
$arg_num , $init_code ;
1131
1131
}
@@ -1135,7 +1135,7 @@ sub as_code {
1135
1135
my $else = ($init_code =~ / \S / ) ? " \t else {\n $init_code ;\n\t }\n " : " " ;
1136
1136
1137
1137
$default =~ s / "/ \\ "/ g ; # escape double quotes
1138
- $pxs -> {xsub_deferred_code_lines }
1138
+ $pxs -> {cur_xbody }{ input_part }{ deferred_code_lines }
1139
1139
.= sprintf " \n\t if (items < %d )\n\t %s = %s ;\n %s " ,
1140
1140
$arg_num ,
1141
1141
$var ,
@@ -1153,7 +1153,8 @@ sub as_code {
1153
1153
1154
1154
print " ;\n " ;
1155
1155
1156
- $pxs -> {xsub_deferred_code_lines } .= sprintf " \n %s ;\n " , $init_code
1156
+ $pxs -> {cur_xbody }{input_part }{deferred_code_lines }
1157
+ .= sprintf " \n %s ;\n " , $init_code
1157
1158
if $init_code =~ / \S / ;
1158
1159
}
1159
1160
else {
@@ -1167,7 +1168,7 @@ sub as_code {
1167
1168
}
1168
1169
1169
1170
if (defined $defer ) {
1170
- $pxs -> {xsub_deferred_code_lines }
1171
+ $pxs -> {cur_xbody }{ input_part }{ deferred_code_lines }
1171
1172
.= $pxs -> eval_input_typemap_code(" qq\a $defer \a " , $eval_vars ) . " \n " ;
1172
1173
}
1173
1174
}
@@ -2236,6 +2237,18 @@ BEGIN { $build_subclass->('', # parent
2236
2237
# info from any INPUT and OUTPUT sections (which can
2237
2238
# vary between different CASEs)
2238
2239
2240
+
2241
+ # Objects representing the various parts of an xbody. These
2242
+ # are aliases of the same objects in @{$self->{kids}} for easier
2243
+ # access.
2244
+ ' input_part' ,
2245
+ ' init_part' ,
2246
+ ' code_part' ,
2247
+ ' output_part' ,
2248
+ ' cleanup_part' ,
2249
+
2250
+ # Misc parse state
2251
+
2239
2252
' seen_RETVAL_in_CODE' , # Bool: have seen 'RETVAL' within a CODE block
2240
2253
' seen_autocall' , # Bool: this xbody has an autocall node
2241
2254
' OUTPUT_SETMAGIC_state' , # Bool: most recent value of SETMAGIC in an
@@ -2291,6 +2304,7 @@ sub parse {
2291
2304
my $kid = " ExtUtils::ParseXS::Node::$part " -> new();
2292
2305
if ($kid -> parse($pxs )) {
2293
2306
push @{$self -> {kids }}, $kid ;
2307
+ $self -> {$part } = $kid ;
2294
2308
}
2295
2309
}
2296
2310
@@ -2344,6 +2358,12 @@ EOF
2344
2358
package ExtUtils::ParseXS::Node::input_part ;
2345
2359
2346
2360
BEGIN { $build_subclass -> (' ' , # parent
2361
+
2362
+ # Used during code generation:
2363
+ # a multi-line string containing lines of code to be emitted *after*
2364
+ # all INPUT and PREINIT keywords have been processed.
2365
+ ' deferred_code_lines' ,
2366
+
2347
2367
)};
2348
2368
2349
2369
@@ -2353,10 +2373,6 @@ sub parse {
2353
2373
2354
2374
$self -> SUPER::parse($pxs ); # set file/line_no
2355
2375
2356
- # First, initialize variables manipulated by INPUT_handler().
2357
- $pxs -> {xsub_deferred_code_lines } = " " ; # lines to be emitted after
2358
- # PREINIT/INPUT
2359
-
2360
2376
$pxs -> {xsub_stack_was_reset } = 0; # XSprePUSH not yet emitted
2361
2377
2362
2378
# Process any implicit INPUT section.
@@ -2423,6 +2439,11 @@ sub as_code {
2423
2439
2424
2440
my $ioparams = $xbody -> {ioparams };
2425
2441
2442
+ # Lines to be emitted after PREINIT/INPUT. This may get populated
2443
+ # by the as_code() methods we call of our kids.
2444
+ $self -> {deferred_code_lines } = " " ;
2445
+
2446
+
2426
2447
if ($self -> {kids }) {
2427
2448
$_ -> as_code($pxs , $xsub , $xbody ) for @{$self -> {kids }};
2428
2449
}
@@ -2472,7 +2493,7 @@ EOF
2472
2493
# have been done. This is typically INPUT typemaps which don't
2473
2494
# start with a simple '$var =' and so would not have been emitted
2474
2495
# at the variable declaration stage.
2475
- print $pxs -> {xsub_deferred_code_lines };
2496
+ print $self -> {deferred_code_lines };
2476
2497
}
2477
2498
2478
2499
@@ -4005,7 +4026,7 @@ sub parse {
4005
4026
# "; extra code" or "+ extra code" :
4006
4027
# append the extra code (after passing through eval) after all the
4007
4028
# INPUT and PREINIT blocks have been processed, indirectly using
4008
- # the $pxs ->{xsub_deferred_code_lines } mechanism.
4029
+ # the $input_part ->{deferred_code_lines } mechanism.
4009
4030
# In addition, for '+', also generate the normal initialisation
4010
4031
# code from the standard typemap - assuming that it's a real
4011
4032
# parameter that appears in the signature as well as the INPUT
0 commit comments