summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/fiddle/lib/fiddle/import.rb9
-rw-r--r--ext/fiddle/lib/fiddle/pack.rb21
-rw-r--r--ext/fiddle/lib/fiddle/value.rb27
-rw-r--r--test/fiddle/test_cparser.rb10
-rw-r--r--test/fiddle/test_import.rb2
5 files changed, 47 insertions, 22 deletions
diff --git a/ext/fiddle/lib/fiddle/import.rb b/ext/fiddle/lib/fiddle/import.rb
index 59ab3ee6f76..ae44914ec36 100644
--- a/ext/fiddle/lib/fiddle/import.rb
+++ b/ext/fiddle/lib/fiddle/import.rb
@@ -115,8 +115,6 @@ module Fiddle
return SIZEOF_INT
when TYPE_LONG
return SIZEOF_LONG
- when TYPE_LONG_LONG
- return SIZEOF_LONG_LONG
when TYPE_FLOAT
return SIZEOF_FLOAT
when TYPE_DOUBLE
@@ -124,7 +122,12 @@ module Fiddle
when TYPE_VOIDP
return SIZEOF_VOIDP
else
- raise(DLError, "unknown type: #{ty}")
+ if defined?(TYPE_LONG_LONG) and
+ ty == TYPE_LONG_LONG
+ return SIZEOF_LONG_LONG
+ else
+ raise(DLError, "unknown type: #{ty}")
+ end
end
when Class
if( ty.instance_methods().include?(:to_ptr) )
diff --git a/ext/fiddle/lib/fiddle/pack.rb b/ext/fiddle/lib/fiddle/pack.rb
index 3c9e3c8ad7a..5467d3de4bb 100644
--- a/ext/fiddle/lib/fiddle/pack.rb
+++ b/ext/fiddle/lib/fiddle/pack.rb
@@ -18,7 +18,7 @@ module Fiddle
}
PACK_MAP = {
- TYPE_VOIDP => ((SIZEOF_VOIDP == SIZEOF_LONG_LONG) ? "q" : "l!"),
+ TYPE_VOIDP => "l!",
TYPE_CHAR => "c",
TYPE_SHORT => "s!",
TYPE_INT => "i!",
@@ -48,6 +48,7 @@ module Fiddle
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
+ PACK_MAP[TYPE_VOIDP] = PACK_MAP[TYPE_LONG_LONG] # override
end
def align(addr, align)
@@ -80,10 +81,13 @@ module Fiddle
case SIZEOF_VOIDP
when SIZEOF_LONG
ary.pack(@template)
- when SIZEOF_LONG_LONG
- ary.pack(@template)
else
- raise(RuntimeError, "sizeof(void*)?")
+ if defined?(TYPE_LONG_LONG) and
+ SIZEOF_VOIDP == SIZEOF_LONG_LONG
+ ary.pack(@template)
+ else
+ raise(RuntimeError, "sizeof(void*)?")
+ end
end
end
@@ -91,10 +95,13 @@ module Fiddle
case SIZEOF_VOIDP
when SIZEOF_LONG
ary.join().unpack(@template)
- when SIZEOF_LONG_LONG
- ary.join().unpack(@template)
else
- raise(RuntimeError, "sizeof(void*)?")
+ if defined?(TYPE_LONG_LONG) and
+ SIZEOF_VOIDP == SIZEOF_LONG_LONG
+ ary.join().unpack(@template)
+ else
+ raise(RuntimeError, "sizeof(void*)?")
+ end
end
end
diff --git a/ext/fiddle/lib/fiddle/value.rb b/ext/fiddle/lib/fiddle/value.rb
index a043b9b0669..01fec1c206d 100644
--- a/ext/fiddle/lib/fiddle/value.rb
+++ b/ext/fiddle/lib/fiddle/value.rb
@@ -13,10 +13,13 @@ module Fiddle
[val].pack("i!").unpack("I!")[0]
when TYPE_LONG
[val].pack("l!").unpack("L!")[0]
- when TYPE_LONG_LONG
- [val].pack("q").unpack("Q")[0]
else
- val
+ if defined?(TYPE_LONG_LONG) and
+ ty.abs == TYPE_LONG_LONG
+ [val].pack("q").unpack("Q")[0]
+ else
+ val
+ end
end
end
@@ -30,10 +33,13 @@ module Fiddle
[val].pack("I!").unpack("i!")[0]
when TYPE_LONG
[val].pack("L!").unpack("l!")[0]
- when TYPE_LONG_LONG
- [val].pack("Q").unpack("q")[0]
else
- val
+ if defined?(TYPE_LONG_LONG) and
+ ty.abs == TYPE_LONG_LONG
+ [val].pack("Q").unpack("q")[0]
+ else
+ val
+ end
end
end
@@ -75,10 +81,13 @@ module Fiddle
case SIZEOF_VOIDP
when SIZEOF_LONG
return [arg].pack("p").unpack("l!")[0]
- when SIZEOF_LONG_LONG
- return [arg].pack("p").unpack("q")[0]
else
- raise(RuntimeError, "sizeof(void*)?")
+ if defined?(SIZEOF_LONG_LONG) and
+ SIZEOF_VOIDP == SIZEOF_LONG_LONG
+ return [arg].pack("p").unpack("q")[0]
+ else
+ raise(RuntimeError, "sizeof(void*)?")
+ end
end
end
when Float, Integer
diff --git a/test/fiddle/test_cparser.rb b/test/fiddle/test_cparser.rb
index c053706e136..5d9ac3c8151 100644
--- a/test/fiddle/test_cparser.rb
+++ b/test/fiddle/test_cparser.rb
@@ -127,10 +127,13 @@ module Fiddle
'short', 'unsigned short',
'int', 'unsigned int',
'long', 'unsigned long',
+ defined?(TYPE_LONG_LONG) && \
+ [
'long long', 'unsigned long long',
+ ],
'float', 'double',
'const char*', 'void*',
- ]
+ ].flatten.compact
func, ret, args = parse_signature("void func(#{types.join(',')})")
assert_equal 'func', func
assert_equal TYPE_VOID, ret
@@ -139,10 +142,13 @@ module Fiddle
TYPE_SHORT, -TYPE_SHORT,
TYPE_INT, -TYPE_INT,
TYPE_LONG, -TYPE_LONG,
+ defined?(TYPE_LONG_LONG) && \
+ [
TYPE_LONG_LONG, -TYPE_LONG_LONG,
+ ],
TYPE_FLOAT, TYPE_DOUBLE,
TYPE_VOIDP, TYPE_VOIDP,
- ], args
+ ].flatten.compact, args
end
def test_signature_single_variable
diff --git a/test/fiddle/test_import.rb b/test/fiddle/test_import.rb
index ff16d17d50f..e08853da146 100644
--- a/test/fiddle/test_import.rb
+++ b/test/fiddle/test_import.rb
@@ -64,7 +64,7 @@ module Fiddle
assert_equal(SIZEOF_VOIDP, LIBC.sizeof("FILE*"))
assert_equal(LIBC::MyStruct.size(), LIBC.sizeof(LIBC::MyStruct))
assert_equal(LIBC::MyStruct.size(), LIBC.sizeof(LIBC::MyStruct.malloc()))
- assert_equal(SIZEOF_LONG_LONG, LIBC.sizeof("long long"))
+ assert_equal(SIZEOF_LONG_LONG, LIBC.sizeof("long long")) if defined?(SIZEOF_LONG_LONG)
end
Fiddle.constants.grep(/\ATYPE_(?!VOID\z)(.*)/) do