In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/4125141464884619e852c7b0986a51eba8fe1636?hp=526fd1b4d7270fff44588238f2411032c109da6e>

- Log -----------------------------------------------------------------
commit 4125141464884619e852c7b0986a51eba8fe1636
Author: Karl Williamson <pub...@khwilliamson.com>
Date:   Tue Aug 31 20:20:01 2010 -0600

    handy.h: Add bounds checking to case change arrays
    
    This makes sure that the index into the arrays used to change between
    lower and upper case will fit into their bounds; returning an error
    character if not.  The check is likely to be optimized out if the index
    is stored in 8 bits.

M       handy.h

commit cf301eb7d17e4d58d25337e997b1c7b0133e3c91
Author: Karl Williamson <pub...@khwilliamson.com>
Date:   Tue Aug 31 19:34:50 2010 -0600

    handy.h: Add FITS_IN_8_BITS() macro
    
    This macro is designed to be optimized out if the argument is
    byte-length, but otherwise to be a bomb-proof way of making sure that
    the argument occupies only 8 bits or fewer in whatever storage class it
    is in.

M       handy.h
-----------------------------------------------------------------------

Summary of changes:
 handy.h |   34 +++++++++++++++++++++++++++-------
 1 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/handy.h b/handy.h
index bbeb1ff..a1d753d 100644
--- a/handy.h
+++ b/handy.h
@@ -482,6 +482,20 @@ patched there.  The file as of this writing is 
cpan/Devel-PPPort/parts/inc/misc
 
 */
 
+/* FITS_IN_8_BITS(c) returns true if c occupies no more than 8 bits.  It is
+ * designed to be hopefully bomb-proof, making sure that no bits of
+ * information are lost even on a 64-bit machine, but to get the compiler to
+ * optimize it out if possible.  This is because Configure makes sure that the
+ * 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 */
+#ifdef HAS_QUAD
+#  define FITS_IN_8_BITS(c) ((sizeof(c) == 1) || (((U64)(c) & 0xFF) == 
(U64)(c)))
+#else
+#  define FITS_IN_8_BITS(c) ((sizeof(c) == 1) || (((U32)(c) & 0xFF) == 
(U32)(c)))
+#endif
+
 #define isALNUM(c)     (isALPHA(c) || isDIGIT(c) || (c) == '_')
 #define isIDFIRST(c)   (isALPHA(c) || (c) == '_')
 #define isALPHA(c)     (isUPPER(c) || isLOWER(c))
@@ -514,9 +528,7 @@ patched there.  The file as of this writing is 
cpan/Devel-PPPort/parts/inc/misc
 #   define isPUNCT(c)  ispunct(c)
 #   define isXDIGIT(c) isxdigit(c)
 #   define toUPPER(c)  toupper(c)
-#   define toUPPER_LATIN1_MOD(c)    UNI_TO_NATIVE(PL_mod_latin1_uc[(U8) 
NATIVE_TO_UNI(c)])
 #   define toLOWER(c)  tolower(c)
-#   define toLOWER_LATIN1(c)   UNI_TO_NATIVE(PL_latin1_lc[(U8) 
NATIVE_TO_UNI(c)])
 #else
 #   define isUPPER(c)  ((c) >= 'A' && (c) <= 'Z')
 #   define isLOWER(c)  ((c) >= 'a' && (c) <= 'z')
@@ -528,12 +540,20 @@ patched there.  The file as of this writing is 
cpan/Devel-PPPort/parts/inc/misc
 #   define isPUNCT(c)  (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64)  
|| ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126))
 #   define isXDIGIT(c)  (isDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 
'A' && (c) <= 'F'))
 
-/* Use table lookup for speed */
-#   define toLOWER_LATIN1(c)   (PL_latin1_lc[(U8) c])
 
-/* Modified uc.  Is correct uc except for three non-ascii chars which are
- * all mapped to one of them, and these need special handling */
-#   define toUPPER_LATIN1_MOD(c)    (PL_mod_latin1_uc[(U8) c])
+    /* Use table lookup for speed; return error character for input
+     * out-of-range */
+#   define toLOWER_LATIN1(c)    (FITS_IN_8_BITS(c)                            \
+                                ? UNI_TO_NATIVE(PL_latin1_lc[                 \
+                                                  NATIVE_TO_UNI( (U8) (c)) ]) \
+                                : UNICODE_REPLACEMENT)
+    /* Modified uc.  Is correct uc except for three non-ascii chars which are
+     * all mapped to one of them, and these need special handling; error
+     * character for input out-of-range */
+#   define toUPPER_LATIN1_MOD(c) (FITS_IN_8_BITS(c)                           \
+                                 ? UNI_TO_NATIVE(PL_mod_latin1_uc[            \
+                                                  NATIVE_TO_UNI( (U8) (c)) ]) \
+                                 : UNICODE_REPLACEMENT)
 
 /* ASCII casing. */
 #   define toUPPER(c)  (isLOWER(c) ? (c) - ('a' - 'A') : (c))

--
Perl5 Master Repository

Reply via email to