[perl #108794] Call special blocks in void context
authorFather Chrysostomos <sprout@cpan.org>
Sun, 22 Jan 2012 23:59:16 +0000 (15:59 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 22 Jan 2012 23:59:16 +0000 (15:59 -0800)
Now BEGIN blocks, etc., are called in void context, so the result of
evaluating the last statement is not wastefully copied.

perl.c
t/op/blocks.t

diff --git a/perl.c b/perl.c
index 0f9ab00..eb9889c 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -92,7 +92,7 @@ static I32 read_e_script(pTHX_ int idx, SV *buf_sv, int maxlen);
 
 #define CALL_LIST_BODY(cv) \
     PUSHMARK(PL_stack_sp); \
-    call_sv(MUTABLE_SV((cv)), G_EVAL|G_DISCARD);
+    call_sv(MUTABLE_SV((cv)), G_EVAL|G_DISCARD|G_VOID);
 
 static void
 S_init_tls_and_interp(PerlInterpreter *my_perl)
index 8460371..e6c53d7 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan tests => 5;
+plan tests => 6;
 
 my @expect = qw(
 b1
@@ -113,3 +113,21 @@ SCRIPT70614
 # [perl #78634] Make sure block names can be used as constants.
 use constant INIT => 5;
 ::is INIT, 5, 'constant named after a special block';
+
+# [perl #108794] context
+fresh_perl_is(<<'SCRIPT3', <<expEct,{stderr => 1 },'context');
+sub context {
+    print qw[void scalar list][wantarray + defined wantarray], "\n"
+}
+BEGIN     {context}
+UNITCHECK {context}
+CHECK     {context}
+INIT      {context}
+END       {context}
+SCRIPT3
+void
+void
+void
+void
+void
+expEct