Skip to content

Commit

Permalink
Remove finalizer (#55)
Browse files Browse the repository at this point in the history
* remove finalizer

* remove extra finalize

* require CodecBzip2 0.8.5 or later
  • Loading branch information
nhz2 authored Dec 23, 2024
1 parent 87bfb21 commit d7857c2
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
[compat]
ArgTools = "1"
BufferedStreams = "1"
CodecBzip2 = "0.6, 0.7, 0.8"
CodecBzip2 = "0.8.5"
SuffixArrays = "0.3, 1"
TranscodingStreams = "0.9.5, 0.10, 0.11"
julia = "1.6"
1 change: 0 additions & 1 deletion src/BSDiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ function bspatch(
arg_write(new) do new_io
new_io = BufferedOutputStream(new_io)
apply_patch(patch_obj, old_data, new_io)
finalize(patch_obj)
flush(new_io)
end
end
Expand Down
11 changes: 1 addition & 10 deletions src/classic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function ClassicPatch(patch_io::IO, new_size::Int64 = typemax(Int64))
diff = TranscodingStream(compressor(), IOBuffer())
data = TranscodingStream(compressor(), IOBuffer())
patch = ClassicPatch(patch_io, new_size, ctrl, diff, data)
finalizer(finalize_patch, patch)
return patch
end

Expand All @@ -36,17 +35,9 @@ function read_start(::Type{ClassicPatch}, patch_io::IO)
diff = TranscodingStream(decompressor(), diff_io)
data = TranscodingStream(decompressor(), data_io)
patch = ClassicPatch(patch_io, new_size, ctrl, diff, data)
finalizer(finalize_patch, patch)
return patch
end

function finalize_patch(patch::ClassicPatch)
for stream in (patch.ctrl, patch.diff, patch.data)
# must be called to avoid leaking memory
TranscodingStreams.changemode!(stream, :close)
end
end

function write_finish(patch::ClassicPatch)
for stream in (patch.ctrl, patch.diff, patch.data)
write(stream, TranscodingStreams.TOKEN_END)
Expand All @@ -61,7 +52,7 @@ function write_finish(patch::ClassicPatch)
write(patch.io, v)
end
flush(patch.io)
finalize(patch)
nothing
end

function encode_control(
Expand Down
10 changes: 1 addition & 9 deletions src/endsley.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function write_start(
write_int(patch_io, new_size)
stream = TranscodingStream(compressor(), patch_io)
patch = EndsleyPatch(stream, new_size)
finalizer(finalize_patch, patch)
return patch
end

Expand All @@ -25,19 +24,12 @@ function read_start(::Type{EndsleyPatch}, patch_io::IO)
EndsleyPatch(TranscodingStream(decompressor(), patch_io), new_size)
end

function finalize_patch(patch::EndsleyPatch)
if patch.io isa TranscodingStream
# must be called to avoid leaking memory
TranscodingStreams.changemode!(patch.io, :close)
end
end

function write_finish(patch::EndsleyPatch)
if patch.io isa TranscodingStream
write(patch.io, TranscodingStreams.TOKEN_END)
end
flush(patch.io)
finalize(patch)
nothing
end

function encode_control(
Expand Down

0 comments on commit d7857c2

Please sign in to comment.