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

RCPP-46 fix type safe queries #171

Merged
merged 16 commits into from
Mar 6, 2024
Merged
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ X.Y.Z Release notes (YYYY-MM-DD)

### Fixed
* Managed objects would exhibit undefined behaviour when returned from the subscript operator in `std::vector` & `std::map`.
* Type safe queries would not work correctly when link properties were used.

### Enhancements
* Add `realm::holds_alternative` which acts as a substitute to `std::holds_alternative` when using `managed<realm::mixed>`.
Expand All @@ -18,7 +19,7 @@ X.Y.Z Release notes (YYYY-MM-DD)
* Fileformat: Generates files with format v23. Reads and automatically upgrade from fileformat v5.

### Internals
* None
* Upgraded to Core v14.1.0

----------------------------------------------

Expand Down Expand Up @@ -313,4 +314,4 @@ The following functions now return `std::future` instead of `std::promise`
### Internals
* Upgraded to Core v13.9.2

----------------------------------------------
----------------------------------------------
23 changes: 21 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import PackageDescription

let sdkVersion = Version("1.0.0")
let coreVersion = Version("13.26.0")
let coreVersion = Version("14.1.0")

var cxxSettings: [CXXSetting] = [
.define("REALM_ENABLE_SYNC", to: "1"),
Expand Down Expand Up @@ -61,7 +61,7 @@ let package = Package(
targets: ["realm-cpp-sdk"]),
],
dependencies: [
.package(url: "https://github.com/realm/realm-core.git", revision: "334d534a49b39d70f1b2ae5d982272e30f74dd82")
.package(url: "https://github.com/realm/realm-core.git", revision: "08c61e87add15b0d7fcd52c818c43fb4804e1216")
],
targets: [
cppSdkTarget,
Expand Down Expand Up @@ -97,6 +97,25 @@ let package = Package(
sources: [
"main.hpp",
"main.cpp",
"db/binary_tests.cpp",
"db/date_tests.cpp",
"db/decimal_tests.cpp",
"db/embedded_object_tests.cpp",
"db/frozen_tests.cpp",
"db/list_tests.cpp",
"db/map_tests.cpp",
"db/mixed_tests.cpp",
"db/numeric_tests.cpp",
"db/object_id_tests.cpp",
"db/object_tests.cpp",
"db/optional_tests.cpp",
"db/performance_tests.cpp",
"db/query_tests.cpp",
"db/realm_tests.cpp",
"db/results_tests.cpp",
"db/run_loop_tests.cpp",
"db/set_tests.cpp",
"db/string_tests.cpp"
],
resources: [
.copy("setup_baas.rb"),
Expand Down
2 changes: 1 addition & 1 deletion ports/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vcpkg_execute_required_process(
LOGNAME submodules
)

set(CPPREALM_CMAKE_OPTIONS -DREALM_CPP_NO_TESTS=ON)
set(CPPREALM_CMAKE_OPTIONS -DREALM_CPP_NO_TESTS=ON -DREALM_CORE_SUBMODULE_BUILD=OFF)

if (ANDROID OR WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND CPPREALM_CMAKE_OPTIONS -DREALM_USE_SYSTEM_OPENSSL=ON)
Expand Down
2 changes: 1 addition & 1 deletion realm-core
Submodule realm-core updated 403 files
9 changes: 5 additions & 4 deletions src/cpprealm/flex_sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ namespace realm {
auto schema = m_realm.get().schema().find(managed<T>::schema.name);
auto group = m_realm.get().read_group();
auto table_ref = group.get_table(schema.table_key());
auto builder = internal::bridge::query(table_ref);
auto root_query = internal::bridge::query(table_ref);

if (query_fn) {
auto q = realm::query<managed<T>>(builder, std::move(schema), m_realm);
auto full_query = (*query_fn)(q).q;
rbool query = rbool(std::move(root_query));
auto query_object = managed<T>::prepare_for_query(m_realm, &query);
auto full_query = (*query_fn)(query_object).q;
insert_or_assign(name, full_query);
} else {
insert_or_assign(name, builder);
insert_or_assign(name, root_query);
}
}

Expand Down
20 changes: 12 additions & 8 deletions src/cpprealm/internal/bridge/mixed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ namespace realm::internal::bridge {
}

mixed::mixed(const mixed& other) {
if (other.type() == data_type::String) {
m_owned_string = other.m_owned_string;
} else if (other.type() == data_type::Binary) {
m_owned_data = other.m_owned_data;
if (!other.is_null()) {
if (other.type() == data_type::String) {
m_owned_string = other.m_owned_string;
} else if (other.type() == data_type::Binary) {
m_owned_data = other.m_owned_data;
}
}

#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
Expand All @@ -39,10 +41,12 @@ namespace realm::internal::bridge {

mixed& mixed::operator=(const mixed& other) {
if (this != &other) {
if (other.type() == data_type::String) {
m_owned_string = other.m_owned_string;
} else if (other.type() == data_type::Binary) {
m_owned_data = other.m_owned_data;
if (!other.is_null()) {
if (other.type() == data_type::String) {
m_owned_string = other.m_owned_string;
} else if (other.type() == data_type::Binary) {
m_owned_data = other.m_owned_data;
}
}
#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
*reinterpret_cast<Mixed*>(&m_mixed) = *reinterpret_cast<const Mixed*>(&other.m_mixed);
Expand Down
Loading
Loading