Skip Menu |

This queue is for tickets about the List-MoreUtils CPAN distribution.

Report information
The Basics
Id: 80385
Status: resolved
Priority: 0/
Queue: List-MoreUtils

People
Owner: Nobody in particular
Requestors: paul.a.liebert [...] hp.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.33
Fixed in: 0.414_001



Subject: part() output references input in XS, not in PP
The XS version of part() appears to create scalars in its output by making aliases to values in its input stream. Subsequent changes to either the input or the output values, end up affecting the other. This behavior is not present in the PP implementation. Here is sample output from running the enclosed 'bug' program: $ LIST_MOREUTILS_PP=1 ./bug 1 2 3 4 1 2 3 4 $ LIST_MOREUTILS_PP=0 ./bug 1 2 3 4 1 bogus 3 4 Here is the 'bug' program #!/usr/bin/perl use warnings; use strict; use List::MoreUtils qw(part); my( $s1, $s2, $s3, $s4 ) = 1..4; my $i=0; my @array = part{ int( $i++ / 2 )} ( $s1, $s2, $s3, $s4 ); print "@{$_}\n" foreach @array; print "\n"; $s2 = 'bogus'; print "@{$_}\n" foreach @array; This is for List::MoreUtils 0.33 perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux Linux lxcvipal.cv.hp.com 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux Redhat-5 Enterprise Linux Sorry, no patch. Thanks -Paul
Subject: bug
Download bug
application/octet-stream 271b

Message body not shown because it is not plain text.

From: paul.a.liebert [...] hp.com
Here are patches for Test.pm and MoreUtils.xs that detect and fix (i believe) the issue. -Paul
Subject: MoreUtils.xs.diff
--- List-MoreUtils-0.33/MoreUtils.xs 2011-08-04 02:39:36.000000000 -0700 +++ fixed/MoreUtils.xs 2012-10-24 15:48:49.000000000 -0700 @@ -1307,8 +1307,8 @@ } if (!tmp[idx]) tmp[idx] = newAV(); - av_push(tmp[idx], args[i]); - SvREFCNT_inc(args[i]); + + av_push(tmp[idx], newSVsv( args[i] )); } POP_MULTICALL;
Subject: Test.pm.diff
--- List-MoreUtils-0.33/t/lib/Test.pm 2011-08-04 02:39:36.000000000 -0700 +++ fixed/t/lib/Test.pm 2012-10-25 07:52:19.000000000 -0700 @@ -698,6 +698,10 @@ ok( arrayeq($part[1], [ 2, 5, 8, 11 ]) ); ok( arrayeq($part[2], [ 3, 6, 9, 12 ]) ); + $list[2] = 0; + is( $part[2][0], 3, 'Values are not aliases' ); + @list = 1 .. 12; + @part = part { 3 } @list; is( $part[0], undef ); is( $part[1], undef );
Fixes applied and pushed with 1b75bcf, sorry for late recognize ... To much open issues and to much noise from foreigns ...