From 291c1133df948e2042f412f31670cbf3a5eaadad Mon Sep 17 00:00:00 2001 From: "Viral B. Shah" Date: Mon, 21 Aug 2023 22:11:33 -0400 Subject: [PATCH] Simplify some of the dispatch messiness in #90 Possible since we have os/arch specific wrappers now. --- Project.toml | 2 +- src/gz.jl | 32 ++++++-------------------------- src/zlib.jl | 2 +- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/Project.toml b/Project.toml index 2669da5..92a19f3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GZip" uuid = "92fee26a-97fe-5a0c-ad85-20a5f3185b63" authors = ["staticfloat@gmail.com "] -version = "0.6.0" +version = "0.6.1" [deps] Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" diff --git a/src/gz.jl b/src/gz.jl index 8c10be9..cb0e63a 100644 --- a/src/gz.jl +++ b/src/gz.jl @@ -136,31 +136,11 @@ gzwrite(s::GZipStream, p::Ptr, len::Integer) = gzread(s::GZipStream, p::Ptr, len::Integer) = @test_gzerror(s, Zlib_h.gzread(s.gz_file, reinterpret(Ptr{Cvoid}, p), Cuint(len)), -1) -global gzbuffer, _gzopen, _gzseek, _gztell, _gzoffset - -# Doesn't exist in zlib 1.2.3 or earlier -if Libdl.dlsym_e(Zlib_jll.libz_handle, :gzbuffer) != C_NULL - gzbuffer(gz_file::Zlib_h.gzFile, gz_buf_size::Integer) = Zlib_h.gzbuffer(gz_file, gz_buf_size) -else - gzbuffer(gz_file::Zlib_h.gzFile, gz_buf_size::Integer) = Cint(-1) -end +# Needs zlib 1.2.3 or higher (Julia 1.9 has zlib 1.2.13) +gzbuffer(gz_file::Zlib_h.gzFile, gz_buf_size::Integer) = Zlib_h.gzbuffer(gz_file, gz_buf_size) ##### -# Use 64-bit functions if available - -if Libdl.dlsym_e(Zlib_jll.libz_handle, :gzopen64) != C_NULL && (z_off_t_sz == 8 || !Sys.iswindows()) - const _gzopen = Zlib_h.gzopen64 - const _gzseek = Zlib_h.gzseek64 - const _gztell = Zlib_h.gztell64 - const _gzoffset = Zlib_h.gzoffset64 -else - const _gzopen = Zlib_h.gzopen - const _gzseek = Zlib_h.gzseek - const _gztell = Zlib_h.gztell - const _gzoffset = Zlib_h.gzoffset -end - """ gzopen(fname::AbstractString, [gzmode::AbstractString, buf_size::Integer])::GZipStream @@ -207,7 +187,7 @@ function gzopen(fname::AbstractString, gzmode::AbstractString, gz_buf_size::Inte gzmode *= "b" end - gz_file = _gzopen(fname, gzmode) + gz_file = Zlib_h.gzopen(fname, gzmode) if gz_file == C_NULL errno = unsafe_load(cglobal((:errno, :libc), Cint)) throw(SystemError("$(fname)", errno)) @@ -306,15 +286,15 @@ function seek(s::GZipStream, n::Integer) end end # Mimic behavior of seek(s::IOStream, n) - _gzseek(s.gz_file, Clong(n), SEEK_SET) != -1 || error("seek (gzseek) failed") + Zlib_h.gzseek(s.gz_file, Clong(n), SEEK_SET) != -1 || error("seek (gzseek) failed") end # Note: skips bytes within uncompressed data stream # Mimic behavior of skip(s::IOStream, n) skip(s::GZipStream, n::Integer) = - _gzseek(s.gz_file, Clong(n), SEEK_CUR) != -1 || error("skip (gzseek) failed") + Zlib_h.gzseek(s.gz_file, Clong(n), SEEK_CUR) != -1 || error("skip (gzseek) failed") -position(s::GZipStream, raw::Bool=false) = raw ? _gzoffset(s.gz_file) : _gztell(s.gz_file) +position(s::GZipStream, raw::Bool=false) = raw ? Zlib_h.gzoffset(s.gz_file) : Zlib_h.gztell(s.gz_file) eof(s::GZipStream) = Bool(Zlib_h.gzeof(s.gz_file)) diff --git a/src/zlib.jl b/src/zlib.jl index 436f540..9562172 100644 --- a/src/zlib.jl +++ b/src/zlib.jl @@ -48,7 +48,7 @@ const Z_BIG_BUFSIZE = 131072 # Get compile-time option flags const zlib_compile_flags = Zlib_h.zlibCompileFlags() const z_off_t_sz = 2 << ((zlib_compile_flags >> 6) & UInt(3)) -if z_off_t_sz == 8 || (!Sys.iswindows() && Libdl.dlsym_e(Zlib_jll.libz_handle, :gzopen64) != C_NULL) +if z_off_t_sz == 8 || (!Sys.iswindows() && isdefined(GZip.Zlib_h, :gzopen64)) const ZFileOffset = Int64 elseif z_off_t_sz == 4 const ZFileOffset = Int32