summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--handy.h7
-rw-r--r--perl.c4
-rw-r--r--perl.h7
-rw-r--r--pod/perlhacktips.pod12
4 files changed, 25 insertions, 5 deletions
diff --git a/handy.h b/handy.h
index 131ede2e42..d345abe91f 100644
--- a/handy.h
+++ b/handy.h
@@ -69,7 +69,7 @@ Null SV pointer. (No longer available when C<PERL_CORE> is defined.)
#define MUTABLE_IO(p) ((IO *)MUTABLE_PTR(p))
#define MUTABLE_SV(p) ((SV *)MUTABLE_PTR(p))
-#ifdef I_STDBOOL
+#if defined(I_STDBOOL) && !defined(PERL_BOOL_AS_CHAR)
# include <stdbool.h>
# ifndef HAS_BOOL
# define HAS_BOOL 1
@@ -85,9 +85,11 @@ Null SV pointer. (No longer available when C<PERL_CORE> is defined.)
Andy Dougherty February 2000
*/
#ifdef __GNUG__ /* GNU g++ has bool built-in */
+# ifndef PERL_BOOL_AS_CHAR
# ifndef HAS_BOOL
# define HAS_BOOL 1
# endif
+# endif
#endif
/* The NeXT dynamic loader headers will not build with the bool macro
@@ -104,6 +106,9 @@ Null SV pointer. (No longer available when C<PERL_CORE> is defined.)
#endif /* NeXT || __NeXT__ */
#ifndef HAS_BOOL
+# ifdef bool
+# undef bool
+# endif
# define bool char
# define HAS_BOOL 1
#endif
diff --git a/perl.c b/perl.c
index 4c80edbb1c..15adb8abdf 100644
--- a/perl.c
+++ b/perl.c
@@ -42,10 +42,6 @@
# include <sys/sysctl.h>
#endif
-#ifdef USE_NSGETEXECUTABLEPATH
-# include <mach-o/dyld.h>
-#endif
-
#ifdef DEBUG_LEAKING_SCALARS_FORK_DUMP
# ifdef I_SYSUIO
# include <sys/uio.h>
diff --git a/perl.h b/perl.h
index dc140bdfcf..0a8beda7d0 100644
--- a/perl.h
+++ b/perl.h
@@ -2298,6 +2298,13 @@ typedef SV PADNAME;
# define PERL_SAWAMPERSAND
#endif
+/* Include mach-o/dyld.h here for perl.c’s sake, since it may #define bool,
+ and handy.h needs to be able to re#define it under
+ -Accflags=-DPERL_BOOL_AS_CHAR. */
+#if defined(USE_NSGETEXECUTABLEPATH) && defined(PERL_IN_PERL_C)
+# include <mach-o/dyld.h>
+#endif
+
#include "handy.h"
#if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_RAWIO)
diff --git a/pod/perlhacktips.pod b/pod/perlhacktips.pod
index 7851db939a..32739ff690 100644
--- a/pod/perlhacktips.pod
+++ b/pod/perlhacktips.pod
@@ -1329,6 +1329,18 @@ op slabs belonging to C<BEGIN> blocks.
However, as an 80% solution it is still effective, as it has caught
bugs in the past.
+=head2 When is a bool not a bool?
+
+On pre-C99 compilers, C<bool> is defined as equivalent to C<char>.
+Consequently assignment of any larger type to a C<bool> is unsafe and may
+be truncated. The C<cBOOL> macro exists to cast it correctly.
+
+On those platforms and compilers where C<bool> really is a boolean (C++,
+C99), it is easy to forget the cast. You can force C<bool> to be a C<char>
+by compiling with C<-Accflags=-DPERL_BOOL_AS_CHAR>. You may also wish to
+add C<-Accflags=-Werror=conversion> or your compiler's equivalent to make
+it impossible to ignore the unsafe truncations.
+
=head2 The .i Targets
You can expand the macros in a F<foo.c> file by saying