From 8037a4bf79b8ae49162c2b6f099d62ec17a7f283 Mon Sep 17 00:00:00 2001 From: Gil Date: Thu, 24 May 2018 11:00:23 -0700 Subject: Replace Objective-C assertions with C++ assertions (#1327) * Migrate FSTFail to HARD_FAIL * FSTCFail -> HARD_FAIL * FSTCAssert -> HARD_ASSERT * FSTAssert -> HARD_ASSERT * Replace FSTAssert with NSAssert in dead Objective-C code * Remove FSTAssert.h --- Firestore/Source/Util/FSTAssert.h | 77 ------------------------------ Firestore/Source/Util/FSTDispatchQueue.mm | 4 +- Firestore/Source/Util/FSTUsageValidation.h | 2 +- 3 files changed, 3 insertions(+), 80 deletions(-) delete mode 100644 Firestore/Source/Util/FSTAssert.h (limited to 'Firestore/Source/Util') diff --git a/Firestore/Source/Util/FSTAssert.h b/Firestore/Source/Util/FSTAssert.h deleted file mode 100644 index 610d306..0000000 --- a/Firestore/Source/Util/FSTAssert.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2017 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -// Fails the current Objective-C method if the given condition is false. -// -// Unlike NSAssert, this macro is never compiled out if assertions are disabled. -#define FSTAssert(condition, format, ...) \ - do { \ - if (!(condition)) { \ - FSTFail((format), ##__VA_ARGS__); \ - } \ - } while (0) - -// Fails the current C function if the given condition is false. -// -// Unlike NSCAssert, this macro is never compiled out if assertions are disabled. -#define FSTCAssert(condition, format, ...) \ - do { \ - if (!(condition)) { \ - FSTCFail((format), ##__VA_ARGS__); \ - } \ - } while (0) - -// Unconditionally fails the current Objective-C method. -// -// This macro fails by calling [[NSAssertionHandler currentHandler] handleFailureInMethod]. It -// also calls abort(3) in order to make this macro appear to never return, even though the call -// to handleFailureInMethod itself never returns. -#define FSTFail(format, ...) \ - do { \ - NSString *_file = [NSString stringWithUTF8String:__FILE__]; \ - NSString *_description = [NSString stringWithFormat:(format), ##__VA_ARGS__]; \ - [[NSAssertionHandler currentHandler] \ - handleFailureInMethod:_cmd \ - object:self \ - file:_file \ - lineNumber:__LINE__ \ - description:@"FIRESTORE INTERNAL ASSERTION FAILED: %@", _description]; \ - abort(); \ - } while (0) - -// Unconditionally fails the current C function. -// -// This macro fails by calling [[NSAssertionHandler currentHandler] handleFailureInFunction]. It -// also calls abort(3) in order to make this macro appear to never return, even though the call -// to handleFailureInFunction itself never returns. -#define FSTCFail(format, ...) \ - do { \ - NSString *_file = [NSString stringWithUTF8String:__FILE__]; \ - NSString *_function = [NSString stringWithUTF8String:__PRETTY_FUNCTION__]; \ - NSString *_description = [NSString stringWithFormat:(format), ##__VA_ARGS__]; \ - [[NSAssertionHandler currentHandler] \ - handleFailureInFunction:_function \ - file:_file \ - lineNumber:__LINE__ \ - description:@"FIRESTORE INTERNAL ASSERTION FAILED: %@", _description]; \ - abort(); \ - } while (0) - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Util/FSTDispatchQueue.mm b/Firestore/Source/Util/FSTDispatchQueue.mm index 01b2732..b921484 100644 --- a/Firestore/Source/Util/FSTDispatchQueue.mm +++ b/Firestore/Source/Util/FSTDispatchQueue.mm @@ -19,11 +19,11 @@ #include #include -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTDispatchQueue.h" #include "Firestore/core/src/firebase/firestore/util/async_queue.h" #include "Firestore/core/src/firebase/firestore/util/executor_libdispatch.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "absl/memory/memory.h" using firebase::firestore::util::AsyncQueue; @@ -74,7 +74,7 @@ NS_ASSUME_NONNULL_BEGIN case TimerId::OnlineStateTimeout: return converted; default: - FSTAssert(false, @"Unknown value of enum FSTTimerID."); + HARD_FAIL("Unknown value of enum FSTTimerID."); } } diff --git a/Firestore/Source/Util/FSTUsageValidation.h b/Firestore/Source/Util/FSTUsageValidation.h index 05933ea..afc5412 100644 --- a/Firestore/Source/Util/FSTUsageValidation.h +++ b/Firestore/Source/Util/FSTUsageValidation.h @@ -30,7 +30,7 @@ NSException *FSTInvalidUsage(NSString *exceptionName, NSString *format, ...); * invalid method arguments. * * For recoverable runtime errors, use NSError**. - * For internal programming errors, use FSTFail(). + * For internal programming errors, use HARD_FAIL(). */ #define FSTThrowInvalidUsage(exceptionName, format, ...) \ do { \ -- cgit v1.2.3