Parse the feature hint bits & assert their usability
authorFather Chrysostomos <sprout@cpan.org>
Thu, 22 Dec 2011 16:34:31 +0000 (08:34 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 24 Dec 2011 17:25:12 +0000 (09:25 -0800)
regen/feature.pl

index 3e20574..b57a30e 100644 (file)
@@ -116,6 +116,26 @@ while (<DATA>) {
 
 read_only_bottom_close_and_rename($pm);
 
+open "perl.h", "perl.h" or die "$0 cannot open perl.h: $!";
+perlh: {
+    while (readline "perl.h") {
+       next unless /#define\s+HINT_FEATURE_MASK/;
+       /(0x[A-Fa-f0-9]+)/ or die "No hex number in:\n\n$_\n ";
+       my $hex = $1;
+       my $bits = sprintf "%b", oct $1;
+       $bits =~ /^0*1+0*\z/
+        or die "Non-contiguous bits in $bits (binary for $hex):\n\n$_\n ";
+       my $bits_needed =
+           length sprintf "%b", scalar keys(%feature_bundle) - @same;
+       $bits =~ /1{$bits_needed}/
+           or die "Not enough bits (need $bits_needed)"
+                . " in $bits (binary for $hex):\n\n$_\n";
+       last perlh;
+    }
+    die "No HINT_FEATURE_MASK defined in perl.h";
+}
+close "perl.h";
+
 __END__
 package feature;