From 00c867220b04f90e128c2ae49178e51354ddc9fa Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 11 Jan 2024 01:11:41 -0800 Subject: [PATCH] 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 --- cxx/fbjni/detail/CoreClasses-inl.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cxx/fbjni/detail/CoreClasses-inl.h b/cxx/fbjni/detail/CoreClasses-inl.h index bf70fc4..96c2af4 100644 --- a/cxx/fbjni/detail/CoreClasses-inl.h +++ b/cxx/fbjni/detail/CoreClasses-inl.h @@ -425,7 +425,8 @@ auto JArrayClass::newArray(size_t count) -> local_ref { static const auto elementClass = findClassStatic(jtype_traits::kBaseName.c_str()); const auto env = Environment::current(); - auto rawArray = env->NewObjectArray(count, elementClass.get(), nullptr); + auto rawArray = env->NewObjectArray( + static_cast(count), elementClass.get(), nullptr); FACEBOOK_JNI_THROW_EXCEPTION_IF(!rawArray); return adopt_local(static_cast(rawArray)); } @@ -434,7 +435,9 @@ template inline void JArrayClass::setElement(size_t idx, T value) { const auto env = Environment::current(); env->SetObjectArrayElement( - this->self(), idx, detail::toPlainJniReference(value)); + this->self(), + static_cast(idx), + detail::toPlainJniReference(value)); } template @@ -625,7 +628,12 @@ inline void PinnedPrimitiveArray::abort() { template inline void PinnedPrimitiveArray::releaseImpl(jint mode) { FACEBOOK_JNI_THROW_EXCEPTION_IF(array_.get() == nullptr); - Alloc::release(array_, elements_, start_, size_, mode); + Alloc::release( + array_, + elements_, + static_cast(start_), + static_cast(size_), + mode); } template