From a44f4b74513a213052e4f78beb022f158efcf1a1 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Thu, 4 Nov 2010 15:02:17 -0600 Subject: [PATCH] utf8_heavy.pl: Make callable during Perl's compilation It's possible for this to be called during the compilation phase of Perl by miniperl before the Unicode tables have been built. This patch checks if dynamic loading is available, and if not evals the require needed to gain access to the tables. If it succeeds, the tables have been built; if it doesn't, instead of dying, just return empty tables, as currently the things being built don't require information outside the ASCII range, which is hard-coded into Perl without needing the tables. In the future, that may not be the case, and then likely the tables will have to be shipped with Perl, and make regen would be done to rebuild them. --- lib/utf8_heavy.pl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/utf8_heavy.pl b/lib/utf8_heavy.pl index 250eb69..56cfe05 100644 --- a/lib/utf8_heavy.pl +++ b/lib/utf8_heavy.pl @@ -25,7 +25,7 @@ sub croak { require Carp; Carp::croak(@_) } my ($class, $type, $list, $minbits, $none) = @_; local $^D = 0 if $^D; - print STDERR __LINE__, ": ", join(", ", @_), "\n" if DEBUG; + print STDERR __LINE__, ": class=$class, type=$type, list=$list, minbits=$minbits, none=$none\n" if DEBUG; ## ## Get the list of codepoints for the type. @@ -78,7 +78,8 @@ sub croak { require Carp; Carp::croak(@_) } GETFILE: { ## - ## It could be a user-defined property. + ## It could be a user-defined property. Look in current + ## package if no package given ## my $caller1 = $type =~ s/(.+)::// ? $1 : caller(1); @@ -93,7 +94,19 @@ sub croak { require Carp; Carp::croak(@_) } } } - require "$unicore_dir/Heavy.pl"; + # During Perl's compilation, this routine may be called before + # the tables are constructed. If so, we have a chicken/egg + # problem. If we die, the tables never get constructed, so + # keep going, but return an empty table so only what the code + # has compiled in internally (currently ASCII/Latin1 range + # matching) will work. + if (! defined &DynaLoader::boot_DynaLoader) { + eval "require '$unicore_dir/Heavy.pl'"; + last GETFILE if $@; + } + else { + require "$unicore_dir/Heavy.pl"; + } # Everything is caseless matching my $property_and_table = lc $type; -- 2.7.4