@@ -334,7 +334,7 @@ function Base.readuntil(stream::TranscodingStream, delim::UInt8; keep::Bool=fals
334
334
@assert filled == 0
335
335
ret = Vector {UInt8} (undef, sz)
336
336
end
337
- copydata! (pointer (ret, filled+ 1 ), buffer1, sz)
337
+ GC . @preserve ret copydata! (pointer (ret, filled+ 1 ), buffer1, sz)
338
338
filled += sz
339
339
if found
340
340
if ! keep
@@ -360,6 +360,7 @@ function Base.unsafe_read(stream::TranscodingStream, output::Ptr{UInt8}, nbytes:
360
360
m = min (buffersize (buffer), p_end - p)
361
361
copydata! (p, buffer, m)
362
362
p += m
363
+ GC. safepoint ()
363
364
end
364
365
if p < p_end && eof (stream)
365
366
throw (EOFError ())
@@ -376,7 +377,7 @@ function Base.readbytes!(stream::TranscodingStream, b::AbstractArray{UInt8}, nb=
376
377
resize! (b, min (length (b) * 2 , nb))
377
378
resized = true
378
379
end
379
- filled += unsafe_read (stream, pointer (b, filled+ 1 ), min (length (b), nb)- filled)
380
+ filled += GC . @preserve b unsafe_read (stream, pointer (b, filled+ 1 ), min (length (b), nb)- filled)
380
381
end
381
382
if resized
382
383
resize! (b, filled)
392
393
function Base. readavailable (stream:: TranscodingStream )
393
394
n = bytesavailable (stream)
394
395
data = Vector {UInt8} (undef, n)
395
- unsafe_read (stream, pointer (data), n)
396
+ GC . @preserve data unsafe_read (stream, pointer (data), n)
396
397
return data
397
398
end
398
399
@@ -405,7 +406,7 @@ The next `read(stream, sizeof(data))` call will read data that are just
405
406
inserted.
406
407
"""
407
408
function unread (stream:: TranscodingStream , data:: ByteData )
408
- unsafe_unread (stream, pointer (data), sizeof (data))
409
+ GC . @preserve data unsafe_unread (stream, pointer (data), sizeof (data))
409
410
end
410
411
411
412
"""
@@ -462,6 +463,7 @@ function Base.unsafe_write(stream::TranscodingStream, input::Ptr{UInt8}, nbytes:
462
463
m = min (marginsize (buffer1), p_end - p)
463
464
copydata! (buffer1, p, m)
464
465
p += m
466
+ GC. safepoint ()
465
467
end
466
468
return Int (p - input)
467
469
end
636
638
function callprocess (stream:: TranscodingStream , inbuf:: Buffer , outbuf:: Buffer )
637
639
state = stream. state
638
640
input = buffermem (inbuf)
639
- makemargin! (outbuf, minoutsize (stream. codec, input))
640
- Δin, Δout, state. code = process (stream. codec, input, marginmem (outbuf), state. error)
641
+ GC . @preserve inbuf makemargin! (outbuf, minoutsize (stream. codec, input))
642
+ Δin, Δout, state. code = GC . @preserve inbuf outbuf process (stream. codec, input, marginmem (outbuf), state. error)
641
643
@debug (
642
644
" called process()" ,
643
645
code = state. code,
@@ -677,7 +679,7 @@ function readdata!(input::IO, output::Buffer)
677
679
navail = bytesavailable (input)
678
680
end
679
681
n = min (navail, marginsize (output))
680
- Base. unsafe_read (input, marginptr (output), n)
682
+ GC . @preserve output Base. unsafe_read (input, marginptr (output), n)
681
683
supplied! (output, n)
682
684
nread += n
683
685
return nread
@@ -691,10 +693,12 @@ function writedata!(output::IO, input::Buffer)
691
693
end
692
694
nwritten:: Int = 0
693
695
while buffersize (input) > 0
694
- n = Base. unsafe_write (output, bufferptr (input), buffersize (input))
696
+ n = GC . @preserve input Base. unsafe_write (output, bufferptr (input), buffersize (input))
695
697
consumed! (input, n)
696
698
nwritten += n
699
+ GC. safepoint ()
697
700
end
701
+ GC. safepoint ()
698
702
return nwritten
699
703
end
700
704
0 commit comments