-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pledgeinsize
#64
Open
nhz2
wants to merge
10
commits into
master
Choose a base branch
from
nz-pledgeinsize
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add pledgeinsize
#64
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
11cff42
Add pledgeinsize
nhz2 9f89a86
Merge branch 'master' into nz-pledgeinsize
nhz2 04e818f
Merge branch 'master' into nz-pledgeinsize
nhz2 e0c0238
Add tests for pledgeinsize
nhz2 b2c4e97
test errors
nhz2 783ecc9
Add coverage for upstream tests
nhz2 e1f070b
test unknown pledgeinsize
nhz2 2a5b290
fix tests for 32 bit
nhz2 0e13c10
remove dead code
nhz2 055af7b
bump compat
nhz2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Upstream | ||
on: | ||
push: | ||
branches: [master] | ||
tags: [v*] | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: julia-actions/setup-julia@v2 | ||
with: | ||
version: 1 | ||
arch: x64 | ||
- uses: julia-actions/julia-buildpkg@latest | ||
- name: Load the upstream packages and run the tests | ||
shell: julia --color=yes {0} | ||
run: | | ||
using Pkg | ||
Pkg.Registry.update() | ||
Pkg.activate(;temp=true) | ||
# force it to use this PR's version of the package | ||
ENV["JULIA_PKG_DEVDIR"]= mktempdir() | ||
Pkg.develop([ | ||
PackageSpec(path="."), | ||
PackageSpec(name="TranscodingStreams"), | ||
]) | ||
Pkg.update() | ||
Pkg.test("CodecZstd"; coverage=true) | ||
- uses: julia-actions/julia-processcoverage@v1 | ||
- uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: lcov.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,17 +101,31 @@ function TranscodingStreams.startproc(codec::ZstdCompressor, mode::Symbol, error | |
return :error | ||
end | ||
end | ||
code = reset!(codec.cstream, 0 #=unknown source size=#) | ||
reset!(codec.cstream) | ||
return :ok | ||
end | ||
|
||
function TranscodingStreams.pledgeinsize(codec::ZstdCompressor, insize::Int64, error::Error)::Symbol | ||
if codec.cstream.ptr == C_NULL | ||
Base.error("`startproc` must be called before `pledgeinsize`") | ||
end | ||
srcsize = if signbit(insize) | ||
ZSTD_CONTENTSIZE_UNKNOWN | ||
else | ||
Culonglong(insize) | ||
end | ||
code = LibZstd.ZSTD_CCtx_setPledgedSrcSize(codec.cstream, srcsize) | ||
if iserror(code) | ||
error[] = ErrorException("zstd error") | ||
return :error | ||
error[] = ErrorException("zstd error setting pledged source size") | ||
:error | ||
else | ||
:ok | ||
end | ||
return :ok | ||
end | ||
|
||
function TranscodingStreams.process(codec::ZstdCompressor, input::Memory, output::Memory, error::Error) | ||
if codec.cstream.ptr == C_NULL | ||
error("startproc must be called before process") | ||
Base.error("`startproc` must be called before `process`") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
cstream = codec.cstream | ||
ibuffer_starting_pos = UInt(0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,9 +130,17 @@ include("utils.jl") | |
@test CodecZstd.find_decompressed_size(v) == 22 | ||
|
||
codec = ZstdCompressor | ||
buffer3 = transcode(codec, b"Hello") | ||
buffer4 = transcode(codec, b"World!") | ||
sink = IOBuffer() | ||
s = TranscodingStream(codec(), sink; stop_on_end=true) | ||
write(s, b"Hello") | ||
close(s) | ||
buffer3 = take!(sink) | ||
@test CodecZstd.find_decompressed_size(buffer3) == CodecZstd.ZSTD_CONTENTSIZE_UNKNOWN | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
sink = IOBuffer() | ||
s = TranscodingStream(codec(), sink; stop_on_end=true) | ||
write(s, b"Hello") | ||
close(s) | ||
buffer4 = take!(sink) | ||
@test CodecZstd.find_decompressed_size(buffer4) == CodecZstd.ZSTD_CONTENTSIZE_UNKNOWN | ||
|
||
write(iob, buffer1) | ||
|
@@ -156,6 +164,66 @@ include("utils.jl") | |
@test CodecZstd.find_decompressed_size(v) == CodecZstd.ZSTD_CONTENTSIZE_ERROR | ||
end | ||
|
||
@testset "pledgeinsize" begin | ||
# when pledgeinsize is available transcode should save the | ||
# decompressed size in a header | ||
for n in [0:30; 1000; 1000000;] | ||
v = transcode(ZstdCompressor, rand(UInt8, n)) | ||
@test CodecZstd.find_decompressed_size(v) == n | ||
end | ||
|
||
# Test what happens if pledgeinsize promise is broken | ||
d1 = zeros(UInt8, 10000) | ||
d2 = zeros(UInt8, 10000) | ||
GC.@preserve d1 d2 begin | ||
@testset "too many bytes" begin | ||
m1 = TranscodingStreams.Memory(pointer(d1), 1000) | ||
m2 = TranscodingStreams.Memory(pointer(d2), 1000) | ||
codec = ZstdCompressor() | ||
e = TranscodingStreams.Error() | ||
@test TranscodingStreams.startproc(codec, :read, e) === :ok | ||
@test TranscodingStreams.pledgeinsize(codec, Int64(10), e) === :ok | ||
@test TranscodingStreams.process(codec, m1, m2, e) === (0, 0, :error) | ||
@test e[] == ErrorException("zstd error: Src size is incorrect") | ||
TranscodingStreams.finalize(codec) | ||
end | ||
@testset "too few bytes" begin | ||
m1 = TranscodingStreams.Memory(pointer(d1), 10) | ||
m2 = TranscodingStreams.Memory(pointer(d2), 1000) | ||
codec = ZstdCompressor() | ||
e = TranscodingStreams.Error() | ||
@test TranscodingStreams.startproc(codec, :read, e) === :ok | ||
@test TranscodingStreams.pledgeinsize(codec, Int64(10000), e) === :ok | ||
@test TranscodingStreams.process(codec, m1, m2, e)[3] === :ok | ||
m1 = TranscodingStreams.Memory(pointer(d1), 0) | ||
@test TranscodingStreams.process(codec, m1, m2, e)[3] === :error | ||
@test e[] == ErrorException("zstd error: Src size is incorrect") | ||
TranscodingStreams.finalize(codec) | ||
end | ||
@testset "set pledgeinsize after process" begin | ||
m1 = TranscodingStreams.Memory(pointer(d1), 1000) | ||
m2 = TranscodingStreams.Memory(pointer(d2), 1000) | ||
codec = ZstdCompressor() | ||
e = TranscodingStreams.Error() | ||
@test TranscodingStreams.startproc(codec, :read, e) === :ok | ||
@test TranscodingStreams.process(codec, m1, m2, e)[3] === :ok | ||
@test TranscodingStreams.pledgeinsize(codec, Int64(10000), e) === :error | ||
@test e[] == ErrorException("zstd error setting pledged source size") | ||
TranscodingStreams.finalize(codec) | ||
end | ||
@testset "set unknown pledgeinsize" begin | ||
m1 = TranscodingStreams.Memory(pointer(d1), 1000) | ||
m2 = TranscodingStreams.Memory(pointer(d2), 1000) | ||
codec = ZstdCompressor() | ||
e = TranscodingStreams.Error() | ||
@test TranscodingStreams.startproc(codec, :read, e) === :ok | ||
@test TranscodingStreams.pledgeinsize(codec, Int64(-1), e) === :ok | ||
@test TranscodingStreams.process(codec, m1, m2, e)[3] === :ok | ||
TranscodingStreams.finalize(codec) | ||
end | ||
end | ||
end | ||
|
||
include("compress_endOp.jl") | ||
include("static_only_tests.jl") | ||
|
||
|
@@ -195,6 +263,10 @@ include("utils.jl") | |
TranscodingStreams.finalize(codec) | ||
data = [0x00,0x01] | ||
GC.@preserve data let m = TranscodingStreams.Memory(pointer(data), length(data)) | ||
try | ||
TranscodingStreams.pledgeinsize(codec, Int64(10), TranscodingStreams.Error()) | ||
catch | ||
end | ||
try | ||
TranscodingStreams.expectedsize(codec, m) | ||
catch | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ensures fresh versions of the developed packages, in case this is run locally.