Skip to content

Commit

Permalink
Merge commit 'd2167d34120f617f64f48090f2495fc6e9ae8cf5' into mmap
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSellner committed May 14, 2024
2 parents 0c8787d + d2167d3 commit 694f0a1
Show file tree
Hide file tree
Showing 106 changed files with 4,795 additions and 2,412 deletions.
10 changes: 4 additions & 6 deletions DEVELOPING-GUIDE.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
Some conventions used in C-Blosc2
=================================

* Use C99 designated initialization whenever possible (specially in examples).
* Use C99 designated initialization only in examples. Libraries should use C89 initialization, which is more portable, specially with C++ (designated initialization in C++ is supported only since C++20).

* Use _new and _free for memory allocating constructors and destructors and _init and _destroy for non-memory allocating constructors and destructors.

* Lines must not exceed 120 characters. If a line is too long, it must be broken into several lines.

Naming things
-------------
* Conditional bodies must always use braces, even if they are one-liners. The only exception that can be is when the conditional is a single line and the body is a single line:

Naming is one of the most time-consuming tasks, but critical for communicating effectively. Here it is a preliminary list of names that I am not comfortable with:

* We are currently calling `filters` to a data transformation function that essentially produces the same amount of data, but with bytes shuffled or transformed in different ways. Perhaps `transformers` would be a better name?
if (condition) whatever();
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Release notes for C-Blosc2
Changes from 2.14.4 to 2.14.5
=============================

#XXX version-specific blurb XXX#
* Internal zstd sources updated to 1.5.6.


Changes from 2.14.3 to 2.14.4
Expand Down
2 changes: 1 addition & 1 deletion blosc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ if(NOT DEACTIVATE_ZSTD)
target_link_libraries(blosc_testing PUBLIC ${ZSTD_LIBRARY})
endif()
else()
set(ZSTD_LOCAL_DIR ${INTERNAL_LIBS}/zstd-1.5.5)
set(ZSTD_LOCAL_DIR ${INTERNAL_LIBS}/zstd-1.5.6)
if(BUILD_SHARED)
target_include_directories(blosc2_shared PRIVATE ${ZSTD_LOCAL_DIR} ${ZSTD_LOCAL_DIR}/common)
endif()
Expand Down
1 change: 1 addition & 0 deletions blosc/bitshuffle-altivec.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <altivec.h>

#include <stdint.h>
#include <stdlib.h>

/* The next is useful for debugging purposes */
#if 0
Expand Down
16 changes: 16 additions & 0 deletions blosc/blosc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -4713,3 +4713,19 @@ int blosc2_get_slice_nchunks(blosc2_schunk* schunk, int64_t *start, int64_t *sto

return rc;
}

blosc2_cparams blosc2_get_blosc2_cparams_defaults(void) {
return BLOSC2_CPARAMS_DEFAULTS;
};

blosc2_dparams blosc2_get_blosc2_dparams_defaults(void) {
return BLOSC2_DPARAMS_DEFAULTS;
};

blosc2_storage blosc2_get_blosc2_storage_defaults(void) {
return BLOSC2_STORAGE_DEFAULTS;
};

blosc2_io blosc2_get_blosc2_io_defaults(void) {
return BLOSC2_IO_DEFAULTS;
};
2 changes: 1 addition & 1 deletion blosc/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ int frame_update_trailer(blosc2_frame_s* frame, blosc2_schunk* schunk) {
}

// Create the trailer in msgpack (see the frame format document)
int64_t trailer_len = FRAME_TRAILER_MINLEN;
uint32_t trailer_len = FRAME_TRAILER_MINLEN;
uint8_t* trailer = (uint8_t*)calloc((size_t)trailer_len, 1);
uint8_t* ptrailer = trailer;
*ptrailer = 0x90 + 4; // fixarray with 4 elements
Expand Down
20 changes: 20 additions & 0 deletions include/blosc2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,26 @@ typedef struct {
*/
static const blosc2_storage BLOSC2_STORAGE_DEFAULTS = {false, NULL, NULL, NULL, NULL};

/**
* @brief Get default struct for compression params meant for user initialization.
*/
BLOSC_EXPORT blosc2_cparams blosc2_get_blosc2_cparams_defaults(void);

/**
* @brief Get default struct for decompression params meant for user initialization.
*/
BLOSC_EXPORT blosc2_dparams blosc2_get_blosc2_dparams_defaults(void);

/**
* @brief Get default struct for #blosc2_storage meant for user initialization.
*/
BLOSC_EXPORT blosc2_storage blosc2_get_blosc2_storage_defaults(void);

/**
* @brief Get default struct for #blosc2_io meant for user initialization.
*/
BLOSC_EXPORT blosc2_io blosc2_get_blosc2_io_defaults(void);

typedef struct blosc2_frame_s blosc2_frame; /* opaque type */

/**
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# You may select, at your option, one of the above-listed licenses.
# ################################################################

# default target (when running `make` with no argument)
lib-release:

# Modules
ZSTD_LIB_COMPRESSION ?= 1
ZSTD_LIB_DECOMPRESSION ?= 1
Expand Down Expand Up @@ -54,12 +57,11 @@ VERSION := $(ZSTD_VERSION)
# Note: by default, the static library is built single-threaded and dynamic library is built
# multi-threaded. It is possible to force multi or single threaded builds by appending
# -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
.PHONY: default
default: lib-release


CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # dynamic library build defaults to multi-threaded
LDFLAGS_DYNLIB += -pthread
CPPFLAGS_STATLIB += # static library build defaults to single-threaded
CPPFLAGS_STATICLIB += # static library build defaults to single-threaded


ifeq ($(findstring GCC,$(CCVER)),GCC)
Expand Down Expand Up @@ -91,7 +93,7 @@ all: lib


.PHONY: libzstd.a # must be run every time
libzstd.a: CPPFLAGS += $(CPPFLAGS_STATLIB)
libzstd.a: CPPFLAGS += $(CPPFLAGS_STATICLIB)

SET_CACHE_DIRECTORY = \
+$(MAKE) --no-print-directory $@ \
Expand All @@ -109,19 +111,19 @@ libzstd.a:
else
# BUILD_DIR is defined

ZSTD_STATLIB_DIR := $(BUILD_DIR)/static
ZSTD_STATLIB := $(ZSTD_STATLIB_DIR)/libzstd.a
ZSTD_STATLIB_OBJ := $(addprefix $(ZSTD_STATLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
$(ZSTD_STATLIB): ARFLAGS = rcs
$(ZSTD_STATLIB): | $(ZSTD_STATLIB_DIR)
$(ZSTD_STATLIB): $(ZSTD_STATLIB_OBJ)
ZSTD_STATICLIB_DIR := $(BUILD_DIR)/static
ZSTD_STATICLIB := $(ZSTD_STATICLIB_DIR)/libzstd.a
ZSTD_STATICLIB_OBJ := $(addprefix $(ZSTD_STATICLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
$(ZSTD_STATICLIB): ARFLAGS = rcs
$(ZSTD_STATICLIB): | $(ZSTD_STATICLIB_DIR)
$(ZSTD_STATICLIB): $(ZSTD_STATICLIB_OBJ)
# Check for multithread flag at target execution time
$(if $(filter -DZSTD_MULTITHREAD,$(CPPFLAGS)),\
@echo compiling multi-threaded static library $(LIBVER),\
@echo compiling single-threaded static library $(LIBVER))
$(AR) $(ARFLAGS) $@ $^

libzstd.a: $(ZSTD_STATLIB)
libzstd.a: $(ZSTD_STATICLIB)
cp -f $< $@

endif
Expand Down Expand Up @@ -182,14 +184,14 @@ lib : libzstd.a libzstd
# make does not consider implicit pattern rule for .PHONY target

%-mt : CPPFLAGS_DYNLIB := -DZSTD_MULTITHREAD
%-mt : CPPFLAGS_STATLIB := -DZSTD_MULTITHREAD
%-mt : CPPFLAGS_STATICLIB := -DZSTD_MULTITHREAD
%-mt : LDFLAGS_DYNLIB := -pthread
%-mt : %
@echo multi-threaded build completed

%-nomt : CPPFLAGS_DYNLIB :=
%-nomt : LDFLAGS_DYNLIB :=
%-nomt : CPPFLAGS_STATLIB :=
%-nomt : CPPFLAGS_STATICLIB :=
%-nomt : %
@echo single-threaded build completed

Expand All @@ -200,42 +202,52 @@ lib : libzstd.a libzstd

# Generate .h dependencies automatically

DEPFLAGS = -MT $@ -MMD -MP -MF
# -MMD: compiler generates dependency information as a side-effect of compilation, without system headers
# -MP: adds phony target for each dependency other than main file.
DEPFLAGS = -MMD -MP

$(ZSTD_DYNLIB_DIR)/%.o : %.c $(ZSTD_DYNLIB_DIR)/%.d | $(ZSTD_DYNLIB_DIR)
# ensure that ZSTD_DYNLIB_DIR exists prior to generating %.o
$(ZSTD_DYNLIB_DIR)/%.o : %.c | $(ZSTD_DYNLIB_DIR)
@echo CC $@
$(COMPILE.c) $(DEPFLAGS) $(ZSTD_DYNLIB_DIR)/$*.d $(OUTPUT_OPTION) $<
$(COMPILE.c) $(DEPFLAGS) $(OUTPUT_OPTION) $<

$(ZSTD_STATLIB_DIR)/%.o : %.c $(ZSTD_STATLIB_DIR)/%.d | $(ZSTD_STATLIB_DIR)
$(ZSTD_STATICLIB_DIR)/%.o : %.c | $(ZSTD_STATICLIB_DIR)
@echo CC $@
$(COMPILE.c) $(DEPFLAGS) $(ZSTD_STATLIB_DIR)/$*.d $(OUTPUT_OPTION) $<
$(COMPILE.c) $(DEPFLAGS) $(OUTPUT_OPTION) $<

$(ZSTD_DYNLIB_DIR)/%.o : %.S | $(ZSTD_DYNLIB_DIR)
@echo AS $@
$(COMPILE.S) $(OUTPUT_OPTION) $<

$(ZSTD_STATLIB_DIR)/%.o : %.S | $(ZSTD_STATLIB_DIR)
$(ZSTD_STATICLIB_DIR)/%.o : %.S | $(ZSTD_STATICLIB_DIR)
@echo AS $@
$(COMPILE.S) $(OUTPUT_OPTION) $<

MKDIR ?= mkdir
$(BUILD_DIR) $(ZSTD_DYNLIB_DIR) $(ZSTD_STATLIB_DIR):
$(MKDIR) -p $@
MKDIR ?= mkdir -p
$(BUILD_DIR) $(ZSTD_DYNLIB_DIR) $(ZSTD_STATICLIB_DIR):
$(MKDIR) $@

DEPFILES := $(ZSTD_DYNLIB_OBJ:.o=.d) $(ZSTD_STATLIB_OBJ:.o=.d)
DEPFILES := $(ZSTD_DYNLIB_OBJ:.o=.d) $(ZSTD_STATICLIB_OBJ:.o=.d)
$(DEPFILES):

include $(wildcard $(DEPFILES))
# The leading '-' means: do not fail is include fails (ex: directory does not exist yet)
-include $(wildcard $(DEPFILES))


# Special case : building library in single-thread mode _and_ without zstdmt_compress.c
ZSTDMT_FILES = compress/zstdmt_compress.c
ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES))
# Special case : build library in single-thread mode _and_ without zstdmt_compress.c
# Note : we still need threading.c and pool.c for the dictionary builder,
# but they will correctly behave single-threaded.
ZSTDMT_FILES = zstdmt_compress.c
ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(notdir $(ZSTD_FILES)))
libzstd-nomt: CFLAGS += -fPIC -fvisibility=hidden
libzstd-nomt: LDFLAGS += -shared
libzstd-nomt: $(ZSTD_NOMT_FILES)
@echo compiling single-thread dynamic library $(LIBVER)
@echo files : $(ZSTD_NOMT_FILES)
@if echo "$(ZSTD_NOMT_FILES)" | tr ' ' '\n' | $(GREP) -q zstdmt; then \
echo "Error: Found zstdmt in list."; \
exit 1; \
fi
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@

.PHONY: clean
Expand All @@ -249,7 +261,7 @@ clean:
#-----------------------------------------------------------------------------
# make install is validated only for below listed environments
#-----------------------------------------------------------------------------
ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX))
ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT CYGWIN_NT))

lib: libzstd.pc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The file structure is designed to make this selection manually achievable for an
For example, advanced API for version `v0.4` is exposed in `lib/legacy/zstd_v04.h` .

- While invoking `make libzstd`, it's possible to define build macros
`ZSTD_LIB_COMPRESSION, ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`,
`ZSTD_LIB_COMPRESSION`, `ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`,
and `ZSTD_LIB_DEPRECATED` as `0` to forgo compilation of the
corresponding features. This will also disable compilation of all
dependencies (e.g. `ZSTD_LIB_COMPRESSION=0` will also disable
Expand Down Expand Up @@ -119,6 +119,15 @@ The file structure is designed to make this selection manually achievable for an
binary is achieved by using `HUF_FORCE_DECOMPRESS_X1` and
`ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT` (implied by `ZSTD_LIB_MINIFY`).

On the compressor side, Zstd's compression levels map to several internal
strategies. In environments where the higher compression levels aren't used,
it is possible to exclude all but the fastest strategy with
`ZSTD_LIB_EXCLUDE_COMPRESSORS_DFAST_AND_UP=1`. (Note that this will change
the behavior of the default compression level.) Or if you want to retain the
default compressor as well, you can set
`ZSTD_LIB_EXCLUDE_COMPRESSORS_GREEDY_AND_UP=1`, at the cost of an additional
~20KB or so.

For squeezing the last ounce of size out, you can also define
`ZSTD_NO_INLINE`, which disables inlining, and `ZSTD_STRIP_ERROR_STRINGS`,
which removes the error messages that are otherwise returned by
Expand Down Expand Up @@ -169,6 +178,10 @@ The file structure is designed to make this selection manually achievable for an
`ZSTDERRORLIB_VSIBILITY`, and `ZDICTLIB_VISIBILITY` if unset, for backwards compatibility
with the old macro names.

- The C compiler macro `HUF_DISABLE_FAST_DECODE` disables the newer Huffman fast C
and assembly decoding loops. You may want to use this macro if these loops are
slower on your platform.

#### Windows : using MinGW+MSYS to create DLL

DLL can be created using MinGW+MSYS with the `make libzstd` command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define ZSTD_DEPS_NEED_MALLOC
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */

#include "mem.h" /* MEM_STATIC */
#include "compiler.h" /* MEM_STATIC */
#define ZSTD_STATIC_LINKING_ONLY
#include "../zstd.h" /* ZSTD_customMem */

Expand Down
File renamed without changes.
Loading

0 comments on commit 694f0a1

Please sign in to comment.