@@ -99,7 +99,7 @@ function unsafe_read(from::GenericIOBuffer, p::Ptr{UInt8}, nb::UInt)
9999 from. readable || throw (ArgumentError (" read failed, IOBuffer is not readable" ))
100100 avail = nb_available (from)
101101 adv = min (avail, nb)
102- unsafe_copy! (p, pointer (from. data, from. ptr), adv)
102+ @gc_preserve from unsafe_copy! (p, pointer (from. data, from. ptr), adv)
103103 from. ptr += adv
104104 if nb > avail
105105 throw (EOFError ())
@@ -114,7 +114,7 @@ function read_sub(from::GenericIOBuffer, a::AbstractArray{T}, offs, nel) where T
114114 end
115115 if isbits (T) && isa (a,Array)
116116 nb = UInt (nel * sizeof (T))
117- unsafe_read (from, pointer (a, offs), nb)
117+ @gc_preserve a unsafe_read (from, pointer (a, offs), nb)
118118 else
119119 for i = offs: offs+ nel- 1
120120 a[i] = read (to, T)
@@ -334,7 +334,7 @@ function write_sub(to::GenericIOBuffer, a::AbstractArray{UInt8}, offs, nel)
334334 if offs+ nel- 1 > length (a) || offs < 1 || nel < 0
335335 throw (BoundsError ())
336336 end
337- unsafe_write (to, pointer (a, offs), UInt (nel))
337+ @gc_preserve a unsafe_write (to, pointer (a, offs), UInt (nel))
338338end
339339
340340@inline function write (to:: GenericIOBuffer , a:: UInt8 )
@@ -367,7 +367,7 @@ read(io::GenericIOBuffer, nb::Integer) = read!(io,StringVector(min(nb, nb_availa
367367
368368function search (buf:: IOBuffer , delim:: UInt8 )
369369 p = pointer (buf. data, buf. ptr)
370- q = ccall (:memchr ,Ptr{UInt8},(Ptr{UInt8},Int32,Csize_t),p,delim,nb_available (buf))
370+ q = @gc_preserve buf ccall (:memchr ,Ptr{UInt8},(Ptr{UInt8},Int32,Csize_t),p,delim,nb_available (buf))
371371 nb:: Int = (q == C_NULL ? 0 : q- p+ 1 )
372372 return nb
373373end
@@ -413,7 +413,7 @@ function crc32c(io::IOBuffer, nb::Integer, crc::UInt32=0x00000000)
413413 io. readable || throw (ArgumentError (" read failed, IOBuffer is not readable" ))
414414 n = min (nb, nb_available (io))
415415 n == 0 && return crc
416- crc = unsafe_crc32c (pointer (io. data, io. ptr), n, crc)
416+ crc = @gc_preserve io unsafe_crc32c (pointer (io. data, io. ptr), n, crc)
417417 io. ptr += n
418418 return crc
419419end
0 commit comments