Subject: | Invalid compile-time use constant encoding for perlcc |
perlcc fails to run code which uses Net::DNS
because Net::DNS::Domain captures a ptr to an external XS encoding object
at compile-time.
use constant ASCII => eval {
require Encode;
Encode::find_encoding('ASCII'); # return encoding object
} || 0;
The PVMG contains in the IV the ptr to the external symbol
of &ascii_encoding. which is an external symbol from the shared library.
The only workaround in the compiler which needs to thaw the state of the compile-time
state is to do something like:
#include <dlfcn.h>
void *handle = dlopen(sv_list[5032].sv_u.svu_pv, RTLD_NOW|RTLD_NOLOAD); // <pathto/Encode.so>
void *ascii_encoding = dlsym(handle, "ascii_encoding");
SvIV_set(&sv_list[1], PTR2IV(ascii_encoding));
which is not managable generally.
Please store the encodings at run-time as in the attached patch.
Btw: using lower-case encoding names is recommended.
INIT {
sub ASCII {
eval {
require Encode;
Encode::find_encoding('ASCII'); # return encoding object
} || 0;
}
...
See https://code.google.com/p/perl-compiler/issues/detail?id=305
Subject: | Net-DNS-0.74-perlcc.patch |
diff -bu Net-DNS-0.74-RJ8GaG/lib/Net/DNS/Domain.pm~ Net-DNS-0.74-RJ8GaG/lib/Net/DNS/Domain.pm
--- Net-DNS-0.74-RJ8GaG/lib/Net/DNS/Domain.pm~ 2014-01-16 03:48:52.000000000 -0600
+++ Net-DNS-0.74-RJ8GaG/lib/Net/DNS/Domain.pm 2014-03-20 16:44:32.763915278 -0500
@@ -40,21 +40,28 @@
use integer;
use Carp;
-
-use constant ASCII => eval {
+INIT {
+ sub ASCII {
+ eval {
require Encode;
Encode::find_encoding('ASCII'); # return encoding object
-} || 0;
+ } || 0;
+ }
-use constant UTF8 => eval {
+ sub UTF8 {
+ eval {
die if Encode::decode_utf8( chr(91) ) ne '['; # not UTF-EBCDIC [see UTR#16 3.6]
Encode::find_encoding('UTF8'); # return encoding object
-} || 0;
+ } || 0;
+ }
-use constant LIBIDN => eval {
+ sub LIBIDN {
+ eval {
require Net::LibIDN; # tested and working
UTF8 && Net::LibIDN::idn_to_ascii( pack( 'U*', 20013, 22269 ), 'utf-8' ) eq 'xn--fiqs8s';
-} || 0;
+ } || 0;
+ }
+}
=head1 METHODS