mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
memory_view.c: Check availability in rb_memory_view_get
This commit is contained in:
parent
7172272c4c
commit
82dc0c6aa3
3 changed files with 22 additions and 1 deletions
|
@ -35,7 +35,8 @@ exportable_string_get_memory_view(VALUE obj, rb_memory_view_t *view, int flags)
|
||||||
static int
|
static int
|
||||||
exportable_string_memory_view_available_p(VALUE obj)
|
exportable_string_memory_view_available_p(VALUE obj)
|
||||||
{
|
{
|
||||||
return Qtrue;
|
VALUE str = rb_ivar_get(obj, id_str);
|
||||||
|
return !NIL_P(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const rb_memory_view_entry_t exportable_string_memory_view_entry = {
|
static const rb_memory_view_entry_t exportable_string_memory_view_entry = {
|
||||||
|
@ -232,6 +233,9 @@ memory_view_ref_count_while_exporting(VALUE mod, VALUE obj, VALUE n)
|
||||||
static VALUE
|
static VALUE
|
||||||
expstr_initialize(VALUE obj, VALUE s)
|
expstr_initialize(VALUE obj, VALUE s)
|
||||||
{
|
{
|
||||||
|
if (!NIL_P(s)) {
|
||||||
|
Check_Type(s, T_STRING);
|
||||||
|
}
|
||||||
rb_ivar_set(obj, id_str, s);
|
rb_ivar_set(obj, id_str, s);
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
|
@ -592,6 +592,10 @@ rb_memory_view_get(VALUE obj, rb_memory_view_t* view, int flags)
|
||||||
VALUE klass = CLASS_OF(obj);
|
VALUE klass = CLASS_OF(obj);
|
||||||
const rb_memory_view_entry_t *entry = lookup_memory_view_entry(klass);
|
const rb_memory_view_entry_t *entry = lookup_memory_view_entry(klass);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
|
if (!(*entry->available_p_func)(obj)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int rv = (*entry->get_func)(obj, view, flags);
|
int rv = (*entry->get_func)(obj, view, flags);
|
||||||
if (rv) {
|
if (rv) {
|
||||||
register_exported_object(view->obj);
|
register_exported_object(view->obj);
|
||||||
|
|
|
@ -197,6 +197,13 @@ class TestMemoryView < Test::Unit::TestCase
|
||||||
assert_equal(expected_result, members)
|
assert_equal(expected_result, members)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_rb_memory_view_available_p
|
||||||
|
es = MemoryViewTestUtils::ExportableString.new("ruby")
|
||||||
|
assert_equal(true, MemoryViewTestUtils.available?(es))
|
||||||
|
es = MemoryViewTestUtils::ExportableString.new(nil)
|
||||||
|
assert_equal(false, MemoryViewTestUtils.available?(es))
|
||||||
|
end
|
||||||
|
|
||||||
def test_ref_count_with_exported_object
|
def test_ref_count_with_exported_object
|
||||||
es = MemoryViewTestUtils::ExportableString.new("ruby")
|
es = MemoryViewTestUtils::ExportableString.new("ruby")
|
||||||
assert_equal(1, MemoryViewTestUtils.ref_count_while_exporting(es, 1))
|
assert_equal(1, MemoryViewTestUtils.ref_count_while_exporting(es, 1))
|
||||||
|
@ -223,6 +230,12 @@ class TestMemoryView < Test::Unit::TestCase
|
||||||
memory_view_info)
|
memory_view_info)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_rb_memory_view_get_with_memory_view_unavailable_object
|
||||||
|
es = MemoryViewTestUtils::ExportableString.new(nil)
|
||||||
|
memory_view_info = MemoryViewTestUtils.get_memory_view_info(es)
|
||||||
|
assert_nil(memory_view_info)
|
||||||
|
end
|
||||||
|
|
||||||
def test_rb_memory_view_fill_contiguous_strides
|
def test_rb_memory_view_fill_contiguous_strides
|
||||||
row_major_strides = MemoryViewTestUtils.fill_contiguous_strides(3, 8, [2, 3, 4], true)
|
row_major_strides = MemoryViewTestUtils.fill_contiguous_strides(3, 8, [2, 3, 4], true)
|
||||||
assert_equal([96, 32, 8],
|
assert_equal([96, 32, 8],
|
||||||
|
|
Loading…
Add table
Reference in a new issue