X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=handy.h;h=3d2d46a394552a74412d140e75e7d3375c4eea2c;hb=b9272e1a27e24180316da1215eea7f3ddf2cdff8;hp=d12972d529702e5183b64413bf601b722b66819f;hpb=cb233ae346c666d88ee890fc837f4cd3195c1f0b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/handy.h b/handy.h index d12972d..3d2d46a 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,7 +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_INETNTOP HAS_INETPTON CHARBITS HAS_PRCTL * Not (yet) used at top level, but mention them for metaconfig */ @@ -398,7 +404,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) /* @@ -457,6 +463,11 @@ 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. + */ #define isALNUM(c) (isALPHA(c) || isDIGIT(c) || (c) == '_') @@ -498,8 +509,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)) @@ -653,16 +664,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; @@ -912,6 +916,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