diff options
| author | NARUSE, Yui <nurse@users.noreply.github.com> | 2024-02-04 22:54:36 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-04 13:54:36 +0000 |
| commit | d7dc57a545d75c01313a9020b162ebb648a3ea18 (patch) | |
| tree | a2643d1691ca967289a76d836e2e76fdd8c0295a /io_buffer.c | |
| parent | a065b68bd8d93505304f90bbb1855c864e17ad61 (diff) | |
merge revision(s) c5cf4d4e129f64cb69aaf0a829aed068ef1943c4: [Backport#19542] (#9829)
merge revision(s) c5cf4d4e129f64cb69aaf0a829aed068ef1943c4: [Backport #19542]
Improve behavioural consistency of unallocated (zero length)
`IO::Buffer`. (#9532)
This makes the behaviour of IO::Buffer.new(0) and IO::Buffer.new.slice(0, 0) consistent.
Fixes https://bugs.ruby-lang.org/issues/19542 and https://bugs.ruby-lang.org/issues/18805.
---
io_buffer.c | 14 ++++++--------
test/ruby/test_io_buffer.rb | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 8 deletions(-)
Diffstat (limited to 'io_buffer.c')
| -rw-r--r-- | io_buffer.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/io_buffer.c b/io_buffer.c index 7e580c8633..7715aa0d37 100644 --- a/io_buffer.c +++ b/io_buffer.c @@ -854,11 +854,10 @@ io_buffer_get_bytes_for_writing(struct rb_io_buffer *buffer, void **base, size_t if (buffer->base) { *base = buffer->base; *size = buffer->size; - - return; + } else { + *base = NULL; + *size = 0; } - - rb_raise(rb_eIOBufferAllocationError, "The buffer is not allocated!"); } void @@ -880,11 +879,10 @@ io_buffer_get_bytes_for_reading(struct rb_io_buffer *buffer, const void **base, if (buffer->base) { *base = buffer->base; *size = buffer->size; - - return; + } else { + *base = NULL; + *size = 0; } - - rb_raise(rb_eIOBufferAllocationError, "The buffer is not allocated!"); } void |
