OK, I've got something. Very misterious!!!
Fortunately the segmentation fault happens in the first call to the
function and some printfs where enough to arrive to what seems the key.
The C subroutine receives an array in its second argument:
int __next_partition_of_size_p(SV* k_avptr, SV* M_avptr, int p) {
AV* k = GETAV(k_avptr);
AV* M = GETAV(M_avptr);
...
}
that is initialized in the Perl side:
my @M = (0) x $q;
push @M, $_ - $q + 1 for $q..(@$data-1);
...
__next_partition_of_size_p([EMAIL PROTECTED], [EMAIL PROTECTED], $p)
The values of $q and @$data do not matter, they are correct. OK, [EMAIL PROTECTED]
is passed to the function as the second argument, and if I print its
contents in XS I get garbage from some index on. Just in case, that
call lives in a closure:
my $iter = Algorithm::Combinatorics::Iterator->new(sub {
__next_partition_of_size_p([EMAIL PROTECTED], [EMAIL PROTECTED], $p) ==
-1 ? ...;
}, __slice_partition_of_size_p([EMAIL PROTECTED], $p, $data));
NOW THE MISTERY COMES, If I just print @M in Perl before that line,
the values in XS are right and execution completes without errors. I
mean, I just really added
print join(", ", @M), "\n";
before the call and all of a sudden the values of M in the XS side
are fine and thus the code completes OK.
I am puzzled here! Any ideas?
-- fxn