From 664eb5660389695cb9be0a55f616f4bf6702c3b8 Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Thu, 12 Jun 2025 20:26:37 -0700 Subject: [PATCH] Return retained objects from NSError constructors. Summary: Don't use autorelease pool Reviewed By: cccclai Differential Revision: D76491603 --- extension/apple/ExecuTorch/Exported/ExecuTorchError.h | 2 ++ extension/apple/ExecuTorch/Exported/ExecuTorchError.m | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchError.h b/extension/apple/ExecuTorch/Exported/ExecuTorchError.h index 4c6fa574588..6a8ab7bc2fc 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchError.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchError.h @@ -63,6 +63,7 @@ NSString *ExecuTorchErrorDescription(ExecuTorchErrorCode code) * @return An NSError with ExecuTorchErrorDomain, the specified code, and a localized description. */ FOUNDATION_EXPORT +NS_RETURNS_RETAINED __attribute__((deprecated("This API is experimental."))) NSError *ExecuTorchErrorWithCode(ExecuTorchErrorCode code) NS_SWIFT_NAME(Error(code:)); @@ -75,6 +76,7 @@ NSError *ExecuTorchErrorWithCode(ExecuTorchErrorCode code) * @return An NSError with ExecuTorchErrorDomain, the specified code, and a localized description. */ FOUNDATION_EXPORT + NS_RETURNS_RETAINED __attribute__((deprecated("This API is experimental."))) NSError *ExecuTorchErrorWithCodeAndDescription(ExecuTorchErrorCode code, NSString * __nullable description) NS_SWIFT_NAME(Error(code:description:)); diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchError.m b/extension/apple/ExecuTorch/Exported/ExecuTorchError.m index c54acb20e75..20b3af2e349 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchError.m +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchError.m @@ -58,9 +58,9 @@ } NSError *ExecuTorchErrorWithCodeAndDescription(ExecuTorchErrorCode code, NSString * __nullable description) { - return [NSError errorWithDomain:ExecuTorchErrorDomain - code:code - userInfo:@{ + return [[NSError alloc] initWithDomain:ExecuTorchErrorDomain + code:code + userInfo:@{ NSLocalizedDescriptionKey: description.length > 0 ? [ExecuTorchErrorDescription(code) stringByAppendingFormat:@": %@", description]