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
splice generates undef? #7403
Comments
From perl@nevcal.comCreated by perl@nevcal.comApologies if this is fixed in newer versions; could someone please test Where does the undef come from in the below? Looks like handling [ -2 ] d:\MY\PERL\src>type test.pl d:\MY\PERL\src>perl -w test.pl Perl Info
|
From @iabynOn Sat, Jul 03, 2004 at 06:17:22AM -0000, Glenn Linderman wrote:
Two things are interracting here to produce the effect you see. sub f { @a=(); print $_[0],"\n" } prints an uninit value. This menas that when splice deletes elements Second, splice in a void context behaves the same is in scalar context, Not sure of the best fix yet. -- |
The RT System itself - Status changed from 'new' to 'open' |
From @pjcjOn Sat, Jul 03, 2004 at 12:16:12PM +0100, Dave Mitchell wrote:
I suppose this is also the reason for this bug, reported at sub foo { Sample output: $ perl perlbug.pl -- |
From perl5-porters@ton.iguana.beIn article <20040703111612.GA1887@iabyn.com>,
While finding a fix would be neat, I don't think it *HAS* to be fixed It's not really different from e.g.: perl -wle 'sub foo { shift @{$_[0]}; print $_[1] } @a="a".."z"; foo(\@a,$a[0])' |
From perl@nevcal.comOn approximately 7/3/2004 4:16 AM, came the following characters from
I appreciate your confirmation that there is a problem, and your testing I don't understand your explanation, as noted below, and although I'm On the other hand, a fix won't help me for months, likely, and I have my $tmp = $stk[ -2 ]; works fine, and would seem to avoid the bug. Although the circumstances
I don't understand why f shouldn't be expected to print an uninit OK, maybe you meant to f(@a); ? I see that even that prints an uninit OK, so @_ is getting only aliases to values? and unreference counted Maybe I'm close to understanding this now. I don't guess I understand how it becomes undef rather than 67, though,
I guess I don't understand this comment either... but maybe it is But maybe... since you bring up the function call and the stack, I guess I guess I'm close to understanding this now too, if all my assumptions So another workaround would be @stk = ( 1, 2, 3 ); Curiously, my original case had an expression, but it was composed of a
--
|
From wolfgang.laun@alcatel.at
On Sat, Jul 03, 2004 at 12:16:12PM +0100, Dave Mitchell wrote:
All right, I understand that (boast, boast ;-). Consequentely Being evil (according to H.Merijn Brand ;-), I tried (perl 5.8.0 on Linux and Solaris; 5.8.4 on Solaris): Kind regards |
From @rgsDave Mitchell wrote:
Shouldn't this be fixed ? (or "optimized out") ? |
From @iabynOn Tue, Jul 06, 2004 at 10:47:09AM +0200, Rafael Garcia-Suarez wrote:
Yep. I plan to do this too once I find some time to fix splice. -- |
From wolfgang.laun@alcatel.atThe patch fixes the problems arising from using elements deleted from On 3 Jul 2004 06:17:22 -0000 Glenn Linderman wrote:
Dave Mitchell has provided an analysis <20040703111612.GA1887@iabyn.com>. On Sat, 3 Jul 2004 14:31:16 +0000 Ton Hospel wrote:
I disagree, since a single call to splice() shouldn't considered as being The patch is simple: Don't postpone the creation of SV's for the new Regards Inline Patch--- pp.c.old Fri Jul 9 13:25:23 2004
+++ pp.c Fri Jul 9 20:43:06 2004
@@ -4125,6 +4125,13 @@
if (newlen && !AvREAL(ary) && AvREIFY(ary))
av_reify(ary);
+ /* make new elements SVs now: avoid problems if they're from the array */
+ for (dst = MARK, i = newlen; i; i--) {
+ SV *h = *dst;
+ *dst = NEWSV(46, 0);
+ sv_setsv(*dst++, h);
+ }
+
if (diff < 0) { /* shrinking the area */
if (newlen) {
New(451, tmparyval, newlen, SV*); /* so remember insertion */
@@ -4181,11 +4188,7 @@
dst[--i] = &PL_sv_undef;
if (newlen) {
- for (src = tmparyval, dst = AvARRAY(ary) + offset;
- newlen; newlen--) {
- *dst = NEWSV(46, 0);
- sv_setsv(*dst++, *src++);
- }
+ Copy( tmparyval, AvARRAY(ary) + offset, newlen, SV* );
Safefree(tmparyval);
}
}
@@ -4224,11 +4227,11 @@
}
}
- for (src = MARK, dst = AvARRAY(ary) + offset; newlen; newlen--) {
- *dst = NEWSV(46, 0);
- sv_setsv(*dst++, *src++);
+ if (newlen) {
+ Copy( MARK, AvARRAY(ary) + offset, newlen, SV* );
}
+
MARK = ORIGMARK + 1;
if (GIMME == G_ARRAY) { /* copy return vals to stack */
if (length) {
--- t/op/splice.t.old Fri Jul 9 19:21:39 2004
+++ t/op/splice.t Fri Jul 9 20:08:21 2004
@@ -1,6 +1,6 @@
#!./perl
-print "1..12\n";
+print "1..18\n";
@a = (1..10);
@@ -52,3 +52,33 @@
print "not " unless $foo eq 'red';
print "ok 12\n";
+# Bug [perl #30568] - insertions of deleted elements
+@a = (1, 2, 3);
+splice( @a, 0, 3, $a[1], $a[0] );
+print "not " unless j(@a) eq j(2,1);
+print "ok 13\n";
+
+@a = (1, 2, 3);
+splice( @a, 0, 3 ,$a[0], $a[1] );
+print "not " unless j(@a) eq j(1,2);
+print "ok 14\n";
+
+@a = (1, 2, 3);
+splice( @a, 0, 3 ,$a[2], $a[1], $a[0] );
+print "not " unless j(@a) eq j(3,2,1);
+print "ok 15\n";
+
+@a = (1, 2, 3);
+splice( @a, 0, 3, $a[0], $a[1], $a[2], $a[0], $a[1], $a[2] );
+print "not " unless j(@a) eq j(1,2,3,1,2,3);
+print "ok 16\n";
+
+@a = (1, 2, 3);
+splice( @a, 1, 2, $a[2], $a[1] );
+print "not " unless j(@a) eq j(1,3,2);
+print "ok 17\n";
+
+@a = (1, 2, 3);
+splice( @a, 1, 2, $a[1], $a[1] );
+print "not " unless j(@a) eq j(1,2,2);
+print "ok 18\n"; |
From @rgsLAUN Wolfgang wrote:
Thanks, applied to bleadperl as #23092. |
@rspier - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#30568 (status was 'resolved')
Searchable as RT30568$
The text was updated successfully, but these errors were encountered: