diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm index 69bb59c860e..eeb3b3929e5 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm @@ -258,11 +258,11 @@ - (instancetype)initWithFilePath:(NSString *)filePath std::vector dataFilePathsVector; if (dataFilePaths != nil) { for (NSString *dataFile in dataFilePaths) { - dataFilePathsVector.emplace_back(dataFile.UTF8String); + dataFilePathsVector.emplace_back(dataFile.UTF8String ?: ""); } } _module = std::make_unique( - filePath.UTF8String, + filePath.UTF8String ?: "", dataFilePathsVector, static_cast(loadMode) ); @@ -314,7 +314,7 @@ - (BOOL)isLoaded { - (BOOL)loadMethod:(NSString *)methodName error:(NSError **)error { - const auto errorCode = _module->load_method(methodName.UTF8String); + const auto errorCode = _module->load_method(methodName.UTF8String ?: ""); if (errorCode != Error::Ok) { if (error) { *error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode); @@ -325,11 +325,11 @@ - (BOOL)loadMethod:(NSString *)methodName } - (BOOL)isMethodLoaded:(NSString *)methodName { - return _module->is_method_loaded(methodName.UTF8String); + return _module->is_method_loaded(methodName.UTF8String ?: ""); } - (BOOL)unloadMethod:(NSString *)methodName { - const auto didUnload = _module->unload_method(methodName.UTF8String); + const auto didUnload = _module->unload_method(methodName.UTF8String ?: ""); [_inputs removeObjectForKey:methodName]; [_outputs removeObjectForKey:methodName]; return didUnload; @@ -352,7 +352,7 @@ - (BOOL)unloadMethod:(NSString *)methodName { - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName error:(NSError **)error { - const auto result = _module->method_meta(methodName.UTF8String); + const auto result = _module->method_meta(methodName.UTF8String ?: ""); if (!result.ok()) { if (error) { *error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)result.error()); @@ -366,7 +366,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName - (nullable NSArray *)executeMethod:(NSString *)methodName withInputs:(NSArray *)values error:(NSError **)error { - const char *methodNameString = methodName.UTF8String; + const char *methodNameString = methodName.UTF8String ?: ""; __block auto errorCode = Error::Ok; [values enumerateObjectsUsingBlock:^(ExecuTorchValue *value, NSUInteger index, BOOL *stop) { errorCode = _module->set_input(methodNameString, toEValue(value), index); @@ -497,7 +497,7 @@ - (BOOL)setInput:(ExecuTorchValue *)value forMethod:(NSString *)methodName atIndex:(NSInteger)index error:(NSError **)error { - const auto errorCode = _module->set_input(methodName.UTF8String, toEValue(value), index); + const auto errorCode = _module->set_input(methodName.UTF8String ?: "", toEValue(value), index); if (errorCode != Error::Ok) { if (error) { *error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode); @@ -537,7 +537,7 @@ - (BOOL)setInputs:(NSArray *)values for (ExecuTorchValue *value in values) { inputs.push_back(toEValue(value)); } - const auto errorCode = _module->set_inputs(methodName.UTF8String, inputs); + const auto errorCode = _module->set_inputs(methodName.UTF8String ?: "", inputs); if (errorCode != Error::Ok) { if (error) { *error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode); @@ -580,7 +580,7 @@ - (BOOL)setOutput:(ExecuTorchValue *)value forMethod:(NSString *)methodName atIndex:(NSInteger)index error:(NSError **)error { - const auto errorCode = _module->set_output(methodName.UTF8String, toEValue(value), index); + const auto errorCode = _module->set_output(methodName.UTF8String ?: "", toEValue(value), index); if (errorCode != Error::Ok) { if (error) { *error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode);