From e587cf273099ee1e0dbaafdc47f220ea8b81e2e9 Mon Sep 17 00:00:00 2001 From: ttate Date: Fri, 30 Jun 2006 18:05:40 +0000 Subject: fixed the alignment problems discussed in [ruby-dev:28667]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/dl/lib/dl/struct.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'ext/dl/lib') diff --git a/ext/dl/lib/dl/struct.rb b/ext/dl/lib/dl/struct.rb index 01445cf55a..4272b3960c 100644 --- a/ext/dl/lib/dl/struct.rb +++ b/ext/dl/lib/dl/struct.rb @@ -54,19 +54,25 @@ module DL def CStructEntity.size(types) offset = 0 + max_align = 0 types.each_with_index{|t,i| orig_offset = offset if( t.is_a?(Array) ) - offset = PackInfo.align(orig_offset, PackInfo::ALIGN_MAP[TYPE_VOIDP]) + align = PackInfo::ALIGN_MAP[t[0]] + offset = PackInfo.align(orig_offset, align) size = offset - orig_offset offset += (PackInfo::SIZE_MAP[t[0]] * t[1]) else - offset = PackInfo.align(orig_offset, PackInfo::ALIGN_MAP[t]) + align = PackInfo::ALIGN_MAP[t] + offset = PackInfo.align(orig_offset, align) size = offset - orig_offset offset += PackInfo::SIZE_MAP[t] end + if (max_align < align) + max_align = align + end } - offset = PackInfo.align(offset, PackInfo::ALIGN_MAP[TYPE_VOIDP]) + offset = PackInfo.align(offset, max_align) offset end @@ -83,13 +89,15 @@ module DL @ctypes = types @offset = [] offset = 0 + max_align = 0 types.each_with_index{|t,i| orig_offset = offset if( t.is_a?(Array) ) - offset = align(orig_offset, ALIGN_MAP[TYPE_VOIDP]) + align = ALIGN_MAP[t[0]] else - offset = align(orig_offset, ALIGN_MAP[t]) + align = ALIGN_MAP[t] end + offset = PackInfo.align(orig_offset, align) size = offset - orig_offset @offset[i] = offset if( t.is_a?(Array) ) @@ -97,8 +105,11 @@ module DL else offset += SIZE_MAP[t] end + if (max_align < align) + max_align = align + end } - offset = align(offset, ALIGN_MAP[TYPE_VOIDP]) + offset = PackInfo.align(offset, max_align) @size = offset end -- cgit v1.2.3