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.
This commit is contained in:
Samuel Williams 2024-01-15 10:47:13 +13:00 committed by GitHub
parent 5c823aa686
commit c5cf4d4e12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 8 deletions

View file

@ -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