This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.h, et.al.: Clean up some casts
authorKarl Williamson <khw@cpan.org>
Fri, 6 Nov 2015 16:11:55 +0000 (09:11 -0700)
committerKarl Williamson <khw@cpan.org>
Sun, 6 Dec 2015 05:06:49 +0000 (22:06 -0700)
By making sure the no-op macros cast the output appropriately, we can
eliminate the casts that have been added in things that call them

regexec.c
toke.c
utf8.c
utf8.h
utfebcdic.h

index a21e71a..dbc0156 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -5810,8 +5810,8 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
             }
             else if (UTF8_IS_DOWNGRADEABLE_START(nextchr)) {
                 if (! (to_complement ^ cBOOL(isFOO_lc(FLAGS(scan),
-                                           (U8) EIGHT_BIT_UTF8_TO_NATIVE(nextchr,
-                                                            *(locinput + 1))))))
+                                               EIGHT_BIT_UTF8_TO_NATIVE(nextchr,
+                                               *(locinput + 1))))))
                 {
                     sayNO;
                 }
diff --git a/toke.c b/toke.c
index b9fe9ae..7f45f1b 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -3593,7 +3593,7 @@ S_scan_const(pTHX_ char *start)
                                                   /* The regex compiler is
                                                    * expecting Unicode, not
                                                    * native */
-                                                  (U8) NATIVE_TO_LATIN1(*str));
+                                                  NATIVE_TO_LATIN1(*str));
                                     PERL_MY_SNPRINTF_POST_GUARD(len,
                                                            sizeof(hex_string));
                                     Copy(hex_string, d, 3, char);
diff --git a/utf8.c b/utf8.c
index 91af0bd..5185dd4 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -109,7 +109,7 @@ Perl_uvoffuni_to_utf8_flags(pTHX_ U8 *d, UV uv, UV flags)
     PERL_ARGS_ASSERT_UVOFFUNI_TO_UTF8_FLAGS;
 
     if (OFFUNI_IS_INVARIANT(uv)) {
-       *d++ = (U8) LATIN1_TO_NATIVE(uv);
+       *d++ = LATIN1_TO_NATIVE(uv);
        return d;
     }
 
@@ -165,10 +165,10 @@ Perl_uvoffuni_to_utf8_flags(pTHX_ U8 *d, UV uv, UV flags)
        STRLEN len  = OFFUNISKIP(uv);
        U8 *p = d+len-1;
        while (p > d) {
-           *p-- = (U8) I8_TO_NATIVE_UTF8((uv & UTF_CONTINUATION_MASK) | UTF_CONTINUATION_MARK);
+           *p-- = I8_TO_NATIVE_UTF8((uv & UTF_CONTINUATION_MASK) | UTF_CONTINUATION_MARK);
            uv >>= UTF_ACCUMULATION_SHIFT;
        }
-       *p = (U8) I8_TO_NATIVE_UTF8((uv & UTF_START_MASK(len)) | UTF_START_MARK(len));
+       *p = I8_TO_NATIVE_UTF8((uv & UTF_START_MASK(len)) | UTF_START_MARK(len));
        return d+len;
     }
 #else /* Non loop style */
diff --git a/utf8.h b/utf8.h
index 277ed52..464cf09 100644 (file)
--- a/utf8.h
+++ b/utf8.h
@@ -136,8 +136,8 @@ END_EXTERN_C
 
 /* Native character to/from iso-8859-1.  Are the identity functions on ASCII
  * platforms */
-#define NATIVE_TO_LATIN1(ch)     (__ASSERT_(FITS_IN_8_BITS(ch)) (ch))
-#define LATIN1_TO_NATIVE(ch)     (__ASSERT_(FITS_IN_8_BITS(ch)) (ch))
+#define NATIVE_TO_LATIN1(ch)     (__ASSERT_(FITS_IN_8_BITS(ch)) ((U8) (ch)))
+#define LATIN1_TO_NATIVE(ch)     (__ASSERT_(FITS_IN_8_BITS(ch)) ((U8) (ch)))
 
 /* I8 is an intermediate version of UTF-8 used only in UTF-EBCDIC.  We thus
  * consider it to be identical to UTF-8 on ASCII platforms.  Strictly speaking
@@ -145,12 +145,12 @@ END_EXTERN_C
  * because they are 8-bit encodings that serve the same purpose in Perl, and
  * rarely do we need to distinguish them.  The term "NATIVE_UTF8" applies to
  * whichever one is applicable on the current platform */
-#define NATIVE_UTF8_TO_I8(ch) (__ASSERT_(FITS_IN_8_BITS(ch)) (ch))
-#define I8_TO_NATIVE_UTF8(ch) (__ASSERT_(FITS_IN_8_BITS(ch)) (ch))
+#define NATIVE_UTF8_TO_I8(ch) (__ASSERT_(FITS_IN_8_BITS(ch)) ((U8) (ch)))
+#define I8_TO_NATIVE_UTF8(ch) (__ASSERT_(FITS_IN_8_BITS(ch)) ((U8) (ch)))
 
 /* Transforms in wide UV chars */
-#define UNI_TO_NATIVE(ch)        (ch)
-#define NATIVE_TO_UNI(ch)        (ch)
+#define UNI_TO_NATIVE(ch)        ((UV) (ch))
+#define NATIVE_TO_UNI(ch)        ((UV) (ch))
 
 /*
 
@@ -446,9 +446,9 @@ only) byte is pointed to by C<s>.
 /* The next two macros are used when the source should be a single byte
  * character; checked for under DEBUGGING */
 #define UTF8_EIGHT_BIT_HI(c) (__ASSERT_(FITS_IN_8_BITS(c))                    \
-                             ((U8) __BASE_TWO_BYTE_HI(c, NATIVE_TO_LATIN1)))
+                             ( __BASE_TWO_BYTE_HI(c, NATIVE_TO_LATIN1)))
 #define UTF8_EIGHT_BIT_LO(c) (__ASSERT_(FITS_IN_8_BITS(c))                    \
-                             ((U8) __BASE_TWO_BYTE_LO(c, NATIVE_TO_LATIN1)))
+                             (__BASE_TWO_BYTE_LO(c, NATIVE_TO_LATIN1)))
 
 /* These final two macros in the series are used when the source can be any
  * code point whose UTF-8 is known to occupy 2 bytes; they are less efficient
@@ -459,11 +459,11 @@ only) byte is pointed to by C<s>.
 #define UTF8_TWO_BYTE_HI(c)                                                    \
        (__ASSERT_((sizeof(c) ==  1)                                            \
                   || !(((WIDEST_UTYPE)(c)) & ~MAX_UTF8_TWO_BYTE))              \
-        ((U8) __BASE_TWO_BYTE_HI(c, NATIVE_TO_UNI)))
+        (__BASE_TWO_BYTE_HI(c, NATIVE_TO_UNI)))
 #define UTF8_TWO_BYTE_LO(c)                                                    \
        (__ASSERT_((sizeof(c) ==  1)                                            \
                   || !(((WIDEST_UTYPE)(c)) & ~MAX_UTF8_TWO_BYTE))              \
-        ((U8) __BASE_TWO_BYTE_LO(c, NATIVE_TO_UNI)))
+        (__BASE_TWO_BYTE_LO(c, NATIVE_TO_UNI)))
 
 /* This is illegal in any well-formed UTF-8 in both EBCDIC and ASCII
  * as it is only in overlongs. */
index 09defa9..9ab6de4 100644 (file)
@@ -146,8 +146,8 @@ END_EXTERN_C
 #define I8_TO_NATIVE_UTF8(b)           (__ASSERT_(FITS_IN_8_BITS(b)) PL_utf2e[(U8)(b)])
 
 /* Transforms in wide UV chars */
-#define NATIVE_TO_UNI(ch)    (FITS_IN_8_BITS(ch) ? NATIVE_TO_LATIN1(ch) : (ch))
-#define UNI_TO_NATIVE(ch)    (FITS_IN_8_BITS(ch) ? LATIN1_TO_NATIVE(ch) : (ch))
+#define NATIVE_TO_UNI(ch)    (FITS_IN_8_BITS(ch) ? NATIVE_TO_LATIN1(ch) : (UV) (ch))
+#define UNI_TO_NATIVE(ch)    (FITS_IN_8_BITS(ch) ? LATIN1_TO_NATIVE(ch) : (UV) (ch))
 
 /* How wide can a single UTF-8 encoded character become in bytes. */
 /* NOTE: Strictly speaking Perl's UTF-8 should not be called UTF-8 since UTF-8