Partial incompatibility with Sort::Key
lokapal opened this issue · 3 comments
Hello!
Your B::C is very good (and important!) Perl subsystem but unfortunately I cannot use it for really important project. This code:
`#!/usr/bin/perl
use strict;
use Sort::Key::Maker BED_keysort => qw(integer integer);
my @unsorted;
for (my $i=0;$i<10;$i++) { $unsorted[$i] {beg} = $i;
$unsorted[$i] {center} = 20-$i; }
print "Unsorted:\nBeg:\t"; for (my $i=0;$i<10;$i++) { print "$unsorted[$i]{beg} "; }.
print "\n";
print "Center:\t";for (my $i=0;$i<10;$i++) { print "$unsorted[$i]{center} "; }.
print "\n";
BED_keysort_inplace { $_->{center}, $_->{beg} } @unsorted;
print "Sorted\nBeg:\t"; for (my $i=0;$i<10;$i++) { print "$unsorted[$i]{beg} "; }.
print "\n";
print "Center:\t";for (my $i=0;$i<10;$i++) { print "$unsorted[$i]{center} "; }.
print "\n";`
Is running Ok in pure Perl, compiles by perlcc without any problems, but if I try to run it the answer is:
Undefined subroutine &main::BED_keysort_inplace called at test.pl line 15.
Perl:
This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi (with 44 registered patches, see perl -V for more detail)
OS: Ubuntu 14.04.5 LTS
The problem obviously is in the string
BED_keysort_inplace { $->{center}, $->{beg} } @unsorted;
_inplace are dynamically created functions made by main sorting module Sort::Key
With typical errors like this you need to give the compiler the hint not to drop this package. Use the perlcc -uSort::Key flag if this is the package of the generated sub.
forward$ perlcc -uSort::Key::Maker -uSort::Key --staticxs test.pl forward$ ./test Unsorted: Beg: 0 1 2 3 4 5 6 7 8 9 Center: 20 19 18 17 16 15 14 13 12 11 Undefined subroutine &main::BED_keysort_inplace called at test.pl line 15.
What can I do more?
Ok, I've looked at it, and it seems to be very tricky.
BED_keysort_inplace
is basically created by the importer to
sub BED_keysort_inplace (&@) {
my $keygen = shift;
@_ or die "too few keys";
my $ptypes = Sort::Key::Types::combine_types(@_);
my $sub = Sort::Key::Types::combine_sub($keygen, undef, @_);
return Sort::Key::_multikeysorter_inplace($ptypes, $sub, undef);
}
but even with that it does not work. Need to figure out what the importer does.