summaryrefslogtreecommitdiff
path: root/handy.h
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2010-09-19 12:29:02 -0600
committerFather Chrysostomos <sprout@cpan.org>2010-09-22 16:02:42 -0700
commitd0dcc4028a160eba03640da1ff1d34087f930ec1 (patch)
treed61642cec6830e2dd4bf23484085225d8bf4da92 /handy.h
parent89e8dfa95ef07c947545bb90a358cf884038b1eb (diff)
downloadperl-d0dcc4028a160eba03640da1ff1d34087f930ec1.tar.gz
handy.h: isASCII() extend to work on > 8 bit values
Prior to this patch, if isASCII() is called with something like '256', it would return true. For some reason unknown to me, U64 is defined only inside the perl core. However, the equivalent U64TYPE is known everywhere, so in the macro that can be called outside of core, use that instead. The commit log doesn't give a reason for not defining U64 outside of core, and no tests in the suite fail when it is defined outside core. But out of caution, I'm just doing this workaround instead of exposing U64.
Diffstat (limited to 'handy.h')
-rw-r--r--handy.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/handy.h b/handy.h
index f6460298c2..b41c1c8b0c 100644
--- a/handy.h
+++ b/handy.h
@@ -502,9 +502,10 @@ patched there. The file as of this writing is cpan/Devel-PPPort/parts/inc/misc
* machine has an 8-bit byte, so if c is stored in a byte, the sizeof()
* guarantees that this evaluates to a constant true at compile time. The use
* of the mask instead of '< 256' keeps gcc from complaining that it is alway
- * true, when c's storage class is a byte */
+ * true, when c's storage class is a byte. Use U64TYPE because U64 is known
+ * only in the perl core, and this macro can be called from outside that */
#ifdef HAS_QUAD
-# define FITS_IN_8_BITS(c) ((sizeof(c) == 1) || (((U64)(c) & 0xFF) == (U64)(c)))
+# define FITS_IN_8_BITS(c) ((sizeof(c) == 1) || (((U64TYPE)(c) & 0xFF) == (U64TYPE)(c)))
#else
# define FITS_IN_8_BITS(c) ((sizeof(c) == 1) || (((U32)(c) & 0xFF) == (U32)(c)))
#endif
@@ -530,7 +531,7 @@ patched there. The file as of this writing is cpan/Devel-PPPort/parts/inc/misc
#define isBLANK(c) ((c) == ' ' || (c) == '\t')
#define isDIGIT(c) ((c) >= '0' && (c) <= '9')
#define isOCTAL(c) ((c) >= '0' && (c) <= '7')
-#define isASCII(c) (NATIVE_TO_UNI((U8) c) <= 127)
+#define isASCII(c) (FITS_IN_8_BITS(c) ? NATIVE_TO_UNI((U8) c) <= 127 : 0)
#ifdef EBCDIC
/* In EBCDIC we do not do locales: therefore() isupper() is fine. */
# define isUPPER(c) isupper(c)