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

Table copy error has been fixed #104

Merged
merged 10 commits into from
Jul 1, 2013
Merged

Table copy error has been fixed #104

merged 10 commits into from
Jul 1, 2013

Conversation

kspangsege
Copy link
Contributor

The table copy error has been fixed.

As part of the solution, Array::Copy() has been replaced by Table::clone() whose semantics is better suited to our needs.

The actual error was due to a call to Array::CalcByteLen() in Array::Copy().

Alexander, can you take a look at my fix? I believe you are the original author of Table::Copy().

\cc @astigsen

@bmunkholm
Copy link
Contributor

+1
I suggest anything that isn't released, can be merged directly without pull requests.

@kspangsege
Copy link
Contributor Author

Brian, I am not sure what you mean.

For now this pull request is simply a bug-report. No attempt at fixing the bug has been made yet.

Using pull requests to report bugs has been a long-time custom of mine, and of Alexander.

@kspangsege
Copy link
Contributor Author

I found the error.

It is due to the call to Array::CalcByteLen() in Array::Copy(). The problem is that CalcByteLen() is virtual and has a special implementation for string arrays, however, the recursion in Array::Copy() does not create StringArray objects, it always creates Array objects.

The immediate fix is to avoid calling CalcByteLen(), but manually calculate the value in a way similar to what is done in Array::get_alloc_size_from_header().

An even better approach would be to change Array::Copy() so that it works directly on "refs" and thereby avoids instantiating array objects for string arrays.

…Copy() has been replaced by Table::clone() whose semantics is better suited to our needs.
@ghost ghost assigned astigsen Jun 29, 2013
@kspangsege
Copy link
Contributor Author

All unit tests pass, and valgrind reports no issues.

…, Array::Copy() has been replaced by Table::clone() whose semantics is better suited to our needs.
size_t size = get_byte_size_from_header(header);
// FIXME: Alexander, what is the reasoning behing this precise
// amount of extra capacity in the new array?
const size_t new_size = size + 64;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty much just an arbitrary number to give a bit of a buffer for future changes. It might actually be better to not give any buffer, and then just do the usual extension on inserts. That might reduce our memory footprint a bit in the (probably quite usual) cases, where it just get copied and no modified afterwards.

@astigsen
Copy link
Contributor

astigsen commented Jul 1, 2013

+1

kspangsege added a commit that referenced this pull request Jul 1, 2013
@kspangsege kspangsege merged commit c92d617 into realm:master Jul 1, 2013
@kspangsege kspangsege deleted the ks-table-copy-error branch July 1, 2013 20:04
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants