The three types char, signed char, and unsigned char are collectively called the character types. The implementation shall define char to have the same range, representation, and behavior as either signed char or unsigned char.
With a footnote:
CHAR_MIN, defined in <limits.h>, will have one of the values 0 or SCHAR_MIN, and this can be used to distinguish the two options. Irrespective of the choice made, char is a separate type from the other two and is not compatible with either.
Doesn't the problem with "char" vs. "unsigned char" leak out everywhere else in the bytes-related C-API?
Is the problem here only that we're using a literal outside the range of "signed char"? If so, could we adjust the initializer for the single-byte bytes objects with a cast or using CHAR_MIN or something like that?
The revert in #149514 (commit f0daba1) overreached: besides reverting the ob_sval change in Include/cpython/bytesobject.h, it also reverted gh-79638 ("Treat an unreachable robots.txt as 'disallow all'"), which is unrelated.
It backed out the read() 5xx→disallow_all branch in Lib/urllib/robotparser.py, the corresponding tests in Lib/test/test_robotparser.py, and the gh-issue-79638 NEWS entry.
gh-79638 had landed in 310fe88 immediately before, so the revert was likely cut from a stale base.
Activity
godlygeek commented on Jul 12, 2023
Per C11:
With a footnote:
pythongh-106693: Explicitly mark ob_sval as unsigned char to avoid UB
pythongh-106693: Explicitly mark ob_sval as unsigned char to avoid UB
ericsnowcurrently commented on Jul 17, 2023
Doesn't the problem with "char" vs. "unsigned char" leak out everywhere else in the bytes-related C-API?
Is the problem here only that we're using a literal outside the range of "signed char"? If so, could we adjust the initializer for the single-byte bytes objects with a cast or using CHAR_MIN or something like that?
pablogsal commented on Jul 17, 2023
It does not unless you assign something bigger than 128 or something negative to it.
Exactly. We should restrict the initialisation to only the signed char range or change the type
markshannon commented on Aug 1, 2023
We should change the type to unsigned char or uint8_t
markshannon commented on Aug 1, 2023
It shouldn't, but it will need a few casts in on entry or return to those functions.
pythongh-106693: Explicitly mark ob_sval as unsigned char to avoid UB
Merge branch 'main' into pythongh-106693
gh-106693: Explicitly mark ob_sval as unsigned char to avoid UB (#106826
gh-106693: Revert "Explicitly mark ob_sval as unsigned char to avoid …
serhiy-storchaka commented on Jun 28, 2026
The revert in #149514 (commit f0daba1) overreached: besides reverting the ob_sval change in Include/cpython/bytesobject.h, it also reverted gh-79638 ("Treat an unreachable robots.txt as 'disallow all'"), which is unrelated.
It backed out the read() 5xx→disallow_all branch in Lib/urllib/robotparser.py, the corresponding tests in Lib/test/test_robotparser.py, and the gh-issue-79638 NEWS entry.
gh-79638 had landed in 310fe88 immediately before, so the revert was likely cut from a stale base.
gh-79638: Restore "Treat an unreachable robots.txt as disallow all" (G…
[3.13] gh-79638: Restore "Treat an unreachable robots.txt as disallow…
[3.14] gh-79638: Restore "Treat an unreachable robots.txt as disallow…
[3.15] gh-79638: Restore "Treat an unreachable robots.txt as disallow…
pythongh-79638: Restore "Treat an unreachable robots.txt as disallow …