ruby-changes:64485
From: Kenta <ko1@a...>
Date: Wed, 23 Dec 2020 09:25:30 +0900 (JST)
Subject: [ruby-changes:64485] 74652e640a (master): [memory_view][fiddle] Rename len to byte_size in rb_memory_view_t
https://git.ruby-lang.org/ruby.git/commit/?id=74652e640a From 74652e640a3ef50eb5442eb98438e3d634a4faf7 Mon Sep 17 00:00:00 2001 From: Kenta Murata <mrkn@m...> Date: Wed, 23 Dec 2020 00:33:24 +0900 Subject: [memory_view][fiddle] Rename len to byte_size in rb_memory_view_t diff --git a/ext/-test-/memory_view/memory_view.c b/ext/-test-/memory_view/memory_view.c index 00572b9..c847eac 100644 --- a/ext/-test-/memory_view/memory_view.c +++ b/ext/-test-/memory_view/memory_view.c @@ -12,7 +12,7 @@ static VALUE sym_offset; https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_view/memory_view.c#L12 static VALUE sym_size; static VALUE sym_repeat; static VALUE sym_obj; -static VALUE sym_len; +static VALUE sym_byte_size; static VALUE sym_readonly; static VALUE sym_format; static VALUE sym_item_size; @@ -122,7 +122,7 @@ memory_view_get_memory_view_info(VALUE mod, VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_view/memory_view.c#L122 VALUE hash = rb_hash_new(); rb_hash_aset(hash, sym_obj, view.obj); - rb_hash_aset(hash, sym_len, SSIZET2NUM(view.len)); + rb_hash_aset(hash, sym_byte_size, SSIZET2NUM(view.byte_size)); rb_hash_aset(hash, sym_readonly, view.readonly ? Qtrue : Qfalse); rb_hash_aset(hash, sym_format, view.format ? rb_str_new_cstr(view.format) : Qnil); rb_hash_aset(hash, sym_item_size, SSIZET2NUM(view.item_size)); @@ -398,7 +398,7 @@ Init_memory_view(void) https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_view/memory_view.c#L398 sym_size = ID2SYM(rb_intern_const("size")); sym_repeat = ID2SYM(rb_intern_const("repeat")); sym_obj = ID2SYM(rb_intern_const("obj")); - sym_len = ID2SYM(rb_intern_const("len")); + sym_byte_size = ID2SYM(rb_intern_const("byte_size")); sym_readonly = ID2SYM(rb_intern_const("readonly")); sym_format = ID2SYM(rb_intern_const("format")); sym_item_size = ID2SYM(rb_intern_const("item_size")); diff --git a/ext/fiddle/memory_view.c b/ext/fiddle/memory_view.c index 819a8bd..172b1f1 100644 --- a/ext/fiddle/memory_view.c +++ b/ext/fiddle/memory_view.c @@ -48,7 +48,7 @@ static size_t https://github.com/ruby/ruby/blob/trunk/ext/fiddle/memory_view.c#L48 fiddle_memview_memsize(const void *ptr) { const struct memview_data *data = ptr; - return sizeof(*data) + sizeof(rb_memory_view_item_component_t)*data->n_members + (size_t)data->view.len; + return sizeof(*data) + sizeof(rb_memory_view_item_component_t)*data->n_members + (size_t)data->view.byte_size; } static const rb_data_type_t fiddle_memview_data_type = { @@ -90,13 +90,13 @@ rb_fiddle_memview_get_obj(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/fiddle/memory_view.c#L90 } static VALUE -rb_fiddle_memview_get_length(VALUE obj) +rb_fiddle_memview_get_byte_size(VALUE obj) { struct memview_data *data; TypedData_Get_Struct(obj, struct memview_data, &fiddle_memview_data_type, data); if (NIL_P(data->view.obj)) return Qnil; - return SSIZET2NUM(data->view.len); + return SSIZET2NUM(data->view.byte_size); } static VALUE @@ -240,7 +240,7 @@ Init_fiddle_memory_view(void) https://github.com/ruby/ruby/blob/trunk/ext/fiddle/memory_view.c#L240 rb_define_alloc_func(rb_cMemoryView, rb_fiddle_memview_s_allocate); rb_define_method(rb_cMemoryView, "initialize", rb_fiddle_memview_initialize, 1); rb_define_method(rb_cMemoryView, "obj", rb_fiddle_memview_get_obj, 0); - rb_define_method(rb_cMemoryView, "length", rb_fiddle_memview_get_length, 0); + rb_define_method(rb_cMemoryView, "byte_size", rb_fiddle_memview_get_byte_size, 0); rb_define_method(rb_cMemoryView, "readonly?", rb_fiddle_memview_get_readonly, 0); rb_define_method(rb_cMemoryView, "format", rb_fiddle_memview_get_format, 0); rb_define_method(rb_cMemoryView, "item_size", rb_fiddle_memview_get_item_size, 0); diff --git a/include/ruby/memory_view.h b/include/ruby/memory_view.h index b90a32d..6ff5cbf 100644 --- a/include/ruby/memory_view.h +++ b/include/ruby/memory_view.h @@ -46,7 +46,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/include/ruby/memory_view.h#L46 void *data; /* The number of bytes in data. */ - ssize_t len; + ssize_t byte_size; /* true for readonly memory, false for writable memory. */ bool readonly; diff --git a/memory_view.c b/memory_view.c index 08ff967..743a736 100644 --- a/memory_view.c +++ b/memory_view.c @@ -199,7 +199,7 @@ rb_memory_view_init_as_byte_array(rb_memory_view_t *view, VALUE obj, void *data, https://github.com/ruby/ruby/blob/trunk/memory_view.c#L199 { view->obj = obj; view->data = data; - view->len = len; + view->byte_size = len; view->readonly = readonly; view->format = NULL; view->item_size = 1; diff --git a/test/fiddle/test_memory_view.rb b/test/fiddle/test_memory_view.rb index 3c310c2..c673d26 100644 --- a/test/fiddle/test_memory_view.rb +++ b/test/fiddle/test_memory_view.rb @@ -33,7 +33,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_memory_view.rb#L33 ptr = Pointer[str] mview = MemoryView.new(ptr) assert_same(ptr, mview.obj) - assert_equal(str.length, mview.length) + assert_equal(str.bytesize, mview.byte_size) assert_equal(true, mview.readonly?) assert_equal(nil, mview.format) assert_equal(1, mview.item_size) @@ -43,7 +43,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_memory_view.rb#L43 assert_equal(nil, mview.sub_offsets) codes = str.codepoints - assert_equal(codes, (0...str.length).map {|i| mview[i] }) + assert_equal(codes, (0...str.bytesize).map {|i| mview[i] }) end def test_memory_view_multi_dimensional @@ -55,7 +55,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_memory_view.rb#L55 shape = [3, 4] md = MemoryViewTestUtils::MultiDimensionalView.new(buf, "l!", shape, nil) mview = Fiddle::MemoryView.new(md) - assert_equal(buf.length, mview.length) + assert_equal(buf.bytesize, mview.byte_size) assert_equal("l!", mview.format) assert_equal(Fiddle::SIZEOF_LONG, mview.item_size) assert_equal(2, mview.ndim) @@ -79,7 +79,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_memory_view.rb#L79 mview = Fiddle::MemoryView.new(md) assert_equal("l!", mview.format) assert_equal(Fiddle::SIZEOF_LONG, mview.item_size) - assert_equal(buf.length, mview.length) + assert_equal(buf.bytesize, mview.byte_size) assert_equal(2, mview.ndim) assert_equal(shape, mview.shape) assert_equal(strides, mview.strides) @@ -101,7 +101,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_memory_view.rb#L101 mview = Fiddle::MemoryView.new(md) assert_equal("ss", mview.format) assert_equal(Fiddle::SIZEOF_SHORT*2, mview.item_size) - assert_equal(buf.length, mview.length) + assert_equal(buf.bytesize, mview.byte_size) assert_equal(2, mview.ndim) assert_equal(shape, mview.shape) assert_equal(strides, mview.strides) diff --git a/test/ruby/test_memory_view.rb b/test/ruby/test_memory_view.rb index ed2f53c..5a39084 100644 --- a/test/ruby/test_memory_view.rb +++ b/test/ruby/test_memory_view.rb @@ -269,7 +269,7 @@ class TestMemoryView < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_memory_view.rb#L269 memory_view_info = MemoryViewTestUtils.get_memory_view_info(es) assert_equal({ obj: es, - len: 4, + byte_size: 4, readonly: true, format: nil, item_size: 1, -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/