From f650fa729f03aabdf12058228971129d911b4aa1 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 26 Aug 2011 23:50:06 -0700 Subject: &CORE::reset() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit allows &CORE::reset to be called through references and via ampersand syntax. pp_reset is modified to take into account the nulls pushed on to the stack in pp_coreargs, which happens because pp_coreargs has no other way to tell reset how many arguments it’s actually getting. See commit 0163043a for details. --- gv.c | 2 +- pp_ctl.c | 3 ++- t/op/coreamp.t | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gv.c b/gv.c index cbbf326136..b9516d8a39 100644 --- a/gv.c +++ b/gv.c @@ -1357,7 +1357,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags, case KEY_keys: case KEY_lstat: case KEY_pop: - case KEY_push: case KEY_reset: + case KEY_push: case KEY_select: case KEY_send: case KEY_setpgrp: case KEY_shift: case KEY_sleep: case KEY_splice: diff --git a/pp_ctl.c b/pp_ctl.c index 971e78b451..67b11e3228 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -2007,7 +2007,8 @@ PP(pp_reset) { dVAR; dSP; - const char * const tmps = (MAXARG < 1) ? (const char *)"" : POPpconstx; + const char * const tmps = + (MAXARG < 1 || (!TOPs && !POPs)) ? (const char *)"" : POPpconstx; sv_reset(tmps, CopSTASH(PL_curcop)); PUSHs(&PL_sv_yes); RETURN; diff --git a/t/op/coreamp.t b/t/op/coreamp.t index b77d56a939..ef6db6314c 100644 --- a/t/op/coreamp.t +++ b/t/op/coreamp.t @@ -33,6 +33,7 @@ my %op_desc = ( join => 'join or string', readline => '', readpipe => 'quoted execution (``, qx)', + reset => 'symbol reset', ref => 'reference-type operator', ); sub op_desc($) { @@ -577,6 +578,19 @@ test_proto 'rename'; test_proto 'ref', [], 'ARRAY'; +test_proto 'reset'; +$tests += 2; +my $oncer = sub { "a" =~ m?a? }; +&$oncer; +&myreset; +ok &$oncer, '&reset with one arg'; +package resettest { + $b = "c"; + $banana = "cream"; + &::myreset('b'); + ::lis [$b,$banana],[(undef)x2], '2-arg &reset'; +} + test_proto 'reverse'; $tests += 2; is &myreverse('reward'), 'drawer', '&reverse'; -- cgit v1.2.1