summaryrefslogtreecommitdiff
path: root/ext/dl/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-03 06:07:24 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-03 06:07:24 +0000
commitdaa2217d48e8076d07f4d4c352b7932ecbb5ad67 (patch)
tree111be6b00e9884e4e6fdc106ae9d48183e55ac64 /ext/dl/lib
parent0cceff94ca29bed2d934a495f1a97041f46b2e76 (diff)
* ext/dl/lib/dl/pack.rb (DL::PackInfo): reduced redundant
initialization. * ext/dl/lib/dl/stack.rb (DL::Stack): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/lib')
-rw-r--r--ext/dl/lib/dl/pack.rb57
-rw-r--r--ext/dl/lib/dl/stack.rb44
2 files changed, 13 insertions, 88 deletions
diff --git a/ext/dl/lib/dl/pack.rb b/ext/dl/lib/dl/pack.rb
index ad91833b3a..085b42bf17 100644
--- a/ext/dl/lib/dl/pack.rb
+++ b/ext/dl/lib/dl/pack.rb
@@ -2,55 +2,6 @@ require 'dl'
module DL
module PackInfo
- if( defined?(TYPE_LONG_LONG) )
- ALIGN_MAP = {
- TYPE_VOIDP => ALIGN_VOIDP,
- TYPE_CHAR => ALIGN_CHAR,
- TYPE_SHORT => ALIGN_SHORT,
- TYPE_INT => ALIGN_INT,
- TYPE_LONG => ALIGN_LONG,
- TYPE_LONG_LONG => ALIGN_LONG_LONG,
- TYPE_FLOAT => ALIGN_FLOAT,
- TYPE_DOUBLE => ALIGN_DOUBLE,
- -TYPE_CHAR => ALIGN_CHAR,
- -TYPE_SHORT => ALIGN_SHORT,
- -TYPE_INT => ALIGN_INT,
- -TYPE_LONG => ALIGN_LONG,
- -TYPE_LONG_LONG => ALIGN_LONG_LONG,
- }
-
- PACK_MAP = {
- TYPE_VOIDP => ((SIZEOF_VOIDP == SIZEOF_LONG_LONG) ? "q" : "l!"),
- TYPE_CHAR => "c",
- TYPE_SHORT => "s!",
- TYPE_INT => "i!",
- TYPE_LONG => "l!",
- TYPE_LONG_LONG => "q",
- TYPE_FLOAT => "f",
- TYPE_DOUBLE => "d",
- -TYPE_CHAR => "c",
- -TYPE_SHORT => "s!",
- -TYPE_INT => "i!",
- -TYPE_LONG => "l!",
- -TYPE_LONG_LONG => "q",
- }
-
- SIZE_MAP = {
- TYPE_VOIDP => SIZEOF_VOIDP,
- TYPE_CHAR => SIZEOF_CHAR,
- TYPE_SHORT => SIZEOF_SHORT,
- TYPE_INT => SIZEOF_INT,
- TYPE_LONG => SIZEOF_LONG,
- TYPE_LONG_LONG => SIZEOF_LONG_LONG,
- TYPE_FLOAT => SIZEOF_FLOAT,
- TYPE_DOUBLE => SIZEOF_DOUBLE,
- -TYPE_CHAR => SIZEOF_CHAR,
- -TYPE_SHORT => SIZEOF_SHORT,
- -TYPE_INT => SIZEOF_INT,
- -TYPE_LONG => SIZEOF_LONG,
- -TYPE_LONG_LONG => SIZEOF_LONG_LONG,
- }
- else
ALIGN_MAP = {
TYPE_VOIDP => ALIGN_VOIDP,
TYPE_CHAR => ALIGN_CHAR,
@@ -92,6 +43,10 @@ module DL
-TYPE_INT => SIZEOF_INT,
-TYPE_LONG => SIZEOF_LONG,
}
+ if defined?(TYPE_LONG_LONG)
+ ALIGN_MAP[TYPE_LONG_LONG] = ALIGN_MAP[-TYPE_LONG_LONG] = ALIGN_LONG_LONG
+ PACK_MAP[TYPE_LONG_LONG] = PACK_MAP[-TYPE_LONG_LONG] = "q"
+ SIZE_MAP[TYPE_LONG_LONG] = SIZE_MAP[-TYPE_LONG_LONG] = SIZEOF_LONG_LONG
end
def align(addr, align)
@@ -108,8 +63,8 @@ module DL
class Packer
include PackInfo
- def Packer.[](*types)
- Packer.new(types)
+ def self.[](*types)
+ new(types)
end
def initialize(types)
diff --git a/ext/dl/lib/dl/stack.rb b/ext/dl/lib/dl/stack.rb
index 99a24bc1ba..f05a83e580 100644
--- a/ext/dl/lib/dl/stack.rb
+++ b/ext/dl/lib/dl/stack.rb
@@ -2,8 +2,8 @@ require 'dl'
module DL
class Stack
- def Stack.[](*types)
- Stack.new(types)
+ def self.[](*types)
+ new(types)
end
def initialize(types)
@@ -51,14 +51,12 @@ module DL
end
end
-if( defined?(TYPE_LONG_LONG) )
ALIGN_MAP = {
TYPE_VOIDP => ALIGN_VOIDP,
TYPE_CHAR => ALIGN_VOIDP,
TYPE_SHORT => ALIGN_VOIDP,
TYPE_INT => ALIGN_VOIDP,
TYPE_LONG => ALIGN_VOIDP,
- TYPE_LONG_LONG => ALIGN_LONG_LONG,
TYPE_FLOAT => ALIGN_FLOAT,
TYPE_DOUBLE => ALIGN_DOUBLE,
}
@@ -69,7 +67,6 @@ if( defined?(TYPE_LONG_LONG) )
TYPE_SHORT => "s!",
TYPE_INT => "i!",
TYPE_LONG => "l!",
- TYPE_LONG_LONG => "q",
TYPE_FLOAT => "f",
TYPE_DOUBLE => "d",
}
@@ -80,41 +77,14 @@ if( defined?(TYPE_LONG_LONG) )
TYPE_SHORT => SIZEOF_SHORT,
TYPE_INT => SIZEOF_INT,
TYPE_LONG => SIZEOF_LONG,
- TYPE_LONG_LONG => SIZEOF_LONG_LONG,
TYPE_FLOAT => SIZEOF_FLOAT,
TYPE_DOUBLE => SIZEOF_DOUBLE,
}
-else
- ALIGN_MAP = {
- TYPE_VOIDP => ALIGN_VOIDP,
- TYPE_CHAR => ALIGN_VOIDP,
- TYPE_SHORT => ALIGN_VOIDP,
- TYPE_INT => ALIGN_VOIDP,
- TYPE_LONG => ALIGN_VOIDP,
- TYPE_FLOAT => ALIGN_FLOAT,
- TYPE_DOUBLE => ALIGN_DOUBLE,
- }
-
- PACK_MAP = {
- TYPE_VOIDP => ((SIZEOF_VOIDP == SIZEOF_LONG_LONG)? "q" : "l!"),
- TYPE_CHAR => "c",
- TYPE_SHORT => "s!",
- TYPE_INT => "i!",
- TYPE_LONG => "l!",
- TYPE_FLOAT => "f",
- TYPE_DOUBLE => "d",
- }
-
- SIZE_MAP = {
- TYPE_VOIDP => SIZEOF_VOIDP,
- TYPE_CHAR => SIZEOF_CHAR,
- TYPE_SHORT => SIZEOF_SHORT,
- TYPE_INT => SIZEOF_INT,
- TYPE_LONG => SIZEOF_LONG,
- TYPE_FLOAT => SIZEOF_FLOAT,
- TYPE_DOUBLE => SIZEOF_DOUBLE,
- }
-end
+ if defined?(TYPE_LONG_LONG)
+ ALIGN_MAP[TYPE_LONG_LONG] = ALIGN_LONG_LONG
+ PACK_MAP[TYPE_LONG_LONG] = "q"
+ SIZE_MAP[TYPE_LONG_LONG] = SIZEOF_LONG_LONG
+ end
def parse_types(types)
@types = types