Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check GenericIOBuffer data is contiguous #54640

Conversation

nhz2
Copy link
Contributor

@nhz2 nhz2 commented May 31, 2024

Fix #54636 by throwing an error on construction of the GenericIOBuffer if its data isn't stored contiguously in memory.

@vtjnash
Copy link
Member

vtjnash commented May 31, 2024

That error may somewhat violate the expected contract. The unsafe_copyto should probably be replaced with just using normal reads from the source array, and only unsafe_load on the pointer argument

@nhz2
Copy link
Contributor Author

nhz2 commented Jun 1, 2024

There is already a fallback method for this in

julia/base/io.jl

Lines 334 to 339 in 4896473

function unsafe_read(s::IO, p::Ptr{UInt8}, n::UInt)
for i = 1:n
unsafe_store!(p, read(s, UInt8)::UInt8, i)
end
nothing
end

So it should be possible to just use that method if the GenericIOBuffer isn't wrapping a dense vector.

@nhz2 nhz2 closed this Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GenericIOBuffer assumes data is stored contiguously in memory
2 participants