From 51299b2d1ba3d7a8101f2247b846a8fb8b24675c Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Mon, 21 Oct 2024 21:50:19 +0100 Subject: [PATCH 1/2] 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. --- src/npyffi/types.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/npyffi/types.rs b/src/npyffi/types.rs index 68df9c52f..eb03b801b 100644 --- a/src/npyffi/types.rs +++ b/src/npyffi/types.rs @@ -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; From 204d487c6838007442fb5d0fac94eb6e445e15fd Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Mon, 21 Oct 2024 23:40:35 +0100 Subject: [PATCH 2/2] Re-enable builds on 32-bit Windows The parent commit fixes the problems with 32-bit Windows, this one simply re-enables the build and re-activates the CI runs of it. --- .github/workflows/ci.yml | 11 +++++++++++ src/lib.rs | 3 --- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9689d19a8..21f8bacf4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,11 @@ jobs: python-architecture: "x64", rust-target: "x86_64-pc-windows-msvc", }, + { + os: "windows-latest", + python-architecture: "x86", + rust-target: "i686-pc-windows-msvc", + }, ] include: # ubuntu-24.04 does not support 3.7 @@ -141,6 +146,11 @@ jobs: python-architecture: "x64", rust-target: "x86_64-pc-windows-msvc", }, + { + os: "windows-latest", + python-architecture: "x86", + rust-target: "i686-pc-windows-msvc", + }, ] include: # ubuntu-24.04 does not support 3.7 @@ -181,6 +191,7 @@ jobs: nox -f examples/simple/noxfile.py env: CARGO_TERM_VERBOSE: true + CARGO_BUILD_TARGET: ${{ matrix.platform.rust-target }} RUST_BACKTRACE: 1 cross-build: diff --git a/src/lib.rs b/src/lib.rs index 2b2d1f088..6b72c2151 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,9 +74,6 @@ as well as the [`PyReadonlyArray::try_as_matrix`] and [`PyReadwriteArray::try_as // and similar aren't constructible #![cfg_attr(feature = "gil-refs", deny(missing_debug_implementations))] -#[cfg(all(target_os = "windows", target_arch = "x86"))] -compile_error!("Compilation for 32-bit windows is not currently supported. See https://github.com/PyO3/rust-numpy/issues/448"); - pub mod array; mod array_like; pub mod borrow;