summaryrefslogtreecommitdiff
path: root/io_buffer.c
diff options
context:
space:
mode:
authorSamuel Williams <[email protected]>2024-01-15 10:47:13 +1300
committerGitHub <[email protected]>2024-01-15 10:47:13 +1300
commitc5cf4d4e129f64cb69aaf0a829aed068ef1943c4 (patch)
tree7f8e459feadd36ec6bcd6085794d6003c8c64dcf /io_buffer.c
parent5c823aa686a5549649df4af86d173bebed2418e1 (diff)
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.
Diffstat (limited to 'io_buffer.c')
-rw-r--r--io_buffer.c14
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