From e9e62a33f9afd7dbcd350df6b42d0c26c291cba2 Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Thu, 13 Apr 2017 14:50:52 -0400 Subject: [PATCH 1/7] Add Compat.StringVector --- README.md | 2 ++ src/Compat.jl | 7 +++++++ test/runtests.jl | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 1f099c77a..a6d044354 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `bswap` is supported for `Complex` arguments on 0.5 and below. ([#21346]) +* `Compat.StringVector` is supported on 0.5 and below. ([#19449]) + ## Renamed functions * `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively diff --git a/src/Compat.jl b/src/Compat.jl index cd7a49b5e..ef9158cf0 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1464,6 +1464,13 @@ if VERSION < v"0.6.0-pre.beta.102" Base.bswap(z::Complex) = Complex(bswap(real(z)), bswap(imag(z))) end +# https://github.com/JuliaLang/julia/pull/19449 +if VERSION < v"0.6.0-dev.1988" + StringVector = Vector{UInt8} +else + using Base: StringVector +end + include("to-be-deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index 06ad23148..44f5438e6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1822,6 +1822,12 @@ let zbuf = IOBuffer([0xbf, 0xc0, 0x00, 0x00, 0x40, 0x20, 0x00, 0x00, @test bswap(z2) === 3.5 - 4.5im end +# PR 19449 +using Compat: StringVector +@test length(StringVector(5)) == 5 +@test String(fill!(StringVector(5), 0x61)) == "aaaaa" +@test (x = fill!(StringVector(5), 0x61); pointer(x) == pointer(String(x))) + include("to-be-deprecated.jl") nothing From b979c79c328ecaca0e46750302413872137ce753 Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Thu, 13 Apr 2017 17:06:29 -0400 Subject: [PATCH 2/7] Fix 0.4 test failure --- src/Compat.jl | 2 +- test/runtests.jl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Compat.jl b/src/Compat.jl index ef9158cf0..6bd995fcd 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -953,7 +953,7 @@ else end if VERSION >= v"0.4.0-dev+1246" @compat (::Type{Base.ByteString})(s::Cstring) = bytestring(s) - @compat (::Type{Base.ByteString})(v::Vector{UInt8}) = bytestring(v) + @compat (::Type{Base.ByteString})(v::Vector{UInt8}) = UTF8String(v) @compat (::Type{Base.ByteString})(p::Union{Ptr{Int8},Ptr{UInt8}}) = bytestring(p) @compat (::Type{Base.ByteString})(p::Union{Ptr{Int8},Ptr{UInt8}}, len::Integer) = bytestring(p, len) @compat (::Type{Base.ByteString})(s::AbstractString) = bytestring(s) diff --git a/test/runtests.jl b/test/runtests.jl index 44f5438e6..e1372ad63 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1826,7 +1826,9 @@ end using Compat: StringVector @test length(StringVector(5)) == 5 @test String(fill!(StringVector(5), 0x61)) == "aaaaa" -@test (x = fill!(StringVector(5), 0x61); pointer(x) == pointer(String(x))) +let x = fill!(StringVector(5), 0x61) + @test pointer(x) == pointer(String(x)) +end include("to-be-deprecated.jl") From 5c23e77a015009115c3677e85118a3378e9ffeb7 Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Thu, 13 Apr 2017 17:53:59 -0400 Subject: [PATCH 3/7] Avoid changing behavior of Compat.String --- src/Compat.jl | 2 +- test/runtests.jl | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Compat.jl b/src/Compat.jl index 6bd995fcd..ef9158cf0 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -953,7 +953,7 @@ else end if VERSION >= v"0.4.0-dev+1246" @compat (::Type{Base.ByteString})(s::Cstring) = bytestring(s) - @compat (::Type{Base.ByteString})(v::Vector{UInt8}) = UTF8String(v) + @compat (::Type{Base.ByteString})(v::Vector{UInt8}) = bytestring(v) @compat (::Type{Base.ByteString})(p::Union{Ptr{Int8},Ptr{UInt8}}) = bytestring(p) @compat (::Type{Base.ByteString})(p::Union{Ptr{Int8},Ptr{UInt8}}, len::Integer) = bytestring(p, len) @compat (::Type{Base.ByteString})(s::AbstractString) = bytestring(s) diff --git a/test/runtests.jl b/test/runtests.jl index e1372ad63..6bdc8e029 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1826,8 +1826,11 @@ end using Compat: StringVector @test length(StringVector(5)) == 5 @test String(fill!(StringVector(5), 0x61)) == "aaaaa" -let x = fill!(StringVector(5), 0x61) - @test pointer(x) == pointer(String(x)) + +if isdefined(Core, :String) + let x = fill!(StringVector(5), 0x61) + @test pointer(x) == pointer(String(x)) + end end include("to-be-deprecated.jl") From 74b614a4eae57e0c05470c7445b2eac1c0c60acf Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Fri, 14 Apr 2017 22:25:56 -0400 Subject: [PATCH 4/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a6d044354..00a6340ec 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ Currently, the `@compat` macro supports the following syntaxes: * `bswap` is supported for `Complex` arguments on 0.5 and below. ([#21346]) -* `Compat.StringVector` is supported on 0.5 and below. ([#19449]) +* `Compat.StringVector` is supported on 0.5 and below. On 0.6 and later, it aliases `Base.StringVector`. ([#19449]) ## Renamed functions From d9bad7d9b8cd0ef807c326093f6bda9c52d32a84 Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Fri, 14 Apr 2017 22:26:31 -0400 Subject: [PATCH 5/7] Update Compat.jl --- src/Compat.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compat.jl b/src/Compat.jl index ef9158cf0..d672e46fd 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1466,7 +1466,7 @@ end # https://github.com/JuliaLang/julia/pull/19449 if VERSION < v"0.6.0-dev.1988" - StringVector = Vector{UInt8} + StringVector(n::Integer) = Vector{UInt8}(n) else using Base: StringVector end From 1f5207f0804d30723dd694b3d5fafa1436801093 Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Fri, 14 Apr 2017 22:51:55 -0400 Subject: [PATCH 6/7] Update runtests.jl --- test/runtests.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6bdc8e029..8b815e570 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1827,10 +1827,8 @@ using Compat: StringVector @test length(StringVector(5)) == 5 @test String(fill!(StringVector(5), 0x61)) == "aaaaa" -if isdefined(Core, :String) - let x = fill!(StringVector(5), 0x61) - @test pointer(x) == pointer(String(x)) - end +let x = fill!(StringVector(5), 0x61) + @test pointer(x) == pointer(Compat.UTF8String(x)) end include("to-be-deprecated.jl") From 3fc421602999cb751ffa29a6b563f32cb2e90e93 Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Sat, 15 Apr 2017 14:24:16 -0400 Subject: [PATCH 7/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 00a6340ec..e7376c776 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ Currently, the `@compat` macro supports the following syntaxes: * `bswap` is supported for `Complex` arguments on 0.5 and below. ([#21346]) -* `Compat.StringVector` is supported on 0.5 and below. On 0.6 and later, it aliases `Base.StringVector`. ([#19449]) +* `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]) ## Renamed functions