Closed atoomic closed 7 years ago
This is working when the two packages are in a single file
package myConstants;
use constant SOMETHING => 42;
my %h = (
&SOMETHING => 'used-as-hash-key',
);
package main;
BEGIN { unshift @INC, '.' }
sub ok {
print qq[ok\n] if &myConstants::SOMETHING;
}
ok();
1;
> perl test.pl ; rm -f test test.c; perlcc -r -g -S -v4 test.pl ; echo =====; ./test
ok
/usr/local/cpanel/3rdparty/perl/524/bin/perlcc: Using gcc '-g' compilation option.
/usr/local/cpanel/3rdparty/perl/524/bin/perlcc: Writing C on test.c
/usr/local/cpanel/3rdparty/perl/524/bin/perlcc: Calling /usr/local/cpanel/3rdparty/perl/524/bin/perl -MO=C,-otest.c test.pl
/usr/local/cpanel/3rdparty/perl/524/bin/perlcc: Calling /usr/bin/gcc -g -DPERL_DISABLE_PMC -fPIC -DPIC -I/usr/local/cpanel/3rdparty/perl/524/include -L/usr/local/cpanel/3rdparty/perl/524/lib64 -I/usr/local/cpanel/3rdparty/include -L/usr/local/cpanel/3rdparty/lib64 -m64 -fwrapv -fno-strict-aliasing -fstack-protector-strong -I/usr/local/cpanel/3rdparty/include -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/cpanel/3rdparty/perl/524/lib64/perl5/5.24.1/x86_64-linux-64int/CORE -o ./test test.c -Wl,-E -Wl,-rpath,/usr/local/cpanel/3rdparty/perl/524/lib64/perl5/5.24.1/x86_64-linux-64int/CORE -Wl,-rpath -Wl,/usr/local/cpanel/3rdparty/perl/524/lib64 -L/usr/local/cpanel/3rdparty/perl/524/lib64 -L/usr/local/cpanel/3rdparty/lib64 -L/usr/local/cpanel/3rdparty/perl/524/lib64 -L/usr/local/cpanel/3rdparty/lib64 -L/usr/lib64 -L/lib64 -lgdbm -fstack-protector-strong -L/usr/local/lib -L/usr/local/cpanel/3rdparty/perl/524/lib64/perl5/5.24.1/x86_64-linux-64int/CORE /usr/local/cpanel/3rdparty/perl/524/lib64/perl5/5.24.1/x86_64-linux-64int/CORE/libperl.so -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
/usr/local/cpanel/3rdparty/perl/524/bin/perlcc: Running code ./test
ok
=====
ok
But when split in two files: myConstants.pm
package myConstants;
use constant SOMETHING => 42;
my %h = (
&SOMETHING => 'used-as-hash-key',
);
1;
test.pl
package main;
BEGIN { unshift @INC, '.' }
use myConstants;
sub ok {
print qq[ok\n] if &myConstants::SOMETHING;
}
ok();
1;
then this is failing...
> perl test.pl ; rm -f test test.c; perlcc -r -g -S -v4 test.pl ; echo =====; ./test
ok
/usr/local/cpanel/3rdparty/perl/524/bin/perlcc: Using gcc '-g' compilation option.
/usr/local/cpanel/3rdparty/perl/524/bin/perlcc: Writing C on test.c
/usr/local/cpanel/3rdparty/perl/524/bin/perlcc: Calling /usr/local/cpanel/3rdparty/perl/524/bin/perl -MO=C,-otest.c test.pl
/usr/local/cpanel/3rdparty/perl/524/bin/perlcc: Calling /usr/bin/gcc -g -DPERL_DISABLE_PMC -fPIC -DPIC -I/usr/local/cpanel/3rdparty/perl/524/include -L/usr/local/cpanel/3rdparty/perl/524/lib64 -I/usr/local/cpanel/3rdparty/include -L/usr/local/cpanel/3rdparty/lib64 -m64 -fwrapv -fno-strict-aliasing -fstack-protector-strong -I/usr/local/cpanel/3rdparty/include -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/cpanel/3rdparty/perl/524/lib64/perl5/5.24.1/x86_64-linux-64int/CORE -o ./test test.c -Wl,-E -Wl,-rpath,/usr/local/cpanel/3rdparty/perl/524/lib64/perl5/5.24.1/x86_64-linux-64int/CORE -Wl,-rpath -Wl,/usr/local/cpanel/3rdparty/perl/524/lib64 -L/usr/local/cpanel/3rdparty/perl/524/lib64 -L/usr/local/cpanel/3rdparty/lib64 -L/usr/local/cpanel/3rdparty/perl/524/lib64 -L/usr/local/cpanel/3rdparty/lib64 -L/usr/lib64 -L/lib64 -lgdbm -fstack-protector-strong -L/usr/local/lib -L/usr/local/cpanel/3rdparty/perl/524/lib64/perl5/5.24.1/x86_64-linux-64int/CORE /usr/local/cpanel/3rdparty/perl/524/lib64/perl5/5.24.1/x86_64-linux-64int/CORE/libperl.so -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
/usr/local/cpanel/3rdparty/perl/524/bin/perlcc: Running code ./test
Undefined subroutine &myConstants::SOMETHING called at test.pl line 19.
=====
Undefined subroutine &myConstants::SOMETHING called at test.pl line 19.
when using the constant as a hash key it's upgraded from IV to PVIV... and PVIV was not in the valid constant types :-) so the fix is easy there
fixed by commit 00be6ec