Skip to content

Commit

Permalink
Compat.StringVector (from #348)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Sep 10, 2018
1 parent cb4e731 commit bd7f2db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Compat.invokelatest` supports keywords ([#22646]).

* `Compat.StringVector` is supported on 0.5 and below. On 0.6 and later, it aliases `Base.StringVector`. This function allocates a `Vector{UInt8}` whose data can be made into a `String` in constant time; that is, without copying. On 0.5 and later, use `String(...)` with the vector allocated by `StringVector` as an argument to create a string without copying. Note that if 0.4 support is needed, `Compat.UTF8String(...)` should be used instead. ([#19449])

* `@__MODULE__` is aliased to `current_module()` for Julia versions 0.6 and below. Versions of `Base.binding_module`, `expand`, `macroexpand`, and `include_string` were added that accept a module as the first argument. ([#22064])

* `Cmd` elements can be accessed as if the `Cmd` were an array of strings for 0.6 and below ([#21197]).
Expand Down Expand Up @@ -456,7 +454,6 @@ includes this fix. Find the minimum version from there.
[#13681]: https://github.com/JuliaLang/julia/issues/13681
[#17302]: https://github.com/JuliaLang/julia/issues/17302
[#17323]: https://github.com/JuliaLang/julia/issues/17323
[#19449]: https://github.com/JuliaLang/julia/issues/19449
[#19784]: https://github.com/JuliaLang/julia/issues/19784
[#20005]: https://github.com/JuliaLang/julia/issues/20005
[#20974]: https://github.com/JuliaLang/julia/issues/20974
Expand Down
8 changes: 2 additions & 6 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,8 @@ import Base.Iterators # TODO deprecate, remove
readuntil(f, d::Vector{T}; keep::Bool = false) where {T<:Union{UInt8,Char}} = convert(Vector{T}, readuntil(f, String(d), keep=keep))
end

# https://github.com/JuliaLang/julia/pull/19449
@static if VERSION < v"0.6.0-dev.1988"
StringVector(n::Integer) = Vector{UInt8}(n)
else
using Base: StringVector
end
# TODO deprecate/remove this unexported binding (along wiht its tests)
using Base: StringVector

# https://github.com/JuliaLang/julia/pull/19784
@static if isdefined(Base, :invokelatest)
Expand Down
11 changes: 6 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,15 @@ for (t, s, m, kept) in [
end

# PR 19449
# TODO remove these tests when Compat.StringVector is deprecated
using Compat: StringVector
@test length(StringVector(5)) == 5
@test String(fill!(StringVector(5), 0x61)) == "aaaaa"
let x = fill!(StringVector(5), 0x61)
# 0.7
@test pointer(x) == pointer(String(x))
end


# PR 22064
module Test22064
Expand Down Expand Up @@ -247,11 +253,6 @@ eval(Expr(struct_sym, false, :TestType, Expr(:block, :(a::Int), :b)))
# PR 22761
@test_throws OverflowError throw(OverflowError("overflow"))

let x = fill!(StringVector(5), 0x61)
# 0.7
@test pointer(x) == pointer(String(x))
end

# PR 22907
using Compat: pairs

Expand Down

0 comments on commit bd7f2db

Please sign in to comment.