Skip to content

Commit 1c551ac

Browse files
Avoid hardcoded assumed pointer types
Depends on blas-lapack-rs/lapack-sys#15 This replaces hardcoded platform-specific `char*` types with the opaque types from [`core::ffi`](https://doc.rust-lang.org/stable/core/ffi/type.c_char.html). This is necessary when cross-compiling. I believe when interacting with C and Fortran, both `lax` and `lapack-sys` should not assume integer and pointer types. Current setup is biased towards x86_64 platform and it could cause broken builds and undefined behavior on other platforms. For example, cross compilation build could fail with: error[E0308]: mismatched types --> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lax-0.16.0/src/cholesky.rs:30:26 | 30 | $trf(uplo.as_ptr(), &n, AsPtr::as_mut_ptr(a), &n, &mut info); | ---- ^^^^^^^^^^^^^ expected `*const u8`, found `*const i8` | | | arguments to this function are incorrect ... 41 | impl_cholesky_!(c64, lapack_sys::zpotrf_); | ----------------------------------------- in this macro invocation | = note: expected raw pointer `*const u8` found raw pointer `*const i8` note: function defined here --> /workdir/.build/docker-aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/release/build/lapack-sys-5fad11066d38a1a6/out/bindings.rs:12886:12 Full build log for aarch64-unknown-linux-gnu: [build.log.txt](https://github.com/user-attachments/files/17706011/build.log.txt) In this PR I change `i8` to `core::ffi::c_char` - this, for example, resolves to `i8` on x86 and to `u8` on ARM, but is also universal for any platform rust supports, removing bias towards x86.
1 parent 3e13736 commit 1c551ac

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lax/src/flags.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Charactor flags, e.g. `'T'`, used in LAPACK API
2+
use core::ffi::c_char;
23

34
/// Upper/Lower specification for seveal usages
45
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -17,8 +18,8 @@ impl UPLO {
1718
}
1819

1920
/// To use Fortran LAPACK API in lapack-sys crate
20-
pub fn as_ptr(&self) -> *const i8 {
21-
self as *const UPLO as *const i8
21+
pub fn as_ptr(&self) -> *const c_char {
22+
self as *const UPLO as *const c_char
2223
}
2324
}
2425

@@ -32,8 +33,8 @@ pub enum Transpose {
3233

3334
impl Transpose {
3435
/// To use Fortran LAPACK API in lapack-sys crate
35-
pub fn as_ptr(&self) -> *const i8 {
36-
self as *const Transpose as *const i8
36+
pub fn as_ptr(&self) -> *const c_char {
37+
self as *const Transpose as *const c_char
3738
}
3839
}
3940

@@ -55,8 +56,8 @@ impl NormType {
5556
}
5657

5758
/// To use Fortran LAPACK API in lapack-sys crate
58-
pub fn as_ptr(&self) -> *const i8 {
59-
self as *const NormType as *const i8
59+
pub fn as_ptr(&self) -> *const c_char {
60+
self as *const NormType as *const c_char
6061
}
6162
}
6263

@@ -87,8 +88,8 @@ impl JobEv {
8788
}
8889

8990
/// To use Fortran LAPACK API in lapack-sys crate
90-
pub fn as_ptr(&self) -> *const i8 {
91-
self as *const JobEv as *const i8
91+
pub fn as_ptr(&self) -> *const c_char {
92+
self as *const JobEv as *const c_char
9293
}
9394
}
9495

@@ -117,8 +118,8 @@ impl JobSvd {
117118
}
118119
}
119120

120-
pub fn as_ptr(&self) -> *const i8 {
121-
self as *const JobSvd as *const i8
121+
pub fn as_ptr(&self) -> *const c_char {
122+
self as *const JobSvd as *const c_char
122123
}
123124
}
124125

@@ -133,7 +134,7 @@ pub enum Diag {
133134
}
134135

135136
impl Diag {
136-
pub fn as_ptr(&self) -> *const i8 {
137-
self as *const Diag as *const i8
137+
pub fn as_ptr(&self) -> *const c_char {
138+
self as *const Diag as *const c_char
138139
}
139140
}

0 commit comments

Comments
 (0)