Skip to content

Commit

Permalink
Refine error checks in onnxruntime/core/providers/coreml/model/model.…
Browse files Browse the repository at this point in the history
…mm. (#18620)

#18606 updated the original error checks to check that the returned object != nil to appease the static analyzer. However, per the API docs, checking `error != nil` is the way to determine whether an error occurred. This change adds back the `error != nil` check to be safe.
  • Loading branch information
edgchen1 authored Nov 29, 2023
1 parent d2dfbf4 commit 483c490
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions onnxruntime/core/providers/coreml/model/model.mm
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Status CreateInputFeatureProvider(const std::unordered_map<std::string, OnnxTens
deallocator:^(void* /* bytes */) {
}
error:&error];
ORT_RETURN_IF(multi_array == nil,
ORT_RETURN_IF(error != nil || multi_array == nil,
"Failed to create MLMultiArray for feature: ", name,
(error != nil) ? MakeString(", error: ", [[error localizedDescription] UTF8String]) : "");

Expand All @@ -170,7 +170,7 @@ Status CreateInputFeatureProvider(const std::unordered_map<std::string, OnnxTens

auto* feature_provider = [[MLDictionaryFeatureProvider alloc] initWithDictionary:feature_dictionary
error:&error];
ORT_RETURN_IF(feature_provider == nil,
ORT_RETURN_IF(error != nil || feature_provider == nil,
"Failed to create MLDictionaryFeatureProvider",
(error != nil) ? MakeString(", error: ", [[error localizedDescription] UTF8String]) : "");

Expand Down Expand Up @@ -303,12 +303,12 @@ - (void)dealloc {
}

- (Status)loadModel {
NSError* error = nil;
NSURL* modelUrl = [NSURL URLWithString:coreml_model_path_];
if (modelUrl == nil) {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Failed to create model URL from path");
}

NSError* error = nil;
NSURL* compileUrl = [MLModel compileModelAtURL:modelUrl error:&error];

if (error != nil) {
Expand All @@ -324,7 +324,7 @@ - (Status)loadModel {
: MLComputeUnitsAll;
_model = [MLModel modelWithContentsOfURL:compileUrl configuration:config error:&error];

if (_model == nil) {
if (error != nil || _model == nil) {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Failed to create MLModel",
(error != nil) ? MakeString(", error: ", [[error localizedDescription] UTF8String]) : "");
}
Expand Down

0 comments on commit 483c490

Please sign in to comment.