From d7857c2e3c1f44668e20194bdd27a2686c220cea Mon Sep 17 00:00:00 2001 From: Nathan Zimmerberg <39104088+nhz2@users.noreply.github.com> Date: Mon, 23 Dec 2024 15:59:21 -0500 Subject: [PATCH] Remove finalizer (#55) * remove finalizer * remove extra finalize * require CodecBzip2 0.8.5 or later --- Project.toml | 2 +- src/BSDiff.jl | 1 - src/classic.jl | 11 +---------- src/endsley.jl | 10 +--------- 4 files changed, 3 insertions(+), 21 deletions(-) diff --git a/Project.toml b/Project.toml index de70187..2b04984 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/BSDiff.jl b/src/BSDiff.jl index c9d7527..34ab7ec 100644 --- a/src/BSDiff.jl +++ b/src/BSDiff.jl @@ -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 diff --git a/src/classic.jl b/src/classic.jl index 3f07083..941ee5d 100644 --- a/src/classic.jl +++ b/src/classic.jl @@ -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 @@ -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) @@ -61,7 +52,7 @@ function write_finish(patch::ClassicPatch) write(patch.io, v) end flush(patch.io) - finalize(patch) + nothing end function encode_control( diff --git a/src/endsley.jl b/src/endsley.jl index 9259079..b85e3f5 100644 --- a/src/endsley.jl +++ b/src/endsley.jl @@ -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 @@ -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(