Commit d5fadf75 authored by Fred Drake's avatar Fred Drake

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.
parent 1b618594
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
#include "patchlevel.h" #include "patchlevel.h"
#include "config.h" #include "config.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
/* config.h may or may not define DL_IMPORT */ /* config.h may or may not define DL_IMPORT */
#ifndef DL_IMPORT /* declarations for DLL import/export */ #ifndef DL_IMPORT /* declarations for DLL import/export */
#define DL_IMPORT(RTYPE) RTYPE #define DL_IMPORT(RTYPE) RTYPE
......
...@@ -24,14 +24,7 @@ extern DL_IMPORT(void *) PyLong_AsVoidPtr(PyObject *); ...@@ -24,14 +24,7 @@ extern DL_IMPORT(void *) PyLong_AsVoidPtr(PyObject *);
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
/* Hopefully this is portable... */ /* Hopefully this is portable... */
#ifndef LONG_MAX
#define LONG_MAX 2147483647L
#endif
#ifndef ULONG_MAX #ifndef ULONG_MAX
#define ULONG_MAX 4294967295U #define ULONG_MAX 4294967295U
#endif #endif
......
...@@ -354,6 +354,38 @@ typedef struct fd_set { ...@@ -354,6 +354,38 @@ typedef struct fd_set {
#endif /* fd manipulation macros */ #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 #ifdef __cplusplus
} }
#endif #endif
......
...@@ -15,7 +15,6 @@ This software comes with no warranty. Use at your own risk. ...@@ -15,7 +15,6 @@ This software comes with no warranty. Use at your own risk.
#include <errno.h> #include <errno.h>
#include <locale.h> #include <locale.h>
#include <string.h> #include <string.h>
#include <limits.h>
#include <ctype.h> #include <ctype.h>
#if defined(MS_WIN32) #if defined(MS_WIN32)
......
...@@ -40,12 +40,6 @@ char copyright[] = " SRE 0.9.8 Copyright (c) 1997-2000 by Secret Labs AB "; ...@@ -40,12 +40,6 @@ char copyright[] = " SRE 0.9.8 Copyright (c) 1997-2000 by Secret Labs AB ";
#include "sre.h" #include "sre.h"
#if defined(HAVE_LIMITS_H)
#include <limits.h>
#else
#define INT_MAX 2147483647
#endif
#include <ctype.h> #include <ctype.h>
/* name of this module, minus the leading underscore */ /* name of this module, minus the leading underscore */
......
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
#include <sys/types.h> /* For size_t */ #include <sys/types.h> /* For size_t */
#endif /* DONT_HAVE_SYS_TYPES_H */ #endif /* DONT_HAVE_SYS_TYPES_H */
#endif /* !STDC_HEADERS */ #endif /* !STDC_HEADERS */
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif /* HAVE_LIMITS_H */
struct arrayobject; /* Forward */ struct arrayobject; /* Forward */
......
...@@ -33,21 +33,14 @@ typedef unsigned char *POINTER; ...@@ -33,21 +33,14 @@ typedef unsigned char *POINTER;
/* UINT2 defines a two byte word */ /* UINT2 defines a two byte word */
typedef unsigned short int UINT2; typedef unsigned short int UINT2;
#ifdef HAVE_LIMITS_H
#include <limits.h>
#else
/* Wild guess */
#define LONG_MAX 2147483647L
#endif
/* UINT4 defines a four byte word */ /* UINT4 defines a four byte word */
#if defined(INT_MAX) && INT_MAX == 2147483647 #if SIZEOF_LONG == 4
typedef unsigned int UINT4;
#else
#if defined(LONG_MAX) && LONG_MAX == 2147483647L
typedef unsigned long int UINT4; typedef unsigned long int UINT4;
#else
#if INT_MAX == 2147483647
typedef unsigned int UINT4;
#endif #endif
/* Too bad if neither is */ /* Too bad if neither is; pyport.h would need to be fixed. */
#endif #endif
/* ========== End global.h; continue md5.h ========== */ /* ========== End global.h; continue md5.h ========== */
......
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef HAVE_POLL_H #ifdef HAVE_POLL_H
#include <poll.h> #include <poll.h>
#endif #endif
......
...@@ -9,12 +9,6 @@ this module directly."; ...@@ -9,12 +9,6 @@ this module directly.";
#include "Python.h" #include "Python.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#else
#define INT_MAX 2147483647
#endif
#include <ctype.h> #include <ctype.h>
/* XXX This file assumes that the <ctype.h> is*() functions /* XXX This file assumes that the <ctype.h> is*() functions
XXX are defined for all 8-bit characters! */ XXX are defined for all 8-bit characters! */
......
...@@ -31,7 +31,6 @@ The variable struct.error is an exception raised on errors."; ...@@ -31,7 +31,6 @@ The variable struct.error is an exception raised on errors.";
#include "Python.h" #include "Python.h"
#include <limits.h>
#include <ctype.h> #include <ctype.h>
......
...@@ -9,10 +9,6 @@ ...@@ -9,10 +9,6 @@
#include "Python.h" #include "Python.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
/* elementary operations on complex numbers */ /* elementary operations on complex numbers */
......
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
#include "Python.h" #include "Python.h"
#include "structmember.h" #include "structmember.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifndef DONT_HAVE_SYS_TYPES_H #ifndef DONT_HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif /* DONT_HAVE_SYS_TYPES_H */ #endif /* DONT_HAVE_SYS_TYPES_H */
......
...@@ -23,36 +23,6 @@ ...@@ -23,36 +23,6 @@
#define CHECK(x) /* Don't know how to check */ #define CHECK(x) /* Don't know how to check */
#endif #endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#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) #if !defined(__STDC__) && !defined(macintosh)
extern double fmod(double, double); extern double fmod(double, double);
extern double pow(double, double); extern double pow(double, double);
......
...@@ -4,18 +4,6 @@ ...@@ -4,18 +4,6 @@
#include "Python.h" #include "Python.h"
#include <ctype.h> #include <ctype.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifndef LONG_MAX
#define LONG_MAX 0X7FFFFFFFL
#endif
#ifndef LONG_MIN
#define LONG_MIN (-LONG_MAX-1)
#endif
#ifndef CHAR_BIT #ifndef CHAR_BIT
#define CHAR_BIT 8 #define CHAR_BIT 8
#endif #endif
......
...@@ -8,9 +8,6 @@ ...@@ -8,9 +8,6 @@
#else #else
#include <sys/types.h> /* For size_t */ #include <sys/types.h> /* For size_t */
#endif #endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#define ROUNDUP(n, PyTryBlock) \ #define ROUNDUP(n, PyTryBlock) \
((((n)+(PyTryBlock)-1)/(PyTryBlock))*(PyTryBlock)) ((((n)+(PyTryBlock)-1)/(PyTryBlock))*(PyTryBlock))
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
/* Generic object operations; and implementation of None (NoObject) */ /* Generic object operations; and implementation of None (NoObject) */
#include "Python.h" #include "Python.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef macintosh #ifdef macintosh
#include "macglue.h" #include "macglue.h"
......
...@@ -9,13 +9,9 @@ ...@@ -9,13 +9,9 @@
int null_strings, one_strings; int null_strings, one_strings;
#endif #endif
#ifdef HAVE_LIMITS_H #if !defined(HAVE_LIMITS_H) && !defined(UCHAR_MAX)
#include <limits.h>
#else
#ifndef UCHAR_MAX
#define UCHAR_MAX 255 #define UCHAR_MAX 255
#endif #endif
#endif
static PyStringObject *characters[UCHAR_MAX + 1]; static PyStringObject *characters[UCHAR_MAX + 1];
#ifndef DONT_SHARE_SHORT_STRINGS #ifndef DONT_SHARE_SHORT_STRINGS
......
...@@ -67,12 +67,6 @@ Copyright (c) Corporation for National Research Initiatives. ...@@ -67,12 +67,6 @@ Copyright (c) Corporation for National Research Initiatives.
#include "unicodeobject.h" #include "unicodeobject.h"
#include "ucnhash.h" #include "ucnhash.h"
#if defined(HAVE_LIMITS_H)
#include <limits.h>
#else
#define INT_MAX 2147483647
#endif
#ifdef MS_WIN32 #ifdef MS_WIN32
#include <windows.h> #include <windows.h>
#endif #endif
......
...@@ -10,9 +10,6 @@ ...@@ -10,9 +10,6 @@
*/ */
#include "Python.h" #include "Python.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
int (*PyOS_InputHook)(void) = NULL; int (*PyOS_InputHook)(void) = NULL;
......
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
/* Forward */ /* Forward */
static PyObject *filterstring(PyObject *, PyObject *); static PyObject *filterstring(PyObject *, PyObject *);
......
...@@ -20,12 +20,6 @@ ...@@ -20,12 +20,6 @@
#include <ctype.h> #include <ctype.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#else
#define INT_MAX 2147483647
#endif
/* Turn this on if your compiler chokes on the big switch: */ /* Turn this on if your compiler chokes on the big switch: */
/* #define CASE_TOO_BIG 1 */ /* #define CASE_TOO_BIG 1 */
......
...@@ -10,9 +10,6 @@ Copyright (c) Corporation for National Research Initiatives. ...@@ -10,9 +10,6 @@ Copyright (c) Corporation for National Research Initiatives.
#include "Python.h" #include "Python.h"
#include <ctype.h> #include <ctype.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
/* --- Globals ------------------------------------------------------------ */ /* --- Globals ------------------------------------------------------------ */
......
...@@ -24,12 +24,6 @@ ...@@ -24,12 +24,6 @@
#include "structmember.h" #include "structmember.h"
#include <ctype.h> #include <ctype.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
/* Three symbols from graminit.h are also defined in Python.h, with /* Three symbols from graminit.h are also defined in Python.h, with
Py_ prefixes to their names. Python.h can't include graminit.h Py_ prefixes to their names. Python.h can't include graminit.h
......
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
#include "Python.h" #include "Python.h"
#include <ctype.h> #include <ctype.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
int PyArg_Parse(PyObject *, char *, ...); int PyArg_Parse(PyObject *, char *, ...);
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
/* Module support implementation */ /* Module support implementation */
#include "Python.h" #include "Python.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef MPW /* MPW pushes 'extended' for float and double types with varargs */ #ifdef MPW /* MPW pushes 'extended' for float and double types with varargs */
typedef extended va_double; typedef extended va_double;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment