Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5fadf7

Browse files
committed
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.
1 parent 1b61859 commit d5fadf7

25 files changed

Lines changed: 42 additions & 133 deletions

Include/Python.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include "patchlevel.h"
2424
#include "config.h"
2525

26+
#ifdef HAVE_LIMITS_H
27+
#include <limits.h>
28+
#endif
29+
2630
/* config.h may or may not define DL_IMPORT */
2731
#ifndef DL_IMPORT /* declarations for DLL import/export */
2832
#define DL_IMPORT(RTYPE) RTYPE

Include/longobject.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@ extern DL_IMPORT(void *) PyLong_AsVoidPtr(PyObject *);
2424

2525
#ifdef HAVE_LONG_LONG
2626

27-
#ifdef HAVE_LIMITS_H
28-
#include <limits.h>
29-
#endif
30-
3127
/* Hopefully this is portable... */
32-
#ifndef LONG_MAX
33-
#define LONG_MAX 2147483647L
34-
#endif
3528
#ifndef ULONG_MAX
3629
#define ULONG_MAX 4294967295U
3730
#endif

Include/pyport.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,38 @@ typedef struct fd_set {
354354
#endif /* fd manipulation macros */
355355

356356

357+
/* limits.h constants that may be missing */
358+
359+
#ifndef INT_MAX
360+
#define INT_MAX 2147483647
361+
#endif
362+
363+
#ifndef LONG_MAX
364+
#if SIZEOF_LONG == 4
365+
#define LONG_MAX 0X7FFFFFFFL
366+
#elif SIZEOF_LONG == 8
367+
#define LONG_MAX 0X7FFFFFFFFFFFFFFFL
368+
#else
369+
#error "could not set LONG_MAX in pyport.h"
370+
#endif
371+
#endif
372+
373+
#ifndef LONG_MIN
374+
#define LONG_MIN (-LONG_MAX-1)
375+
#endif
376+
377+
#ifdef __NeXT__
378+
#ifdef __sparc__
379+
/*
380+
* This works around a bug in the NS/Sparc 3.3 pre-release
381+
* limits.h header file.
382+
* 10-Feb-1995 [email protected]
383+
*/
384+
#undef LONG_MIN
385+
#define LONG_MIN (-LONG_MAX-1)
386+
#endif
387+
#endif
388+
357389
#ifdef __cplusplus
358390
}
359391
#endif

Modules/_localemodule.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ This software comes with no warranty. Use at your own risk.
1515
#include <errno.h>
1616
#include <locale.h>
1717
#include <string.h>
18-
#include <limits.h>
1918
#include <ctype.h>
2019

2120
#if defined(MS_WIN32)

Modules/_sre.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ char copyright[] = " SRE 0.9.8 Copyright (c) 1997-2000 by Secret Labs AB ";
4040

4141
#include "sre.h"
4242

43-
#if defined(HAVE_LIMITS_H)
44-
#include <limits.h>
45-
#else
46-
#define INT_MAX 2147483647
47-
#endif
48-
4943
#include <ctype.h>
5044

5145
/* name of this module, minus the leading underscore */

Modules/arraymodule.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
#include <sys/types.h> /* For size_t */
1313
#endif /* DONT_HAVE_SYS_TYPES_H */
1414
#endif /* !STDC_HEADERS */
15-
#ifdef HAVE_LIMITS_H
16-
#include <limits.h>
17-
#endif /* HAVE_LIMITS_H */
1815

1916
struct arrayobject; /* Forward */
2017

Modules/md5.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,14 @@ typedef unsigned char *POINTER;
3333
/* UINT2 defines a two byte word */
3434
typedef unsigned short int UINT2;
3535

36-
#ifdef HAVE_LIMITS_H
37-
#include <limits.h>
38-
#else
39-
/* Wild guess */
40-
#define LONG_MAX 2147483647L
41-
#endif
42-
4336
/* UINT4 defines a four byte word */
44-
#if defined(INT_MAX) && INT_MAX == 2147483647
45-
typedef unsigned int UINT4;
46-
#else
47-
#if defined(LONG_MAX) && LONG_MAX == 2147483647L
37+
#if SIZEOF_LONG == 4
4838
typedef unsigned long int UINT4;
39+
#else
40+
#if INT_MAX == 2147483647
41+
typedef unsigned int UINT4;
4942
#endif
50-
/* Too bad if neither is */
43+
/* Too bad if neither is; pyport.h would need to be fixed. */
5144
#endif
5245

5346
/* ========== End global.h; continue md5.h ========== */

Modules/selectmodule.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
#ifdef HAVE_UNISTD_H
1313
#include <unistd.h>
1414
#endif
15-
#ifdef HAVE_LIMITS_H
16-
#include <limits.h>
17-
#endif
1815
#ifdef HAVE_POLL_H
1916
#include <poll.h>
2017
#endif

Modules/stropmodule.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ this module directly.";
99

1010
#include "Python.h"
1111

12-
#ifdef HAVE_LIMITS_H
13-
#include <limits.h>
14-
#else
15-
#define INT_MAX 2147483647
16-
#endif
17-
1812
#include <ctype.h>
1913
/* XXX This file assumes that the <ctype.h> is*() functions
2014
XXX are defined for all 8-bit characters! */

Modules/structmodule.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ The variable struct.error is an exception raised on errors.";
3131

3232
#include "Python.h"
3333

34-
#include <limits.h>
3534
#include <ctype.h>
3635

3736

0 commit comments

Comments
 (0)