Issue #9036: Throughout the code base, Py_CHARMASK is used on 8-bit wide
authorStefan Krah <stefan@bytereef.org>
Mon, 19 Jul 2010 12:36:57 +0000 (12:36 +0000)
committerStefan Krah <stefan@bytereef.org>
Mon, 19 Jul 2010 12:36:57 +0000 (12:36 +0000)
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.

Include/Python.h

index c0e469ecdb996e663f1fb2681126e34f2af22452..972beec7cbb48a2a9498342fc920b92ea1489ade 100644 (file)
@@ -134,13 +134,8 @@ PyAPI_FUNC(wchar_t *) _Py_char2wchar(char *);
 }
 #endif
 
-/* Convert a possibly signed character to a nonnegative int */
-/* XXX This assumes characters are 8 bits wide */
-#ifdef __CHAR_UNSIGNED__
-#define Py_CHARMASK(c)         (c)
-#else
+/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
 #define Py_CHARMASK(c)         ((unsigned char)((c) & 0xff))
-#endif
 
 #include "pyfpe.h"