From 91715ee53b370e958a7c1a2e1036aa71eed66fc1 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Tue, 2 Jan 2018 06:41:47 +0000 Subject: long long is a C99ism git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/-test-/memory_status/memory_status.c | 4 ++++ internal.h | 8 +++++++- test/ruby/test_pack.rb | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ext/-test-/memory_status/memory_status.c b/ext/-test-/memory_status/memory_status.c index 23c4806472..5775fa56f3 100644 --- a/ext/-test-/memory_status/memory_status.c +++ b/ext/-test-/memory_status/memory_status.c @@ -32,6 +32,10 @@ read_status(VALUE self) error = task_info(mach_task_self(), flavor, (task_info_t)&taskinfo, &out_count); if (error != KERN_SUCCESS) return Qnil; +#ifndef ULL2NUM +/* "long long" does not exist here, use size_t instead. */ +#define ULL2NUM SIZET2NUM +#endif size = ULL2NUM(taskinfo.virtual_size); rss = ULL2NUM(taskinfo.resident_size); rb_struct_aset(self, INT2FIX(1), rss); diff --git a/internal.h b/internal.h index 94c8f3ff67..f3ba39f2d1 100644 --- a/internal.h +++ b/internal.h @@ -512,13 +512,19 @@ rb_fix_mod_fix(VALUE x, VALUE y) return mod; } -#if defined(HAVE_UINT128_T) +#if defined(HAVE_UINT128_T) && defined(HAVE_LONG_LONG) # define bit_length(x) \ (unsigned int) \ (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \ sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \ sizeof(x) <= SIZEOF_LONG_LONG ? SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x)) : \ SIZEOF_INT128_T * CHAR_BIT - nlz_int128((uint128_t)(x))) +#elif defined(HAVE_UINT128_T) +# define bit_length(x) \ + (unsigned int) \ + (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \ + sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \ + SIZEOF_INT128_T * CHAR_BIT - nlz_int128((uint128_t)(x))) #elif defined(HAVE_LONG_LONG) # define bit_length(x) \ (unsigned int) \ diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb index 62a7a54e8d..475031bdfc 100644 --- a/test/ruby/test_pack.rb +++ b/test/ruby/test_pack.rb @@ -428,6 +428,7 @@ class TestPack < Test::Unit::TestCase assert_operator(4, :<=, [1].pack("L!").bytesize) end + require 'rbconfig' def test_pack_unpack_qQ s1 = [578437695752307201, -506097522914230529].pack("q*") s2 = [578437695752307201, 17940646550795321087].pack("Q*") @@ -437,6 +438,7 @@ class TestPack < Test::Unit::TestCase # Note: q! and Q! should not work on platform which has no long long type. # Is there a such platform now? + # @shyouhei: Yes. gcc -ansi is one of such platform. s1 = [578437695752307201, -506097522914230529].pack("q!*") s2 = [578437695752307201, 17940646550795321087].pack("Q!*") assert_equal([578437695752307201, -506097522914230529], s2.unpack("q!*")) @@ -446,7 +448,7 @@ class TestPack < Test::Unit::TestCase assert_equal(8, [1].pack("Q").bytesize) assert_operator(8, :<=, [1].pack("q!").bytesize) assert_operator(8, :<=, [1].pack("Q!").bytesize) - end + end if RbConfig::CONFIG['HAVE_LONG_LONG'] def test_pack_unpack_jJ # Note: we assume that the size of intptr_t and uintptr_t equals to the size -- cgit v1.2.3