From: Perl 5 Porters Date: Sun, 1 Sep 1996 22:35:00 +0000 (+0000) Subject: Patch for LONG_MAX & co. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=27d4fb967e484643f49397f430300f14a7bf480b;p=p5sagit%2Fp5-mst-13.2.git Patch for LONG_MAX & co. Sorry about adding yet another #ifdef forest, but hopefully this should resolve the *_MAX issues permanently. It adds to the previously defined PERL_LONG_MAX, PERL_LONG_MIN, and PERL_ULONG_MAX symbols the complete set of /PERL_U?(CHAR|SHORT|INT|LONG)_(MAX|MIN)/, and installs aliases to those from /(I|U)(8|16|32|V)_(MAX|MIN)/ so that for any standard Perl typedef, like I32 or UV, you can reference I32_MAX or UV_MIN, and get appropriate figures. All references to LONG_(MIN|MAX) are changed appropriately. The .c changes have the side effect of making cast_uv properly use quad limits if quads are in use, but longs aren't 64 bit. Hopefully this all works, but I don't have any handy Crays to try it out on. Add notes on perl's internal types, specifically Quad_t and IV. --- diff --git a/handy.h b/handy.h index ee31bf0..2d0e81f 100644 --- a/handy.h +++ b/handy.h @@ -32,6 +32,11 @@ #define TRUE (1) #define FALSE (0) + +/* XXX Configure ought to have a test for a boolean type, if I can + just figure out all the headers such a test needs. + Andy Dougherty August 1996 +*/ /* bool is built-in for g++-2.6.3, which might be used for an extension. If the extension includes <_G_config.h> before this file then _G_HAVE_BOOL will be properly set. If, however, the extension includes @@ -67,18 +72,45 @@ # endif #endif +/* XXX A note on the perl source internal type system. The + original intent was that I32 be *exactly* 32 bits. + + Currently, we only guarantee that I32 is *at least* 32 bits. + Specifically, if int is 64 bits, then so is I32. (This is the case + for the Cray.) This has the advantage of meshing nicely with + standard library calls (where we pass an I32 and the library is + expecting an int), but the disadvantage that an I32 is not 32 bits. + Andy Dougherty August 1996 +*/ + typedef char I8; typedef unsigned char U8; +#define I8_MAX PERL_CHAR_MAX +#define I8_MIN PERL_CHAR_MIN +#define U8_MAX PERL_UCHAR_MAX +#define U8_MIN PERL_UCHAR_MIN typedef short I16; typedef unsigned short U16; +#define I16_MAX PERL_SHORT_MAX +#define I16_MIN PERL_SHORT_MIN +#define U16_MAX PERL_USHORT_MAX +#define U16_MIN PERL_USHORT_MIN #if BYTEORDER > 0x4321 typedef int I32; typedef unsigned int U32; +# define I32_MAX PERL_INT_MAX +# define I32_MIN PERL_INT_MIN +# define U32_MAX PERL_UINT_MAX +# define U32_MIN PERL_UINT_MIN #else typedef long I32; typedef unsigned long U32; +# define I32_MAX PERL_LONG_MAX +# define I32_MIN PERL_LONG_MIN +# define U32_MAX PERL_ULONG_MAX +# define U32_MIN PERL_ULONG_MIN #endif #define Ctl(ch) (ch & 037) @@ -140,6 +172,15 @@ typedef U16 line_t; #define NOLINE ((line_t) 65535) #endif +/* XXX LEAKTEST doesn't really work in perl5. There are direct calls to + safemalloc() in the source, so LEAKTEST won't pick them up. + Further, if you try LEAKTEST, you'll also end up calling + Safefree, which might call safexfree() on some things that weren't + malloced with safexmalloc. The correct "fix" to this, if anyone + is interested, is to ensure that all calls go through the New and + Renew macros. + --Andy Dougherty August 1996 +*/ #ifndef lint #ifndef LEAKTEST #ifndef safemalloc diff --git a/perl.h b/perl.h index f69aac9..e908f22 100644 --- a/perl.h +++ b/perl.h @@ -529,6 +529,19 @@ #undef UV #endif +/* XXX QUAD stuff is not currently supported on most systems. + Specifically, perl internals don't support long long. Among + the many problems is that some compilers support long long, + but the underlying library functions (such as sprintf) don't. + Some things do work (such as quad pack/unpack on convex); + also some systems use long long for the fpos_t typedef. That + seems to work too. + + The IV type is supposed to be long enough to hold any integral + value or a pointer. + --Andy Dougherty August 1996 +*/ + #ifdef HAS_QUAD # ifdef cray # define Quad_t int @@ -541,9 +554,17 @@ # endif typedef Quad_t IV; typedef unsigned Quad_t UV; +# define IV_MAX PERL_QUAD_MAX +# define IV_MIN PERL_QUAD_MIN +# define UV_MAX PERL_UQUAD_MAX +# define UV_MIN PERL_UQUAD_MIN #else typedef long IV; typedef unsigned long UV; +# define IV_MAX PERL_LONG_MAX +# define IV_MIN PERL_LONG_MIN +# define UV_MAX PERL_ULONG_MAX +# define UV_MIN PERL_ULONG_MIN #endif /* Previously these definitions used hardcoded figures. @@ -565,8 +586,104 @@ #endif #endif +#ifdef CHAR_MAX +# define PERL_CHAR_MAX CHAR_MAX +#else +# ifdef MAXCHAR /* Often used in */ +# define PERL_CHAR_MAX MAXCHAR +# else +# define PERL_CHAR_MAX ((char) ((~(unsigned char)0) >> 1)) +# endif +#endif + +#ifdef CHAR_MIN +# define PERL_CHAR_MIN CHAR_MIN +#else +# ifdef MINCHAR +# define PERL_CHAR_MIN MINCHAR +# else +# define PERL_CHAR_MIN (-PERL_CHAR_MAX - ((3 & -1) == 3)) +# endif +#endif + +#ifdef UCHAR_MAX +# define PERL_UCHAR_MAX UCHAR_MAX +#else +# ifdef MAXUCHAR +# define PERL_UCHAR_MAX MAXUCHAR +# else +# define PERL_UCHAR_MAX (~(unsigned char)0) +# endif +#endif + +#define PERL_UCHAR_MIN 0 + +#ifdef SHORT_MAX +# define PERL_SHORT_MAX SHORT_MAX +#else +# ifdef MAXSHORT /* Often used in */ +# define PERL_SHORT_MAX MAXSHORT +# else +# define PERL_SHORT_MAX ((short) ((~(unsigned short)0) >> 1)) +# endif +#endif + +#ifdef SHORT_MIN +# define PERL_SHORT_MIN SHORT_MIN +#else +# ifdef MINSHORT +# define PERL_SHORT_MIN MINSHORT +# else +# define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3)) +# endif +#endif + +#ifdef USHORT_MAX +# define PERL_USHORT_MAX USHORT_MAX +#else +# ifdef MAXUSHORT +# define PERL_USHORT_MAX MAXUSHORT +# else +# define PERL_USHORT_MAX (~(unsigned short)0) +# endif +#endif + +#define PERL_USHORT_MIN 0 + +#ifdef INT_MAX +# define PERL_INT_MAX INT_MAX +#else +# ifdef MAXINT /* Often used in */ +# define PERL_INT_MAX MAXINT +# else +# define PERL_INT_MAX ((int) ((~(unsigned int)0) >> 1)) +# endif +#endif + +#ifdef INT_MIN +# define PERL_INT_MIN INT_MIN +#else +# ifdef MININT +# define PERL_INT_MIN MININT +# else +# define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3)) +# endif +#endif + +#ifdef UINT_MAX +# define PERL_UINT_MAX UINT_MAX +#else +# ifdef MAXUINT +# define PERL_UINT_MAX MAXUINT +# else +# define PERL_UINT_MAX (~(unsigned int)0) +# endif +#endif + +#define PERL_UINT_MIN 0 + #ifdef LONG_MAX -#define PERL_LONG_MAX LONG_MAX +# define PERL_LONG_MAX LONG_MAX #else # ifdef MAXLONG /* Often used in */ # define PERL_LONG_MAX MAXLONG @@ -576,17 +693,17 @@ #endif #ifdef LONG_MIN -#define PERL_LONG_MIN LONG_MIN +# define PERL_LONG_MIN LONG_MIN #else # ifdef MINLONG # define PERL_LONG_MIN MINLONG # else -# define PERL_LONG_MIN (-LONG_MAX - ((3 & -1) == 3)) +# define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3)) # endif #endif #ifdef ULONG_MAX -#define PERL_ULONG_MAX ULONG_MAX +# define PERL_ULONG_MAX ULONG_MAX #else # ifdef MAXULONG # define PERL_ULONG_MAX MAXULONG @@ -595,10 +712,28 @@ # endif #endif -#ifdef ULONG_MIN -#define PERL_ULONG_MIN ULONG_MIN -#else -# define ULONG_MIN 0L +#define PERL_ULONG_MIN 0L + +#ifdef HAS_QUAD +# ifdef QUAD_MAX +# define PERL_QUAD_MAX QUAD_MAX +# else +# define PERL_QUAD_MAX ((IV) ((~(UV)0) >> 1)) +# endif + +# ifdef QUAD_MIN +# define PERL_QUAD_MIN QUAD_MIN +# else +# define PERL_QUAD_MIN (-PERL_LONG_MAX - ((3 & -1) == 3)) +# endif + +# ifdef UQUAD_MAX +# define PERL_UQUAD_MAX UQUAD_MAX +# else +# define PERL_UQUAD_MAX (~(UV)0) +# endif + +# define PERL_UQUAD_MIN 0 #endif typedef MEM_SIZE STRLEN;