From 16cf45ac3ddeca2710112a4bfe2fde817376c92b Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Wed, 17 Feb 2021 17:57:43 -0800 Subject: [PATCH] Migrate Differentiator and RawPropsParser to rn_assert Summary: This will allow these asserts to crash on Android debug builds. We will migrate more sites as we confirm this is stable through testing. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D26409354 fbshipit-source-id: fb35cd8de29890f7c2b761435eaa02de377bdd1e --- ReactCommon/react/renderer/core/BUCK | 1 + ReactCommon/react/renderer/core/RawPropsParser.cpp | 7 ++++--- ReactCommon/react/renderer/debug/BUCK | 10 ---------- ReactCommon/react/renderer/mounting/BUCK | 1 + ReactCommon/react/renderer/mounting/Differentiator.cpp | 7 ++++--- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/ReactCommon/react/renderer/core/BUCK b/ReactCommon/react/renderer/core/BUCK index bda481932dde29..63c5767c9ac19b 100644 --- a/ReactCommon/react/renderer/core/BUCK +++ b/ReactCommon/react/renderer/core/BUCK @@ -58,6 +58,7 @@ rn_xplat_cxx_library( "//xplat/folly:molly", "//xplat/jsi:JSIDynamic", "//xplat/jsi:jsi", + react_native_xplat_target("react/debug:debug"), react_native_xplat_target("react/utils:utils"), react_native_xplat_target("react/renderer/debug:debug"), react_native_xplat_target("react/renderer/graphics:graphics"), diff --git a/ReactCommon/react/renderer/core/RawPropsParser.cpp b/ReactCommon/react/renderer/core/RawPropsParser.cpp index 5735302873a645..b0a795da7e5640 100644 --- a/ReactCommon/react/renderer/core/RawPropsParser.cpp +++ b/ReactCommon/react/renderer/core/RawPropsParser.cpp @@ -8,6 +8,7 @@ #include "RawPropsParser.h" #include +#include #include #include @@ -62,14 +63,14 @@ RawValue const *RawPropsParser::at( // the same order every time. This is trivial if you have a simple Props // constructor, but difficult or impossible if you have a shared sub-prop // Struct that is used by multiple parent Props. -#ifndef NDEBUG +#ifdef RN_DEBUG bool resetLoop = false; #endif do { rawProps.keyIndexCursor_++; if (UNLIKELY(rawProps.keyIndexCursor_ >= size_)) { -#ifndef NDEBUG +#ifdef RN_DEBUG if (resetLoop) { LOG(ERROR) << "Looked up RawProps key that does not exist: " << (std::string)key; @@ -106,7 +107,7 @@ void RawPropsParser::preparse(RawProps const &rawProps) const noexcept { if (!rawProps.value_.isObject()) { LOG(ERROR) << "Preparse props: rawProps value is not object"; } - assert(rawProps.value_.isObject()); + rn_assert(rawProps.value_.isObject()); auto object = rawProps.value_.asObject(runtime); auto names = object.getPropertyNames(runtime); diff --git a/ReactCommon/react/renderer/debug/BUCK b/ReactCommon/react/renderer/debug/BUCK index ffed0b6af41509..9804f184853530 100644 --- a/ReactCommon/react/renderer/debug/BUCK +++ b/ReactCommon/react/renderer/debug/BUCK @@ -37,16 +37,6 @@ rn_xplat_cxx_library( "-std=c++14", "-Wall", ], - exported_platform_linker_flags = [ - ( - "^android.*", - ["-llog"], - ), - ], - fbandroid_linker_flags = [ - # for android rn_assert - "-llog", - ], fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/mounting/BUCK b/ReactCommon/react/renderer/mounting/BUCK index a68a1e314660b8..19f918c2fda153 100644 --- a/ReactCommon/react/renderer/mounting/BUCK +++ b/ReactCommon/react/renderer/mounting/BUCK @@ -57,6 +57,7 @@ rn_xplat_cxx_library( "//xplat/folly:memory", "//xplat/folly:molly", react_native_xplat_target("better:better"), + react_native_xplat_target("react/debug:debug"), react_native_xplat_target("react/renderer/components/root:root"), react_native_xplat_target("react/renderer/components/view:view"), react_native_xplat_target("react/renderer/core:core"), diff --git a/ReactCommon/react/renderer/mounting/Differentiator.cpp b/ReactCommon/react/renderer/mounting/Differentiator.cpp index 7d84711daa198d..2fc0e14ad76c43 100644 --- a/ReactCommon/react/renderer/mounting/Differentiator.cpp +++ b/ReactCommon/react/renderer/mounting/Differentiator.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -82,7 +83,7 @@ class TinyMap final { inline Iterator find(KeyT key) { cleanVector(); - assert(key != 0); + rn_assert(key != 0); if (begin_() == nullptr) { return end(); @@ -98,7 +99,7 @@ class TinyMap final { } inline void insert(Pair pair) { - assert(pair.first != 0); + rn_assert(pair.first != 0); vector_.push_back(pair); } @@ -1489,7 +1490,7 @@ ShadowViewMutation::List calculateShadowViewMutations( SystraceSection s("calculateShadowViewMutations"); // Root shadow nodes must be belong the same family. - assert(ShadowNode::sameFamily(oldRootShadowNode, newRootShadowNode)); + rn_assert(ShadowNode::sameFamily(oldRootShadowNode, newRootShadowNode)); auto mutations = ShadowViewMutation::List{}; mutations.reserve(256);