Skip to content

Commit

Permalink
cleaner workaround for JuliaLang#16730
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Jun 3, 2016
1 parent 7af694b commit 71dc957
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
18 changes: 17 additions & 1 deletion base/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ This representation is often appropriate for passing strings to C.
String(s::AbstractString) = print_to_string(s)
String(s::String) = s

# String constructor docstring from boot.jl, workaround for #16730
# and the unavailability of @doc in boot.jl context.
"""
String(v::Vector{UInt8})
Create a new `String` from a vector `v` of bytes containing
UTF-8 encoded characters. This function takes "ownership" of
the array, which means that you should not subsequently modify
`v` (since strings are supposed to be immutable in Julia) for
as long as the string exists.
If you need to subsequently modify `v`, use `String(copy(v))` instead.
"""
String(v::Array{UInt8,1})


"""
unsafe_string(p::Ptr{UInt8}, [length::Integer])
Expand All @@ -38,7 +54,7 @@ function unsafe_string(p::Union{Ptr{UInt8},Ptr{Int8}}, len::Integer)
end
function unsafe_string(p::Union{Ptr{UInt8},Ptr{Int8}})
p == C_NULL && throw(ArgumentError("cannot convert NULL to string"))
ccall(:jl_cstr_to_string, Ref{String}, (Cstring,), p)
ccall(:jl_cstr_to_string, Ref{String}, (Ptr{UInt8},), p)
end

convert(::Type{Vector{UInt8}}, s::AbstractString) = String(s).data
Expand Down
15 changes: 0 additions & 15 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -341,21 +341,6 @@ include("docs/Docs.jl")
using .Docs, .Markdown
Docs.loaddocs(Core.Inference.CoreDocs.DOCS)

# String constructor docstring, ugly workaround for #16730
Docs.doc!(Docs.Binding(current_module(),:String), Docs.docstr(Core.svec(
"""
String(v::Vector{UInt8})
Create a new `String` from a vector `v` of bytes containing
UTF-8 encoded characters. This function takes "ownership" of
the array, which means that you should not subsequently modify
`v` (since strings are supposed to be immutable in Julia) for
as long as the string exists.
If you need to subsequently modify `v`, use `String(copy(v))` instead.
"""
), Dict(:source => :(String(v::Vector{UInt8}) = new(v)), :path=>"boot.jl", :linenumber=>219, :module=>current_module())), Tuple{Vector{UInt8}})

function __init__()
# Base library init
reinit_stdio()
Expand Down

0 comments on commit 71dc957

Please sign in to comment.