Skip to content

Commit 97ef9d2

Browse files
committed
Avoid accessing .data field of strings
This is needed to avoid breakage due to changed String representation in Julia 0.6. Note that we still need to access the .data field of LegacyStrings types since the Vector() method for them goes through String, which defeats the purpose of getting UTF-16 or UTF-32 data.
1 parent df995ac commit 97ef9d2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

deps/build.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ function validate_iconv(n, h)
1818
cd == Ptr{Void}(-1) && return false
1919

2020
s = "café"
21-
a = similar(s.data)
22-
inbufptr = Ref{Ptr{UInt8}}(pointer(s.data))
23-
inbytesleft = Ref{Csize_t}(length(s.data))
21+
a = Vector{UInt8}(sizeof(s))
22+
inbufptr = Ref{Ptr{UInt8}}(pointer(s))
23+
inbytesleft = Ref{Csize_t}(sizeof(s))
2424
outbufptr = Ref{Ptr{UInt8}}(pointer(a))
2525
outbytesleft = Ref{Csize_t}(length(a))
2626
ret = ccall(Libdl.dlsym_e(h, "iconv"), Csize_t,

test/runtests.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ for (s, enc) in (("noël", "ISO-8859-1"),
2929
end
3030

3131
# Test that attempt to close stream in the middle of incomplete sequence throws
32-
let s = "a string チャネルパートナーの選択"
32+
let s = "a string チャネルパートナーの選択", a = Vector{UInt8}(s)
3333
# First, correct version
3434
p = StringEncoder(IOBuffer(), "UTF-16LE")
35-
write(p, s.data)
35+
write(p, a)
3636
close(p)
3737
# Test that closed pipe behaves correctly
3838
@test_throws ArgumentError write(p, 'a')
3939

4040
b = IOBuffer()
4141
p = StringEncoder(b, "UTF-16LE")
4242
@test string(p) == "StringEncoder{UTF-8, UTF-16LE}($(string(b)))"
43-
write(p, s.data[1:10])
43+
write(p, a[1:10])
4444
@test_throws IncompleteSequenceError close(p)
4545
# Test that closed pipe behaves correctly even after an error
4646
@test_throws ArgumentError write(p, 'a')
4747

4848
# This time, call show
4949
p = StringEncoder(IOBuffer(), "UTF-16LE")
50-
write(p, s.data[1:10])
50+
write(p, a[1:10])
5151
try
5252
close(p)
5353
catch err

0 commit comments

Comments
 (0)