From d5fadf75e4d18df61db41205ace0cda28d98eeaa Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Tue, 26 Sep 2000 05:46:01 +0000 Subject: [PATCH] Rationalize use of limits.h, moving the inclusion to Python.h. Add definitions of INT_MAX and LONG_MAX to pyport.h. Remove includes of limits.h and conditional definitions of INT_MAX and LONG_MAX elsewhere. This closes SourceForge patch #101659 and bug #115323. --- Include/Python.h | 4 ++++ Include/longobject.h | 7 ------- Include/pyport.h | 32 ++++++++++++++++++++++++++++++++ Modules/_localemodule.c | 1 - Modules/_sre.c | 6 ------ Modules/arraymodule.c | 3 --- Modules/md5.h | 17 +++++------------ Modules/selectmodule.c | 3 --- Modules/stropmodule.c | 6 ------ Modules/structmodule.c | 1 - Objects/complexobject.c | 4 ---- Objects/fileobject.c | 4 ---- Objects/floatobject.c | 30 ------------------------------ Objects/intobject.c | 12 ------------ Objects/listobject.c | 3 --- Objects/object.c | 3 --- Objects/stringobject.c | 6 +----- Objects/unicodeobject.c | 6 ------ Parser/myreadline.c | 3 --- Python/bltinmodule.c | 3 --- Python/ceval.c | 6 ------ Python/codecs.c | 3 --- Python/compile.c | 6 ------ Python/getargs.c | 3 --- Python/modsupport.c | 3 --- 25 files changed, 42 insertions(+), 133 deletions(-) diff --git a/Include/Python.h b/Include/Python.h index 153ba079786..308655250de 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -23,6 +23,10 @@ #include "patchlevel.h" #include "config.h" +#ifdef HAVE_LIMITS_H +#include +#endif + /* config.h may or may not define DL_IMPORT */ #ifndef DL_IMPORT /* declarations for DLL import/export */ #define DL_IMPORT(RTYPE) RTYPE diff --git a/Include/longobject.h b/Include/longobject.h index f2dea9340b5..7ebceecaed7 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -24,14 +24,7 @@ extern DL_IMPORT(void *) PyLong_AsVoidPtr(PyObject *); #ifdef HAVE_LONG_LONG -#ifdef HAVE_LIMITS_H -#include -#endif - /* Hopefully this is portable... */ -#ifndef LONG_MAX -#define LONG_MAX 2147483647L -#endif #ifndef ULONG_MAX #define ULONG_MAX 4294967295U #endif diff --git a/Include/pyport.h b/Include/pyport.h index 48cd45b9442..4914886df15 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -354,6 +354,38 @@ typedef struct fd_set { #endif /* fd manipulation macros */ +/* limits.h constants that may be missing */ + +#ifndef INT_MAX +#define INT_MAX 2147483647 +#endif + +#ifndef LONG_MAX +#if SIZEOF_LONG == 4 +#define LONG_MAX 0X7FFFFFFFL +#elif SIZEOF_LONG == 8 +#define LONG_MAX 0X7FFFFFFFFFFFFFFFL +#else +#error "could not set LONG_MAX in pyport.h" +#endif +#endif + +#ifndef LONG_MIN +#define LONG_MIN (-LONG_MAX-1) +#endif + +#ifdef __NeXT__ +#ifdef __sparc__ +/* + * This works around a bug in the NS/Sparc 3.3 pre-release + * limits.h header file. + * 10-Feb-1995 bwarsaw@cnri.reston.va.us + */ +#undef LONG_MIN +#define LONG_MIN (-LONG_MAX-1) +#endif +#endif + #ifdef __cplusplus } #endif diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 2588b8e913d..80bfbb27296 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -15,7 +15,6 @@ This software comes with no warranty. Use at your own risk. #include #include #include -#include #include #if defined(MS_WIN32) diff --git a/Modules/_sre.c b/Modules/_sre.c index cf4982dd560..2412d42af10 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -40,12 +40,6 @@ char copyright[] = " SRE 0.9.8 Copyright (c) 1997-2000 by Secret Labs AB "; #include "sre.h" -#if defined(HAVE_LIMITS_H) -#include -#else -#define INT_MAX 2147483647 -#endif - #include /* name of this module, minus the leading underscore */ diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 991fdc22e3f..ad7bcc2bc9b 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -12,9 +12,6 @@ #include /* For size_t */ #endif /* DONT_HAVE_SYS_TYPES_H */ #endif /* !STDC_HEADERS */ -#ifdef HAVE_LIMITS_H -#include -#endif /* HAVE_LIMITS_H */ struct arrayobject; /* Forward */ diff --git a/Modules/md5.h b/Modules/md5.h index 12b3aa3db7d..e169f779fab 100644 --- a/Modules/md5.h +++ b/Modules/md5.h @@ -33,21 +33,14 @@ typedef unsigned char *POINTER; /* UINT2 defines a two byte word */ typedef unsigned short int UINT2; -#ifdef HAVE_LIMITS_H -#include -#else -/* Wild guess */ -#define LONG_MAX 2147483647L -#endif - /* UINT4 defines a four byte word */ -#if defined(INT_MAX) && INT_MAX == 2147483647 -typedef unsigned int UINT4; -#else -#if defined(LONG_MAX) && LONG_MAX == 2147483647L +#if SIZEOF_LONG == 4 typedef unsigned long int UINT4; +#else +#if INT_MAX == 2147483647 +typedef unsigned int UINT4; #endif -/* Too bad if neither is */ +/* Too bad if neither is; pyport.h would need to be fixed. */ #endif /* ========== End global.h; continue md5.h ========== */ diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 55c3a49c535..114ac35fb7a 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -12,9 +12,6 @@ #ifdef HAVE_UNISTD_H #include #endif -#ifdef HAVE_LIMITS_H -#include -#endif #ifdef HAVE_POLL_H #include #endif diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c index b8f7519f2df..203feb942d5 100644 --- a/Modules/stropmodule.c +++ b/Modules/stropmodule.c @@ -9,12 +9,6 @@ this module directly."; #include "Python.h" -#ifdef HAVE_LIMITS_H -#include -#else -#define INT_MAX 2147483647 -#endif - #include /* XXX This file assumes that the is*() functions XXX are defined for all 8-bit characters! */ diff --git a/Modules/structmodule.c b/Modules/structmodule.c index 4d6012258b4..a28ca548dd9 100644 --- a/Modules/structmodule.c +++ b/Modules/structmodule.c @@ -31,7 +31,6 @@ The variable struct.error is an exception raised on errors."; #include "Python.h" -#include #include diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 3c9830f6b19..dc1d83741fc 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -9,10 +9,6 @@ #include "Python.h" -#ifdef HAVE_LIMITS_H -#include -#endif - /* elementary operations on complex numbers */ diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 88e60275dfa..2978d259d90 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -4,10 +4,6 @@ #include "Python.h" #include "structmember.h" -#ifdef HAVE_LIMITS_H -#include -#endif - #ifndef DONT_HAVE_SYS_TYPES_H #include #endif /* DONT_HAVE_SYS_TYPES_H */ diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 004cf5747aa..17f70b22103 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -23,36 +23,6 @@ #define CHECK(x) /* Don't know how to check */ #endif -#ifdef HAVE_LIMITS_H -#include -#endif - -#ifndef LONG_MAX -#if SIZEOF_LONG == 4 -#define LONG_MAX 0X7FFFFFFFL -#elif SIZEOF_LONG == 8 -#define LONG_MAX 0X7FFFFFFFFFFFFFFFL -#else -#error "could not set LONG_MAX" -#endif -#endif - -#ifndef LONG_MIN -#define LONG_MIN (-LONG_MAX-1) -#endif - -#ifdef __NeXT__ -#ifdef __sparc__ -/* - * This works around a bug in the NS/Sparc 3.3 pre-release - * limits.h header file. - * 10-Feb-1995 bwarsaw@cnri.reston.va.us - */ -#undef LONG_MIN -#define LONG_MIN (-LONG_MAX-1) -#endif -#endif - #if !defined(__STDC__) && !defined(macintosh) extern double fmod(double, double); extern double pow(double, double); diff --git a/Objects/intobject.c b/Objects/intobject.c index 411e4dd1746..8477a023817 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -4,18 +4,6 @@ #include "Python.h" #include -#ifdef HAVE_LIMITS_H -#include -#endif - -#ifndef LONG_MAX -#define LONG_MAX 0X7FFFFFFFL -#endif - -#ifndef LONG_MIN -#define LONG_MIN (-LONG_MAX-1) -#endif - #ifndef CHAR_BIT #define CHAR_BIT 8 #endif diff --git a/Objects/listobject.c b/Objects/listobject.c index 3d02b5f9a2b..b874af9f543 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -8,9 +8,6 @@ #else #include /* For size_t */ #endif -#ifdef HAVE_LIMITS_H -#include -#endif #define ROUNDUP(n, PyTryBlock) \ ((((n)+(PyTryBlock)-1)/(PyTryBlock))*(PyTryBlock)) diff --git a/Objects/object.c b/Objects/object.c index 4f395ff3571..9b7c551d85b 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -2,9 +2,6 @@ /* Generic object operations; and implementation of None (NoObject) */ #include "Python.h" -#ifdef HAVE_LIMITS_H -#include -#endif #ifdef macintosh #include "macglue.h" diff --git a/Objects/stringobject.c b/Objects/stringobject.c index acae8803254..ec7eb908a32 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -9,13 +9,9 @@ int null_strings, one_strings; #endif -#ifdef HAVE_LIMITS_H -#include -#else -#ifndef UCHAR_MAX +#if !defined(HAVE_LIMITS_H) && !defined(UCHAR_MAX) #define UCHAR_MAX 255 #endif -#endif static PyStringObject *characters[UCHAR_MAX + 1]; #ifndef DONT_SHARE_SHORT_STRINGS diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 1559542d8aa..b096faa3f29 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -67,12 +67,6 @@ Copyright (c) Corporation for National Research Initiatives. #include "unicodeobject.h" #include "ucnhash.h" -#if defined(HAVE_LIMITS_H) -#include -#else -#define INT_MAX 2147483647 -#endif - #ifdef MS_WIN32 #include #endif diff --git a/Parser/myreadline.c b/Parser/myreadline.c index 6451824ede0..963a90e0385 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -10,9 +10,6 @@ */ #include "Python.h" -#ifdef HAVE_LIMITS_H -#include -#endif int (*PyOS_InputHook)(void) = NULL; diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 88656ca630f..4ca1310be21 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -12,9 +12,6 @@ #ifdef HAVE_UNISTD_H #include #endif -#ifdef HAVE_LIMITS_H -#include -#endif /* Forward */ static PyObject *filterstring(PyObject *, PyObject *); diff --git a/Python/ceval.c b/Python/ceval.c index 491a73bdf1d..36cdab84e58 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -20,12 +20,6 @@ #include -#ifdef HAVE_LIMITS_H -#include -#else -#define INT_MAX 2147483647 -#endif - /* Turn this on if your compiler chokes on the big switch: */ /* #define CASE_TOO_BIG 1 */ diff --git a/Python/codecs.c b/Python/codecs.c index c3f93ccda95..3324b806fc9 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -10,9 +10,6 @@ Copyright (c) Corporation for National Research Initiatives. #include "Python.h" #include -#ifdef HAVE_LIMITS_H -#include -#endif /* --- Globals ------------------------------------------------------------ */ diff --git a/Python/compile.c b/Python/compile.c index 0409f2d0d82..e14fc01df8b 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -24,12 +24,6 @@ #include "structmember.h" #include -#ifdef HAVE_LIMITS_H -#include -#endif -#ifndef INT_MAX -#define INT_MAX 2147483647 -#endif /* Three symbols from graminit.h are also defined in Python.h, with Py_ prefixes to their names. Python.h can't include graminit.h diff --git a/Python/getargs.c b/Python/getargs.c index 797e9df77d6..46251ae75e3 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -9,9 +9,6 @@ #include "Python.h" #include -#ifdef HAVE_LIMITS_H -#include -#endif int PyArg_Parse(PyObject *, char *, ...); diff --git a/Python/modsupport.c b/Python/modsupport.c index 9c2dc18a451..ef36d108f5b 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -2,9 +2,6 @@ /* Module support implementation */ #include "Python.h" -#ifdef HAVE_LIMITS_H -#include -#endif #ifdef MPW /* MPW pushes 'extended' for float and double types with varargs */ typedef extended va_double;