Skip to content

Commit

Permalink
Fixes for 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Feb 13, 2018
1 parent 33d7306 commit 4920667
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/FlatBuffers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ function getvalue(t, o, ::Type{Vector{T}}) where {T}
return getarray(t, vp, vl, T)
end

Base.convert(::Type{T}, e::Integer) where {T <: Enum} = T(e)

# fallback which recursively calls read
function getvalue(t, o, ::Type{T}) where {T}
if isstruct(T)
Expand Down
2 changes: 1 addition & 1 deletion src/internals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function createbytevector(b::Builder, v::AbstractVector{UInt8})
l = length(v)

b.head -= l
copy!(b.bytes, b.head+1, v, 1, l)
copyto!(b.bytes, b.head+1, v, 1, l)

return endvector(b, length(v))
end
Expand Down
27 changes: 15 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ using FlatBuffers
else
using Test
end
if !isdefined(Base, :Nothing)
const Nothing = Void
end

include("internals.jl")
CheckByteLayout()
Expand Down Expand Up @@ -146,7 +149,7 @@ inst7_2 = FlatBuffers.read(t)
# x::TestUnionI
# }

@UNION TestUnionU (Void,TestInt8T,TestInt8A)
@UNION TestUnionU (Nothing,TestInt8T,TestInt8A)

mutable struct TestUnionT
x_type::Int8
Expand Down Expand Up @@ -178,15 +181,15 @@ inst9_2 = FlatBuffers.read(t)
a::Int32
end
@test sizeof(A) == 4
@test fieldnames(A) == [:a]
@test all(fieldnames(A) .== [:a])
@test A(1) == A(1)

@STRUCT struct B
a::Int8
b::Int32
end
@test sizeof(B) == 8
@test fieldnames(B) == [:a, :_pad_a_B_0, :_pad_a_B_1, :b]
@test all(fieldnames(B) .== [:a, :_pad_a_B_0, :_pad_a_B_1, :b])
@test B(1,2) == B(1,2)

@STRUCT struct C
Expand All @@ -195,23 +198,23 @@ end
c::Int16
end
@test sizeof(C) == 12
@test fieldnames(C) == [:a, :_pad_a_C_0, :b, :c, :_pad_c_C_1]
@test all(fieldnames(C) .== [:a, :_pad_a_C_0, :b, :c, :_pad_c_C_1])
@test C(1,2,3) == C(1,2,3)

@STRUCT struct D
a::Int8
b::Int64
end
@test sizeof(D) == 16
@test fieldnames(D) == [:a, :_pad_a_D_0, :_pad_a_D_1, :_pad_a_D_2, :b]
@test all(fieldnames(D) .== [:a, :_pad_a_D_0, :_pad_a_D_1, :_pad_a_D_2, :b])
@test D(1,2) == D(1,2)

@STRUCT struct E
a::Int64
b::Int32
end
@test sizeof(E) == 16
@test fieldnames(E) == [:a, :b, :_pad_b_E_0]
@test all(fieldnames(E) .== [:a, :b, :_pad_b_E_0])
@test E(1,2) == E(1,2)

@STRUCT struct F
Expand All @@ -222,7 +225,7 @@ end
e::Int64
end
@test sizeof(F) == 24
@test fieldnames(F) == [:a, :b, :_pad_b_F_0, :c, :d, :e]
@test all(fieldnames(F) .== [:a, :b, :_pad_b_F_0, :c, :d, :e])
@test F(1,2,3,4,5) == F(1,2,3,4,5)

@STRUCT struct G
Expand All @@ -232,7 +235,7 @@ end
d::Int32
end
@test sizeof(G) == 24
@test fieldnames(G) == [:a, :b, :_pad_b_G_0, :c, :_pad_c_G_1, :d]
@test all(fieldnames(G) .== [:a, :b, :_pad_b_G_0, :c, :_pad_c_G_1, :d])
@test G(1,2,3,4) == G(1,2,3,4)

@STRUCT struct H
Expand All @@ -241,7 +244,7 @@ end
c::Int16
end
@test sizeof(H) == 8
@test fieldnames(H) == [:a, :b, :_pad_b_H_0, :c]
@test all(fieldnames(H) .== [:a, :b, :_pad_b_H_0, :c])
@test H(1,2,3) == H(1,2,3)

@STRUCT struct I
Expand All @@ -250,15 +253,15 @@ end
c::Int32
end
@test sizeof(I) == 16
@test fieldnames(I) == [:a, :b, :_pad_b_I_0, :_pad_b_I_1, :c]
@test all(fieldnames(I) .== [:a, :b, :_pad_b_I_0, :_pad_b_I_1, :c])
@test I(1,2,3) == I(1,2,3)

@STRUCT struct J
a::Int8
b::A
end
@test sizeof(J) == 8
@test fieldnames(J) == [:a, :_pad_a_J_0, :_pad_a_J_1, :b_A_a]
@test all(fieldnames(J) .== [:a, :_pad_a_J_0, :_pad_a_J_1, :b_A_a])
@test J(1,A(2)) == J(1,A(2))

@STRUCT struct K
Expand All @@ -267,5 +270,5 @@ end
c::J
end
@test sizeof(K) == 48
@test fieldnames(K) == [:a_J_a, :a_J__pad_a_J_0, :a_J__pad__pad_a_J_0_J_0, :a_J__pad_a_J_1, :a_J__pad__pad_a_J_1_J_1, :a_J_b_A_a, :b_I_a, :b_I_b, :b_I__pad_b_I_0, :b_I__pad__pad_b_I_0_I_0, :b_I__pad_b_I_1, :b_I__pad__pad_b_I_1_I_1, :b_I_c, :c_J_a, :c_J__pad_a_J_0, :c_J__pad__pad_a_J_0_J_0, :c_J__pad_a_J_1, :c_J__pad__pad_a_J_1_J_1, :c_J_b_A_a]
@test all(fieldnames(K) .== [:a_J_a, :a_J__pad_a_J_0, :a_J__pad__pad_a_J_0_J_0, :a_J__pad_a_J_1, :a_J__pad__pad_a_J_1_J_1, :a_J_b_A_a, :b_I_a, :b_I_b, :b_I__pad_b_I_0, :b_I__pad__pad_b_I_0_I_0, :b_I__pad_b_I_1, :b_I__pad__pad_b_I_1_I_1, :b_I_c, :c_J_a, :c_J__pad_a_J_0, :c_J__pad__pad_a_J_0_J_0, :c_J__pad_a_J_1, :c_J__pad__pad_a_J_1_J_1, :c_J_b_A_a])
@test K(J(1,A(2)), I(3.0, 4, 5), J(6, A(7))) == K(J(1,A(2)), I(3.0, 4, 5), J(6, A(7)))

0 comments on commit 4920667

Please sign in to comment.