Skip to content

Commit

Permalink
add back finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 committed Sep 15, 2024
1 parent 0c6a43d commit fdb6ec9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- 'min'
- '1'
- 'pre'
os:
- ubuntu-latest
- windows-latest
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Zstd_jll = "3161d3a3-bdf6-5164-811a-617609db77b4"
[compat]
TranscodingStreams = "0.9, 0.10, 0.11"
Zstd_jll = "1.5.5"
julia = "1.3"
julia = "1.7"
9 changes: 9 additions & 0 deletions src/compression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ end
# Methods
# -------

function TranscodingStreams.finalize(codec::ZstdCompressor)
cstream = codec.cstream
p = @atomicswap cstream.ptr = C_NULL
# no need to check if p is already C_NULL
# because ZSTD_freeCStream will handle that.
LibZstd.ZSTD_freeCStream(p)
return
end

function TranscodingStreams.startproc(codec::ZstdCompressor, mode::Symbol, error::Error)
code = reset!(codec.cstream, 0 #=unknown source size=#)
if iserror(code)
Expand Down
7 changes: 4 additions & 3 deletions src/libzstd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ end

# ZSTD_CStream
mutable struct CStream
ptr::Ptr{LibZstd.ZSTD_CStream}
@atomic ptr::Ptr{LibZstd.ZSTD_CStream}
ibuffer::InBuffer
obuffer::OutBuffer

Expand All @@ -80,8 +80,9 @@ mutable struct CStream
end
cstream = new(ptr, InBuffer(), OutBuffer())
finalizer(cstream) do x
local p = x.ptr
x.ptr = C_NULL
local p = @atomicswap x.ptr = C_NULL
# no need to check if p is already C_NULL
# because ZSTD_freeCStream will handle that.
LibZstd.ZSTD_freeCStream(p)
nothing
end
Expand Down

0 comments on commit fdb6ec9

Please sign in to comment.