-
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
Auto initialize in startproc
#74
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,16 +78,6 @@ | |
# Methods | ||
# ------- | ||
|
||
function TranscodingStreams.initialize(codec::ZstdCompressor) | ||
code = initialize!(codec.cstream, codec.level) | ||
if iserror(code) | ||
zstderror(codec.cstream, code) | ||
end | ||
reset!(codec.cstream.ibuffer) | ||
reset!(codec.cstream.obuffer) | ||
return | ||
end | ||
|
||
function TranscodingStreams.finalize(codec::ZstdCompressor) | ||
if codec.cstream.ptr != C_NULL | ||
code = free!(codec.cstream) | ||
|
@@ -96,12 +86,22 @@ | |
end | ||
codec.cstream.ptr = C_NULL | ||
end | ||
reset!(codec.cstream.ibuffer) | ||
reset!(codec.cstream.obuffer) | ||
return | ||
nothing | ||
nhz2 marked this conversation as resolved.
Show resolved
Hide resolved
nhz2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
function TranscodingStreams.startproc(codec::ZstdCompressor, mode::Symbol, error::Error) | ||
if codec.cstream.ptr == C_NULL | ||
ptr = LibZstd.ZSTD_createCStream() | ||
if ptr == C_NULL | ||
throw(OutOfMemoryError()) | ||
end | ||
codec.cstream.ptr = ptr | ||
nhz2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
i_code = initialize!(codec.cstream, codec.level) | ||
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. Also see notes in #73 Should 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. Yes, if initialize! is changed to throw, then this needs to catch that error and return |
||
if iserror(i_code) | ||
error[] = ErrorException("zstd initialization error") | ||
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. These errors are unreachable unless there is some allocation error. 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. Could you mock the out of memory condition them by using that advanced API that provides the memory allocation functions? 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. I'm not sure if even that would reliably trigger an error specifically here, because memory allocations are happening in |
||
return :error | ||
end | ||
end | ||
code = reset!(codec.cstream, 0 #=unknown source size=#) | ||
if iserror(code) | ||
error[] = ErrorException("zstd error") | ||
|
@@ -111,6 +111,9 @@ | |
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") | ||
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. This error should also be unreachable in normal operation. |
||
end | ||
cstream = codec.cstream | ||
ibuffer_starting_pos = UInt(0) | ||
if codec.endOp == LibZstd.ZSTD_e_end && | ||
|
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.
Where does this happen now?
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 happens in
reset!
CodecZstd.jl/src/libzstd.jl
Lines 73 to 74 in 60079dd
Which is called in
startproc
CodecZstd.jl/src/compression.jl
Line 104 in 60079dd