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

Use reconstructor function for unpickling #207

Merged
merged 8 commits into from Aug 5, 2023
Merged

Use reconstructor function for unpickling #207

merged 8 commits into from Aug 5, 2023

Conversation

ilanschnell
Copy link
Owner

Until now we have been using bitarray() itself for unpickling. We want to store the memory efficient buffer representation in the pickle object. However, as the buffer also includes pad bits, we have been using a hack to make this possible. That is, we added a head byte to the buffer representation in the pickle object. This head byte can have values 0x00 to 0x07 and represents the number of pad bits at the end of the buffer. This was necessary as bitarray() does not (and should not) take a pad bits argument (nor does it allow creating a bytes object as the initializer (except for when explicitly using the buffer option)). This hack has caused issue #206.

In this PR, we simplify the pickling format and use a separate function (_bitarray_reconstructor) for creating a bitarray from the pickle object. This is less hackish, because it does not require bitarray() to handle unpickling.

For backwards compatibility bitarray() is left unchanged in this PR. That is, pickle objects created with existing/older versions of bitarray can still be unpickled correctly. Eventually, the hope is that people will have used new versions of bitarray (with the new pickling format) long enough such that all pickle files will use the new reconstructor format. At this point in time (which I expect to be about a year from now), the existing hack (basically newbitarray_from_pickle()) can be removed and #206 can finally be closed.

@ilanschnell ilanschnell merged commit 0a94420 into master Aug 5, 2023
@ilanschnell ilanschnell deleted the reconst branch August 9, 2023 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant