Skip to content

Commit 3fdbbe5

Browse files
committed
Issue #9036: Throughout the code base, Py_CHARMASK is used on 8-bit wide
signed/unsigned chars or on integers directly derived from those. In all cases, it could be replaced by a simple cast to (unsigned char). Reasons for the change: a) Make the comment more explicit. b) If char is unsigned, the cast is optimized away. c) If char is unsigned, gcc emits spurious "array subscript has type 'char'" warnings.
1 parent 1c0f715 commit 3fdbbe5

1 file changed

Lines changed: 1 addition & 6 deletions

File tree

Include/Python.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,8 @@ PyAPI_FUNC(wchar_t *) _Py_char2wchar(char *);
134134
}
135135
#endif
136136

137-
/* Convert a possibly signed character to a nonnegative int */
138-
/* XXX This assumes characters are 8 bits wide */
139-
#ifdef __CHAR_UNSIGNED__
140-
#define Py_CHARMASK(c) (c)
141-
#else
137+
/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
142138
#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
143-
#endif
144139

145140
#include "pyfpe.h"
146141

0 commit comments

Comments
 (0)