Use reconstructor function for unpickling #207
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 asbitarray()
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 thebuffer
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 requirebitarray()
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 (basicallynewbitarray_from_pickle()
) can be removed and #206 can finally be closed.