mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
long long is a C99ism
so SIZEOF_LONG_LONG is not always available. We have to check its defined?-ness before using. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
131dc83145
commit
1aaeeb326e
5 changed files with 47 additions and 22 deletions
|
@ -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) )
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue