mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/dl/lib/dl/struct.rb (DL::CUnionEntity::size): Fixed ::size to
return the size of the union. * test/dl/test_c_union_entity.rb: Test for DL::CUnionEntity::size Reviewed by Aaron Patterson git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e88c8880b1
commit
f1cb6ea08f
3 changed files with 27 additions and 11 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Thu May 31 08:20:14 2012 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* ext/dl/lib/dl/struct.rb (DL::CUnionEntity::size): Fixed ::size to
|
||||||
|
return the size of the union.
|
||||||
|
* test/dl/test_c_union_entity.rb: Test for DL::CUnionEntity::size
|
||||||
|
|
||||||
Thu May 31 07:45:43 2012 Eric Hodel <drbrain@segment7.net>
|
Thu May 31 07:45:43 2012 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* ext/dl: Added documentation. Patch by Vincent Batts.
|
* ext/dl: Added documentation. Patch by Vincent Batts.
|
||||||
|
|
|
@ -234,17 +234,9 @@ module DL
|
||||||
# DL::TYPE_VOIDP])
|
# DL::TYPE_VOIDP])
|
||||||
# => 8
|
# => 8
|
||||||
def CUnionEntity.size(types)
|
def CUnionEntity.size(types)
|
||||||
size = 0
|
types.map { |type, count = 1|
|
||||||
types.each_with_index{|t,i|
|
PackInfo::SIZE_MAP[type] * count
|
||||||
if( t.is_a?(Array) )
|
}.max
|
||||||
tsize = PackInfo::SIZE_MAP[t[0]] * t[1]
|
|
||||||
else
|
|
||||||
tsize = PackInfo::SIZE_MAP[t]
|
|
||||||
end
|
|
||||||
if( tsize > size )
|
|
||||||
size = tsize
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Given +types+, calculate the necessary offset and for each union member
|
# Given +types+, calculate the necessary offset and for each union member
|
||||||
|
|
18
test/dl/test_c_union_entity.rb
Normal file
18
test/dl/test_c_union_entity.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
require_relative 'test_base'
|
||||||
|
|
||||||
|
require 'dl/cparser'
|
||||||
|
|
||||||
|
class DL::TestCUnionEntity < DL::TestBase
|
||||||
|
def test_class_size
|
||||||
|
size = DL::CUnionEntity.size([DL::TYPE_DOUBLE, DL::TYPE_CHAR])
|
||||||
|
|
||||||
|
assert_equal DL::SIZEOF_DOUBLE, size
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_class_size_with_count
|
||||||
|
size = DL::CUnionEntity.size([[DL::TYPE_DOUBLE, 2], [DL::TYPE_CHAR, 20]])
|
||||||
|
|
||||||
|
assert_equal DL::SIZEOF_CHAR * 20, size
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue