Skip to content

Commit

Permalink
Fix eltype() and pointer() of Cstring (JuliaLang#31471)
Browse files Browse the repository at this point in the history
  • Loading branch information
nstiurca authored and JeffBezanson committed Mar 28, 2019
1 parent c0ebd97 commit dbe50f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Calling [`Ref(array[, index])`](@ref Ref) is generally preferable to this functi
"""
function pointer end

pointer(p::Cstring) = convert(Ptr{UInt8}, p)
pointer(p::Cstring) = convert(Ptr{Cchar}, p)
pointer(p::Cwstring) = convert(Ptr{Cwchar_t}, p)

# comparisons against pointers (mainly to support `cstr==C_NULL`)
Expand All @@ -203,7 +203,7 @@ function cconvert(::Type{Cwstring}, s::AbstractString)
return v
end

eltype(::Type{Cstring}) = UInt8
eltype(::Type{Cstring}) = Cchar
eltype(::Type{Cwstring}) = Cwchar_t

containsnul(p::Ptr, len) =
Expand Down
8 changes: 8 additions & 0 deletions test/strings/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,11 @@ let
@test cstring != C_NULL
@test C_NULL != cstring
end

# issue #31381: eltype(Cstring) != Cchar
let
s = Cstring(C_NULL)
@test eltype(Cstring) == Cchar
@test eltype(s) == Cchar
@test pointer(s) isa Ptr{Cchar}
end

0 comments on commit dbe50f9

Please sign in to comment.