This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regen/mk_invlists.pl: Better handle preprocessor directives
authorKarl Williamson <khw@cpan.org>
Thu, 19 Apr 2018 16:29:28 +0000 (10:29 -0600)
committerKarl Williamson <khw@cpan.org>
Fri, 20 Apr 2018 07:11:51 +0000 (01:11 -0600)
Prior to this patch it was possible for the code to get confused about
what to do when an #ifdef had multiple conditions

charclass_invlists.h
regen/mk_invlists.pl

index ef2b916..0197052 100644 (file)
@@ -170534,5 +170534,5 @@ static const U8 WB_table[24][24] = {
  * ba5b13123afb59ea004c14fcbac80b5ff428c5b8f1b84bf8602b4ffb7da0407f lib/unicore/mktables
  * 21653d2744fdd071f9ef138c805393901bb9547cf3e777ebf50215a191f986ea lib/unicore/version
  * 913d2f93f3cb6cdf1664db888bf840bc4eb074eef824e082fceda24a9445e60c regen/charset_translations.pl
- * ffdcde26e9060a767a5decebd137a1aa255ed105e90c10fb0b9eff32d29b9542 regen/mk_invlists.pl
+ * f171fb8760e1dc7afd4cce3af4e54bfa5fcb98ac41e4c9eefe2ccf139d2fda1b regen/mk_invlists.pl
  * ex: set ro: */
index a84bdb2..31716c4 100644 (file)
@@ -39,7 +39,7 @@ my $out_fh = open_new('charclass_invlists.h', '>',
                      {style => '*', by => 'regen/mk_invlists.pl',
                       from => "Unicode::UCD"});
 
-my $in_file_pound_if = 0;
+my $in_file_pound_if = "";
 
 my $max_hdr_len = 3;    # In headings, how wide a name is allowed?
 
@@ -91,7 +91,7 @@ sub a2n($) {
 sub end_file_pound_if {
     if ($in_file_pound_if) {
         print $out_fh "\n#endif\t/* $in_file_pound_if */\n";
-        $in_file_pound_if = 0;
+        $in_file_pound_if = "";
     }
 }
 
@@ -99,31 +99,31 @@ sub switch_pound_if ($$) {
     my $name = shift;
     my $new_pound_if = shift;
     my @new_pound_if = ref ($new_pound_if)
-                       ? @$new_pound_if
+                       ? sort @$new_pound_if
                        : $new_pound_if;
 
     # Switch to new #if given by the 2nd argument.  If there is an override
     # for this, it instead switches to that.  The 1st argument is the
-    # static's name, used to look up the overrides
+    # static's name, used only to check if there is an override for this
 
     if (exists $exceptions_to_where_to_define{$name}) {
         @new_pound_if = $exceptions_to_where_to_define{$name};
     }
-    $new_pound_if = join "", @new_pound_if;
 
-    # Exit current #if if the new one is different from the old
-    if (   $in_file_pound_if
-        && $in_file_pound_if !~ /$new_pound_if/)
-    {
-        end_file_pound_if;
+    foreach my $element (@new_pound_if) {
+        $element = "defined($element)";
     }
+    $new_pound_if = join " || ", @new_pound_if;
 
-    # Enter new #if, if not already in it.
-    if (! $in_file_pound_if) {
-        foreach my $element (@new_pound_if) {
-            $element = "defined($element)";
+    # Change to the new one if different from old
+    if ($in_file_pound_if ne $new_pound_if) {
+
+        # Exit any current #if
+        if ($in_file_pound_if) {
+            end_file_pound_if;
         }
-        $in_file_pound_if = join " || ", @new_pound_if;
+
+        $in_file_pound_if = $new_pound_if;
         print $out_fh "\n#if $in_file_pound_if\n";
     }
 }