Skip to content

Commit 38c78c8

Browse files
committed
Use the same strategy also for memoryview
1 parent 92b0e84 commit 38c78c8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
The struct module now loads native booleans as ``char`` rather than
2-
``_Bool`` to avoid triggering undefined behavior. The behavior is the same
3-
on all supported (tested) platforms.
1+
The struct module and memoryview now load native booleans as ``char`` rather
2+
than ``_Bool`` to avoid triggering undefined behavior. For valid native _Bool,
3+
the behavior is the same on all supported (tested) platforms.

Objects/memoryobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,9 @@ unpack_single(const char *ptr, const char *fmt)
16991699
case 'l': UNPACK_SINGLE(ld, ptr, long); goto convert_ld;
17001700

17011701
/* boolean */
1702-
case '?': UNPACK_SINGLE(ld, ptr, _Bool); goto convert_bool;
1702+
// memcpy-ing values other than 0 or 1 to a _Bool variable triggers
1703+
// undefined behavior, so cast from char instead. See bpo-39689.
1704+
case '?': ld = (_Bool)*ptr; goto convert_bool;
17031705

17041706
/* unsigned integers */
17051707
case 'H': UNPACK_SINGLE(lu, ptr, unsigned short); goto convert_lu;

0 commit comments

Comments
 (0)