From 9a8aa25b28a859846cf1458bfe11f17ad258e982 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sun, 22 Jan 2012 15:59:16 -0800 Subject: [PATCH] [perl #108794] Call special blocks in void context Now BEGIN blocks, etc., are called in void context, so the result of evaluating the last statement is not wastefully copied. --- perl.c | 2 +- t/op/blocks.t | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/perl.c b/perl.c index 0f9ab00..eb9889c 100644 --- 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) diff --git a/t/op/blocks.t b/t/op/blocks.t index 8460371..e6c53d7 100644 --- a/t/op/blocks.t +++ b/t/op/blocks.t @@ -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', < 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 -- 2.7.4