From 00540265a065eaadc6794513186c5cf8da9afcf5 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Mon, 11 Jul 2016 20:01:38 -0700 Subject: [PATCH 1/3] adjust indentation in doc/manual/types.rst --- doc/manual/types.rst | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/doc/manual/types.rst b/doc/manual/types.rst index a193c1a7c3809..67993e82e345b 100644 --- a/doc/manual/types.rst +++ b/doc/manual/types.rst @@ -123,8 +123,8 @@ using :func:`convert`: .. doctest:: foo-func julia> function foo() - x::Int8 = 100 - x + x::Int8 = 100 + x end foo (generic function with 1 method) @@ -251,7 +251,7 @@ An important use of abstract types is to provide default implementations for concrete types. To give a simple example, consider:: function myplus(x,y) - x+y + x+y end The first thing to note is that the above argument declarations are equivalent @@ -266,7 +266,7 @@ arguments based on the generic function given above, i.e., it implicitly defines and compiles:: function myplus(x::Int,y::Int) - x+y + x+y end and finally, it invokes this specific method. @@ -378,9 +378,9 @@ operator: .. doctest:: julia> type Foo - bar - baz::Int - qux::Float64 + bar + baz::Int + qux::Float64 end Fields with no type annotation default to :obj:`Any`, and can accordingly @@ -477,8 +477,8 @@ It is also possible to define *immutable* composite types by using the keyword ``immutable`` instead of ``type``:: immutable Complex - real::Float64 - imag::Float64 + real::Float64 + imag::Float64 end Such types behave much like other composite types, except that instances @@ -620,16 +620,16 @@ Parametric Composite Types abstract Pointy{T} type Point{T} <: Pointy{T} - x::T - y::T + x::T + y::T end Type parameters are introduced immediately after the type name, surrounded by curly braces:: type Point{T} - x::T - y::T + x::T + y::T end This declaration defines a new parametric type, ``Point{T}``, holding @@ -853,8 +853,8 @@ example, have declared ``Point{T}`` to be a subtype of ``Pointy{T}`` as follows:: type Point{T} <: Pointy{T} - x::T - y::T + x::T + y::T end Given such a declaration, for each choice of ``T``, we have ``Point{T}`` @@ -883,7 +883,7 @@ Consider if we create a point-like implementation that only requires a single coordinate because the point is on the diagonal line *x = y*:: type DiagPoint{T} <: Pointy{T} - x::T + x::T end Now both ``Point{Float64}`` and ``DiagPoint{Float64}`` are @@ -928,8 +928,8 @@ Type parameters for parametric composite types can be restricted in the same manner:: type Point{T<:Real} <: Pointy{T} - x::T - y::T + x::T + y::T end To give a real-world example of how all this parametric type @@ -938,8 +938,8 @@ machinery can be useful, here is the actual definition of Julia's for simplicity), representing an exact ratio of integers:: immutable Rational{T<:Integer} <: Real - num::T - den::T + num::T + den::T end It only makes sense to take ratios of integer values, so the parameter @@ -958,8 +958,8 @@ of one field. For example, a 2-element tuple type resembles the following immutable type:: immutable Tuple2{A,B} - a::A - b::B + a::A + b::B end However, there are three key differences: From 0e834c51270b39e55ec1acb7fcad2dec4439323b Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Mon, 11 Jul 2016 20:08:55 -0700 Subject: [PATCH 2/3] Remove use of 'abstract type' when discussing parametric composite types this is a bit confusing and we don't have a great word for it, but since Point wasn't declared with abstract here we probably shouldn't use that term --- doc/manual/types.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual/types.rst b/doc/manual/types.rst index 67993e82e345b..11fd15d6b920b 100644 --- a/doc/manual/types.rst +++ b/doc/manual/types.rst @@ -661,7 +661,7 @@ However, ``Point`` itself is also a valid type object: Point{T} Here the ``T`` is the dummy type symbol used in the original declaration -of ``Point``. What does ``Point`` by itself mean? It is an abstract type +of ``Point``. What does ``Point`` by itself mean? It is a type that contains all the specific instances ``Point{Float64}``, ``Point{AbstractString}``, etc.: From ebff12b6edff92cf1c20197a4070cfccf5237b88 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Sun, 10 Jul 2016 11:41:12 -0700 Subject: [PATCH 3/3] Rename AbstractIOBuffer to IOBufferBase ref discussion at https://github.com/JuliaLang/julia/pull/11554#commitcomment-16067265 it might be better to rename this to IOBuffer but I'm not sure how to make that work --- base/deprecated.jl | 4 ++- base/iobuffer.jl | 90 +++++++++++++++++++++++----------------------- base/stream.jl | 4 +-- base/strings/io.jl | 2 +- 4 files changed, 51 insertions(+), 49 deletions(-) diff --git a/base/deprecated.jl b/base/deprecated.jl index 9f0247a809e21..a3c740fe00b5d 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -455,7 +455,7 @@ end @deprecate bytestring(s::Cstring) unsafe_string(s) @deprecate bytestring(v::Vector{UInt8}) String(copy(v)) -@deprecate bytestring(io::Base.AbstractIOBuffer) String(io) +@deprecate bytestring(io::Base.IOBufferBase) String(io) @deprecate bytestring(p::Union{Ptr{Int8},Ptr{UInt8}}) unsafe_string(p) @deprecate bytestring(p::Union{Ptr{Int8},Ptr{UInt8}}, len::Integer) unsafe_string(p,len) @deprecate bytestring(s::AbstractString...) string(s...) @@ -793,6 +793,8 @@ function transpose(x) return x end +@deprecate_binding AbstractIOBuffer IOBufferBase + # During the 0.5 development cycle, do not add any deprecations below this line # To be deprecated in 0.6 diff --git a/base/iobuffer.jl b/base/iobuffer.jl index e644a7e3af497..949fbfcbf3ea6 100644 --- a/base/iobuffer.jl +++ b/base/iobuffer.jl @@ -3,7 +3,7 @@ ## work with AbstractVector{UInt8} via I/O primitives ## # Stateful string -type AbstractIOBuffer{T<:AbstractVector{UInt8}} <: IO +type IOBufferBase{T<:AbstractVector{UInt8}} <: IO data::T # T should support: getindex, setindex!, length, copy!, resize!, and T() readable::Bool writable::Bool @@ -14,27 +14,27 @@ type AbstractIOBuffer{T<:AbstractVector{UInt8}} <: IO ptr::Int # read (and maybe write) pointer mark::Int # reset mark location for ptr (or <0 for no mark) - AbstractIOBuffer(data::T,readable::Bool,writable::Bool,seekable::Bool,append::Bool,maxsize::Int) = + IOBufferBase(data::T,readable::Bool,writable::Bool,seekable::Bool,append::Bool,maxsize::Int) = new(data,readable,writable,seekable,append,length(data),maxsize,1,-1) end -typealias IOBuffer AbstractIOBuffer{Vector{UInt8}} +typealias IOBuffer IOBufferBase{Vector{UInt8}} -AbstractIOBuffer{T<:AbstractVector{UInt8}}(data::T, readable::Bool, writable::Bool, seekable::Bool, append::Bool, maxsize::Int) = - AbstractIOBuffer{T}(data, readable, writable, seekable, append, maxsize) +IOBufferBase{T<:AbstractVector{UInt8}}(data::T, readable::Bool, writable::Bool, seekable::Bool, append::Bool, maxsize::Int) = + IOBufferBase{T}(data, readable, writable, seekable, append, maxsize) # IOBuffers behave like Files. They are typically readable and writable. They are seekable. (They can be appendable). IOBuffer(data::AbstractVector{UInt8}, readable::Bool=true, writable::Bool=false, maxsize::Int=typemax(Int)) = - AbstractIOBuffer(data, readable, writable, true, false, maxsize) + IOBufferBase(data, readable, writable, true, false, maxsize) IOBuffer(readable::Bool, writable::Bool) = IOBuffer(UInt8[], readable, writable) IOBuffer() = IOBuffer(true, true) IOBuffer(maxsize::Int) = (x=IOBuffer(Array{UInt8}(maxsize), true, true, maxsize); x.size=0; x) # PipeBuffers behave like Unix Pipes. They are typically readable and writable, they act appendable, and are not seekable. PipeBuffer(data::Vector{UInt8}=UInt8[], maxsize::Int=typemax(Int)) = - AbstractIOBuffer(data,true,true,false,true,maxsize) + IOBufferBase(data,true,true,false,true,maxsize) PipeBuffer(maxsize::Int) = (x = PipeBuffer(Array{UInt8}(maxsize),maxsize); x.size=0; x) -function copy(b::AbstractIOBuffer) +function copy(b::IOBufferBase) ret = typeof(b)(b.writable ? copy(b.data) : b.data, b.readable, b.writable, b.seekable, b.append, b.maxsize) ret.size = b.size @@ -42,7 +42,7 @@ function copy(b::AbstractIOBuffer) return ret end -show(io::IO, b::AbstractIOBuffer) = print(io, "IOBuffer(data=UInt8[...], ", +show(io::IO, b::IOBufferBase) = print(io, "IOBuffer(data=UInt8[...], ", "readable=", b.readable, ", ", "writable=", b.writable, ", ", "seekable=", b.seekable, ", ", @@ -52,7 +52,7 @@ show(io::IO, b::AbstractIOBuffer) = print(io, "IOBuffer(data=UInt8[...], ", "ptr=", b.ptr, ", ", "mark=", b.mark, ")") -function unsafe_read(from::AbstractIOBuffer, p::Ptr{UInt8}, nb::UInt) +function unsafe_read(from::IOBufferBase, p::Ptr{UInt8}, nb::UInt) from.readable || throw(ArgumentError("read failed, IOBuffer is not readable")) avail = nb_available(from) adv = min(avail, nb) @@ -64,7 +64,7 @@ function unsafe_read(from::AbstractIOBuffer, p::Ptr{UInt8}, nb::UInt) nothing end -function read_sub{T}(from::AbstractIOBuffer, a::AbstractArray{T}, offs, nel) +function read_sub{T}(from::IOBufferBase, a::AbstractArray{T}, offs, nel) from.readable || throw(ArgumentError("read failed, IOBuffer is not readable")) if offs+nel-1 > length(a) || offs < 1 || nel < 0 throw(BoundsError()) @@ -80,7 +80,7 @@ function read_sub{T}(from::AbstractIOBuffer, a::AbstractArray{T}, offs, nel) return a end -@inline function read(from::AbstractIOBuffer, ::Type{UInt8}) +@inline function read(from::IOBufferBase, ::Type{UInt8}) from.readable || throw(ArgumentError("read failed, IOBuffer is not readable")) ptr = from.ptr size = from.size @@ -92,7 +92,7 @@ end return byte end -function peek(from::AbstractIOBuffer) +function peek(from::IOBufferBase) from.readable || throw(ArgumentError("read failed, IOBuffer is not readable")) if from.ptr > from.size throw(EOFError()) @@ -100,43 +100,43 @@ function peek(from::AbstractIOBuffer) return from.data[from.ptr] end -read{T}(from::AbstractIOBuffer, ::Type{Ptr{T}}) = convert(Ptr{T}, read(from, UInt)) +read{T}(from::IOBufferBase, ::Type{Ptr{T}}) = convert(Ptr{T}, read(from, UInt)) -isreadable(io::AbstractIOBuffer) = io.readable -iswritable(io::AbstractIOBuffer) = io.writable +isreadable(io::IOBufferBase) = io.readable +iswritable(io::IOBufferBase) = io.writable -# TODO: AbstractIOBuffer is not iterable, so doesn't really have a length. +# TODO: IOBufferBase is not iterable, so doesn't really have a length. # This should maybe be sizeof() instead. -#length(io::AbstractIOBuffer) = (io.seekable ? io.size : nb_available(io)) -nb_available(io::AbstractIOBuffer) = io.size - io.ptr + 1 -position(io::AbstractIOBuffer) = io.ptr-1 +#length(io::IOBufferBase) = (io.seekable ? io.size : nb_available(io)) +nb_available(io::IOBufferBase) = io.size - io.ptr + 1 +position(io::IOBufferBase) = io.ptr-1 -function skip(io::AbstractIOBuffer, n::Integer) +function skip(io::IOBufferBase, n::Integer) seekto = io.ptr + n n < 0 && return seek(io, seekto-1) # Does error checking io.ptr = min(seekto, io.size+1) return io end -function seek(io::AbstractIOBuffer, n::Integer) +function seek(io::IOBufferBase, n::Integer) if !io.seekable ismarked(io) || throw(ArgumentError("seek failed, IOBuffer is not seekable and is not marked")) n == io.mark || throw(ArgumentError("seek failed, IOBuffer is not seekable and n != mark")) end # TODO: REPL.jl relies on the fact that this does not throw (by seeking past the beginning or end - # of an AbstractIOBuffer), so that would need to be fixed in order to throw an error here + # of an IOBufferBase), so that would need to be fixed in order to throw an error here #(n < 0 || n > io.size) && throw(ArgumentError("Attempted to seek outside IOBuffer boundaries.")) #io.ptr = n+1 io.ptr = max(min(n+1, io.size+1), 1) return io end -function seekend(io::AbstractIOBuffer) +function seekend(io::IOBufferBase) io.ptr = io.size+1 return io end -function truncate(io::AbstractIOBuffer, n::Integer) +function truncate(io::IOBufferBase, n::Integer) io.writable || throw(ArgumentError("truncate failed, IOBuffer is not writeable")) io.seekable || throw(ArgumentError("truncate failed, IOBuffer is not seekable")) n < 0 && throw(ArgumentError("truncate failed, n bytes must be ≥ 0, got $n")) @@ -151,7 +151,7 @@ function truncate(io::AbstractIOBuffer, n::Integer) return io end -function compact(io::AbstractIOBuffer) +function compact(io::IOBufferBase) io.writable || throw(ArgumentError("compact failed, IOBuffer is not writeable")) io.seekable && throw(ArgumentError("compact failed, IOBuffer is seekable")) local ptr::Int, bytes_to_move::Int @@ -170,8 +170,8 @@ function compact(io::AbstractIOBuffer) return io end -@inline ensureroom(io::AbstractIOBuffer, nshort::Int) = ensureroom(io, UInt(nshort)) -@inline function ensureroom(io::AbstractIOBuffer, nshort::UInt) +@inline ensureroom(io::IOBufferBase, nshort::Int) = ensureroom(io, UInt(nshort)) +@inline function ensureroom(io::IOBufferBase, nshort::UInt) io.writable || throw(ArgumentError("ensureroom failed, IOBuffer is not writeable")) if !io.seekable nshort >= 0 || throw(ArgumentError("ensureroom failed, requested number of bytes must be ≥ 0, got $nshort")) @@ -196,9 +196,9 @@ end return io end -eof(io::AbstractIOBuffer) = (io.ptr-1 == io.size) +eof(io::IOBufferBase) = (io.ptr-1 == io.size) -@noinline function close{T}(io::AbstractIOBuffer{T}) +@noinline function close{T}(io::IOBufferBase{T}) io.readable = false io.writable = false io.seekable = false @@ -214,15 +214,15 @@ eof(io::AbstractIOBuffer) = (io.ptr-1 == io.size) nothing end -isopen(io::AbstractIOBuffer) = io.readable || io.writable || io.seekable || nb_available(io) > 0 +isopen(io::IOBufferBase) = io.readable || io.writable || io.seekable || nb_available(io) > 0 -function String(io::AbstractIOBuffer) +function String(io::IOBufferBase) io.readable || throw(ArgumentError("IOBuffer is not readable")) io.seekable || throw(ArgumentError("IOBuffer is not seekable")) return String(copy!(Array{UInt8}(io.size), 1, io.data, 1, io.size)) end -function takebuf_array(io::AbstractIOBuffer) +function takebuf_array(io::IOBufferBase) ismarked(io) && unmark(io) if io.seekable nbytes = io.size @@ -259,9 +259,9 @@ function takebuf_array(io::IOBuffer) end return data end -takebuf_string(io::AbstractIOBuffer) = String(takebuf_array(io)) +takebuf_string(io::IOBufferBase) = String(takebuf_array(io)) -function write(to::AbstractIOBuffer, from::AbstractIOBuffer) +function write(to::IOBufferBase, from::IOBufferBase) if to === from from.ptr = from.size + 1 return 0 @@ -271,7 +271,7 @@ function write(to::AbstractIOBuffer, from::AbstractIOBuffer) return written end -function unsafe_write(to::AbstractIOBuffer, p::Ptr{UInt8}, nb::UInt) +function unsafe_write(to::IOBufferBase, p::Ptr{UInt8}, nb::UInt) ensureroom(to, nb) ptr = (to.append ? to.size+1 : to.ptr) written = min(nb, length(to.data) - ptr + 1) @@ -290,7 +290,7 @@ function unsafe_write(to::AbstractIOBuffer, p::Ptr{UInt8}, nb::UInt) return written end -function write_sub{T}(to::AbstractIOBuffer, a::AbstractArray{T}, offs, nel) +function write_sub{T}(to::IOBufferBase, a::AbstractArray{T}, offs, nel) if offs+nel-1 > length(a) || offs < 1 || nel < 0 throw(BoundsError()) end @@ -308,7 +308,7 @@ function write_sub{T}(to::AbstractIOBuffer, a::AbstractArray{T}, offs, nel) return written end -@inline function write(to::AbstractIOBuffer, a::UInt8) +@inline function write(to::IOBufferBase, a::UInt8) ensureroom(to, UInt(1)) ptr = (to.append ? to.size+1 : to.ptr) if ptr > to.maxsize @@ -323,8 +323,8 @@ end return sizeof(UInt8) end -readbytes!(io::AbstractIOBuffer, b::Array{UInt8}, nb=length(b)) = readbytes!(io, b, Int(nb)) -function readbytes!(io::AbstractIOBuffer, b::Array{UInt8}, nb::Int) +readbytes!(io::IOBufferBase, b::Array{UInt8}, nb=length(b)) = readbytes!(io, b, Int(nb)) +function readbytes!(io::IOBufferBase, b::Array{UInt8}, nb::Int) nr = min(nb, nb_available(io)) if length(b) < nr resize!(b, nr) @@ -332,9 +332,9 @@ function readbytes!(io::AbstractIOBuffer, b::Array{UInt8}, nb::Int) read_sub(io, b, 1, nr) return nr end -read(io::AbstractIOBuffer) = read!(io,Array{UInt8}(nb_available(io))) -readavailable(io::AbstractIOBuffer) = read(io) -read(io::AbstractIOBuffer, nb::Integer) = read!(io,Array{UInt8}(min(nb, nb_available(io)))) +read(io::IOBufferBase) = read!(io,Array{UInt8}(nb_available(io))) +readavailable(io::IOBufferBase) = read(io) +read(io::IOBufferBase, nb::Integer) = read!(io,Array{UInt8}(min(nb, nb_available(io)))) function search(buf::IOBuffer, delim::UInt8) p = pointer(buf.data, buf.ptr) @@ -343,7 +343,7 @@ function search(buf::IOBuffer, delim::UInt8) return nb end -function search(buf::AbstractIOBuffer, delim::UInt8) +function search(buf::IOBufferBase, delim::UInt8) data = buf.data for i = buf.ptr : buf.size @inbounds b = data[i] @@ -354,7 +354,7 @@ function search(buf::AbstractIOBuffer, delim::UInt8) return 0 end -function readuntil(io::AbstractIOBuffer, delim::UInt8) +function readuntil(io::IOBufferBase, delim::UInt8) lb = 70 A = Array{UInt8}(lb) n = 0 diff --git a/base/stream.jl b/base/stream.jl index d649b88116736..2b685cdb50d96 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -13,7 +13,7 @@ abstract LibuvServer <: IOServer abstract LibuvStream <: IO # IO -# +- AbstractIOBuffer{T<:AbstractArray{UInt8,1}} (not exported) +# +- IOBufferBase{T<:AbstractArray{UInt8,1}} (not exported) # +- AbstractPipe (not exported) # . +- Pipe # . +- Process (not exported) @@ -28,7 +28,7 @@ abstract LibuvStream <: IO # . +- TCPSocket # . +- TTY (not exported) # . +- UDPSocket -# +- IOBuffer = Base.AbstractIOBuffer{Array{UInt8,1}} +# +- IOBuffer = Base.IOBufferBase{Array{UInt8,1}} # +- IOStream # IOServer diff --git a/base/strings/io.jl b/base/strings/io.jl index 151909d6405e4..5501cb8e15b71 100644 --- a/base/strings/io.jl +++ b/base/strings/io.jl @@ -69,7 +69,7 @@ print(io::IO, s::AbstractString) = (write(io, s); nothing) write(io::IO, s::AbstractString) = (len = 0; for c in s; len += write(io, c); end; len) show(io::IO, s::AbstractString) = print_quoted(io, s) -write(to::AbstractIOBuffer, s::SubString{String}) = +write(to::IOBufferBase, s::SubString{String}) = s.endof==0 ? 0 : write_sub(to, s.string.data, s.offset + 1, nextind(s, s.endof) - 1) ## printing literal quoted string data ##