New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
for lvalue_sub #6761
Comments
From @AbigailCreated by @Abigail#!/usr/bin/perl use strict; my @foo = qw /one two three/; print for foo; However, I expect it to print "onetwothree" (which is does in 5.6.0). This bug occurs from 5.6.1 up to and including bleadperl. Abigail Perl Info
|
From kasei@cpan.orgpadav is leaving an arrayref on the stack when it told to return an |
The RT System itself - Status changed from 'new' to 'open' |
From voropaev.andrey@gmail.comCreated by voropaev.andrey@gmail.comI know, that lvalue subs are experimental. So this is not really an issue, just The code example ########################################## sub canmod : lvalue { @a; } Produces --------------------------------------------- Perl Info
|
From kasei@cpan.orgAttached a fix for lvalue subs returning an array into the args of I've modified leavesublv in that case to convert the returned arrayref |
From kasei@cpan.org0001-fix-for-23790.patchFrom ba8f5d50c4a9a94867872ba5c341fa7e5b546e48 Mon Sep 17 00:00:00 2001
From: Marty Pauley <marty@martian.org>
Date: Sun, 24 Oct 2010 18:02:40 +0900
Subject: [PATCH] fix for #23790.
padav is leaving an arrayref on the stack when producing the return value for an
lvalue sub. But when this is in an argument list it really should be a array,
not a ref. So, in leavesublv I check for this case and expand the arrayref to
an array.
---
pp_hot.c | 23 +++++++++++++++++++++++
t/op/sub_lval.t | 12 +++++++++---
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/pp_hot.c b/pp_hot.c
index 34542c2..2d6cba9 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2598,6 +2598,29 @@ PP(pp_leavesublv)
if (gimme == G_SCALAR)
goto temporise;
if (gimme == G_ARRAY) {
+ mark = newsp + 1;
+ /* We want an array here, but padav will have left us an arrayref for an lvalue,
+ * so we need to expand it */
+ if(SvTYPE(*mark) == SVt_PVAV) {
+ AV *const av = MUTABLE_AV(*mark);
+ const I32 maxarg = AvFILL(av) + 1;
+ (void)POPs; /* get rid of the array ref */
+ EXTEND(SP, maxarg);
+ if (SvRMAGICAL(av)) {
+ U32 i;
+ for (i=0; i < (U32)maxarg; i++) {
+ SV ** const svp = av_fetch(av, i, FALSE);
+ SP[i+1] = svp
+ ? SvGMAGICAL(*svp) ? (mg_get(*svp), *svp) : *svp
+ : &PL_sv_undef;
+ }
+ }
+ else {
+ Copy(AvARRAY(av), SP+1, maxarg, SV*);
+ }
+ SP += maxarg;
+ PUTBACK;
+ }
if (!CvLVALUE(cx->blk_sub.cv))
goto temporise_array;
EXTEND_MORTAL(SP - newsp);
diff --git a/t/op/sub_lval.t b/t/op/sub_lval.t
index aedaba0..d0ba84a 100644
--- a/t/op/sub_lval.t
+++ b/t/op/sub_lval.t
@@ -3,7 +3,7 @@ BEGIN {
@INC = '../lib';
require './test.pl';
}
-plan tests=>74;
+plan tests=>76;
sub a : lvalue { my $a = 34; ${\(bless \$a)} } # Return a temporary
sub b : lvalue { ${\shift} }
@@ -527,8 +527,7 @@ TODO: {
is($blah, 8, "yada");
}
-TODO: {
- local $TODO = "bug #23790";
+{ # bug #23790
my @arr = qw /one two three/;
my $line = "zero";
sub lval_array () : lvalue {@arr}
@@ -538,6 +537,13 @@ TODO: {
}
is($line, "zeroonetwothree");
+
+ sub trythislval { scalar(@_)."x".join "", @_ }
+ is(trythislval(lval_array()), "3xonetwothree");
+
+ sub changeme { $_[2] = "free" }
+ changeme(lval_array);
+ is("@arr", "one two free");
}
{
--
1.7.2.3
|
From @cpansproutOn Mon Nov 01 08:46:20 2010, maokt wrote:
Thank you. Applied as 91e34d8. |
@cpansprout - Status changed from 'open' to 'resolved' |
From @cpansproutOn Thu Oct 28 02:23:36 2010, voropaev.andrey@gmail.com wrote:
Thank you for the report. This is the same as bug #23790, which has just |
The RT System itself - Status changed from 'new' to 'open' |
@cpansprout - Status changed from 'open' to 'resolved' |
From @cpansproutOn Thu Nov 04 00:35:16 2010, sprout wrote:
For the record: That patch only worked if the array were the first thing |
Migrated from rt.perl.org#23790 (status was 'resolved')
Searchable as RT23790$
The text was updated successfully, but these errors were encountered: