]> arthur.barton.de Git - bup.git/commit
Fix hashsplit for python 3; add compat.buffer
authorRob Browning <rlb@defaultvalue.org>
Wed, 9 Oct 2019 06:11:39 +0000 (01:11 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 13 Oct 2019 17:48:24 +0000 (12:48 -0500)
commitaf3ea99bce1b916e6835eb3b3025cc2490fed501
tree70361c0c8051b09423018c1ea5c9844da672d307
parent6385aa493eff14c7b59aa964ea5cce6f6c3b79a7
Fix hashsplit for python 3; add compat.buffer

In order to get hashsplit working, stick with buffer()s in python 2.
We can't use a Py_buffer (via memoryview()) across both python
versions because python 2's zlib.compress() never learned how to
handle them, and we don't want to have to make an extra tobytes() copy
of all the data just to simplify the code.

Instead provide a python 3 only compat.buffer that's returns a
memoryview (slice when appropriate) in python 3.

Also noticed (and a bit unfortunate if accurate) that memoryview is
much larger than buffer, and for our bulk data, we have no need of any
additional sophistication:

  $ python2
  ...
  >>> import sys
  >>> sys.getsizeof(buffer(''))
  64

  $ python3
  ...
  >>> import sys
  >>> sys.getsizeof(buffer(''))
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  NameError: name 'buffer' is not defined
  >>>
  >>> sys.getsizeof(memoryview(b''))
  192

Of course worth keeping in mind when deciding between using one or
just copying the relevant region.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/_helpers.c
lib/bup/compat.py
lib/bup/hashsplit.py
lib/bup/t/thashsplit.py