Browse files

Pointer#cast! accept an alias of types. fix #1488

  • Loading branch information...
1 parent 8b320dc commit 85f0825b40910abcf99578366c48423a8479d980 @Watson1978 Watson1978 committed Mar 27, 2012
Showing with 7 additions and 0 deletions.
  1. +3 −0 bridgesupport.cpp
  2. +4 −0 spec/macruby/core/pointer_spec.rb
View
3 bridgesupport.cpp
@@ -1012,6 +1012,9 @@ rb_pointer_cast(VALUE rcv, SEL sel, VALUE type)
Data_Get_Struct(rcv, rb_vm_pointer_t, ptr);
check_no_magic_cookie(ptr);
+
+ const char *type_str = convert_ffi_type(type, false);
+ type = rb_str_new_cstr(type_str);
rb_pointer_init_type(ptr, type);
return rcv;
}
View
4 spec/macruby/core/pointer_spec.rb
@@ -193,6 +193,10 @@ def coercable_object.to_f; 42.0; end
pointer2.cast!(NSRect.type).should == pointer2
pointer2.type.should == NSRect.type
pointer2[0].should == NSMakeRect(10, 20, 30, 40)
+
+ pointer3 = Pointer.new(:int)
+ pointer3.cast!(:uint)
+ pointer3.type == 'I'
end
it "raises a TypeError when a incompatible object is given into #cast!" do

0 comments on commit 85f0825

Please sign in to comment.