refactor interface for static state allocation #1109
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#1104 fixed an issue impacting the size of states on
OS400
specifically. This is a relatively niche scenario, when statically allocating on stack or as part of another structure (which is not recommended, though allowed).To do that, @jonrumsey fixed the manual size of
LZ4_STREAMSIZE
and other equivalent constants, to fit the scenario ofOS400
, where pointers are 128-bit large.And while the fix is correct, it should not have been necessary.
The interface design requires employing objects such as
LZ4_stream_t
to allocate statically, and never the constants nor internal definitions.LZ4_STREAMSIZE
only exists first due to historical reasons, but also as a way to protect against mismatched library versions. In essence, it guarantees that the state preserves a "minimal size", in case it would evolve or shrink in the future, so that it remains compatible with older library versions.The problem was that this "minimal state size", which is generally >= to the actual state size, ends up being lower that actual state size in the case
OS400
.Still, this shouldn't be a problem, because in this case, the state occupies its actual size.
The problem came from the fact that
LZ4_STREAMSIZE
was used in other parts of the source code, and notably within static assert, resulting in compilation errors. And this wasn't a correct usage of this constant.This PR fix the underlying issue, by making sure that all code now use
sizeof(LZ4_stream_t)
, and no longerLZ4_STREAMSIZE
, which by the way has been renamedLZ4_STREAM_MINSIZE
, to better reflect its role.Such update is also easier to validate thanks to previously merged ABI compatibility test.