-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use NSCAssert() in react_native_assert instead of C assert() (#36177)
Summary: Pull Request resolved: #36177 react_native_assert calls C `assert()`, where XCode does not have a built-in breakpoint navigator to hook to assertion failures (though you can add a symbolic breakpoint to "abort()" to get the effect). This changes the Apple implemented of `react_native_assert()` to use `NSCAssert` under the hood. This is safe to use in C functions, but will be trapped by the default XCode exceptions breakpoint navigator. Changelog: [iOS][Fixed] - Use NSCAssert() in react_native_assert instead of C assert() Reviewed By: cipolleschi Differential Revision: D43275024 fbshipit-source-id: 43c4e4f1ae6b99f32634d4b1880bce712c3ae8f6
- Loading branch information
1 parent
96b2ca4
commit c5bc3f1
Showing
6 changed files
with
37 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import <Foundation/NSException.h> | ||
#import <glog/logging.h> | ||
#import <react/debug/react_native_assert.h> | ||
|
||
#ifdef REACT_NATIVE_DEBUG | ||
|
||
extern "C" void react_native_assert_fail(const char *func, const char *file, int line, const char *expr) | ||
{ | ||
// flush logs because some might be lost on iOS if an assert is hit right after | ||
// this. If you are trying to debug something actively and have added lots of | ||
// LOG statements to track down an issue, there is race between flushing the | ||
// final logs and stopping execution when the assert hits. Thus, if we know an | ||
// assert will fail, we force flushing to happen right before the assert. | ||
LOG(ERROR) << "react_native_assert failure: " << expr; | ||
google::FlushLogFiles(google::GLOG_INFO /*min_severity*/); | ||
|
||
NSCAssert(false, @"%s:%d: function %s: assertion failed (%s)", file, line, func, expr); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters