Skip to content

Commit

Permalink
Add BLOSC2_MAXTYPESIZE and fix deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescAlted committed Feb 18, 2025
1 parent ba78acd commit 2b5c7de
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion blosc/b2nd_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ int b2nd_copy_buffer(int8_t ndim,
const void *src, const int64_t *src_pad_shape,
const int64_t *src_start, const int64_t *src_stop,
void *dst, const int64_t *dst_pad_shape,
const int64_t *dst_start) __attribute__((deprecated("Use b2nd_copy_buffer2 instead"))) {
const int64_t *dst_start) {
// Simply cast itemsize to int32_t and delegate
return b2nd_copy_buffer2(ndim, (int32_t)itemsize, src, src_pad_shape,
src_start, src_stop, dst, dst_pad_shape, dst_start);
Expand Down
6 changes: 6 additions & 0 deletions blosc/blosc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,12 @@ static int initialize_context_compression(
}

/* Check typesize limits */
if (context->typesize > BLOSC2_MAXTYPESIZE) {
// If typesize is too large for Blosc2, return an error
BLOSC_TRACE_ERROR("Typesize cannot exceed %d bytes.", BLOSC2_MAXTYPESIZE);
return BLOSC2_ERROR_INVALID_PARAM;
}
/* Now, cap typesize so that blosc2 split machinery can continue to work */
if (context->typesize > BLOSC_MAX_TYPESIZE) {
/* If typesize is too large, treat buffer as an 1-byte stream. */
context->typesize = 1;
Expand Down
3 changes: 2 additions & 1 deletion include/b2nd.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,8 @@ BLOSC_EXPORT int b2nd_copy_buffer(int8_t ndim,
const void *src, const int64_t *src_pad_shape,
const int64_t *src_start, const int64_t *src_stop,
void *dst, const int64_t *dst_pad_shape,
const int64_t *dst_start);
const int64_t *dst_start)
__attribute__((deprecated("Use b2nd_copy_buffer2 instead")));


/**
Expand Down
3 changes: 2 additions & 1 deletion include/blosc2.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ enum {
*/
enum {
BLOSC2_MAXDICTSIZE = 128 * 1024, //!< maximum size for compression dicts
BLOSC2_MAXBLOCKSIZE = 536866816 //!< maximum size for blocks
BLOSC2_MAXBLOCKSIZE = 536866816, //!< maximum size for blocks
BLOSC2_MAXTYPESIZE = BLOSC2_MAXBLOCKSIZE, //!< maximum size for types
};


Expand Down
20 changes: 3 additions & 17 deletions tests/b2nd/test_b2nd_copy_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CUTEST_TEST_SETUP(copy_buffer) {

CUTEST_TEST_TEST(copy_buffer) {
const int8_t ndim = 3;
const uint8_t itemsize = sizeof(uint8_t);
const int32_t itemsize = sizeof(uint8_t);

const int64_t chunk_shape[] = {3, 3, 1};

Expand All @@ -51,24 +51,10 @@ CUTEST_TEST_TEST(copy_buffer) {
0, 0};
const int64_t dest_shape[] = {2, 2, 2};

B2ND_TEST_ASSERT(b2nd_copy_buffer(ndim, itemsize,
chunk0x, chunk_shape, chunk0s_start, chunk0s_stop,
dest, dest_shape, chunk0s_dest));
B2ND_TEST_ASSERT(b2nd_copy_buffer(ndim, itemsize,
chunk1x, chunk_shape, chunk1s_start, chunk1s_stop,
dest, dest_shape, chunk1s_dest));

for (int i = 0; i < result_length; ++i) {
uint8_t a = dest[i];
uint8_t b = result[i];
CUTEST_ASSERT("Elements are not equal!", a == b);
}

int32_t itemsize2 = itemsize;
B2ND_TEST_ASSERT(b2nd_copy_buffer2(ndim, itemsize2,
B2ND_TEST_ASSERT(b2nd_copy_buffer2(ndim, itemsize,
chunk0x, chunk_shape, chunk0s_start, chunk0s_stop,
dest, dest_shape, chunk0s_dest));
B2ND_TEST_ASSERT(b2nd_copy_buffer2(ndim, itemsize2,
B2ND_TEST_ASSERT(b2nd_copy_buffer2(ndim, itemsize,
chunk1x, chunk_shape, chunk1s_start, chunk1s_stop,
dest, dest_shape, chunk1s_dest));

Expand Down

0 comments on commit 2b5c7de

Please sign in to comment.