Skip to content

Commit

Permalink
Small fix to Table::typed_write
Browse files Browse the repository at this point in the history
When writing the realm to a new file from a write transaction,
the Table may be COW so that the top ref is changed. So don't
use the ref that is present in the group when the operation starts.
  • Loading branch information
jedelbo committed Aug 21, 2024
1 parent 80b95d0 commit 9fe448f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
12 changes: 5 additions & 7 deletions src/realm/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,19 +943,17 @@ ref_type Group::typed_write_tables(_impl::ArrayWriterBase& out) const
ref_type ref = m_top.get_as_ref(1);
if (out.only_modified && m_alloc.is_read_only(ref))
return ref;
Array a(m_alloc);
a.init_from_ref(ref);
REALM_ASSERT_DEBUG(a.has_refs());
TempArray dest(a.size());
for (unsigned j = 0; j < a.size(); ++j) {
RefOrTagged rot = a.get_as_ref_or_tagged(j);
auto num_tables = m_tables.size();
TempArray dest(num_tables);
for (unsigned j = 0; j < num_tables; ++j) {
RefOrTagged rot = m_tables.get_as_ref_or_tagged(j);
if (rot.is_tagged()) {
dest.set(j, rot);
}
else {
auto table = do_get_table(j);
REALM_ASSERT_DEBUG(table);
dest.set_as_ref(j, table->typed_write(rot.get_as_ref(), out));
dest.set_as_ref(j, table->typed_write(out));
}
}
return dest.write(out);
Expand Down
4 changes: 2 additions & 2 deletions src/realm/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3456,9 +3456,9 @@ ColKey Table::find_opposite_column(ColKey col_key) const
return ColKey();
}

ref_type Table::typed_write(ref_type ref, _impl::ArrayWriterBase& out) const
ref_type Table::typed_write(_impl::ArrayWriterBase& out) const
{
REALM_ASSERT(ref == m_top.get_mem().get_ref());
auto ref = m_top.get_ref();
if (out.only_modified && m_alloc.is_read_only(ref))
return ref;
out.table = this;
Expand Down
2 changes: 1 addition & 1 deletion src/realm/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ class Table {
Replication* const* m_repl;
};

ref_type typed_write(ref_type ref, _impl::ArrayWriterBase& out) const;
ref_type typed_write(_impl::ArrayWriterBase& out) const;

private:
enum LifeCycleCookie {
Expand Down

0 comments on commit 9fe448f

Please sign in to comment.