Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterating Android tests #5746

Merged
merged 5 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Fix a data race that could cause a reading thread to read from a no-longer-valid memory mapping ([realm/realm-core#6411](https://github.com/realm/realm-core/pull/6411), since v11.3.0-rc.0).
* Fixed an issue that could cause a crash when performing count() on an undefined query. ([realm/realm-core#6443](https://github.com/realm/realm-core/issues/6443), since v12.0.0-alpha.2)
* Added missing implementation of `User.state` and changed the `UserState` enum values to use pascal case to conform to the v11 implementation (except for `UserState.Active` that we now deprecate in favor of `UserState.LoggedIn`). [#5686](https://github.com/realm/realm-js/issues/5686)
* Getting the `indexOf` a missing value will no longer return `4294967295` instead of `-1` and the `Set#has` will no longer return `true` when missing. Caused by an incorrect conversion of `size_t` to `Number` on x86 (32bit) architectures. ([#5746](https://github.com/realm/realm-js/pull/5746), since 12.0.0-alpha.0)

### Compatibility
* React Native >= v0.71.0
Expand Down
9 changes: 9 additions & 0 deletions packages/bindgen/src/realm_js_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,14 @@ auto schedulerWrapBlockingFunction(F&& f)
};
}

/**
* Helps with correct handling of -1/npos for count_t
*/
template <typename T>
auto asSigned(T num)
{
return std::make_signed_t<T>(num);
}

} // namespace
} // namespace realm::js
8 changes: 4 additions & 4 deletions packages/bindgen/src/templates/jsi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ function convertPrimToJsi(addon: JsiAddon, type: string, expr: string): string {
return `jsi::Value(double(${expr}))`;

case "count_t":
// NOTE: using int64_t cast here to get -1.0 for size_t(-1), aka npos.
return `jsi::Value(double(int64_t(${expr})))`;
// NOTE: using asSigned() here to get -1.0 for size_t(-1), aka npos.
return `jsi::Value(double(asSigned(${expr})))`;

case "int64_t":
return `bigIntFromI64(_env, ${expr})`;
Expand Down Expand Up @@ -317,8 +317,8 @@ function convertPrimFromJsi(addon: JsiAddon, type: string, expr: string): string
return `int32_t((${expr}).asNumber())`;

case "count_t":
// NOTE: using int64_t here is important to correctly handle -1.0 aka npos.
return `size_t(int64_t((${expr}).asNumber()))`;
// NOTE: using size_t here is important to correctly handle -1.0 aka npos.
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved
return `size_t(ptrdiff_t((${expr}).asNumber()))`;

case "int64_t":
return `bigIntToI64(_env, jsi::Value(_env, ${expr}))`;
Expand Down
4 changes: 2 additions & 2 deletions packages/bindgen/src/templates/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ function convertPrimToNode(addon: NodeAddon, type: string, expr: string): string
return `Napi::Number::New(${env}, ${expr})`;

case "count_t":
// NOTE: using int64_t cast here to get -1.0 for size_t(-1), aka npos.
return `Napi::Number::New(${env}, int64_t(${expr}))`;
// NOTE: using asSigned() here to get -1.0 for size_t(-1), aka npos.
return `Napi::Number::New(${env}, asSigned(${expr}))`;

case "int64_t":
case "uint64_t":
Expand Down