Skip to content

Commit

Permalink
Fix static-size FFI type aliases
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jakelishman authored and davidhewitt committed Oct 27, 2024
1 parent 9095a77 commit 64145d2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/npyffi/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ pub type npy_long = c_long;
pub type npy_float = f32;
pub type npy_double = f64;
pub type npy_hash_t = Py_hash_t;
pub type npy_int64 = c_long;
pub type npy_uint64 = c_ulong;
pub type npy_int32 = c_int;
pub type npy_uint32 = c_uint;
pub type npy_int64 = i64;
pub type npy_uint64 = u64;
pub type npy_int32 = i32;
pub type npy_uint32 = u32;
pub type npy_ucs4 = c_uint;
pub type npy_int16 = c_short;
pub type npy_uint16 = c_ushort;
pub type npy_int8 = c_char;
pub type npy_uint8 = c_uchar;
pub type npy_int16 = i16;
pub type npy_uint16 = u16;
pub type npy_int8 = i8;
pub type npy_uint8 = u8;
pub type npy_float64 = f64;
pub type npy_complex128 = npy_cdouble;
pub type npy_float32 = f32;
Expand Down

0 comments on commit 64145d2

Please sign in to comment.