summaryrefslogtreecommitdiff
path: root/io_buffer.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2021-10-22 15:04:22 +1300
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2021-11-12 16:46:08 +1300
commit98b442e013afbb450f1c946d86ed625c39ab3233 (patch)
tree6cce5e1b6e641e7d5160897ba0842c013a6737de /io_buffer.c
parente73197dff54cbe00019bec7a1829fdc6b1821918 (diff)
downloadruby-98b442e013afbb450f1c946d86ed625c39ab3233.tar.gz
More immutability and locking tests.
Diffstat (limited to 'io_buffer.c')
-rw-r--r--io_buffer.c11
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);