Subject: | XS implementation of pairwise fails with memory allocation error when there are more return values than in original lists |
Hey guys,
%subj. Pretty much every call like pairwise { ($a) x $b } @list1, @list2 has the problem.
Attached script listmoreutils-memory.pl can be used to reproduce it.
From what I understand by looking at the code, only a maximum of lists elements are expected to return, which is not always the case.
Interesting that sometimes it works and it's based on the number of elements in arrays, see listmoreutils-ok.pl as an example. Changing the number of elements in the first array produces a vast variety of error messages:
Segmentation fault: 11
perl(90433,0x7fff71397300) malloc: *** error for object 0x7ff098f09bc8: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
Bizarre copy of ARRAY in list assignment at ./listmoreutils-memory-arr.pl line 12.
Use of uninitialized value in freed op during global destruction.
Use of uninitialized value in freed op during global destruction.
Use of uninitialized value in freed op during global destruction.
Use of uninitialized value in freed op during global destruction.
Use of uninitialized value in freed op during global destruction.
Use of uninitialized value in freed op during global destruction.
Sometimes it just works.
--
S. T.
Subject: | listmoreutils-memory.pl |
#!/usr/bin/perl -w
use strict;
use warnings;
use List::MoreUtils qw/ pairwise /;
my @ids = (1, 2, 3);
my @quantities = [map { 42 } @ids];
my @id_stream = pairwise { (our $a) x our $b } @ids, @quantities;
print join(', ', @id_stream);
Subject: | listmoreutils-ok.pl |
#!/usr/bin/perl -w
use strict;
use warnings;
use List::MoreUtils qw/ pairwise /;
my @ids = (1 .. 42);
my @quantities = map { 42 } @ids;
my @id_stream = pairwise { (our $a) x our $b } @ids, @quantities;
print join(', ', @id_stream);