[前][次][番号順一覧][スレッド一覧]

ruby-changes:23797

From: drbrain <ko1@a...>
Date: Thu, 31 May 2012 08:20:39 +0900 (JST)
Subject: [ruby-changes:23797] drbrain:r35848 (trunk): * ext/dl/lib/dl/struct.rb (DL::CUnionEntity::size): Fixed ::size to

drbrain	2012-05-31 08:20:29 +0900 (Thu, 31 May 2012)

  New Revision: 35848

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35848

  Log:
    * 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

  Added files:
    trunk/test/dl/test_c_union_entity.rb
  Modified files:
    trunk/ChangeLog
    trunk/ext/dl/lib/dl/struct.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35847)
+++ ChangeLog	(revision 35848)
@@ -1,3 +1,9 @@
+Thu May 31 08:20:14 2012  Eric Hodel  <drbrain@s...>
+
+	* 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@s...>
 
 	* ext/dl:  Added documentation.  Patch by Vincent Batts.
Index: ext/dl/lib/dl/struct.rb
===================================================================
--- ext/dl/lib/dl/struct.rb	(revision 35847)
+++ ext/dl/lib/dl/struct.rb	(revision 35848)
@@ -234,17 +234,9 @@
     #                          DL::TYPE_VOIDP])
     #   => 8
     def CUnionEntity.size(types)
-      size   = 0
-      types.each_with_index{|t,i|
-        if( t.is_a?(Array) )
-          tsize = PackInfo::SIZE_MAP[t[0]] * t[1]
-        else
-          tsize = PackInfo::SIZE_MAP[t]
-        end
-        if( tsize > size )
-          size = tsize
-        end
-      }
+      types.map { |type, count = 1|
+        PackInfo::SIZE_MAP[type] * count
+      }.max
     end
 
     # Given +types+, calculate the necessary offset and for each union member
Index: test/dl/test_c_union_entity.rb
===================================================================
--- test/dl/test_c_union_entity.rb	(revision 0)
+++ test/dl/test_c_union_entity.rb	(revision 35848)
@@ -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
+

Property changes on: test/dl/test_c_union_entity.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]