This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Peephole optimise adjacent pairs of nextstate ops.
[perl5.git] / handy.h
diff --git a/handy.h b/handy.h
index 1ff7fde..bbeb1ff 100644 (file)
--- a/handy.h
+++ b/handy.h
@@ -314,6 +314,13 @@ Like C<hv_fetch>, but takes a literal string instead of a string/length pair.
 Like C<hv_store>, but takes a literal string instead of a string/length pair
 and omits the hash parameter.
 
+=head1 Lexer interface
+
+=for apidoc Amx|void|lex_stuff_pvs|const char *pv|U32 flags
+
+Like L</lex_stuff_pvn>, but takes a literal string instead of a
+string/length pair.
+
 =cut
 */
 
@@ -344,6 +351,8 @@ and omits the hash parameter.
   ((SV **)Perl_hv_common(aTHX_ (hv), NULL, STR_WITH_LEN(key), 0,       \
                         (HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), (val), 0))
 
+#define lex_stuff_pvs(pv,flags) Perl_lex_stuff_pvn(aTHX_ STR_WITH_LEN(pv), flags)
+
 #define get_cvs(str, flags)                                    \
        Perl_get_cvn_flags(aTHX_ STR_WITH_LEN(str), (flags))
 
@@ -404,7 +413,7 @@ C<strncmp>).
 #endif
 
 #define memEQs(s1, l, s2) \
-       (sizeof(s2)-1 == l && memEQ(s1, (s2 ""), (sizeof(s2)-1)))
+       (sizeof(s2)-1 == l && memEQ(s1, ("" s2 ""), (sizeof(s2)-1)))
 #define memNEs(s1, l, s2) !memEQs(s1, l, s2)
 
 /*
@@ -463,6 +472,14 @@ Converts the specified character to lowercase.  Characters outside the
 US-ASCII (Basic Latin) range are viewed as not having any case.
 
 =cut
+
+NOTE:  Since some of these are macros, there is no check in those that the
+parameter is a char or U8.  This means that if called with a larger width
+parameter, casts can silently truncate and yield wrong results.
+
+Also note that these macros are repeated in Devel::PPPort, so should also be
+patched there.  The file as of this writing is cpan/Devel-PPPort/parts/inc/misc
+
 */
 
 #define isALNUM(c)     (isALPHA(c) || isDIGIT(c) || (c) == '_')
@@ -504,8 +521,8 @@ US-ASCII (Basic Latin) range are viewed as not having any case.
 #   define isUPPER(c)  ((c) >= 'A' && (c) <= 'Z')
 #   define isLOWER(c)  ((c) >= 'a' && (c) <= 'z')
 #   define isALNUMC(c) (isALPHA(c) || isDIGIT(c))
-#   define isASCII(c)  ((c) <= 127)
-#   define isCNTRL(c)  ((c) < ' ' || (c) == 127)
+#   define isASCII(c)  ((U8) (c) <= 127)
+#   define isCNTRL(c)  ((U8) (c) < ' ' || (c) == 127)
 #   define isGRAPH(c)  (isALNUM(c) || isPUNCT(c))
 #   define isPRINT(c)  (((c) >= 32 && (c) < 127))
 #   define isPUNCT(c)  (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64)  || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126))
@@ -659,16 +676,9 @@ US-ASCII (Basic Latin) range are viewed as not having any case.
 #define isPSXSPC_LC_utf8(c)    (isSPACE_LC_utf8(c) ||(c) == '\f')
 #define isBLANK_LC_utf8(c)     isBLANK(c) /* could be wrong */
 
-#ifdef EBCDIC
-#  ifdef PERL_IMPLICIT_CONTEXT
-#    define toCTRL(c)     Perl_ebcdic_control(aTHX_ c)
-#  else
-#    define toCTRL        Perl_ebcdic_control
-#  endif
-#else
-  /* This conversion works both ways, strangely enough. */
-#  define toCTRL(c)    (toUPPER(c) ^ 64)
-#endif
+/* This conversion works both ways, strangely enough. On EBCDIC platforms,
+ * CTRL-@ is 0, CTRL-A is 1, etc, just like on ASCII */
+#  define toCTRL(c)    (toUPPER(NATIVE_TO_UNI(c)) ^ 64)
 
 /* Line numbers are unsigned, 32 bits. */
 typedef U32 line_t;
@@ -918,6 +928,7 @@ void Perl_mem_log_del_sv(const SV *sv, const char *filename, const int linenumbe
 #endif
 
 #define C_ARRAY_LENGTH(a)      (sizeof(a)/sizeof((a)[0]))
+#define C_ARRAY_END(a)         (a) + (sizeof(a)/sizeof((a)[0]))
 
 #ifdef NEED_VA_COPY
 # ifdef va_copy