Skip to content

Commit cf4963f

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Start enabling -Wextra and -Wconversion in "rn_xplat_cxx_library" (1/2)
Summary: ## Stack These can suss out some real bugs, and helps further avoid mismatch with downstream MSVC on /W4 as used by MSFT. I enabled the families of warnings, but suppressed some major individual warnings that weren't clean. But I did clean some up, notably, missing initializer, and shortening 64 bit to 32 bit. We can do some of the rest incrementally (e.g. `-Wunused-parameter` has a fixit). This change illuminates that MapBuffer is missing 64 bit integer support, but we often pass 64 bit counters to it, which is a bug. For now I just left TODOs around those. `rn_xplat_cxx_library` is used for external libraries interfacing with RN, which we probably don't want to police, so I structured these stricter warnings as an opt-in flag, only enabled for our own rules. ## Diff This fixes up source code to avoid emitting the extra warnings now enforced. Of what is enabled, this is mostly shortening 64 to 32, or missing field in initializer. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D52589303 fbshipit-source-id: 11cb778d065799fd0ead3ae706934146d13500bb
1 parent 822bf52 commit cf4963f

File tree

25 files changed

+77
-59
lines changed

25 files changed

+77
-59
lines changed

packages/react-native/React/Base/RCTBridgeModule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ RCT_EXTERN_C_END
236236
*/
237237
#define RCT_REMAP_METHOD(js_name, method) \
238238
_RCT_EXTERN_REMAP_METHOD(js_name, method, NO) \
239-
-(void)method RCT_DYNAMIC;
239+
-(void)method RCT_DYNAMIC
240240

241241
/**
242242
* Similar to RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD but lets you set
@@ -248,7 +248,7 @@ RCT_EXTERN_C_END
248248
*/
249249
#define RCT_REMAP_BLOCKING_SYNCHRONOUS_METHOD(js_name, returnType, method) \
250250
_RCT_EXTERN_REMAP_METHOD(js_name, method, YES) \
251-
-(returnType)method RCT_DYNAMIC;
251+
-(returnType)method RCT_DYNAMIC
252252

253253
/**
254254
* Use this macro in a private Objective-C implementation file to automatically

packages/react-native/ReactAndroid/src/main/jni/react/fabric/CoreComponentsRegistry.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ CoreComponentsRegistry::initHybrid(
8585
[](const EventDispatcher::Weak& eventDispatcher,
8686
const ContextContainer::Shared& contextContainer)
8787
-> ComponentDescriptorRegistry::Shared {
88+
ComponentDescriptorParameters params{
89+
.eventDispatcher = eventDispatcher,
90+
.contextContainer = contextContainer,
91+
.flavor = nullptr};
92+
8893
auto registry = CoreComponentsRegistry::sharedProviderRegistry()
89-
->createComponentDescriptorRegistry(
90-
{eventDispatcher, contextContainer});
94+
->createComponentDescriptorRegistry(params);
9195
auto& mutableRegistry = const_cast<ComponentDescriptorRegistry&>(*registry);
9296
mutableRegistry.setFallbackComponentDescriptor(
93-
std::make_shared<UnimplementedNativeViewComponentDescriptor>(
94-
ComponentDescriptorParameters{
95-
eventDispatcher, contextContainer, nullptr}));
97+
std::make_shared<UnimplementedNativeViewComponentDescriptor>(params));
9698

9799
return registry;
98100
};

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static inline int getIntBufferSizeForType(CppMountItem::Type mountItemType) {
8585

8686
static inline void updateBufferSizes(
8787
CppMountItem::Type mountItemType,
88-
int numInstructions,
88+
size_t numInstructions,
8989
int& batchMountItemIntsSize,
9090
int& batchMountItemObjectsSize) {
9191
if (numInstructions == 0) {
@@ -182,7 +182,7 @@ static inline void computeBufferSizes(
182182

183183
static inline void writeIntBufferTypePreamble(
184184
int mountItemType,
185-
int numItems,
185+
size_t numItems,
186186
_JNIEnv* env,
187187
jintArray& intBufferArray,
188188
int& intBufferPosition) {
@@ -193,7 +193,7 @@ static inline void writeIntBufferTypePreamble(
193193
intBufferPosition += 1;
194194
} else {
195195
temp[0] = mountItemType | CppMountItem::Type::Multiple;
196-
temp[1] = numItems;
196+
temp[1] = static_cast<jint>(numItems);
197197
env->SetIntArrayRegion(intBufferArray, intBufferPosition, 2, temp);
198198
intBufferPosition += 2;
199199
}

packages/react-native/ReactAndroid/src/main/jni/react/fabric/ReactNativeConfigHolder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#import "ReactNativeConfigHolder.h"
8+
#include "ReactNativeConfigHolder.h"
99

1010
#include <fbjni/fbjni.h>
1111

packages/react-native/ReactAndroid/src/main/jni/react/jni/MethodInvoker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ jint extractInteger(const folly::dynamic& value) {
5959
// The logic here is taken from convertDynamicIfIntegral, but the
6060
// return type and exception are different.
6161
if (value.isInt()) {
62-
return value.getInt();
62+
// TODO: this truncates 64 bit ints, valid in JS
63+
return static_cast<jint>(value.getInt());
6364
}
6465
double dbl = value.getDouble();
6566
jint result = static_cast<jint>(dbl);
@@ -227,7 +228,7 @@ MethodCallResult MethodInvoker::invoke(
227228

228229
auto env = Environment::current();
229230
auto argCount = signature_.size() - 2;
230-
JniLocalScope scope(env, argCount);
231+
JniLocalScope scope(env, static_cast<int>(argCount));
231232
jvalue args[argCount];
232233
std::transform(
233234
signature_.begin() + 2,

packages/react-native/ReactAndroid/src/main/jni/react/jni/ReadableNativeArray.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void ReadableNativeArray::mapException(std::exception_ptr ex) {
2323
}
2424

2525
local_ref<JArrayClass<jobject>> ReadableNativeArray::importArray() {
26-
jint size = array_.size();
26+
auto size = static_cast<jint>(array_.size());
2727
auto jarray = JArrayClass<jobject>::newArray(size);
2828
for (jint ii = 0; ii < size; ii++) {
2929
addDynamicToJArray(jarray, ii, array_.at(ii));
@@ -32,7 +32,7 @@ local_ref<JArrayClass<jobject>> ReadableNativeArray::importArray() {
3232
}
3333

3434
local_ref<JArrayClass<jobject>> ReadableNativeArray::importTypeArray() {
35-
jint size = array_.size();
35+
auto size = static_cast<jint>(array_.size());
3636
auto jarray = JArrayClass<jobject>::newArray(size);
3737
for (jint ii = 0; ii < size; ii++) {
3838
(*jarray)[ii] = ReadableType::getType(array_.at(ii).type());

packages/react-native/ReactAndroid/src/main/jni/react/jni/ReadableNativeMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ local_ref<JArrayClass<jstring>> ReadableNativeMap::importKeys() {
8080
local_ref<JArrayClass<jobject>> ReadableNativeMap::importValues() {
8181
throwIfConsumed();
8282

83-
jint size = keys_.value().size();
83+
auto size = static_cast<jint>(keys_.value().size());
8484
auto jarray = JArrayClass<jobject>::newArray(size);
8585
for (jint ii = 0; ii < size; ii++) {
8686
const std::string& key = (*keys_)[ii].getString();
@@ -92,7 +92,7 @@ local_ref<JArrayClass<jobject>> ReadableNativeMap::importValues() {
9292
local_ref<JArrayClass<jobject>> ReadableNativeMap::importTypes() {
9393
throwIfConsumed();
9494

95-
jint size = keys_.value().size();
95+
auto size = static_cast<jint>(keys_.value().size());
9696
auto jarray = JArrayClass<jobject>::newArray(size);
9797
for (jint ii = 0; ii < size; ii++) {
9898
const std::string& key = (*keys_)[ii].getString();

packages/react-native/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultComponentsRegistry.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ DefaultComponentsRegistry::initHybrid(
4040
[](const EventDispatcher::Weak& eventDispatcher,
4141
const ContextContainer::Shared& contextContainer)
4242
-> ComponentDescriptorRegistry::Shared {
43+
ComponentDescriptorParameters params{
44+
.eventDispatcher = eventDispatcher,
45+
.contextContainer = contextContainer,
46+
.flavor = nullptr};
47+
4348
auto registry = DefaultComponentsRegistry::sharedProviderRegistry()
44-
->createComponentDescriptorRegistry(
45-
{eventDispatcher, contextContainer});
49+
->createComponentDescriptorRegistry(params);
4650

4751
auto& mutableRegistry = const_cast<ComponentDescriptorRegistry&>(*registry);
4852
mutableRegistry.setFallbackComponentDescriptor(
49-
std::make_shared<UnimplementedNativeViewComponentDescriptor>(
50-
ComponentDescriptorParameters{
51-
eventDispatcher, contextContainer, nullptr}));
53+
std::make_shared<UnimplementedNativeViewComponentDescriptor>(params));
5254

5355
return registry;
5456
};

packages/react-native/ReactCommon/cxxreact/JSBigString.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ JSBigFileString::JSBigFileString(int fd, size_t size, off_t offset /*= 0*/)
3838
const static auto ps = sysconf(_SC_PAGESIZE);
3939
auto d = lldiv(offset, ps);
4040

41-
m_mapOff = d.quot;
42-
m_pageOff = d.rem;
41+
m_mapOff = static_cast<off_t>(d.quot);
42+
m_pageOff = static_cast<off_t>(d.rem);
4343
m_size = size + m_pageOff;
4444
} else {
4545
m_mapOff = 0;

packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,15 @@ JNIArgs convertJSIArgsToJNIArgs(
250250
size_t count,
251251
const std::shared_ptr<CallInvoker>& jsInvoker,
252252
TurboModuleMethodValueKind valueKind) {
253-
unsigned int expectedArgumentCount = valueKind == PromiseKind
253+
size_t expectedArgumentCount = valueKind == PromiseKind
254254
? methodArgTypes.size() - 1
255255
: methodArgTypes.size();
256256

257257
if (expectedArgumentCount != count) {
258258
throw JavaTurboModuleInvalidArgumentCountException(
259-
methodName, count, expectedArgumentCount);
259+
methodName,
260+
static_cast<int>(count),
261+
static_cast<int>(expectedArgumentCount));
260262
}
261263

262264
JNIArgs jniArgs(valueKind == PromiseKind ? count + 1 : count);
@@ -505,7 +507,8 @@ jsi::Value JavaTurboModule::invokeJavaMethod(
505507
* GlobalReferences. The LocalReferences are then promptly deleted
506508
* after the conversion.
507509
*/
508-
unsigned int actualArgCount = valueKind == VoidKind ? 0 : argCount;
510+
unsigned int actualArgCount =
511+
valueKind == VoidKind ? 0 : static_cast<unsigned int>(argCount);
509512
unsigned int estimatedLocalRefCount =
510513
actualArgCount + maxReturnObjects + buffer;
511514

0 commit comments

Comments
 (0)