Skip to content

Commit 11edb76

Browse files
committed
Fixing void* (finally?)
1 parent 59f4d76 commit 11edb76

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

blosc2/blosc2_ext.pyx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,14 @@ def decompress(src, dst=None, as_bytearray=False):
412412
mem_view_src = memoryview(src)
413413
typed_view_src = mem_view_src.cast('B')
414414
_check_comp_length('src', len(typed_view_src))
415-
blosc2_cbuffer_sizes(<void*>(&typed_view_src[0]), &nbytes, &cbytes, &blocksize)
415+
blosc2_cbuffer_sizes(<void*>&typed_view_src[0], &nbytes, &cbytes, &blocksize)
416416
cdef Py_buffer *buf
417417
if dst is not None:
418418
buf = <Py_buffer *> malloc(sizeof(Py_buffer))
419419
PyObject_GetBuffer(dst, buf, PyBUF_SIMPLE)
420420
if buf.len == 0:
421421
raise ValueError("The dst length must be greater than 0")
422-
size = blosc1_decompress(<void*>(&typed_view_src[0]), buf.buf, buf.len)
422+
size = blosc1_decompress(<void*>&typed_view_src[0], buf.buf, buf.len)
423423
PyBuffer_Release(buf)
424424
else:
425425
dst = PyBytes_FromStringAndSize(NULL, nbytes)
@@ -585,14 +585,14 @@ def decompress2(src, dst=None, **kwargs):
585585
cdef int32_t nbytes
586586
cdef int32_t cbytes
587587
cdef int32_t blocksize
588-
blosc2_cbuffer_sizes(<void*>(&typed_view_src[0]), &nbytes, &cbytes, &blocksize)
588+
blosc2_cbuffer_sizes(<void*>&typed_view_src[0], &nbytes, &cbytes, &blocksize)
589589
cdef Py_buffer *buf
590590
if dst is not None:
591591
buf = <Py_buffer *> malloc(sizeof(Py_buffer))
592592
PyObject_GetBuffer(dst, buf, PyBUF_SIMPLE)
593593
if buf.len == 0:
594594
raise ValueError("The dst length must be greater than 0")
595-
view = <void*>(&typed_view_src[0])
595+
view = <void*>&typed_view_src[0]
596596
with nogil:
597597
size = blosc2_decompress_ctx(dctx, view, cbytes, buf.buf, nbytes)
598598
blosc2_free_ctx(dctx)
@@ -602,7 +602,7 @@ def decompress2(src, dst=None, **kwargs):
602602
if dst is None:
603603
raise RuntimeError("Could not get a bytes object")
604604
dst_buf = <char*>dst
605-
view = <void*>(&typed_view_src[0])
605+
view = <void*>&typed_view_src[0]
606606
with nogil:
607607
size = blosc2_decompress_ctx(dctx, view, cbytes, <void*>dst_buf, nbytes)
608608
blosc2_free_ctx(dctx)
@@ -674,17 +674,19 @@ cdef class SChunk:
674674
cdef const uint8_t[:] typed_view
675675
cdef int64_t index
676676
cdef Py_buffer *buf
677+
cdef uint8_t *buf_ptr
677678
if data is not None:
678679
buf = <Py_buffer *> malloc(sizeof(Py_buffer))
679680
PyObject_GetBuffer(data, buf, PyBUF_SIMPLE)
681+
buf_ptr = <uint8_t *> buf.buf
680682
len_data = buf.len
681683
nchunks = len_data // chunksize + 1 if len_data % chunksize != 0 else len_data // chunksize
682684
len_chunk = chunksize
683685
for i in range(nchunks):
684686
if i == (nchunks - 1):
685687
len_chunk = len_data - i * chunksize
686688
index = i * chunksize
687-
nchunks_ = blosc2_schunk_append_buffer(self.schunk, &buf.buf[index], len_chunk)
689+
nchunks_ = blosc2_schunk_append_buffer(self.schunk, buf_ptr + index, len_chunk)
688690
if nchunks_ != (i + 1):
689691
PyBuffer_Release(buf)
690692
raise RuntimeError("An error occurred while appending the chunks")
@@ -988,14 +990,14 @@ cdef class SChunk:
988990
cdef Py_buffer *buf = <Py_buffer *> malloc(sizeof(Py_buffer))
989991
PyObject_GetBuffer(value, buf, PyBUF_SIMPLE)
990992
cdef uint8_t *buf_ptr = <uint8_t *> buf.buf
993+
cdef int64_t buf_pos = 0
991994
cdef uint8_t *data
992995
cdef uint8_t *chunk
993996
if buf.len < nbytes:
994997
raise ValueError("Not enough data for writing the slice")
995998

996999
if stop > nitems:
9971000
# Increase SChunk's size
998-
buf_pos = 0
9991001
if start < nitems:
10001002
rc = blosc2_schunk_set_slice_buffer(self.schunk, start, nitems, buf.buf)
10011003
buf_pos = (nitems - start) * self.schunk.typesize
@@ -1010,7 +1012,7 @@ cdef class SChunk:
10101012
if rc < 0:
10111013
free(data)
10121014
raise RuntimeError("Error while decompressig the chunk")
1013-
memcpy(&data[nitems * self.schunk.typesize], &buf_ptr[buf_pos], chunk_nbytes - buf_pos)
1015+
memcpy(data + nitems * self.schunk.typesize, buf_ptr + buf_pos, chunk_nbytes - buf_pos)
10141016
chunk = <uint8_t *> malloc(chunk_nbytes + BLOSC2_MAX_OVERHEAD)
10151017
rc = blosc2_compress_ctx(self.schunk.cctx, data, chunk_nbytes, chunk, chunk_nbytes + BLOSC2_MAX_OVERHEAD)
10161018
free(data)
@@ -1032,7 +1034,7 @@ cdef class SChunk:
10321034
chunksize = self.schunk.chunksize
10331035
else:
10341036
chunksize = (stop * self.schunk.typesize) % self.schunk.chunksize
1035-
rc = blosc2_schunk_append_buffer(self.schunk, &buf_ptr[buf_pos], chunksize)
1037+
rc = blosc2_schunk_append_buffer(self.schunk, buf_ptr + buf_pos, chunksize)
10361038
if rc < 0:
10371039
raise RuntimeError("Error while appending the chunk")
10381040
buf_pos += chunksize

0 commit comments

Comments
 (0)