* ext/dl/lib/dl/struct.rb (DL::CUnionEntity#set_ctypes): Refactored
#set_types to reuse DL::CUnionEntity::size * test/dl/test_c_union_entity.rb: Added test Reviewed by Aaron Paterson git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f1cb6ea08f
commit
0381ab0769
@ -1,3 +1,9 @@
|
||||
Thu May 31 08:40:34 2012 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* ext/dl/lib/dl/struct.rb (DL::CUnionEntity#set_ctypes): Refactored
|
||||
#set_types to reuse DL::CUnionEntity::size
|
||||
* test/dl/test_c_union_entity.rb: Added test
|
||||
|
||||
Thu May 31 08:20:14 2012 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* ext/dl/lib/dl/struct.rb (DL::CUnionEntity::size): Fixed ::size to
|
||||
|
@ -242,19 +242,8 @@ module DL
|
||||
# Given +types+, calculate the necessary offset and for each union member
|
||||
def set_ctypes(types)
|
||||
@ctypes = types
|
||||
@offset = []
|
||||
@size = 0
|
||||
types.each_with_index{|t,i|
|
||||
@offset[i] = 0
|
||||
if( t.is_a?(Array) )
|
||||
size = SIZE_MAP[t[0]] * t[1]
|
||||
else
|
||||
size = SIZE_MAP[t]
|
||||
end
|
||||
if( size > @size )
|
||||
@size = size
|
||||
end
|
||||
}
|
||||
@offset = Array.new(types.length, 0)
|
||||
@size = self.class.size types
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -14,5 +14,17 @@ class DL::TestCUnionEntity < DL::TestBase
|
||||
|
||||
assert_equal DL::SIZEOF_CHAR * 20, size
|
||||
end
|
||||
|
||||
def test_set_ctypes
|
||||
union = DL::CUnionEntity.malloc [DL::TYPE_INT, DL::TYPE_LONG]
|
||||
union.assign_names %w[int long]
|
||||
|
||||
# this test is roundabout because the stored ctypes are not accessible
|
||||
union['long'] = 1
|
||||
assert_equal 1, union['long']
|
||||
|
||||
union['int'] = 1
|
||||
assert_equal 1, union['int']
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user