Skip to content

Commit e610b3b

Browse files
committed
Fix warning in wasm import
1 parent 8fc067d commit e610b3b

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

Sources/Matft/library/lapack.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,31 @@ internal typealias lapack_LU<T> = (UnsafeMutablePointer<__CLPK_integer>, UnsafeM
734734

735735
internal typealias lapack_inv<T> = (UnsafeMutablePointer<__CLPK_integer>, UnsafeMutablePointer<T>, UnsafeMutablePointer<__CLPK_integer>, UnsafeMutablePointer<__CLPK_integer>, UnsafeMutablePointer<T>, UnsafeMutablePointer<__CLPK_integer>, UnsafeMutablePointer<__CLPK_integer>) -> Int32
736736

737+
// MARK: - CLAPACK Function Declarations with Correct Signatures
738+
// The CLAPACK header incorrectly declares these as returning int, but the implementation returns void.
739+
// We use @_silgen_name to declare them with the correct void return type to avoid ABI mismatch.
740+
741+
@_silgen_name("dgetrf_")
742+
private func clapack_dgetrf_(
743+
_ m: UnsafeMutablePointer<CLong>,
744+
_ n: UnsafeMutablePointer<CLong>,
745+
_ a: UnsafeMutablePointer<Double>,
746+
_ lda: UnsafeMutablePointer<CLong>,
747+
_ ipiv: UnsafeMutablePointer<CLong>,
748+
_ info: UnsafeMutablePointer<CLong>
749+
) -> Void
750+
751+
@_silgen_name("dgetri_")
752+
private func clapack_dgetri_(
753+
_ n: UnsafeMutablePointer<CLong>,
754+
_ a: UnsafeMutablePointer<Double>,
755+
_ lda: UnsafeMutablePointer<CLong>,
756+
_ ipiv: UnsafeMutablePointer<CLong>,
757+
_ work: UnsafeMutablePointer<Double>,
758+
_ lwork: UnsafeMutablePointer<CLong>,
759+
_ info: UnsafeMutablePointer<CLong>
760+
) -> Void
761+
737762
// MARK: - CLAPACK Wrapper Functions for WASI
738763
// Only dgetrf_ and dgetri_ are available in the CLAPACK eigen-support branch
739764

@@ -761,7 +786,8 @@ internal func dgetrf_(_ m: UnsafeMutablePointer<__CLPK_integer>, _ n: UnsafeMuta
761786
let minMN = min(Int(m.pointee), Int(n.pointee))
762787
var ipivLong = Array<CLong>(repeating: 0, count: minMN)
763788

764-
CLAPACK.dgetrf_(&mLong, &nLong, a, &ldaLong, &ipivLong, &infoLong)
789+
// Use correctly-typed function to avoid ABI mismatch (CLAPACK returns void, not int)
790+
clapack_dgetrf_(&mLong, &nLong, a, &ldaLong, &ipivLong, &infoLong)
765791

766792
for i in 0..<minMN {
767793
ipiv[i] = __CLPK_integer(ipivLong[i])
@@ -786,7 +812,8 @@ internal func dgetri_(_ n: UnsafeMutablePointer<__CLPK_integer>, _ a: UnsafeMuta
786812
ipivLong[i] = CLong(ipiv[i])
787813
}
788814

789-
CLAPACK.dgetri_(&nLong, a, &ldaLong, &ipivLong, work, &lworkLong, &infoLong)
815+
// Use correctly-typed function to avoid ABI mismatch (CLAPACK returns void, not int)
816+
clapack_dgetri_(&nLong, a, &ldaLong, &ipivLong, work, &lworkLong, &infoLong)
790817

791818
info.pointee = __CLPK_integer(infoLong)
792819
return Int32(infoLong)

0 commit comments

Comments
 (0)