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

A few fixes for 0.6 #290

Merged
merged 1 commit into from
Nov 26, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Currently, the `@compat` macro supports the following syntaxes:

* `$` is now `xor` or `⊻` [#18977](https://github.com/JuliaLang/julia/pull/18977).

* `num` and `den` are now `numerator` and `denominator` [#19246](https://github.com/JuliaLang/julia/pull/19246).

* `takebuf_array` is now a method of `take!`. `takebuf_string(io)` becomes `String(take!(io))` [#19088](https://github.com/JuliaLang/julia/pull/19088).
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be Compat.UTF8String(take!(io)) thanks to the Compat.String mess?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I believe takebuf_string on 0.4 is actually type unstable. It can return either ASCIIString or UTF8String.

Copy link
Member

Choose a reason for hiding this comment

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

Then we need to define a ByteString(::Array{UInt8}) method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there anything that's broken? This won't work before the specific 0.4 commit but Compat.jl already require 0.4.0 now. Travis tests also seems to be passing on 0.4?


## New macros

* `@static` has been added [#16219](https://github.com/JuliaLang/julia/pull/16219).
Expand Down
12 changes: 12 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1686,4 +1686,16 @@ if !isdefined(Base, :xor)
export xor, ⊻
end

# julia#19246
if !isdefined(Base, :numerator)
const numerator = num
const denominator = den
export numerator, denominator
end

# julia#19088
if VERSION < v"0.6.0-dev.1256"
Base.take!(io::Base.AbstractIOBuffer) = takebuf_array(io)
end

end # module
18 changes: 15 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ mktempdir() do dir
verbose && println("$name write(::IOBuffer, ...)")
@compat to = IOBuffer(UInt8[convert(UInt8, _) for _ in text], false, true)
write(to, io())
@test takebuf_string(to) == text
@test String(take!(to)) == text

cleanup()
end
Expand Down Expand Up @@ -1106,7 +1106,7 @@ end

for (Fun, func) in [(:AndFun, :&),
(:OrFun, :|),
(:XorFun, :$),
(:XorFun, :),
(:AddFun, :+),
(:DotAddFun, :.+),
(:SubFun, :-),
Expand Down Expand Up @@ -1250,7 +1250,7 @@ end

let io = IOBuffer(), s = "hello"
unsafe_write(io, pointer(s), length(s))
@test takebuf_string(io) == s
@test String(take!(io)) == s
end

@static if VERSION ≥ v"0.4"
Expand Down Expand Up @@ -1512,3 +1512,15 @@ end

@test xor(1,5) == 4
@test 1 ⊻ 5 == 4

# julia#19246
@test numerator(1//2) === 1
@test denominator(1//2) === 2

# julia#19088
let io = IOBuffer()
write(io, "aaa")
@test take!(io) == UInt8['a', 'a', 'a']
Copy link
Member

Choose a reason for hiding this comment

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

Why not test String(take!(io)) too? Otherwise, +1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. It's actually tested twice above already.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but it doesn't hurt to do that explicitly here too.

write(io, "bbb")
@test String(take!(io)) == "bbb"
end