Skip to content

Commit ac4ea13

Browse files
author
Skip Montanaro
committed
There are places in Python which assume bytes have 8-bits. Formalize that a
bit by checking the value of UCHAR_MAX in Include/Python.h. There was a check in Objects/stringobject.c. Remove that. (Note that we don't define UCHAR_MAX if it's not defined as the old test did.)
1 parent 66518bb commit ac4ea13

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Include/Python.h

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
#error "limits.h is required by std C -- why isn't HAVE_LIMITS_H defined?"
2222
#endif
2323

24+
#ifndef UCHAR_MAX
25+
#error "Something's broken. UCHAR_MAX should be defined in limits.h."
26+
#endif
27+
28+
#if UCHAR_MAX != 255
29+
#error "Python's source code currently assumes 8-bit characters."
30+
#endif
31+
2432
#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)
2533
#define _SGI_MP_SOURCE
2634
#endif

Objects/stringobject.c

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
int null_strings, one_strings;
99
#endif
1010

11-
#if !defined(HAVE_LIMITS_H) && !defined(UCHAR_MAX)
12-
#define UCHAR_MAX 255
13-
#endif
14-
1511
static PyStringObject *characters[UCHAR_MAX + 1];
1612
static PyStringObject *nullstring;
1713

0 commit comments

Comments
 (0)