Change LIKELY() and UNLIKELY() to cast their first argument to a bool.
authorNicholas Clark <nick@ccl4.org>
Wed, 6 Mar 2013 15:27:08 +0000 (16:27 +0100)
committerNicholas Clark <nick@ccl4.org>
Mon, 20 May 2013 17:13:50 +0000 (19:13 +0200)
This avoids problems such as pointers being compared with the literal value 1.
Suggested by Zefram.

Note that this is technically a change of behaviour, as the macro EXPECT(),
which they are both both wrappers for, returns its value, so they will now
be returning TRUE or FALSE, rather than the actual value passed to them.
However, all uses in the core and on CPAN are only within if() statements, so
this should not make any difference in practice.

perl.h

diff --git a/perl.h b/perl.h
index 89f4c98..dc5e411 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -3329,8 +3329,8 @@ typedef pthread_key_t     perl_key;
 #else
 #  define EXPECT(expr,val)                  (expr)
 #endif
-#define LIKELY(cond)                        EXPECT(cond,1)
-#define UNLIKELY(cond)                      EXPECT(cond,0)
+#define LIKELY(cond)                        EXPECT(cBOOL(cond),TRUE)
+#define UNLIKELY(cond)                      EXPECT(cBOOL(cond),FALSE)
 #ifdef HAS_BUILTIN_CHOOSE_EXPR
 /* placeholder */
 #endif