X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/c796e3db23c597b99f07485542338844e61a6a69..ac56e7de46621c6f2e373d11984c0a0fe4839b0b:/handy.h?ds=sidebyside diff --git a/handy.h b/handy.h index 81bf1e2..bbeb1ff 100644 --- a/handy.h +++ b/handy.h @@ -110,6 +110,12 @@ Null SV pointer. (No longer available when C is defined.) # define HAS_BOOL 1 #endif +/* a simple (bool) cast may not do the right thing: if bool is defined + * as char for example, then the cast from int is implementation-defined + */ + +#define cBOOL(cbool) ((bool)!!(cbool)) + /* Try to figure out __func__ or __FUNCTION__ equivalent, if any. * XXX Should really be a Configure probe, with HAS__FUNCTION__ * and FUNCTION__ as results. @@ -208,8 +214,7 @@ typedef U64TYPE U64; * GMTIME_MAX GMTIME_MIN LOCALTIME_MAX LOCALTIME_MIN * HAS_CTIME64 HAS_LOCALTIME64 HAS_GMTIME64 HAS_DIFFTIME64 * HAS_MKTIME64 HAS_ASCTIME64 HAS_GETADDRINFO HAS_GETNAMEINFO - * HAS_INETNTOP HAS_INETPTON CHARBITS HAS_PRCTL_SET_NAME - * HAS_PRCTL + * HAS_INETNTOP HAS_INETPTON CHARBITS HAS_PRCTL * Not (yet) used at top level, but mention them for metaconfig */ @@ -309,6 +314,13 @@ Like C, but takes a literal string instead of a string/length pair. Like C, 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, but takes a literal string instead of a +string/length pair. + =cut */ @@ -339,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)) @@ -399,7 +413,7 @@ C). #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) /* @@ -458,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) == '_') @@ -499,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)) @@ -654,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; @@ -913,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