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

[PATCH] Add a nextstate into empty blocks

Thread Next
From:
Ilmari Karonen
Date:
August 18, 2001 17:21
Subject:
[PATCH] Add a nextstate into empty blocks
Message ID:
Pine.SOL.3.96.1010819030007.21846A-100000@simpukka

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);
     LEAVE_SCOPE(floor);
     PL_pad_reset_pending = FALSE;
     PL_compiling.op_private = PL_hints;

-- 
# Ilmari Karonen -- http://www.sci.fi/~iltzu/
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
-_)2_|n\__/\_,_|___/\__|2\__,_|_|1_|\___/\__|_|1_|\___|_|nn4_1\9|3|14|n4__/1-_
)2_|1|5\3_`1|2_|1!1/2-_)2_|n3_|1\___|_|2_|2_|1_|\__,_|\__|_i_\\\___|_|1)n45/n'




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About