mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[memory_view][fiddle] Rename len to byte_size in rb_memory_view_t
This commit is contained in:
parent
05014dcb88
commit
74652e640a
6 changed files with 15 additions and 15 deletions
|
@ -12,7 +12,7 @@ static VALUE sym_offset;
|
|||
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)
|
|||
|
||||
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)
|
|||
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"));
|
||||
|
|
|
@ -48,7 +48,7 @@ static size_t
|
|||
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)
|
|||
}
|
||||
|
||||
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)
|
|||
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);
|
||||
|
|
|
@ -46,7 +46,7 @@ typedef struct {
|
|||
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;
|
||||
|
|
|
@ -199,7 +199,7 @@ rb_memory_view_init_as_byte_array(rb_memory_view_t *view, VALUE obj, void *data,
|
|||
{
|
||||
view->obj = obj;
|
||||
view->data = data;
|
||||
view->len = len;
|
||||
view->byte_size = len;
|
||||
view->readonly = readonly;
|
||||
view->format = NULL;
|
||||
view->item_size = 1;
|
||||
|
|
|
@ -33,7 +33,7 @@ module Fiddle
|
|||
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
|
|||
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
|
|||
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
|
|||
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
|
|||
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)
|
||||
|
|
|
@ -269,7 +269,7 @@ class TestMemoryView < Test::Unit::TestCase
|
|||
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,
|
||||
|
|
Loading…
Reference in a new issue