Skip to content

Commit 7cbe57c

Browse files
committed
Specify signedness of the FFI types, don't match the C types
1 parent b9ed727 commit 7cbe57c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Modules/_ctypes/cfield.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,8 +1415,10 @@ for base_code, base_c_type in [
14151415
TABLE_ENTRY_SW(f, &ffi_type_float);
14161416
TABLE_ENTRY(v, &ffi_type_sshort); /* vBOOL */
14171417

1418-
TABLE_ENTRY(c, FIXINT_FIELDDESC_FOR(char)->pffi_type);
1419-
TABLE_ENTRY(u, FIXINT_FIELDDESC_FOR(wchar_t)->pffi_type);
1418+
// ctypes.c_char is signed for FFI, even where C wchar_t is unsigned.
1419+
TABLE_ENTRY(c, _ctypes_fixint_fielddesc(sizeof(char), true)->pffi_type);
1420+
// ctypes.c_wchar is signed for FFI, even where C wchar_t is unsigned.
1421+
TABLE_ENTRY(u, _ctypes_fixint_fielddesc(sizeof(wchar_t), true)->pffi_type);
14201422

14211423
TABLE_ENTRY(s, &ffi_type_pointer);
14221424
TABLE_ENTRY(P, &ffi_type_pointer);
@@ -1434,7 +1436,8 @@ for base_code, base_c_type in [
14341436

14351437
/* bool has code '?', fill it in manually */
14361438

1437-
formattable.fmt_bool = *FIXINT_FIELDDESC_FOR(bool);
1439+
// ctypes.c_bool is unsigned for FFI, even where C bool is signed.
1440+
formattable.fmt_bool = *_ctypes_fixint_fielddesc(sizeof(bool), false);
14381441
formattable.fmt_bool.code = '?';
14391442
formattable.fmt_bool.setfunc = bool_set;
14401443
formattable.fmt_bool.getfunc = bool_get;

0 commit comments

Comments
 (0)