Skip to content

Commit

Permalink
rename unsafe_x_wrap to unsafe_wrap(x, ...)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Jun 4, 2016
1 parent 7da316e commit 4c44188
Show file tree
Hide file tree
Showing 27 changed files with 79 additions and 73 deletions.
2 changes: 1 addition & 1 deletion base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool}
nc8 = (nc >>> 3) << 3
if nc8 > 0
ind8 = 1
C8 = reinterpret(UInt64, unsafe_array_wrapper(pointer(C, ind), nc8 << 6))
C8 = reinterpret(UInt64, unsafe_wrap(Array, pointer(C, ind), nc8 << 6))
@inbounds for i = 1:nc8
c = UInt64(0)
for j = 0:7
Expand Down
5 changes: 3 additions & 2 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ pointer(p::Cwstring) = convert(Ptr{Cwchar_t}, p)
==(x::Ptr, y::Union{Cstring,Cwstring}) = x == pointer(y)

# here, not in pointer.jl, to avoid bootstrapping problems in coreimg.jl
unsafe_string_wrapper(p::Cstring, own::Bool=false) = unsafe_string_wrapper(convert(Ptr{UInt8}, p), own)
unsafe_string_wrapper(p::Cstring, len::Integer, own::Bool=false) = unsafe_string_wrapper(convert(Ptr{UInt8}, p), len, own)
unsafe_wrap(::Type{String}, p::Cstring, own::Bool=false) = unsafe_wrap(String, convert(Ptr{UInt8}, p), own)
unsafe_wrap(::Type{String}, p::Cstring, len::Integer, own::Bool=false) =
unsafe_wrap(String, convert(Ptr{UInt8}, p), len, own)
unsafe_string(s::Cstring) = unsafe_string(convert(Ptr{UInt8}, s))

# convert strings to String etc. to pass as pointers
Expand Down
7 changes: 4 additions & 3 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,10 @@ hist2d(v::AbstractMatrix) = hist2d(v, sturges(size(v,1)))
@deprecate cell(dims::Integer...) Array{Any}(dims...)
@deprecate cell(dims::Tuple{Vararg{Integer}}) Array{Any}(dims)

@deprecate pointer_to_array{T,N}(p::Ptr{T}, d::Union{Integer,NTuple{N,Int},NTuple{N,Integer}}, own::Bool=false) unsafe_array_wrapper(p, d, own)
@deprecate pointer_to_string(p::Ptr{UInt8}, len::Integer, own::Bool=false) unsafe_string_wrapper(p, len, own)
@deprecate pointer_to_string(p::Ptr{UInt8}, own::Bool=false) unsafe_string_wrapper(p, own)
@deprecate pointer_to_array{T,N}(p::Ptr{T}, d::Union{Integer,NTuple{N,Int},NTuple{N,Integer}},
own::Bool=false) unsafe_wrap(Array, p, d, own)
@deprecate pointer_to_string(p::Ptr{UInt8}, len::Integer, own::Bool=false) unsafe_wrap(String, p, len, own)
@deprecate pointer_to_string(p::Ptr{UInt8}, own::Bool=false) unsafe_wrap(String, p, own)

# During the 0.5 development cycle, do not add any deprecations below this line
# To be deprecated in 0.6
Expand Down
3 changes: 1 addition & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,7 @@ export
disable_sigint,
pointer,
pointer_from_objref,
unsafe_array_wrapper,
unsafe_string_wrapper,
unsafe_wrap,
unsafe_string,
reenable_sigint,
unsafe_copy!,
Expand Down
2 changes: 1 addition & 1 deletion base/fft/FFTW.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ sprint_plan_{T<:fftwDouble}(plan::FFTWPlan{T}) =
sprint_plan_{T<:fftwSingle}(plan::FFTWPlan{T}) =
ccall((:fftwf_sprint_plan,libfftwf), Ptr{UInt8}, (PlanPtr,), plan)
function sprint_plan(plan::FFTWPlan)
unsafe_string_wrapper(sprint_plan_(plan), true)
unsafe_wrap(String, sprint_plan_(plan), true)
end

function show{T,K,inplace}(io::IO, p::cFFTWPlan{T,K,inplace})
Expand Down
2 changes: 1 addition & 1 deletion base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ hex(n::BigInt) = base(16, n)
function base(b::Integer, n::BigInt)
2 <= b <= 62 || throw(ArgumentError("base must be 2 ≤ base ≤ 62, got $b"))
p = ccall((:__gmpz_get_str,:libgmp), Ptr{UInt8}, (Ptr{UInt8}, Cint, Ptr{BigInt}), C_NULL, b, &n)
unsafe_string_wrapper(p, true)
unsafe_wrap(String, p, true)
end

function ndigits0z(x::BigInt, b::Integer=10)
Expand Down
2 changes: 1 addition & 1 deletion base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ elseif is_windows()
len = 0
while unsafe_load(plock, len+1) != 0; len += 1; end
# get Vector{UInt16}, transcode data to UTF-8, make a String of it
s = String(utf16to8(unsafe_array_wrapper(plock, len)))
s = String(utf16to8(unsafe_wrap(Array, plock, len)))
systemerror(:GlobalUnlock, 0==ccall((:GlobalUnlock, "kernel32"), stdcall, Cint, (Ptr{UInt16},), plock))
return s
end
Expand Down
6 changes: 3 additions & 3 deletions base/linalg/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ function _generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractV
@inbounds begin
if tile_size > 0
sz = (tile_size, tile_size)
Atile = unsafe_array_wrapper(convert(Ptr{T}, pointer(Abuf)), sz)
Btile = unsafe_array_wrapper(convert(Ptr{S}, pointer(Bbuf)), sz)
Atile = unsafe_wrap(Array, convert(Ptr{T}, pointer(Abuf)), sz)
Btile = unsafe_wrap(Array, convert(Ptr{S}, pointer(Bbuf)), sz)

z = zero(R)

Expand All @@ -485,7 +485,7 @@ function _generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractV
end
end
else
Ctile = unsafe_array_wrapper(convert(Ptr{R}, pointer(Cbuf)), sz)
Ctile = unsafe_wrap(Array, convert(Ptr{R}, pointer(Cbuf)), sz)
for jb = 1:tile_size:nB
jlim = min(jb+tile_size-1,nB)
jlen = jlim-jb+1
Expand Down
2 changes: 1 addition & 1 deletion base/mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function mmap{T,N}(io::IO,
ptr == C_NULL && error("could not create mapping view: $(Libc.FormatMessage())")
end # os-test
# convert mmapped region to Julia Array at `ptr + (offset - offset_page)` since file was mapped at offset_page
A = unsafe_array_wrapper(convert(Ptr{T}, UInt(ptr) + UInt(offset - offset_page)), dims)
A = unsafe_wrap(Array, convert(Ptr{T}, UInt(ptr) + UInt(offset - offset_page)), dims)
finalizer(A, function(x)
@static if is_unix()
systemerror("munmap", ccall(:munmap, Cint, (Ptr{Void}, Int), ptr, mmaplen) != 0)
Expand Down
2 changes: 1 addition & 1 deletion base/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ else # !windows
function realpath(path::AbstractString)
p = ccall(:realpath, Ptr{UInt8}, (Cstring, Ptr{UInt8}), path, C_NULL)
systemerror(:realpath, p == C_NULL)
return unsafe_string_wrapper(p, true)
return unsafe_wrap(String, p, true)
end
end # os-test

Expand Down
2 changes: 1 addition & 1 deletion base/pcre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function get_ovec(match_data)
(Ptr{Void},), match_data)
n = ccall((:pcre2_get_ovector_count_8, PCRE_LIB), UInt32,
(Ptr{Void},), match_data)
unsafe_array_wrapper(ptr, 2n, false)
unsafe_wrap(Array, ptr, 2n, false)
end

function compile(pattern::AbstractString, options::Integer)
Expand Down
53 changes: 29 additions & 24 deletions base/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,38 @@ unsafe_convert{S,T}(::Type{Ptr{S}}, a::AbstractArray{T}) = convert(Ptr{S}, unsaf
unsafe_convert{T}(::Type{Ptr{T}}, a::AbstractArray{T}) = error("conversion to pointer not defined for $(typeof(a))")

# unsafe pointer to array conversions
function unsafe_array_wrapper{T}(p::Ptr{T}, d::Integer, own::Bool=false)
ccall(:jl_ptr_to_array_1d, Vector{T},
(Any, Ptr{Void}, Csize_t, Cint), Array{T,1}, p, d, own)
end
function unsafe_array_wrapper{T,N}(p::Ptr{T}, dims::NTuple{N,Int}, own::Bool=false)
"""
unsafe_wrap(Array, pointer, dims, own=false)
Wrap a native pointer as a Julia `Array `object. The pointer element type determines the array
element type. `dims` is either an integer (for a 1d array) or a tuple of the array dimensions.
`own` optionally specifies whether Julia should take ownership of the memory,
calling `free` on the pointer when the array is no longer referenced.
This function is labelled "unsafe" because it will crash if `pointer` is not
a valid memory address to data of the requested length.
"""
function unsafe_wrap{T,N}(::Union{Type{Array},Type{Array{T}},Type{Array{T,N}}},
p::Ptr{T}, dims::NTuple{N,Int}, own::Bool=false)
ccall(:jl_ptr_to_array, Array{T,N}, (Any, Ptr{Void}, Any, Int32),
Array{T,N}, p, dims, own)
end
function unsafe_array_wrapper{T,N}(p::Ptr{T}, dims::NTuple{N,Integer}, own::Bool=false)
function unsafe_wrap{T}(::Union{Type{Array},Type{Array{T}},Type{Array{T,1}}},
p::Ptr{T}, d::Integer, own::Bool=false)
ccall(:jl_ptr_to_array_1d, Vector{T},
(Any, Ptr{Void}, Csize_t, Cint), Array{T,1}, p, d, own)
end
function unsafe_wrap{T,N}(Atype::Union{Type{Array},Type{Array{T}},Type{Array{T,N}}},
p::Ptr{T}, dims::NTuple{N,Integer}, own::Bool=false)
i = 1
for d in dims
if !(0 <= d <= typemax(Int))
throw(ArgumentError("Array dimension must be 0 ≤ dim ≤ $(typemax(Int)), got $d for dimension $i"))
end
i += 1
end
unsafe_array_wrapper(p, convert(Tuple{Vararg{Int}}, dims), own)
unsafe_wrap(Atype, p, convert(Tuple{Vararg{Int}}, dims), own)
end
"""
unsafe_array_wrapper(pointer, dims, own=false)
Wrap a native pointer as a Julia Array object. The pointer element type determines the array
element type. `own` optionally specifies whether Julia should take ownership of the memory,
calling `free` on the pointer when the array is no longer referenced.
This function is labelled "unsafe" because it will crash if `pointer` is not
a valid memory address to data of the requested length.
"""
unsafe_array_wrapper

unsafe_load(p::Ptr,i::Integer) = pointerref(p, Int(i))
unsafe_load(p::Ptr) = unsafe_load(p, 1)
Expand All @@ -73,11 +76,8 @@ unsafe_store!{T}(p::Ptr{T}, x) = pointerset(p, convert(T,x), 1)

# unsafe pointer to string conversions (don't make a copy, unlike unsafe_string)
# (Cstring versions are in c.jl)
unsafe_string_wrapper(p::Union{Ptr{UInt8},Ptr{Int8}}, len::Integer, own::Bool=false) = ccall(:jl_array_to_string, Ref{String}, (Any,), ccall(:jl_ptr_to_array_1d, Vector{UInt8}, (Any, Ptr{UInt8}, Csize_t, Cint), Vector{UInt8}, p, len, own))
unsafe_string_wrapper(p::Union{Ptr{UInt8},Ptr{Int8}}, own::Bool=false) =
unsafe_string_wrapper(p, ccall(:strlen, Csize_t, (Ptr{UInt8},), p), own)
"""
unsafe_string_wrapper(p::Ptr{UInt8}, [length,] own=false)
unsafe_wrap(String, p::Ptr{UInt8}, [length,] own=false)
Wrap a pointer `p` to an array of bytes in a `String` object,
interpreting the bytes as UTF-8 encoded characters *without making a
Expand All @@ -91,9 +91,14 @@ This function is labelled "unsafe" because it will crash if `p` is not
a valid memory address to data of the requested length.
See also [`unsafe_string`](:func:`unsafe_string`), which takes a pointer
and makes a copy of the data, and [`unsafe_array_wrapper`](:func:`unsafe_array_wrapper`).
and makes a copy of the data.
"""
unsafe_string_wrapper
unsafe_wrap(::Type{String}, p::Union{Ptr{UInt8},Ptr{Int8}}, len::Integer, own::Bool=false) =
ccall(:jl_array_to_string, Ref{String}, (Any,),
ccall(:jl_ptr_to_array_1d, Vector{UInt8}, (Any, Ptr{UInt8}, Csize_t, Cint),
Vector{UInt8}, p, len, own))
unsafe_wrap(::Type{String}, p::Union{Ptr{UInt8},Ptr{Int8}}, own::Bool=false) =
unsafe_wrap(String, p, ccall(:strlen, Csize_t, (Ptr{UInt8},), p), own)

# convert a raw Ptr to an object reference, and vice-versa
unsafe_pointer_to_objref(x::Ptr) = ccall(:jl_value_ptr, Any, (Ptr{Void},), x)
Expand Down
2 changes: 1 addition & 1 deletion base/profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function fetch()
if (len == maxlen)
warn("The profile data buffer is full; profiling probably terminated\nbefore your program finished. To profile for longer runs, call Profile.init\nwith a larger buffer and/or larger delay.")
end
unsafe_array_wrapper(get_data_pointer(), (len,))
unsafe_wrap(Array, get_data_pointer(), (len,))
end


Expand Down
10 changes: 5 additions & 5 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ end
function rand!{T<:Union{Float16, Float32}}(r::MersenneTwister, A::Array{T}, ::Type{Close1Open2})
n = length(A)
n128 = n * sizeof(T) ÷ 16
rand!(r, unsafe_array_wrapper(convert(Ptr{Float64}, pointer(A)), 2*n128), 2*n128, Close1Open2)
A128 = unsafe_array_wrapper(convert(Ptr{UInt128}, pointer(A)), n128)
rand!(r, unsafe_wrap(Array, convert(Ptr{Float64}, pointer(A)), 2*n128), 2*n128, Close1Open2)
A128 = unsafe_wrap(Array, convert(Ptr{UInt128}, pointer(A)), n128)
@inbounds for i in 1:n128
u = A128[i]
u $= u << 26
Expand Down Expand Up @@ -390,7 +390,7 @@ function rand!(r::MersenneTwister, A::Array{UInt128}, n::Int=length(A))
if n > length(A)
throw(BoundsError(A,n))
end
Af = unsafe_array_wrapper(convert(Ptr{Float64}, pointer(A)), 2n)
Af = unsafe_wrap(Array, convert(Ptr{Float64}, pointer(A)), 2n)
i = n
while true
rand!(r, Af, 2i, Close1Open2)
Expand All @@ -417,7 +417,7 @@ end
function rand!{T<:Union{Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128}}(r::MersenneTwister, A::Array{T})
n=length(A)
n128 = n * sizeof(T) ÷ 16
rand!(r, unsafe_array_wrapper(convert(Ptr{UInt128}, pointer(A)), n128))
rand!(r, unsafe_wrap(Array, convert(Ptr{UInt128}, pointer(A)), n128))
for i = 16*n128÷sizeof(T)+1:n
@inbounds A[i] = rand(r, T)
end
Expand Down Expand Up @@ -534,7 +534,7 @@ if GMP_VERSION.major >= 6
while true
# note: on CRAY computers, the second argument may be of type Cint (48 bits) and not Clong
xd = ccall((:__gmpz_limbs_write, :libgmp), Ptr{Limb}, (Ptr{BigInt}, Clong), &x, g.nlimbs)
limbs = unsafe_array_wrapper(xd, g.nlimbs)
limbs = unsafe_wrap(Array, xd, g.nlimbs)
rand!(rng, limbs)
limbs[end] &= g.mask
ccall((:__gmpz_limbs_finish, :libgmp), Void, (Ptr{BigInt}, Clong), &x, g.nlimbs)
Expand Down
2 changes: 1 addition & 1 deletion base/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ function uv_recvcb(handle::Ptr{Void}, nread::Cssize_t, buf::Ptr{Void}, addr::Ptr
ccall(:jl_sockaddr_host6, UInt32, (Ptr{Void}, Ptr{UInt8}), addr, pointer(tmp))
IPv6(ntoh(tmp[1]))
end
buf = unsafe_array_wrapper(convert(Ptr{UInt8},buf_addr),Int(buf_size),true)
buf = unsafe_wrap(Array, convert(Ptr{UInt8},buf_addr),Int(buf_size),true)
notify(sock.recvnotify,(addrout,buf[1:nread]))
nothing
end
Expand Down
10 changes: 5 additions & 5 deletions base/sparse/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ end

function get_perm(F::Factor)
s = unsafe_load(get(F.p))
p = unsafe_array_wrapper(s.Perm, s.n, false)
p = unsafe_wrap(Array, s.Perm, s.n, false)
p+1
end
get_perm(FC::FactorComponent) = get_perm(Factor(FC))
Expand Down Expand Up @@ -989,21 +989,21 @@ function convert{Tv}(::Type{SparseMatrixCSC{Tv,SuiteSparse_long}}, A::Sparse{Tv}
if s.stype != 0
throw(ArgumentError("matrix has stype != 0. Convert to matrix with stype == 0 before converting to SparseMatrixCSC"))
end
return SparseMatrixCSC(s.nrow, s.ncol, increment(unsafe_array_wrapper(s.p, (s.ncol + 1,), false)), increment(unsafe_array_wrapper(s.i, (s.nzmax,), false)), copy(unsafe_array_wrapper(s.x, (s.nzmax,), false)))
return SparseMatrixCSC(s.nrow, s.ncol, increment(unsafe_wrap(Array, s.p, (s.ncol + 1,), false)), increment(unsafe_wrap(Array, s.i, (s.nzmax,), false)), copy(unsafe_wrap(Array, s.x, (s.nzmax,), false)))
end
function convert(::Type{Symmetric{Float64,SparseMatrixCSC{Float64,SuiteSparse_long}}}, A::Sparse{Float64})
s = unsafe_load(A.p)
if !issymmetric(A)
throw(ArgumentError("matrix is not symmetric"))
end
return Symmetric(SparseMatrixCSC(s.nrow, s.ncol, increment(unsafe_array_wrapper(s.p, (s.ncol + 1,), false)), increment(unsafe_array_wrapper(s.i, (s.nzmax,), false)), copy(unsafe_array_wrapper(s.x, (s.nzmax,), false))), s.stype > 0 ? :U : :L)
return Symmetric(SparseMatrixCSC(s.nrow, s.ncol, increment(unsafe_wrap(Array, s.p, (s.ncol + 1,), false)), increment(unsafe_wrap(Array, s.i, (s.nzmax,), false)), copy(unsafe_wrap(Array, s.x, (s.nzmax,), false))), s.stype > 0 ? :U : :L)
end
function convert{Tv<:VTypes}(::Type{Hermitian{Tv,SparseMatrixCSC{Tv,SuiteSparse_long}}}, A::Sparse{Tv})
s = unsafe_load(A.p)
if !ishermitian(A)
throw(ArgumentError("matrix is not Hermitian"))
end
return Hermitian(SparseMatrixCSC(s.nrow, s.ncol, increment(unsafe_array_wrapper(s.p, (s.ncol + 1,), false)), increment(unsafe_array_wrapper(s.i, (s.nzmax,), false)), copy(unsafe_array_wrapper(s.x, (s.nzmax,), false))), s.stype > 0 ? :U : :L)
return Hermitian(SparseMatrixCSC(s.nrow, s.ncol, increment(unsafe_wrap(Array, s.p, (s.ncol + 1,), false)), increment(unsafe_wrap(Array, s.i, (s.nzmax,), false)), copy(unsafe_wrap(Array, s.x, (s.nzmax,), false))), s.stype > 0 ? :U : :L)
end
function sparse(A::Sparse{Float64}) # Notice! Cannot be type stable because of stype
s = unsafe_load(A.p)
Expand Down Expand Up @@ -1143,7 +1143,7 @@ function getindex{T}(A::Sparse{T}, i0::Integer, i1::Integer)
r1 = Int(unsafe_load(s.p, i1) + 1)
r2 = Int(unsafe_load(s.p, i1 + 1))
(r1 > r2) && return zero(T)
r1 = Int(searchsortedfirst(unsafe_array_wrapper(s.i, (s.nzmax,), false), i0 - 1, r1, r2, Base.Order.Forward))
r1 = Int(searchsortedfirst(unsafe_wrap(Array, s.i, (s.nzmax,), false), i0 - 1, r1, r2, Base.Order.Forward))
((r1 > r2) || (unsafe_load(s.i, r1) + 1 != i0)) ? zero(T) : unsafe_load(s.x, r1)
end

Expand Down
6 changes: 3 additions & 3 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2115,7 +2115,7 @@ function permute_rows!{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}, pI::Vector{Int})
nzvalTemp[k] = nzvalS[i]
k += 1
end
sortperm!(unsafe_array_wrapper(pointer(rowperm), nr), unsafe_array_wrapper(pointer(rowvalTemp), nr))
sortperm!(unsafe_wrap(Array, pointer(rowperm), nr), unsafe_wrap(Array, pointer(rowvalTemp), nr))
k = 1
for i in rowrange
kperm = rowperm[k]
Expand Down Expand Up @@ -3269,8 +3269,8 @@ function sortSparseMatrixCSC!{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}; sortindices::Sym
jj += 1
end

sortperm!(unsafe_array_wrapper(pointer(index), numrows),
unsafe_array_wrapper(pointer(row), numrows))
sortperm!(unsafe_wrap(Array, pointer(index), numrows),
unsafe_wrap(Array, pointer(row), numrows))

jj = 1
@simd for j = col_start:col_end
Expand Down
2 changes: 1 addition & 1 deletion base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ function unsafe_read(s::LibuvStream, p::Ptr{UInt8}, nb::UInt)
else
try
stop_reading(s) # Just playing it safe, since we are going to switch buffers.
newbuf = PipeBuffer(unsafe_array_wrapper(p, nb), #=maxsize=# Int(nb))
newbuf = PipeBuffer(unsafe_wrap(Array, p, nb), #=maxsize=# Int(nb))
newbuf.size = 0 # reset the write pointer to the beginning
s.buffer = newbuf
write(newbuf, sbuf)
Expand Down
2 changes: 1 addition & 1 deletion base/unicode/utf16.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function convert(T::Type{UTF16String}, bytes::AbstractArray{UInt8})
end

utf16(x) = convert(UTF16String, x)
utf16(p::Ptr{UInt16}, len::Integer) = utf16(unsafe_array_wrapper(p, len))
utf16(p::Ptr{UInt16}, len::Integer) = utf16(unsafe_wrap(Array, p, len))
utf16(p::Ptr{Int16}, len::Integer) = utf16(convert(Ptr{UInt16}, p), len)
function utf16(p::Union{Ptr{UInt16}, Ptr{Int16}})
len = 0
Expand Down
2 changes: 1 addition & 1 deletion base/unicode/utf32.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ isvalid(str::Vector{Char}) = isvalid(UTF32String, str)

utf32(x) = convert(UTF32String, x)

utf32(p::Ptr{UInt32}, len::Integer) = utf32(unsafe_array_wrapper(p, len))
utf32(p::Ptr{UInt32}, len::Integer) = utf32(unsafe_wrap(Array, p, len))
utf32(p::Union{Ptr{Char}, Ptr{Int32}}, len::Integer) = utf32(convert(Ptr{UInt32}, p), len)
function utf32(p::Union{Ptr{UInt32}, Ptr{Char}, Ptr{Int32}})
len = 0
Expand Down
2 changes: 1 addition & 1 deletion base/unicode/utf8proc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function utf8proc_map(s::String, flags::Integer)
s, sizeof(s), p, flags)
result < 0 && error(unsafe_string(ccall(:utf8proc_errmsg, Cstring,
(Cssize_t,), result)))
unsafe_string_wrapper(p[], result, true)::String
unsafe_wrap(String, p[], result, true)::String
end

utf8proc_map(s::AbstractString, flags::Integer) = utf8proc_map(String(s), flags)
Expand Down
4 changes: 2 additions & 2 deletions doc/manual/calling-c-and-fortran-code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ Whenever you have created a pointer to Julia data, you must ensure the original
exists until you are done with using the pointer. Many methods in Julia such as
:func:`unsafe_load` and :func:`String` make copies of data instead of taking ownership
of the buffer, so that it is safe to free (or alter) the original data without
affecting Julia. A notable exception is :func:`unsafe_array_wrapper` which, for performance
affecting Julia. A notable exception is :func:`unsafe_wrap` which, for performance
reasons, shares (or can be told to take ownership of) the underlying buffer.

The garbage collector does not guarantee any order of finalization. That is, if ``a``
Expand Down Expand Up @@ -1060,7 +1060,7 @@ Any operation that throws an error is probably currently unimplemented
and should be posted as a bug so that it can be resolved.

If the pointer of interest is a plain-data array (bitstype or immutable), the
function :func:`unsafe_array_wrapper(ptr,dims,[own]) <unsafe_array_wrapper>` may be
function :func:`unsafe_wrap(Array, ptr,dims,[own]) <unsafe_wrap>` may be
more useful. The final parameter should be true if Julia should "take
ownership" of the underlying buffer and call ``free(ptr)`` when the returned
``Array`` object is finalized. If the ``own`` parameter is omitted or false,
Expand Down
Loading

0 comments on commit 4c44188

Please sign in to comment.