Skip to content

Commit

Permalink
get a size of pointer type before converting a type to raise a TypeEr…
Browse files Browse the repository at this point in the history
…ror when passed invalid argument to Pointer#cast!. fix #1489
  • Loading branch information
Watson1978 committed Mar 27, 2012
1 parent e35df75 commit 8b320dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bridgesupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,13 +883,13 @@ rb_pointer_init_type(rb_vm_pointer_t *ptr, VALUE type)

RoxorCore *core = GET_CORE();

ptr->type_size = core->get_sizeof(type_str);
assert(ptr->type_size > 0);

ptr->convert_to_rval =
(VALUE (*)(void *))core->gen_to_rval_convertor(type_str);
ptr->convert_to_ocval =
(void (*)(VALUE, void *))core->gen_to_ocval_convertor(type_str);

ptr->type_size = core->get_sizeof(type_str);
assert(ptr->type_size > 0);
}

extern "C"
Expand Down
7 changes: 7 additions & 0 deletions spec/macruby/core/pointer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ def coercable_object.to_f; 42.0; end
pointer2[0].should == NSMakeRect(10, 20, 30, 40)
end

it "raises a TypeError when a incompatible object is given into #cast!" do
lambda {
pointer = Pointer.new('i')
pointer.cast!('x')
}.should raise_error(TypeError)
end

it "of type 'c' can be passed as a C-style char array argument" do
s = NSString.stringWithString('foo')
ptr = Pointer.new(:char, 4)
Expand Down

0 comments on commit 8b320dc

Please sign in to comment.