Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased
- Support for directly reading from and writing to Vector{UInt8}
- Fix for working with opened IOStream objects
- Proper boundscheck for internal `read_bytestring`

## 0.6.3
- Fix edge case in datatype loading (#692)
Expand Down
15 changes: 7 additions & 8 deletions src/io/mmapio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ end

# Read a null-terminated string
function read_bytestring(io::MmapIO)
# Find the null terminator position without allocating
ptr = pconvert(Ptr{UInt8}, io.curptr)
len = 0
while unsafe_load(ptr, len + 1) != 0x00
len += 1
end
str = len == 0 ? "" : unsafe_string(ptr, len)
io.curptr += len + 1
maxbytes = io.endptr - io.curptr + 1
q = @ccall memchr(ptr::Ptr{UInt8}, 0::Int32, maxbytes::Csize_t)::Ptr{UInt8}
q == C_NULL && throw(EOFError())

str = unsafe_string(ptr, (q - ptr) % Int)
io.curptr += (q - ptr) % Int + 1
str
end

Expand Down Expand Up @@ -239,4 +238,4 @@ function end_checksum(io::MmapIO)
@inbounds v = io.checksum_pos[io.nchecksum]
io.nchecksum -= 1
Lookup3.hash(Ptr{UInt8}(io.startptr + v), position(io) - v)
end
end
Loading