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
3 changes: 3 additions & 0 deletions ext/numo/narray/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ static VALUE nary_swap_byte(VALUE self) {
ndfunc_arg_out_t aout[1] = { { INT2FIX(0), 0 } };
ndfunc_t ndf = { iter_swap_byte, FULL_LOOP | NDF_ACCEPT_BYTESWAP, 1, 1, ain, aout };

if (RTEST(rb_obj_is_kind_of(self, numo_cRObject))) {
rb_raise(rb_eTypeError, "cannot swap bytes of %s", rb_obj_classname(self));
}
if (RTEST(rb_obj_is_kind_of(self, numo_cBit))) {
v = TEST_INPLACE(self) ? self : rb_funcall(self, id_copy, 0);
} else {
Expand Down
1 change: 1 addition & 0 deletions ext/numo/narray/src/t_robject.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ void Init_numo_robject(void) {
rb_undef_method(cT, "to_binary");
rb_undef_method(cT, "to_string");
rb_undef_method(cT, "swap_byte");
rb_undef_method(cT, "hton");
rb_undef_method(cT, "to_network");
rb_undef_method(cT, "to_vacs");
rb_undef_method(cT, "to_host");
Expand Down
13 changes: 13 additions & 0 deletions test/test_narray.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2215,6 +2215,19 @@ def test_robject_rejects_binary_io
end
end

def test_robject_rejects_byte_swap
a = Numo::RObject[1, 2, 3]
b = RObjectSubclass.new(3).allocate

assert_raises(NoMethodError) { a.swap_byte }
assert_raises(NoMethodError) { a.hton }
assert_raises(NoMethodError) { b.hton }

assert_raises(TypeError) { Numo::NArray.instance_method(:swap_byte).bind_call(a) }
assert_raises(TypeError) { Numo::NArray.instance_method(:hton).bind_call(a) }
assert_raises(TypeError) { Numo::NArray.instance_method(:swap_byte).bind_call(b) }
end

def test_marshal_load_rejects_a_non_array_shape
[42, 'AAAAAAAAAAAAAAAA', nil, {}, 1.5, :abc, true, Object.new].each do |bad|
assert_raises(ArgumentError) { Numo::DFloat.allocate.marshal_load([1, bad, 0, +'']) }
Expand Down
Loading