• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / 1786

28 Oct 2023 12:35PM UTC coverage: 91.562% (-0.02%) from 91.582%
1786

push

Evergreen

web-flow
Improve configurations for sanitized builds (#6911)

* Refactor sanitizer flags for different build types:

** Enable address sanitizer for msvc
** Allow to build with sanitizer for diffent optimized build (also Debug)
** Make RelASAN, RelTSAN, RelUSAN, RelUSAN just shortcuts for half-optimized builds

* Fix usage of moved object for fuzz tester
* Check asan/tsan on macos x64/arm64
* Check asan with msvc 2019
* Remove Jenkins sanitized builders replaced by evergreen configs
* Work-around stack-use-after-scope with msvc2019 and mpark
* Fix crash on check with staled ColKeys
* fix a buffer overrun in a test
* fix a race in async_open_realm test util
* Add some logger related test fixes
* Work around catch2 limmitation with not thread safe asserts and TSAN races
* Run multiprocesses tests under sanitizers
* add assert for an error reported by undefined sanitizer
* Workaround uv scheduler main thread only constraint for callbacks called from non main thread and requesting a realm

---------

Co-authored-by: James Stone <james.stone@mongodb.com>

94310 of 173648 branches covered (0.0%)

54 of 63 new or added lines in 15 files covered. (85.71%)

2212 existing lines in 52 files now uncovered.

230602 of 251853 relevant lines covered (91.56%)

6943670.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.01
/src/realm/object-store/set.cpp
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2020 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
#include <realm/object-store/set.hpp>
20

21
#include <realm/object-store/impl/list_notifier.hpp>
22
#include <realm/object-store/impl/realm_coordinator.hpp>
23
#include <realm/object-store/object_schema.hpp>
24
#include <realm/object-store/object_store.hpp>
25
#include <realm/object-store/results.hpp>
26
#include <realm/object-store/schema.hpp>
27
#include <realm/object-store/shared_realm.hpp>
28
#include <realm/exceptions.hpp>
29

30
namespace realm::object_store {
31

32
Set::Set(const Set&) = default;
1,122✔
33
Set::Set(Set&&) = default;
98✔
34
Set& Set::operator=(const Set&) = default;
×
35
Set& Set::operator=(Set&&) = default;
×
36

37
Query Set::get_query() const
38
{
14✔
39
    return get_table()->where(as<Obj>());
14✔
40
}
14✔
41

42
ConstTableRef Set::get_table() const
43
{
16✔
44
    verify_attached();
16✔
45
    if (m_type == PropertyType::Object)
16✔
46
        return set_base().get_target_table();
16✔
47
    throw NotImplemented();
×
48
}
×
49

50
template <class T>
51
size_t Set::find(const T& value) const
52
{
3,900✔
53
    verify_attached();
3,900✔
54
    return as<T>().find(value);
3,900✔
55
}
3,900✔
56

57
size_t Set::find(Query&& q) const
58
{
12✔
59
    verify_attached();
12✔
60
    if (m_type == PropertyType::Object) {
12✔
61
        ObjKey key = get_query().and_query(std::move(q)).find();
12✔
62
        return key ? as<Obj>().find_first(key) : not_found;
12✔
63
    }
12✔
64
    throw NotImplemented();
×
65
}
×
66

67
template <typename T>
68
T Set::get(size_t row_ndx) const
69
{
496✔
70
    return as<T>().get(row_ndx);
496✔
71
}
496✔
72

73
template <class T>
74
std::pair<size_t, bool> Set::insert(T value)
75
{
16,212✔
76
    verify_in_transaction();
16,212✔
77
    return as<T>().insert(value);
16,212✔
78
}
16,212✔
79

80
template <class T>
81
std::pair<size_t, bool> Set::remove(const T& value)
82
{
1,952✔
83
    verify_in_transaction();
1,952✔
84
    return as<T>().erase(value);
1,952✔
85
}
1,952✔
86

87
bool Set::operator==(const Set& rgt) const noexcept
88
{
×
89
    return set_base().get_table() == rgt.set_base().get_table() &&
×
90
           set_base().get_owner_key() == rgt.set_base().get_owner_key() &&
×
91
           set_base().get_col_key() == rgt.set_base().get_col_key();
×
92
}
×
93

94
Results Set::filter(Query q) const
95
{
×
96
    verify_attached();
×
97
    return Results(m_realm, std::dynamic_pointer_cast<LnkSet>(m_coll_base), get_query().and_query(std::move(q)));
×
98
}
×
99

100
Set Set::freeze(const std::shared_ptr<Realm>& frozen_realm) const
101
{
6✔
102
    auto frozen_set(frozen_realm->import_copy_of(*m_coll_base));
6✔
103
    if (frozen_set) {
6✔
104
        return Set(frozen_realm, std::move(frozen_set));
4✔
105
    }
4✔
106
    else {
2✔
107
        return Set{};
2✔
108
    }
2✔
109
}
6✔
110

111
#define REALM_PRIMITIVE_SET_TYPE(T)                                                                                  \
112
    template T Set::get<T>(size_t) const;                                                                            \
113
    template size_t Set::find<T>(const T&) const;                                                                    \
114
    template std::pair<size_t, bool> Set::remove<T>(T const&);                                                       \
115
    template std::pair<size_t, bool> Set::insert<T>(T);
116

117
REALM_PRIMITIVE_SET_TYPE(bool)
118
REALM_PRIMITIVE_SET_TYPE(int64_t)
119
REALM_PRIMITIVE_SET_TYPE(float)
120
REALM_PRIMITIVE_SET_TYPE(double)
121
REALM_PRIMITIVE_SET_TYPE(StringData)
122
REALM_PRIMITIVE_SET_TYPE(BinaryData)
123
REALM_PRIMITIVE_SET_TYPE(Timestamp)
124
REALM_PRIMITIVE_SET_TYPE(ObjKey)
125
REALM_PRIMITIVE_SET_TYPE(ObjectId)
126
REALM_PRIMITIVE_SET_TYPE(Decimal)
127
REALM_PRIMITIVE_SET_TYPE(UUID)
128
REALM_PRIMITIVE_SET_TYPE(util::Optional<bool>)
129
REALM_PRIMITIVE_SET_TYPE(util::Optional<int64_t>)
130
REALM_PRIMITIVE_SET_TYPE(util::Optional<float>)
131
REALM_PRIMITIVE_SET_TYPE(util::Optional<double>)
132
REALM_PRIMITIVE_SET_TYPE(util::Optional<ObjectId>)
133
REALM_PRIMITIVE_SET_TYPE(util::Optional<UUID>)
134

135
#undef REALM_PRIMITIVE_SET_TYPE
136

137
template size_t Set::find<Mixed>(const Mixed&) const;
138
template std::pair<size_t, bool> Set::remove<Mixed>(Mixed const&);
139
template std::pair<size_t, bool> Set::insert<Mixed>(Mixed);
140

141
template <>
142
std::pair<size_t, bool> Set::insert<int>(int value)
143
{
40✔
144
    return insert(int64_t(value));
40✔
145
}
40✔
146

147
template <>
148
std::pair<size_t, bool> Set::remove<int>(const int& value)
149
{
8✔
150
    return remove(int64_t(value));
8✔
151
}
8✔
152

153
std::pair<size_t, bool> Set::insert_any(Mixed value)
154
{
114✔
155
    verify_in_transaction();
114✔
156
    return set_base().insert_any(value);
114✔
157
}
114✔
158

159
Mixed Set::get_any(size_t ndx) const
160
{
401✔
161
    verify_attached();
401✔
162
    auto value = set_base().get_any(ndx);
401✔
163
    record_audit_read(value);
401✔
164
    return value;
401✔
165
}
401✔
166

167
std::pair<size_t, bool> Set::remove_any(Mixed value)
168
{
656✔
169
    verify_in_transaction();
656✔
170
    return set_base().erase_any(value);
656✔
171
}
656✔
172

173
size_t Set::find_any(Mixed value) const
174
{
334✔
175
    verify_attached();
334✔
176
    return set_base().find_any(value);
334✔
177
}
334✔
178

179
void Set::delete_all()
180
{
170✔
181
    verify_in_transaction();
170✔
182
    if (m_type == PropertyType::Object)
170✔
183
        as<Obj>().remove_all_target_rows();
86✔
184
    else
84✔
185
        set_base().clear();
84✔
186
}
170✔
187

188
void Set::remove_all()
189
{
504✔
190
    verify_in_transaction();
504✔
191
    set_base().clear();
504✔
192
}
504✔
193

194
template <>
195
size_t Set::find<int>(const int& value) const
196
{
12✔
197
    return find(int64_t(value));
12✔
198
}
12✔
199

200
template <>
201
Mixed Set::get<Mixed>(size_t row_ndx) const
202
{
152✔
203
    verify_attached();
152✔
204
    auto& set = as<Mixed>();
152✔
205
    auto value = set.get(row_ndx);
152✔
206
    record_audit_read(value);
152✔
207
    return value;
152✔
208
}
152✔
209

210
template <>
211
Obj Set::get<Obj>(size_t row_ndx) const
212
{
325✔
213
    verify_attached();
325✔
214
    auto& set = as<Obj>();
325✔
215
    auto obj = set.get_object(row_ndx);
325✔
216
    record_audit_read(obj);
325✔
217
    return obj;
325✔
218
}
325✔
219

220
template <>
221
size_t Set::find<Obj>(const Obj& obj) const
222
{
20✔
223
    verify_attached();
20✔
224
    validate(obj);
20✔
225
    // FIXME: Handle Mixed / ObjLink
10✔
226
    return as<ObjKey>().find(obj.get_key());
20✔
227
}
20✔
228

229
template <>
230
std::pair<size_t, bool> Set::remove<Obj>(const Obj& obj)
231
{
32✔
232
    verify_in_transaction();
32✔
233
    validate(obj);
32✔
234
    // FIXME: Handle Mixed / ObjLink
16✔
235
    return as<ObjKey>().erase(obj.get_key());
32✔
236
}
32✔
237

238
template <>
239
std::pair<size_t, bool> Set::insert<Obj>(Obj obj)
240
{
368✔
241
    verify_in_transaction();
368✔
242
    validate(obj);
368✔
243
    // FIXME: Handle Mixed / ObjLink
184✔
244
    return as<ObjKey>().insert(obj.get_key());
368✔
245
}
368✔
246

247
bool Set::is_subset_of(const Collection& rhs) const
248
{
8✔
249
    return dispatch([&](auto t) {
8✔
250
        return this->as<std::decay_t<decltype(*t)>>().is_subset_of(rhs.get_impl());
8✔
251
    });
8✔
252
}
8✔
253

254
bool Set::is_strict_subset_of(const Collection& rhs) const
255
{
4✔
256
    return dispatch([&](auto t) {
4✔
257
        return this->as<std::decay_t<decltype(*t)>>().is_strict_subset_of(rhs.get_impl());
4✔
258
    });
4✔
259
}
4✔
260

261
bool Set::is_superset_of(const Collection& rhs) const
UNCOV
262
{
×
UNCOV
263
    return dispatch([&](auto t) {
×
UNCOV
264
        return this->as<std::decay_t<decltype(*t)>>().is_superset_of(rhs.get_impl());
×
UNCOV
265
    });
×
UNCOV
266
}
×
267

268
bool Set::is_strict_superset_of(const Collection& rhs) const
269
{
4✔
270
    return dispatch([&](auto t) {
4✔
271
        return this->as<std::decay_t<decltype(*t)>>().is_strict_superset_of(rhs.get_impl());
4✔
272
    });
4✔
273
}
4✔
274

275
bool Set::intersects(const Collection& rhs) const
276
{
16✔
277
    return dispatch([&](auto t) {
16✔
278
        return this->as<std::decay_t<decltype(*t)>>().intersects(rhs.get_impl());
16✔
279
    });
16✔
280
}
16✔
281

282
bool Set::set_equals(const Collection& rhs) const
283
{
4✔
284
    return dispatch([&](auto t) {
4✔
285
        return this->as<std::decay_t<decltype(*t)>>().set_equals(rhs.get_impl());
4✔
286
    });
4✔
287
}
4✔
288

289
void Set::assign_intersection(const Collection& rhs)
290
{
8✔
291
    return dispatch([&](auto t) {
8✔
292
        return this->as<std::decay_t<decltype(*t)>>().assign_intersection(rhs.get_impl());
8✔
293
    });
8✔
294
}
8✔
295

296
void Set::assign_union(const Collection& rhs)
297
{
8✔
298
    return dispatch([&](auto t) {
8✔
299
        return this->as<std::decay_t<decltype(*t)>>().assign_union(rhs.get_impl());
8✔
300
    });
8✔
301
}
8✔
302

303
void Set::assign_difference(const Collection& rhs)
304
{
8✔
305
    return dispatch([&](auto t) {
8✔
306
        return this->as<std::decay_t<decltype(*t)>>().assign_difference(rhs.get_impl());
8✔
307
    });
8✔
308
}
8✔
309

310
void Set::assign_symmetric_difference(const Collection& rhs)
311
{
4✔
312
    return dispatch([&](auto t) {
4✔
313
        return this->as<std::decay_t<decltype(*t)>>().assign_symmetric_difference(rhs.get_impl());
4✔
314
    });
4✔
315
}
4✔
316

317
} // namespace realm::object_store
318

319
namespace std {
320
size_t hash<realm::object_store::Set>::operator()(realm::object_store::Set const& set) const
UNCOV
321
{
×
UNCOV
322
    return set.hash();
×
UNCOV
323
}
×
324
} // namespace std
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc