summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Crane <arc@cpan.org>2012-09-28 14:14:47 +0100
committerFather Chrysostomos <sprout@cpan.org>2012-09-28 09:27:55 -0700
commitdd5f7cf27c952e8698978713394fb4e4591f13f0 (patch)
tree9c4c23a213d163e697f63a243b49cc3d01da744a
parent4038981c97e0b0ad3fb5a4bc69c0c6ec5a11e021 (diff)
downloadperl-dd5f7cf27c952e8698978713394fb4e4591f13f0.tar.gz
[perl #20636] Make h2xs skip #define macros with empty rhs
Otherwise the generated C code uses such macros in expressions, which causes compilation errors because the macro is expanded to an empty token list.
-rw-r--r--lib/h2xs.t21
-rw-r--r--utils/h2xs.PL4
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/h2xs.t b/lib/h2xs.t
index 6ce37ee357..d10ce75c1c 100644
--- a/lib/h2xs.t
+++ b/lib/h2xs.t
@@ -159,8 +159,10 @@ for (my $i = $#tests; $i > 0; $i-=3) {
# 1 test for running it, 1 test for the expected result, and 1 for each file
# plus 1 to open and 1 to check for the use in lib/$name.pm and Makefile.PL
# And 1 more for our check for "bonus" files, 2 more for ExtUtil::Manifest.
+ # And 1 more to examine const-c.inc contents in tests that use $header.
# use the () to force list context and hence count the number of matches.
$total_tests += 9 + (() = $tests[$i] =~ /(Writing)/sg);
+ $total_tests++ if $tests[$i-2] =~ / \Q$header\E$/;
}
plan tests => $total_tests;
@@ -169,6 +171,8 @@ ok (open (HEADER, ">$header"), "open '$header'");
print HEADER <<HEADER or die $!;
#define Camel 2
#define Dromedary 1
+#define Bactrian /* empty */
+#define Bactrian2
HEADER
ok (close (HEADER), "close '$header'");
@@ -215,6 +219,23 @@ while (my ($args, $version, $expectation) = splice @tests, 0, 3) {
pop @INC;
chdir ($up) or die "chdir $up failed: $!";
+ if ($args =~ / \Q$header\E$/) {
+ my $const_c = File::Spec->catfile($name, 'fallback', 'const-c.inc');
+ my ($found, $diag);
+ if (!open FILE, '<', $const_c) {
+ $diag = "can't open $const_c: $!";
+ }
+ else {
+ while (<FILE>) {
+ next unless /\b Bactrian 2? \b/x;
+ $found = 1;
+ last;
+ }
+ }
+ ok (!$found, "generated $const_c has no Bactrian(2)");
+ diag ($diag) if defined $diag;
+ }
+
foreach my $leaf (File::Spec->catfile('lib', "$name.pm"), 'Makefile.PL') {
my $file = File::Spec->catfile($name, $leaf);
if (ok (open (FILE, $file), "open $file")) {
diff --git a/utils/h2xs.PL b/utils/h2xs.PL
index ee4079f8ea..6b2c78f092 100644
--- a/utils/h2xs.PL
+++ b/utils/h2xs.PL
@@ -862,6 +862,10 @@ if( @path_h ){
$rest =~ s!/\*.*?(\*/|\n)|//.*!!g; # Remove comments
$rest =~ s/^\s+//;
$rest =~ s/\s+$//;
+ if ($rest eq '') {
+ print("Skip empty $def\n") if $opt_d;
+ next defines;
+ }
# Cannot do: (-1) and ((LHANDLE)3) are OK:
#print("Skip non-wordy $def => $rest\n"),
# next defines if $rest =~ /[^\w\$]/;