Skip to content

Commit 64145d2

Browse files
jakelishmandavidhewitt
authored andcommitted
Fix static-size FFI type aliases
Several type aliases with statically sized names (e.g. `npy_uint64`) were being aliased to platform-dependent types like `::std::os::raw::c_long`. Most of these were barely used, so it seems like they didn't cause problems before, but now with `npy_uint64` being used in certain structs, which are the target of pointer punning, the mismatch in sizes became visible. For example, `npy_uint64` was previously typedef'd to `c_ulong`, which is 64 bits on 64-bit platforms and on all Unix-likes, but 32 bits on Windows 32-bit. This caused inaccurate reads through pointers to structs containing them, eventually resulting in attempts to derefence null pointers.
1 parent 9095a77 commit 64145d2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/npyffi/types.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ pub type npy_long = c_long;
1919
pub type npy_float = f32;
2020
pub type npy_double = f64;
2121
pub type npy_hash_t = Py_hash_t;
22-
pub type npy_int64 = c_long;
23-
pub type npy_uint64 = c_ulong;
24-
pub type npy_int32 = c_int;
25-
pub type npy_uint32 = c_uint;
22+
pub type npy_int64 = i64;
23+
pub type npy_uint64 = u64;
24+
pub type npy_int32 = i32;
25+
pub type npy_uint32 = u32;
2626
pub type npy_ucs4 = c_uint;
27-
pub type npy_int16 = c_short;
28-
pub type npy_uint16 = c_ushort;
29-
pub type npy_int8 = c_char;
30-
pub type npy_uint8 = c_uchar;
27+
pub type npy_int16 = i16;
28+
pub type npy_uint16 = u16;
29+
pub type npy_int8 = i8;
30+
pub type npy_uint8 = u8;
3131
pub type npy_float64 = f64;
3232
pub type npy_complex128 = npy_cdouble;
3333
pub type npy_float32 = f32;

0 commit comments

Comments
 (0)