develooper Front page | perl.perl5.porters | Postings from August 2001

[PATCH] Add a nextstate into empty blocks

Thread Next
Ilmari Karonen
August 18, 2001 17:21
[PATCH] Add a nextstate into empty blocks
Message ID:

There's been a recent discussion on comp.lang.perl.misc about the weird
behavior of empty subroutines in list context:

  sub empty { }
  print empty( "What the...?\n" );  

The reason this happens is that no nextstate op is currently compiled
into such subroutines, which makes them leave their arguments on the
stack.  Curiously enough, even just adding a label into the subroutine
is enough to fix this:

  sub label { foo: }
  print label( "This isn't printed.\n" );

The following patch fixes this by inserting a nextstate op into empty
blocks.  No harmful effects are observed, although two test cases
(op/sub_lval:31 and lib/warnings:255) fail because of minor changes in
error messages.  (The former is IMHO an improvement.  The latter is a
mystery to me, but doesn't seem a particularly serious issue.)

--- op.c.orig	Sun Aug 19 02:23:46 2001
+++ op.c	Sun Aug 19 03:00:18 2001
@@ -2146,7 +2146,8 @@
 Perl_block_end(pTHX_ I32 floor, OP *seq)
     int needblockscope = PL_hints & HINT_BLOCK_SCOPE;
-    OP* retval = scalarseq(seq);
+    /* There should be a nextstate in every block. */
+    OP* retval = seq ? scalarseq(seq) : newSTATEOP(0, Nullch, seq);
     PL_pad_reset_pending = FALSE;
     PL_compiling.op_private = PL_hints;

# Ilmari Karonen --
y/n/\n/,s/\d+/$"x$&/eg,print for qw'n4|9|21|3|n1\2||2|(_-<2_|4_`1|3\3_1\2_|3\3

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About