This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Silence compile warnings before uni tables built
authorKarl Williamson <public@khwilliamson.com>
Sun, 6 Feb 2011 16:55:58 +0000 (09:55 -0700)
committerKarl Williamson <public@khwilliamson.com>
Sun, 6 Feb 2011 17:02:10 +0000 (10:02 -0700)
The recent move of Unicode folding to the compilation phase caused
spurious warnings during the miniperl build phase of Perl itself before
the Unicode tables get built.  Before the tables are built, Perl is
unable to know about the Unicode semantics (it has ASCII/Latin1
hard-coded in), but was still trying to access the tables.  Now, it
checks and if the tables aren't present uses just the hard-coded
ASCII/Latin1 semantics.

regcomp.c
utf8.c

index baa0813..1a03564 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -9692,14 +9692,24 @@ parseit:
             * that are involved in it */
            if (! PL_utf8_foldclosures) {
 
-               /* If the folds haven't been read in, call a fold
-                   * function to force that */
-               if (! PL_utf8_tofold) {
-                   U8 dummy[UTF8_MAXBYTES+1];
-                   STRLEN dummy_len;
-                   to_utf8_fold((U8*) "A", dummy, &dummy_len);
+               /* If we were unable to find any folds, then we likely won't be
+                * able to find the closures.  So just create an empty list.
+                * Folding will effectively be restricted to the non-Unicode
+                * rules hard-coded into Perl.  (This case happens legitimately
+                * during compilation of Perl itself before the Unicode tables
+                * are generated) */
+               if (invlist_len(PL_utf8_foldable) == 0) {
+                   PL_utf8_foldclosures = _new_invlist(0);
+               } else {
+                   /* If the folds haven't been read in, call a fold function
+                    * to force that */
+                   if (! PL_utf8_tofold) {
+                       U8 dummy[UTF8_MAXBYTES+1];
+                       STRLEN dummy_len;
+                       to_utf8_fold((U8*) "A", dummy, &dummy_len);
+                   }
+                   PL_utf8_foldclosures = _swash_inversion_hash(PL_utf8_tofold);
                }
-               PL_utf8_foldclosures = _swash_inversion_hash(PL_utf8_tofold);
            }
 
            /* Only the characters in this class that participate in folds need
diff --git a/utf8.c b/utf8.c
index 6053465..f6cdba2 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -2719,6 +2719,7 @@ Perl__swash_to_invlist(pTHX_ SV* const swash)
     STRLEN lcur;
     HV *const hv = MUTABLE_HV(SvRV(swash));
     UV elements = 0;    /* Number of elements in the inversion list */
+    U8 empty[] = "";
 
     /* The string containing the main body of the table */
     SV** const listsvp = hv_fetchs(hv, "LIST", FALSE);
@@ -2734,7 +2735,16 @@ Perl__swash_to_invlist(pTHX_ SV* const swash)
     PERL_ARGS_ASSERT__SWASH_TO_INVLIST;
 
     /* read $swash->{LIST} */
-    l = (U8*)SvPV(*listsvp, lcur);
+    if (SvPOK(*listsvp)) {
+       l = (U8*)SvPV(*listsvp, lcur);
+    }
+    else {
+       /* LIST legitimately doesn't contain a string during compilation phases
+        * of Perl itself, before the Unicode tables are generated.  In this
+        * case, just fake things up by creating an empty list */
+       l = empty;
+       lcur = 0;
+    }
     loc = (char *) l;
     lend = l + lcur;