summaryrefslogtreecommitdiff
path: root/io_buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'io_buffer.c')
-rw-r--r--io_buffer.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/io_buffer.c b/io_buffer.c
index 2fc7ac8a80..4a08811185 100644
--- a/io_buffer.c
+++ b/io_buffer.c
@@ -1001,17 +1001,23 @@ rb_io_buffer_lock(VALUE self)
return self;
}
-VALUE
-rb_io_buffer_unlock(VALUE self)
+static void
+io_buffer_unlock(struct rb_io_buffer *data)
{
- 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_LOCKED)) {
rb_raise(rb_eIOBufferLockedError, "Buffer not locked!");
}
data->flags &= ~RB_IO_BUFFER_LOCKED;
+}
+
+VALUE
+rb_io_buffer_unlock(VALUE self)
+{
+ struct rb_io_buffer *data = NULL;
+ TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, data);
+
+ io_buffer_unlock(data);
return self;
}
@@ -1123,6 +1129,17 @@ rb_io_buffer_free(VALUE self)
return self;
}
+VALUE rb_io_buffer_free_locked(VALUE self)
+{
+ struct rb_io_buffer *data = NULL;
+ TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, data);
+
+ io_buffer_unlock(data);
+ io_buffer_free(data);
+
+ return self;
+}
+
// Validate that access to the buffer is within bounds, assuming you want to
// access length bytes from the specified offset.
static inline void