summaryrefslogtreecommitdiff
path: root/cpan
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2010-09-21 14:55:52 +0100
committerNicholas Clark <nick@ccl4.org>2010-09-21 14:55:52 +0100
commitad39d6d2ab3fa902fe6e879c0ec6efa61f93ae55 (patch)
treee01192b8a04c39d2d59c8c6594ef01b5b7590666 /cpan
parent575f055216d48b9f31b3f00143a8d474fcf7ad80 (diff)
downloadperl-ad39d6d2ab3fa902fe6e879c0ec6efa61f93ae55.tar.gz
Add macro_to_ifndef to ExtUtils::Constant::Base, and use it in place of #else
Previously the code was using the #ifdef generated by macro_to_ifdef(), and immediately following that with an #else. That was ugly. And longer.
Diffstat (limited to 'cpan')
-rw-r--r--cpan/ExtUtils-Constant/lib/ExtUtils/Constant/Base.pm14
-rw-r--r--cpan/ExtUtils-Constant/lib/ExtUtils/Constant/ProxySubs.pm7
2 files changed, 17 insertions, 4 deletions
diff --git a/cpan/ExtUtils-Constant/lib/ExtUtils/Constant/Base.pm b/cpan/ExtUtils-Constant/lib/ExtUtils/Constant/Base.pm
index b5b79af1ea..ecf1bb307a 100644
--- a/cpan/ExtUtils-Constant/lib/ExtUtils/Constant/Base.pm
+++ b/cpan/ExtUtils-Constant/lib/ExtUtils/Constant/Base.pm
@@ -5,7 +5,7 @@ use vars qw($VERSION);
use Carp;
use Text::Wrap;
use ExtUtils::Constant::Utils qw(C_stringify perl_stringify);
-$VERSION = '0.04';
+$VERSION = '0.05';
use constant is_perl56 => ($] < 5.007 && $] > 5.005_50);
@@ -83,6 +83,18 @@ sub macro_to_ifdef {
return "";
}
+sub macro_to_ifndef {
+ my ($self, $macro) = @_;
+ if (ref $macro) {
+ # Can't invert these stylishly, so "bodge it"
+ return "$macro->[0]#else";
+ }
+ if (defined $macro && $macro ne "" && $macro ne "1") {
+ return $macro ? "#ifndef $macro\n" : "#if 1\n";
+ }
+ croak "Can't generate an ifndef for unconditional code";
+}
+
sub macro_to_endif {
my ($self, $macro) = @_;
diff --git a/cpan/ExtUtils-Constant/lib/ExtUtils/Constant/ProxySubs.pm b/cpan/ExtUtils-Constant/lib/ExtUtils/Constant/ProxySubs.pm
index 7b5af870f5..e0d5c7b1f2 100644
--- a/cpan/ExtUtils-Constant/lib/ExtUtils/Constant/ProxySubs.pm
+++ b/cpan/ExtUtils-Constant/lib/ExtUtils/Constant/ProxySubs.pm
@@ -356,11 +356,12 @@ EOBOOT
carp("Attempting to supply a default for '$name' which has no conditional macro");
next;
}
- print $xs_fh $ifdef;
if ($item->{invert_macro}) {
+ print $xs_fh $self->macro_to_ifndef($macro);
print $xs_fh
- " /* This is the default value: */\n" if $type;
- print $xs_fh "#else\n";
+ " /* This is the default value: */\n" if $type;
+ } else {
+ print $xs_fh $ifdef;
}
print $xs_fh " { ", join (', ', "\"$name\"", $namelen,
&$type_to_value($value)), " },\n",