diff options
author | ttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-30 18:05:40 +0000 |
---|---|---|
committer | ttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-30 18:05:40 +0000 |
commit | e587cf273099ee1e0dbaafdc47f220ea8b81e2e9 (patch) | |
tree | 2c0535cb92a6fdc97fecfdb8bfec515d8c4af6dd /ext/dl/lib/dl | |
parent | abbe9742673fbfc2962a2e11e365e70843e59e9f (diff) |
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
Diffstat (limited to 'ext/dl/lib/dl')
-rw-r--r-- | ext/dl/lib/dl/struct.rb | 23 |
1 files changed, 17 insertions, 6 deletions
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 |