Skip to content

Commit af7239e

Browse files
authored
More 0.7 compat (#52)
* `copy!()` -> `copyto!()` * Quash more 0.7 compatibility bugs * Require at least Compat 0.38
1 parent de59699 commit af7239e

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
julia 0.6
2-
Compat
2+
Compat 0.38

src/common.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function update!(context::T, data::U) where {T<:SHA_CTX,
1313
usedspace = context.bytecount % blocklen(T)
1414
while len - data_idx + usedspace >= blocklen(T)
1515
# Fill up as much of the buffer as we can with the data given us
16-
copy!(context.buffer, usedspace + 1, data, data_idx + 1, blocklen(T) - usedspace)
16+
copyto!(context.buffer, usedspace + 1, data, data_idx + 1, blocklen(T) - usedspace)
1717

1818
transform!(context)
1919
context.bytecount += blocklen(T) - usedspace
@@ -23,7 +23,7 @@ function update!(context::T, data::U) where {T<:SHA_CTX,
2323

2424
# There is less than a complete block left, but we need to save the leftovers into context.buffer:
2525
if len > data_idx
26-
copy!(context.buffer, usedspace + 1, data, data_idx + 1, len - data_idx)
26+
copyto!(context.buffer, usedspace + 1, data, data_idx + 1, len - data_idx)
2727
context.bytecount += len - data_idx
2828
end
2929
end

src/types.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ SHA2_256_CTX() = SHA2_256_CTX(copy(SHA2_256_initial_hash_value), 0, zeros(UInt8,
115115
SHA2_384_CTX() = SHA2_384_CTX(copy(SHA2_384_initial_hash_value), 0, zeros(UInt8, blocklen(SHA2_384_CTX)))
116116
SHA2_512_CTX() = SHA2_512_CTX(copy(SHA2_512_initial_hash_value), 0, zeros(UInt8, blocklen(SHA2_512_CTX)))
117117

118-
SHA3_224_CTX() = SHA3_224_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_224_CTX)), Vector{UInt64}(5))
119-
SHA3_256_CTX() = SHA3_256_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_256_CTX)), Vector{UInt64}(5))
120-
SHA3_384_CTX() = SHA3_384_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_384_CTX)), Vector{UInt64}(5))
121-
SHA3_512_CTX() = SHA3_512_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_512_CTX)), Vector{UInt64}(5))
118+
SHA3_224_CTX() = SHA3_224_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_224_CTX)), Vector{UInt64}(uninitialized, 5))
119+
SHA3_256_CTX() = SHA3_256_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_256_CTX)), Vector{UInt64}(uninitialized, 5))
120+
SHA3_384_CTX() = SHA3_384_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_384_CTX)), Vector{UInt64}(uninitialized, 5))
121+
SHA3_512_CTX() = SHA3_512_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_512_CTX)), Vector{UInt64}(uninitialized, 5))
122122

123123
# Nickname'd outer constructor methods for SHA2
124124
const SHA224_CTX = SHA2_224_CTX
@@ -133,7 +133,7 @@ SHA1_CTX() = SHA1_CTX(copy(SHA1_initial_hash_value), 0, zeros(UInt8, blocklen(SH
133133
# Copy functions
134134
copy(ctx::T) where {T<:SHA1_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), copy(ctx.W))
135135
copy(ctx::T) where {T<:SHA2_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer))
136-
copy(ctx::T) where {T<:SHA3_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), Array{UInt64}(5))
136+
copy(ctx::T) where {T<:SHA3_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), Vector{UInt64}(uninitialized, 5))
137137

138138

139139
# Make printing these types a little friendlier

test/perf.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ function do_tests(filepath)
1111
# test performance
1212
print("read: ")
1313
@time begin
14-
const fh = open(filepath, "r")
15-
const bytes = read(fh)
14+
fh = open(filepath, "r")
15+
bytes = read(fh)
1616
end
17-
gc()
17+
GC.gc()
1818

1919
print("SHA-1: ")
2020
sha1(bytes)
21-
gc()
21+
GC.gc()
2222
@time sha1(bytes)
2323

2424
print("SHA2-256: ")
2525
sha256(bytes)
26-
gc()
26+
GC.gc()
2727
@time sha256(bytes)
2828

2929
print("SHA2-512: ")
3030
sha512(bytes)
31-
gc()
31+
GC.gc()
3232
@time sha512(bytes)
3333

3434
print("SHA3-256: ")
3535
sha3_256(bytes)
36-
gc()
36+
GC.gc()
3737
@time sha3_256(bytes)
3838

3939
print("SHA3-512: ")
4040
sha3_512(bytes)
41-
gc()
41+
GC.gc()
4242
@time sha3_512(bytes)
4343
end
4444

0 commit comments

Comments
 (0)