diff --git a/Source/MLX/ErrorHandler.swift b/Source/MLX/ErrorHandler.swift index f7d16d82..85faa1f2 100644 --- a/Source/MLX/ErrorHandler.swift +++ b/Source/MLX/ErrorHandler.swift @@ -282,6 +282,11 @@ private let errorHandler: ErrorHandler = { return ErrorHandler() }() +/// Ensure that the error handler is installed. +func initError() { + _ = errorHandler +} + /// Forward the error to the `ErrorHandler` singleton. See `errorHandler` (above) for how this is /// installed. private func errorHandlerTrampoline(message: UnsafePointer?, data: UnsafeMutableRawPointer?) diff --git a/Source/MLX/MLXArray.swift b/Source/MLX/MLXArray.swift index fe5dbeae..2fefccca 100644 --- a/Source/MLX/MLXArray.swift +++ b/Source/MLX/MLXArray.swift @@ -14,6 +14,9 @@ public final class MLXArray { /// /// This initializer is for `Cmlx` interoperation. public init(_ ctx: consuming mlx_array) { + // We don't have lifecycle control over the MLX system but all interesting + // paths will come through here -- make sure the error handler is installed. + initError() self.ctx = ctx }