зеркало из https://github.com/github/ruby.git
memory_view.c: Check availability in rb_memory_view_get
This commit is contained in:
Родитель
7172272c4c
Коммит
82dc0c6aa3
|
@ -35,7 +35,8 @@ exportable_string_get_memory_view(VALUE obj, rb_memory_view_t *view, int flags)
|
|||
static int
|
||||
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 = {
|
||||
|
@ -232,6 +233,9 @@ memory_view_ref_count_while_exporting(VALUE mod, VALUE obj, VALUE n)
|
|||
static VALUE
|
||||
expstr_initialize(VALUE obj, VALUE s)
|
||||
{
|
||||
if (!NIL_P(s)) {
|
||||
Check_Type(s, T_STRING);
|
||||
}
|
||||
rb_ivar_set(obj, id_str, s);
|
||||
return Qnil;
|
||||
}
|
||||
|
|
|
@ -592,6 +592,10 @@ rb_memory_view_get(VALUE obj, rb_memory_view_t* view, int flags)
|
|||
VALUE klass = CLASS_OF(obj);
|
||||
const rb_memory_view_entry_t *entry = lookup_memory_view_entry(klass);
|
||||
if (entry) {
|
||||
if (!(*entry->available_p_func)(obj)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rv = (*entry->get_func)(obj, view, flags);
|
||||
if (rv) {
|
||||
register_exported_object(view->obj);
|
||||
|
|
|
@ -197,6 +197,13 @@ class TestMemoryView < Test::Unit::TestCase
|
|||
assert_equal(expected_result, members)
|
||||
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
|
||||
es = MemoryViewTestUtils::ExportableString.new("ruby")
|
||||
assert_equal(1, MemoryViewTestUtils.ref_count_while_exporting(es, 1))
|
||||
|
@ -223,6 +230,12 @@ class TestMemoryView < Test::Unit::TestCase
|
|||
memory_view_info)
|
||||
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
|
||||
row_major_strides = MemoryViewTestUtils.fill_contiguous_strides(3, 8, [2, 3, 4], true)
|
||||
assert_equal([96, 32, 8],
|
||||
|
|
Загрузка…
Ссылка в новой задаче