Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 85f0825b40910abcf99578366c48423a8479d980 1 parent 8b320dc
Watson Watson1978 authored

Showing 2 changed files with 7 additions and 0 deletions. Show diff stats Hide diff stats

  1. +3 0  bridgesupport.cpp
  2. +4 0 spec/macruby/core/pointer_spec.rb
3  bridgesupport.cpp
@@ -1012,6 +1012,9 @@ rb_pointer_cast(VALUE rcv, SEL sel, VALUE type)
1012 1012 Data_Get_Struct(rcv, rb_vm_pointer_t, ptr);
1013 1013
1014 1014 check_no_magic_cookie(ptr);
  1015 +
  1016 + const char *type_str = convert_ffi_type(type, false);
  1017 + type = rb_str_new_cstr(type_str);
1015 1018 rb_pointer_init_type(ptr, type);
1016 1019 return rcv;
1017 1020 }
4 spec/macruby/core/pointer_spec.rb
@@ -193,6 +193,10 @@ def coercable_object.to_f; 42.0; end
193 193 pointer2.cast!(NSRect.type).should == pointer2
194 194 pointer2.type.should == NSRect.type
195 195 pointer2[0].should == NSMakeRect(10, 20, 30, 40)
  196 +
  197 + pointer3 = Pointer.new(:int)
  198 + pointer3.cast!(:uint)
  199 + pointer3.type == 'I'
196 200 end
197 201
198 202 it "raises a TypeError when a incompatible object is given into #cast!" do

0 comments on commit 85f0825

Please sign in to comment.
Something went wrong with that request. Please try again.