diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2021-10-22 15:04:22 +1300 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2021-11-12 16:46:08 +1300 |
commit | 98b442e013afbb450f1c946d86ed625c39ab3233 (patch) | |
tree | 6cce5e1b6e641e7d5160897ba0842c013a6737de /io_buffer.c | |
parent | e73197dff54cbe00019bec7a1829fdc6b1821918 (diff) |
More immutability and locking tests.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5109
Diffstat (limited to 'io_buffer.c')
-rw-r--r-- | io_buffer.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/io_buffer.c b/io_buffer.c index af05388036..1acc942987 100644 --- a/io_buffer.c +++ b/io_buffer.c @@ -417,7 +417,6 @@ rb_io_buffer_to_s(VALUE self) } return rb_str_cat2(result, ">"); - } static VALUE @@ -701,6 +700,13 @@ size_t rb_io_buffer_copy(VALUE self, VALUE source, size_t offset) const void *source_base = NULL; size_t source_size = 0; + struct rb_io_buffer *data = NULL; + TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, data); + + if (data->flags & RB_IO_BUFFER_IMMUTABLE) { + rb_raise(rb_eRuntimeError, "Buffer is immutable!"); + } + if (RB_TYPE_P(source, T_STRING)) { RSTRING_GETMEM(source, source_base, source_size); } @@ -708,9 +714,6 @@ size_t rb_io_buffer_copy(VALUE self, VALUE source, size_t offset) rb_io_buffer_get_immutable(source, &source_base, &source_size); } - struct rb_io_buffer *data = NULL; - TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, data); - rb_io_buffer_validate(data, offset, source_size); memcpy((char*)data->base + offset, source_base, source_size); |