summaryrefslogtreecommitdiff
path: root/ext/fiddle/lib/fiddle/value.rb
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-17 09:51:23 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-17 09:51:23 +0000
commit1aaeeb326e754c5c5db83fbf35f780f729a9dfed (patch)
tree965d2c17a5c7d113e86d148c62404744f82dec3b /ext/fiddle/lib/fiddle/value.rb
parent131dc83145fb72da00af94490e630b0339513fb2 (diff)
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
Diffstat (limited to 'ext/fiddle/lib/fiddle/value.rb')
-rw-r--r--ext/fiddle/lib/fiddle/value.rb27
1 files changed, 18 insertions, 9 deletions
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