Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions io_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,15 @@ rb_io_buffer_for_reading(VALUE string_or_buffer, VALUE (*callback)(VALUE, VALUE)
}
}

/* Forward declaration: rb_io_buffer_readonly_p is defined later in this file. */
int rb_io_buffer_readonly_p(VALUE self);
/* Forward declaration: io_buffer_readonly_p is defined later in this file. */
static int io_buffer_readonly_p(struct rb_io_buffer *buffer);

VALUE
rb_io_buffer_for_writing(VALUE string_or_buffer, VALUE (*callback)(VALUE, VALUE), VALUE argument)
{
if (rb_obj_is_kind_of(string_or_buffer, rb_cIOBuffer)) {
if (rb_io_buffer_readonly_p(string_or_buffer)) {
struct rb_io_buffer *buffer = get_io_buffer(string_or_buffer);
if (io_buffer_readonly_p(buffer)) {
rb_raise(rb_eArgError, "buffer is read-only");
}
return callback(string_or_buffer, argument);
Expand Down Expand Up @@ -1509,11 +1510,9 @@ rb_io_buffer_private_p(VALUE self)
return RBOOL(buffer->flags & RB_IO_BUFFER_PRIVATE);
}

int
rb_io_buffer_readonly_p(VALUE self)
static int
io_buffer_readonly_p(struct rb_io_buffer *buffer)
{
struct rb_io_buffer *buffer = get_io_buffer(self);

return buffer->flags & RB_IO_BUFFER_READONLY;
}

Expand All @@ -1527,9 +1526,11 @@ rb_io_buffer_readonly_p(VALUE self)
* backed by a frozen string or a read-only file.
*/
static VALUE
io_buffer_readonly_p(VALUE self)
rb_io_buffer_readonly_p(VALUE self)
{
return RBOOL(rb_io_buffer_readonly_p(self));
struct rb_io_buffer *buffer = get_io_buffer(self);

return RBOOL(io_buffer_readonly_p(buffer));
}

static void
Expand Down Expand Up @@ -4214,7 +4215,7 @@ Init_IO_Buffer(void)
rb_define_method(rb_cIOBuffer, "shared?", rb_io_buffer_shared_p, 0);
rb_define_method(rb_cIOBuffer, "locked?", rb_io_buffer_locked_p, 0);
rb_define_method(rb_cIOBuffer, "private?", rb_io_buffer_private_p, 0);
rb_define_method(rb_cIOBuffer, "readonly?", io_buffer_readonly_p, 0);
rb_define_method(rb_cIOBuffer, "readonly?", rb_io_buffer_readonly_p, 0);

// Locking to prevent changes while using pointer:
// rb_define_method(rb_cIOBuffer, "lock", rb_io_buffer_lock, 0);
Expand Down
4 changes: 0 additions & 4 deletions weakmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ wmap_memsize(const void *ptr)
size_t size = 0;
if (w->table) {
size += st_memsize(w->table);
/* The key and value of the table each take sizeof(VALUE) in size. */
size += st_table_size(w->table) * (2 * sizeof(VALUE));
}

return size;
Expand Down Expand Up @@ -561,8 +559,6 @@ wkmap_memsize(const void *ptr)
size_t size = 0;
if (w->table) {
size += st_memsize(w->table);
/* Each key of the table takes sizeof(VALUE) in size. */
size += st_table_size(w->table) * sizeof(VALUE);
}

return size;
Expand Down