11/*
2- * Copyright 2019 Google
2+ * Copyright 2019 Google LLC
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1414 * limitations under the License.
1515 */
1616
17- #ifndef FIREBASE_FIRESTORE_CLIENT_CPP_SRC_IOS_HARD_ASSERT_IOS_H_
18- #define FIREBASE_FIRESTORE_CLIENT_CPP_SRC_IOS_HARD_ASSERT_IOS_H_
17+ #ifndef FIREBASE_FIRESTORE_CLIENT_CPP_SRC_COMMON_HARD_ASSERT_COMMON_H_
18+ #define FIREBASE_FIRESTORE_CLIENT_CPP_SRC_COMMON_HARD_ASSERT_COMMON_H_
19+
20+ // TODO(b/163140650): Remove this/unify with the iOS implementation.
21+ // On Android we still support customers building with STLPort, which precludes
22+ // use of Abseil here.
1923
2024#include < string>
2125#include < utility>
2226
23- #include " absl/base/optimization.h"
24- #include " Firestore/core/src/util/exception.h"
27+ #include " firestore/src/common/macros.h"
2528
26- // TODO(b/147444199): delete this file and use the one that comes from the
27- // GitHub repo. This file provides simplified versions of `HARD_ASSERT`,
28- // `HARD_FAIL`, and `ThrowInvalidArgument` that don't support string formatting.
29+ # if !defined(__ANDROID__)
30+ # include " Firestore/core/src/util/hard_assert.h "
31+ # endif // !defined(__ANDROID__)
2932
30- #if defined(_MSC_VER)
31- #define FIRESTORE_FUNCTION_NAME __FUNCSIG__
32- #else
33- #define FIRESTORE_FUNCTION_NAME __PRETTY_FUNCTION__
34- #endif
33+ #if defined(__ANDROID__)
3534
3635/* *
3736 * Invokes the internal Fail function below with all the required contextual
4241 */
4342#define INVOKE_INTERNAL_FAIL (...) \
4443 firebase::firestore::util::internal::FailAssertion ( \
45- __FILE__, FIRESTORE_FUNCTION_NAME, __LINE__, __VA_ARGS__)
44+ __FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
45+
46+ #endif // !defined(__ANDROID__)
4647
4748/* *
4849 * Fails the current function if the given condition is false.
4950 *
5051 * Unlike assert(3) or NSAssert, this macro is never compiled out.
5152 *
53+ * Note: this version of `HARD_ASSERT` is deliberately simplified to avoid
54+ * using `util::StringFormat`.
55+ *
5256 * @param condition The condition to test.
5357 * @param message (optional) A message to print.
5458 */
55-
56- // Note: this version of `HARD_ASSERT` is deliberately dumbed down to avoid
57- // using `util::StringFormat`.
58- #define HARD_ASSERT_IOS (condition, ...) \
59+ #define SIMPLE_HARD_ASSERT (condition, ...) \
5960 do { \
60- if (!ABSL_PREDICT_TRUE (condition)) { \
61+ if (!FIRESTORE_PREDICT_TRUE (condition)) { \
6162 std::string _message{__VA_ARGS__}; \
6263 INVOKE_INTERNAL_FAIL (_message, #condition); \
6364 } \
7071 *
7172 * @param message (optional) A message to print.
7273 */
73- #define HARD_FAIL_IOS (...) \
74+ #define SIMPLE_HARD_FAIL (...) \
7475 do { \
7576 std::string _failure{__VA_ARGS__}; \
7677 INVOKE_INTERNAL_FAIL (_failure); \
7778 } while (0 )
7879
79- /* *
80- * Indicates an area of the code that cannot be reached (except possibly due to
81- * undefined behaviour or other similar badness). The only reasonable thing to
82- * do in these cases is to immediately abort.
83- */
84- #define UNREACHABLE () abort()
80+ #if defined(__ANDROID__)
8581
8682/* *
8783 * Returns the given `ptr` if it is non-null; otherwise, results in a failed
9692 * @param ptr The pointer to check and return. Can be a smart pointer.
9793 */
9894#define NOT_NULL (ptr ) \
99- (static_cast <void >(ABSL_PREDICT_FALSE ((ptr) == nullptr ) \
95+ (static_cast <void >(FIRESTORE_PREDICT_FALSE ((ptr) == nullptr ) \
10096 ? INVOKE_INTERNAL_FAIL(" Expected non-null " #ptr) \
10197 : static_cast <void >(0 )), \
10298 (ptr)) // NOLINT(whitespace/indent)
@@ -107,17 +103,22 @@ namespace util {
107103namespace internal {
108104
109105// A no-return helper function. To raise an assertion, use Macro instead.
110- ABSL_ATTRIBUTE_NORETURN void FailAssertion (const char * file, const char * func,
111- int line,
112- const std::string& message);
106+ // These symbols are in the util::internal namespace to match their iOS
107+ // equivalents.
108+ FIRESTORE_ATTRIBUTE_NORETURN void FailAssertion (const char * file,
109+ const char * func, int line,
110+ const std::string& message);
113111
114- ABSL_ATTRIBUTE_NORETURN void FailAssertion (const char * file, const char * func,
115- int line, const std::string& message,
116- const char * condition);
112+ FIRESTORE_ATTRIBUTE_NORETURN void FailAssertion (const char * file,
113+ const char * func, int line,
114+ const std::string& message,
115+ const char * condition);
117116
118117} // namespace internal
119118} // namespace util
120119} // namespace firestore
121120} // namespace firebase
122121
123- #endif // FIREBASE_FIRESTORE_CLIENT_CPP_SRC_IOS_HARD_ASSERT_IOS_H_
122+ #endif // defined(__ANDROID__)
123+
124+ #endif // FIREBASE_FIRESTORE_CLIENT_CPP_SRC_COMMON_HARD_ASSERT_COMMON_H_
0 commit comments