From af7239ed15f6d82622a76b92ba9078ccd75cb3e7 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Tue, 23 Jan 2018 10:52:27 -0800 Subject: [PATCH] More 0.7 compat (#52) * `copy!()` -> `copyto!()` * Quash more 0.7 compatibility bugs * Require at least Compat 0.38 --- REQUIRE | 2 +- src/common.jl | 4 ++-- src/types.jl | 10 +++++----- test/perf.jl | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/REQUIRE b/REQUIRE index 51e7b42473989..5122f092a16ba 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,2 @@ julia 0.6 -Compat +Compat 0.38 diff --git a/src/common.jl b/src/common.jl index 26050b6aa9fee..16d177fdbe7e7 100644 --- a/src/common.jl +++ b/src/common.jl @@ -13,7 +13,7 @@ function update!(context::T, data::U) where {T<:SHA_CTX, usedspace = context.bytecount % blocklen(T) while len - data_idx + usedspace >= blocklen(T) # Fill up as much of the buffer as we can with the data given us - copy!(context.buffer, usedspace + 1, data, data_idx + 1, blocklen(T) - usedspace) + copyto!(context.buffer, usedspace + 1, data, data_idx + 1, blocklen(T) - usedspace) transform!(context) context.bytecount += blocklen(T) - usedspace @@ -23,7 +23,7 @@ function update!(context::T, data::U) where {T<:SHA_CTX, # There is less than a complete block left, but we need to save the leftovers into context.buffer: if len > data_idx - copy!(context.buffer, usedspace + 1, data, data_idx + 1, len - data_idx) + copyto!(context.buffer, usedspace + 1, data, data_idx + 1, len - data_idx) context.bytecount += len - data_idx end end diff --git a/src/types.jl b/src/types.jl index b52023b6accbf..68440f2c36319 100644 --- a/src/types.jl +++ b/src/types.jl @@ -115,10 +115,10 @@ SHA2_256_CTX() = SHA2_256_CTX(copy(SHA2_256_initial_hash_value), 0, zeros(UInt8, SHA2_384_CTX() = SHA2_384_CTX(copy(SHA2_384_initial_hash_value), 0, zeros(UInt8, blocklen(SHA2_384_CTX))) SHA2_512_CTX() = SHA2_512_CTX(copy(SHA2_512_initial_hash_value), 0, zeros(UInt8, blocklen(SHA2_512_CTX))) -SHA3_224_CTX() = SHA3_224_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_224_CTX)), Vector{UInt64}(5)) -SHA3_256_CTX() = SHA3_256_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_256_CTX)), Vector{UInt64}(5)) -SHA3_384_CTX() = SHA3_384_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_384_CTX)), Vector{UInt64}(5)) -SHA3_512_CTX() = SHA3_512_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_512_CTX)), Vector{UInt64}(5)) +SHA3_224_CTX() = SHA3_224_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_224_CTX)), Vector{UInt64}(uninitialized, 5)) +SHA3_256_CTX() = SHA3_256_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_256_CTX)), Vector{UInt64}(uninitialized, 5)) +SHA3_384_CTX() = SHA3_384_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_384_CTX)), Vector{UInt64}(uninitialized, 5)) +SHA3_512_CTX() = SHA3_512_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_512_CTX)), Vector{UInt64}(uninitialized, 5)) # Nickname'd outer constructor methods for SHA2 const SHA224_CTX = SHA2_224_CTX @@ -133,7 +133,7 @@ SHA1_CTX() = SHA1_CTX(copy(SHA1_initial_hash_value), 0, zeros(UInt8, blocklen(SH # Copy functions copy(ctx::T) where {T<:SHA1_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), copy(ctx.W)) copy(ctx::T) where {T<:SHA2_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer)) -copy(ctx::T) where {T<:SHA3_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), Array{UInt64}(5)) +copy(ctx::T) where {T<:SHA3_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), Vector{UInt64}(uninitialized, 5)) # Make printing these types a little friendlier diff --git a/test/perf.jl b/test/perf.jl index a366a6fa6eaf9..c43bda8b36bcd 100644 --- a/test/perf.jl +++ b/test/perf.jl @@ -11,34 +11,34 @@ function do_tests(filepath) # test performance print("read: ") @time begin - const fh = open(filepath, "r") - const bytes = read(fh) + fh = open(filepath, "r") + bytes = read(fh) end - gc() + GC.gc() print("SHA-1: ") sha1(bytes) - gc() + GC.gc() @time sha1(bytes) print("SHA2-256: ") sha256(bytes) - gc() + GC.gc() @time sha256(bytes) print("SHA2-512: ") sha512(bytes) - gc() + GC.gc() @time sha512(bytes) print("SHA3-256: ") sha3_256(bytes) - gc() + GC.gc() @time sha3_256(bytes) print("SHA3-512: ") sha3_512(bytes) - gc() + GC.gc() @time sha3_512(bytes) end