Skip to content

Commit 60a3047

Browse files
committed
Fix some warning in WASM builds
1 parent bab1f10 commit 60a3047

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

Sources/Matft/library/lapack.swift

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

734734
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
735735

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

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

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

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

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

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

0 commit comments

Comments
 (0)