Skip to content

Commit f264ba1

Browse files
committed
Various small fixes for julia-0.6
* Remove depwarns for takebuf_string, typealias, Base.linearindexing * Use Compat.readline for new chomp argument * Fix tests which were broken by simplified array arithmetic promotion
1 parent 9e5bee7 commit f264ba1

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
julia 0.5
2+
Compat 0.13.0

src/PlyIO.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ __precompile__()
22

33
module PlyIO
44

5+
using Compat
6+
57
# Types for the ply data model
68
export Ply, PlyElement, PlyComment, ArrayProperty, ListProperty
79
export plyname # Is there something in base we could overload for this?

src/io.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ply_type_name(::Int64) = "int64"
4444
ply_type_name(::Float32) = "float32"
4545
ply_type_name(::Float64) = "float64"
4646

47-
typealias PlyNativeType Union{UInt8,UInt16,UInt32,UInt64,Int8,Int16,Int32,Int64,Float32,Float64}
47+
@compat const PlyNativeType = Union{UInt8,UInt16,UInt32,UInt64,Int8,Int16,Int32,Int64,Float32,Float64}
4848

4949
ply_type_name{T<:PlyNativeType}(A::AbstractArray{T}) = ply_type_name(T)
5050

@@ -56,23 +56,28 @@ const _host_is_little_endian = (ENDIAN_BOM == 0x04030201)
5656

5757

5858
function read_header(ply_file)
59-
@assert readline(ply_file) == "ply\n"
59+
firstline = Compat.readline(ply_file)
60+
if firstline != "ply"
61+
throw(ErrorException("Expected \"ply\" header, got \"$firstline\""))
62+
end
6063
element_name = ""
6164
element_numel = 0
6265
element_props = Vector{AbstractVector}()
6366
elements = PlyElement[]
6467
comments = PlyComment[]
6568
format = nothing
6669
while true
67-
line = strip(readline(ply_file))
70+
line = Compat.readline(ply_file)
6871
if line == "end_header"
6972
break
7073
elseif startswith(line, "comment")
7174
push!(comments, PlyComment(strip(line[8:end]), length(elements)+1))
7275
elseif startswith(line, "format")
7376
tok, format_type, format_version = split(line)
7477
@assert tok == "format"
75-
@assert format_version == "1.0"
78+
if format_version != "1.0"
79+
throw(ErrorException("Expected ply version 1.0, got $format_version"))
80+
end
7681
format = format_type == "ascii" ? Format_ascii :
7782
format_type == "binary_little_endian" ? Format_binary_little :
7883
format_type == "binary_big_endian" ? Format_binary_big :

src/types.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Return the name that `data` is associated with when serialized in a ply file
99
function plyname
1010
end
1111

12-
typealias PropNameList Union{AbstractVector,Tuple}
12+
@compat const PropNameList = Union{AbstractVector,Tuple}
1313

1414
#--------------------------------------------------
1515
"""
@@ -41,7 +41,7 @@ Base.summary(prop::ArrayProperty) = "$(length(prop))-element $(typeof(prop)) \"$
4141
Base.size(prop::ArrayProperty) = size(prop.data)
4242
Base.getindex(prop::ArrayProperty, i::Int) = prop.data[i]
4343
Base.setindex!(prop::ArrayProperty, v, i::Int) = prop.data[i] = v
44-
Base.linearindexing(prop::ArrayProperty) = Base.LinearFast()
44+
@compat Base.IndexStyle(::Type{<:ArrayProperty}) = IndexLinear()
4545

4646
# List methods
4747
Base.resize!(prop::ArrayProperty, len) = resize!(prop.data, len)
@@ -80,7 +80,7 @@ Base.summary(prop::ListProperty) = "$(length(prop))-element $(typeof(prop)) \"$(
8080
Base.length(prop::ListProperty) = length(prop.start_inds)-1
8181
Base.size(prop::ListProperty) = (length(prop),)
8282
Base.getindex(prop::ListProperty, i::Int) = prop.data[prop.start_inds[i]:prop.start_inds[i+1]-1]
83-
Base.linearindexing(prop::ListProperty) = Base.LinearFast()
83+
@compat Base.IndexStyle(::Type{<:ListProperty}) = IndexLinear()
8484
# TODO: Do we need Base.setindex!() ? Hard to provide with above formulation...
8585

8686
# List methods
@@ -198,7 +198,7 @@ Ply() = Ply(Vector{PlyElement}(), Vector{String}())
198198
function Base.show(io::IO, ply::Ply)
199199
buf = IOBuffer()
200200
write_header(ply, buf, true)
201-
headerstr = takebuf_string(buf)
201+
headerstr = String(take!(buf))
202202
headerstr = replace(strip(headerstr), "\n", "\n ")
203203
print(io, "$Ply with header:\n $headerstr")
204204
end

test/runtests.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using PlyIO
22
using StaticArrays
33
using Base.Test
4+
using Compat
45

56
@testset "PlyIO" begin
67

@@ -22,7 +23,7 @@ using Base.Test
2223

2324
buf = IOBuffer()
2425
save_ply(ply, buf, ascii=true)
25-
str = takebuf_string(buf)
26+
str = String(take!(buf))
2627
open("simple_test_tmp.ply", "w") do fid
2728
write(fid, str)
2829
end
@@ -58,7 +59,7 @@ end
5859

5960
buf = IOBuffer()
6061
save_ply(ply, buf, ascii=true)
61-
str = takebuf_string(buf)
62+
str = String(take!(buf))
6263
open("empty_test_tmp.ply", "w") do fid
6364
write(fid, str)
6465
end
@@ -114,7 +115,7 @@ end
114115
UInt8, UInt16, UInt32, UInt64,
115116
Float32, Float64]
116117
ply = Ply()
117-
arrayprop = zeros(proptype, 1) + 42
118+
arrayprop = fill(proptype(42), 1)
118119
listprop = ListProperty("listprop", proptype<:Integer ? proptype : Int32, proptype)
119120
push!(listprop, collect(proptype, 1:10))
120121
push!(ply, PlyElement("test", ArrayProperty("arrayprop", arrayprop), listprop))
@@ -141,7 +142,7 @@ end
141142
))
142143
buf = IOBuffer()
143144
save_ply(ply, buf, ascii=true)
144-
str = takebuf_string(buf)
145+
str = String(take!(buf))
145146
open("SVector_properties_test_tmp.ply", "w") do fid
146147
write(fid, str)
147148
end

0 commit comments

Comments
 (0)