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

Various IO::Buffer improvements. #5303

Merged
merged 10 commits into from Dec 20, 2021
Merged

Conversation

ioquatix
Copy link
Member

@ioquatix ioquatix commented Dec 19, 2021

https://bugs.ruby-lang.org/issues/18417

  • IO::Buffer.map('README.md') (just a string, I experimented "whether it is smart enough") core dumps.
  • I suspect we might want to set buffer to IMMUTABLE if it is created from the frozen string. Currently, this works: (demo of broken behaviour changing frozen string contents).
  • The buffer raises RuntimeError as the only type of the error. I believe that in some places, it should be other standard errors (for example, "Offset + length out of bounds" could be at least ArgumentError?..), and in other occurrences, special error classes: for example, "Buffer is locked" would probably be helpful to have as some IO::Buffer::LockedError.
  • It seems to_str always returns a string in US-ASCII encoding, I am not sure it is the right behavior. For a low-level buffer, I'd rather expect ASCII-8BIT (what file read in binary mode produces in Ruby).
  • (Not sure if a bug or just not very useful behavior?) #resize applied to a buffer mapped from file seems to "break" the link between the buffer and file; no further copy or set would be reflected on file.
  • It seems that #clear behaves weirdly when offset is provided but length is not.

@ioquatix
Copy link
Member Author

(Not sure if a bug or just not very useful behavior?) #resize applied to a buffer mapped from file seems to "break" the link between the buffer and file; no further copy or set would be reflected on file.

I've reworked the EXTERNAL flag to handle this case better. Now the buffer can be EXTERNAL|MAPPED which means we can't resize it. Resizing this is confusing because it breaks the external mapping (visibility of changes). I think this is a more logical place.

If someone ACTUALLY wants to resize the file, they need to use ftruncate and then REMAP the file. We can try this operation later, specifically handling this case, but it will invalidate all references/slices to the buffer.

@ioquatix ioquatix force-pushed the 18417-io-buffer-fixes branch 2 times, most recently from 8f0e2ea to aa1b823 Compare December 20, 2021 12:02
@ioquatix ioquatix merged commit 617687d into ruby:master Dec 20, 2021
@ioquatix ioquatix deleted the 18417-io-buffer-fixes branch December 20, 2021 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant