Skip to content

Commit

Permalink
Start enabling -Wextra and -Wconversion in "rn_xplat_cxx_library" (1/2)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Jan 11, 2024
1 parent 0f2b807 commit 00c8672
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cxx/fbjni/detail/CoreClasses-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ auto JArrayClass<T>::newArray(size_t count) -> local_ref<javaobject> {
static const auto elementClass =
findClassStatic(jtype_traits<T>::kBaseName.c_str());
const auto env = Environment::current();
auto rawArray = env->NewObjectArray(count, elementClass.get(), nullptr);
auto rawArray = env->NewObjectArray(
static_cast<jsize>(count), elementClass.get(), nullptr);
FACEBOOK_JNI_THROW_EXCEPTION_IF(!rawArray);
return adopt_local(static_cast<javaobject>(rawArray));
}
Expand All @@ -434,7 +435,9 @@ template <typename T>
inline void JArrayClass<T>::setElement(size_t idx, T value) {
const auto env = Environment::current();
env->SetObjectArrayElement(
this->self(), idx, detail::toPlainJniReference(value));
this->self(),
static_cast<jsize>(idx),
detail::toPlainJniReference(value));
}

template <typename T>
Expand Down Expand Up @@ -625,7 +628,12 @@ inline void PinnedPrimitiveArray<T, Alloc>::abort() {
template <typename T, typename Alloc>
inline void PinnedPrimitiveArray<T, Alloc>::releaseImpl(jint mode) {
FACEBOOK_JNI_THROW_EXCEPTION_IF(array_.get() == nullptr);
Alloc::release(array_, elements_, start_, size_, mode);
Alloc::release(
array_,
elements_,
static_cast<jint>(start_),
static_cast<jint>(size_),
mode);
}

template <typename T, typename Alloc>
Expand Down

0 comments on commit 00c8672

Please sign in to comment.