Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Compat.StringVector #348

Merged
merged 7 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. On 0.6 and later, it aliases `Base.StringVector`. ([#19449])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should suggest using Compat.UTF8String(Compat.StringVector(n)) to create strings from arrays without making copies? This way the code would work on 0.4 too. The test could be modified accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.4 is on its way out, and many users might not know/care about Compat.UTF8String. But you are right about the test. I'll change that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until Compat drops support for 0.4, we should explain how to use it "on 0.5 and below".

Copy link
Contributor Author

@TotalVerb TotalVerb Apr 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the README. How's this?


## Renamed functions

* `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively
Expand Down
7 changes: 7 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(n::Integer) = Vector{UInt8}(n)
else
using Base: StringVector
end

include("to-be-deprecated.jl")

end # module Compat
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,17 @@ 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"

if isdefined(Core, :String)
let x = fill!(StringVector(5), 0x61)
@test pointer(x) == pointer(String(x))
end
end

include("to-be-deprecated.jl")

nothing