Skip to content

Commit 411bc16

Browse files
committed
factor out MyBuffer
1 parent c9009b6 commit 411bc16

File tree

11 files changed

+6192
-4257
lines changed

11 files changed

+6192
-4257
lines changed

docs/release.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Release notes
22
=============
33

4+
.. _release_0.1.0:
5+
6+
0.1.0
7+
-----
8+
9+
* Two new compressor codecs :class:`numcodecs.zstd.Zstd` and :class:`numcodecs.lz4.LZ4`
10+
have been added (`#3 <https://github.com/alimanfoo/numcodecs/issues/3>`_,
11+
`#22 <https://github.com/alimanfoo/numcodecs/issues/22>`_). These provide direct support for
12+
compression/decompression using `Zstandard <https://github.com/facebook/zstd>`_ and
13+
`LZ4 <https://github.com/lz4/lz4>`_ respectively.
14+
415
.. _release_0.0.1:
516

617
0.0.1
@@ -19,7 +30,7 @@ the original Zarr module:
1930

2031
* Codec classes have been re-organized into separate modules, mostly one per
2132
codec class, for ease of maintenance.
22-
* Two new codec classes have been added based on 32-bit checksums: CRC32 and
23-
Adler32.
33+
* Two new codec classes have been added based on 32-bit checksums:
34+
:class:`numcodecs.checksum32.CRC32` and :class:`numcodecs.checksum32.Adler32`.
2435
* The Blosc extension has been refactored to remove code duplications related
2536
to handling of buffer compatibility.

numcodecs/blosc.c

Lines changed: 874 additions & 1649 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

numcodecs/blosc.pyx

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import threading
88
import os
99

1010

11-
# noinspection PyUnresolvedReferences
12-
from cpython cimport array, PyObject
13-
import array
14-
from cpython.buffer cimport PyObject_GetBuffer, PyBuffer_Release, PyBUF_ANY_CONTIGUOUS, \
15-
PyBUF_WRITEABLE
11+
from cpython.buffer cimport PyBUF_ANY_CONTIGUOUS, PyBUF_WRITEABLE
1612
from cpython.bytes cimport PyBytes_FromStringAndSize, PyBytes_AS_STRING
1713

1814

15+
from numcodecs.compat_ext cimport MyBuffer
16+
from numcodecs.compat_ext import MyBuffer
1917
from numcodecs.compat import PY2, text_type
2018
from numcodecs.abc import Codec
2119

@@ -98,37 +96,6 @@ def set_nthreads(int nthreads):
9896
return blosc_set_nthreads(nthreads)
9997

10098

101-
cdef class MyBuffer:
102-
"""Compatibility class to work around fact that array.array does not support new-style buffer
103-
interface in PY2."""
104-
105-
cdef:
106-
char *ptr
107-
Py_buffer buffer
108-
size_t nbytes
109-
size_t itemsize
110-
array.array arr
111-
bint new_buffer
112-
113-
def __cinit__(self, obj, flags):
114-
if PY2 and isinstance(obj, array.array):
115-
self.new_buffer = False
116-
self.arr = obj
117-
self.ptr = <char *> self.arr.data.as_voidptr
118-
self.itemsize = self.arr.itemsize
119-
self.nbytes = self.arr.buffer_info()[1] * self.itemsize
120-
else:
121-
self.new_buffer = True
122-
PyObject_GetBuffer(obj, &(self.buffer), flags)
123-
self.ptr = <char *> self.buffer.buf
124-
self.itemsize = self.buffer.itemsize
125-
self.nbytes = self.buffer.len
126-
127-
def release(self):
128-
if self.new_buffer:
129-
PyBuffer_Release(&(self.buffer))
130-
131-
13299
def cbuffer_sizes(source):
133100
"""Return information about a compressed buffer, namely the number of uncompressed bytes (
134101
`nbytes`) and compressed (`cbytes`). It also returns the `blocksize` (which is used
@@ -358,6 +325,10 @@ class Blosc(Codec):
358325
The requested size of the compressed blocks. If 0 (default), an automatic blocksize will
359326
be used.
360327
328+
See Also
329+
--------
330+
numcodecs.zstd.Zstd, numcodecs.lz4.LZ4
331+
361332
"""
362333

363334
codec_id = 'blosc'

0 commit comments

Comments
 (0)