-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Document IO::Buffer #5302
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
Document IO::Buffer #5302
Conversation
|
@ioquatix Please review |
|
Thanks to @rawrafox who proposed we implement In |
|
I am going to give a thorough review of this today. A quick check, this looks amazing. |
| * with the string, and writing to a buffer will reflect on string's content. | ||
| * | ||
| * Note that as IO::Buffer is a low-level mechanism for efficient I/O operations, it | ||
| * will ignore the string being frozen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't sound right semantically, it sounds more like a bug.
Also this could easily corrupt memory/make things crash/segfault if e.g. a fstring is passed and it's mutated by IO::Buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right it was a bug, we have fixed it already. The buffer created from frozen string will be immutable.
Oh, now I get it. Would something like that make sense as a docs for the method?
buffer = fill_the_buffer
Thread.new { some_complicated_writing_operation(buffer) }
# ... if here, some code accidentally changes a buffer, it _might_ happen before the writing will be done
# ...instead, we can "move" (transfer) buffer to a writer to underline it shouldn't be used anymore
Thread.new { some_complicated_writing_operation(buffer.transfer) }
buffer.copy('foo', 0) # will raise |
|
I think something like |
|
I'm going to merge this by hand (trying to get this done as much as possible before rc1 deadline). |
|
I don't know if we ever included the final update regarding |
The "demo" of the new docs: https://zverok.github.io/ruby-rdoc/IO/Buffer.html
The docs are written on "to the best of my understanding" basis 🤷
(For example, I am not sure why
#tranfermight be useful?)See also accompanying "inconsistencies and problems discovered" ticket: https://bugs.ruby-lang.org/issues/18417