ruby-changes:42685
From: nobu <ko1@a...>
Date: Mon, 25 Apr 2016 13:42:37 +0900 (JST)
Subject: [ruby-changes:42685] nobu:r54759 (trunk): rbconfig/sizeof: calculate at compilation time
nobu 2016-04-25 14:39:12 +0900 (Mon, 25 Apr 2016) New Revision: 54759 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54759 Log: rbconfig/sizeof: calculate at compilation time * ext/rbconfig/sizeof/extconf.rb: just check the existence of each types, to reduce configuration time, especially cross-compiling. * template/sizes.c.tmpl: calculate sizes of checked types at compilation time. Modified files: trunk/ChangeLog trunk/ext/rbconfig/sizeof/extconf.rb trunk/template/sizes.c.tmpl Index: template/sizes.c.tmpl =================================================================== --- template/sizes.c.tmpl (revision 54758) +++ template/sizes.c.tmpl (revision 54759) @@ -6,13 +6,25 @@ class String https://github.com/ruby/ruby/blob/trunk/template/sizes.c.tmpl#L6 strip.upcase.tr_s("^A-Z0-9_*", "_").tr_s("*", "P") end end +headers = Hash.new {[]} +sizes = {} types = ARGF.grep(/^\s*RUBY_CHECK_SIZEOF\((\w[^\[\],#]*)[^#]*\)| ^\s*RUBY_DEFINT\((\w[^\[\],#]*)[^#]*\)| - ^\s*check_sizeof\('(.+?)'/x) {$+} + ^\s*have_type\('(.+?)'(?:,\s*%w\[(.+)\])?\)/x) do + sizes[type = $3] = true + hdrs = $4 and hdrs.split.each {|h| headers[h] <<= type} + type || $+ +end conditions = { "long long" => 'defined(HAVE_TRUE_LONG_LONG)', } %> +% headers.each do |h, type| +#if <%= type.map {|t| "defined(HAVE_TYPE_#{t.tr_cpp})"}.join(' || ') %> +# include <<%= h %>> +#endif + +% end void Init_sizeof(void) { @@ -20,8 +32,15 @@ Init_sizeof(void) https://github.com/ruby/ruby/blob/trunk/template/sizes.c.tmpl#L32 rb_define_const(rb_define_module("RbConfig"), "SIZEOF", s); #define DEFINE(type, size) rb_hash_aset(s, rb_str_new_cstr(#type), INT2FIX(SIZEOF_##size)) +#define DEFINE_SIZE(type) rb_hash_aset(s, rb_str_new_cstr(#type), INT2FIX(sizeof(type))) % types.each do |type| +% if sizes[type] +#ifdef HAVE_TYPE_<%= type.tr_cpp %> + DEFINE_SIZE(<%= type %>); +#endif +% next +% end % cond = conditions[type] #if SIZEOF_<%= type.tr_cpp %> != 0<%= " && #{cond}" if cond %> DEFINE(<%= type %>, <%= type.tr_cpp %>); Index: ChangeLog =================================================================== --- ChangeLog (revision 54758) +++ ChangeLog (revision 54759) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Apr 25 14:39:11 2016 Nobuyoshi Nakada <nobu@r...> + + * ext/rbconfig/sizeof/extconf.rb: just check the existence of each + types, to reduce configuration time, especially cross-compiling. + + * template/sizes.c.tmpl: calculate sizes of checked types at + compilation time. + Mon Apr 25 11:27:27 2016 Marcus Stollsteimer <sto.mar@w...> * doc/extension.rdoc: Improvements to english grammers. Index: ext/rbconfig/sizeof/extconf.rb =================================================================== --- ext/rbconfig/sizeof/extconf.rb (revision 54758) +++ ext/rbconfig/sizeof/extconf.rb (revision 54759) @@ -2,35 +2,35 @@ https://github.com/ruby/ruby/blob/trunk/ext/rbconfig/sizeof/extconf.rb#L2 $srcs = %w[sizes.c] $distcleanfiles.concat($srcs) -check_sizeof('int_least8_t') -check_sizeof('int_least16_t') -check_sizeof('int_least32_t') -check_sizeof('int_least64_t') -check_sizeof('int_fast8_t') -check_sizeof('int_fast16_t') -check_sizeof('int_fast32_t') -check_sizeof('int_fast64_t') -check_sizeof('intmax_t') -check_sizeof('sig_atomic_t', %w[signal.h]) -check_sizeof('wchar_t') -check_sizeof('wint_t', %w[wctype.h]) -check_sizeof('wctrans_t', %w[wctype.h]) -check_sizeof('wctype_t', %w[wctype.h]) -check_sizeof('_Bool') -check_sizeof('long double') -check_sizeof('float _Complex') -check_sizeof('double _Complex') -check_sizeof('long double _Complex') -check_sizeof('float _Imaginary') -check_sizeof('double _Imaginary') -check_sizeof('long double _Imaginary') -check_sizeof('__int128') # x86_64 ABI (optional) -check_sizeof('__float128') # x86_64 ABI (optional) -check_sizeof('_Decimal32') # x86_64 ABI -check_sizeof('_Decimal64') # x86_64 ABI -check_sizeof('_Decimal128') # x86_64 ABI -check_sizeof('__m64') # x86_64 ABI (optional) -check_sizeof('__m128') # x86_64 ABI (optional) -check_sizeof('__float80') # gcc x86 +have_type('int_least8_t') +have_type('int_least16_t') +have_type('int_least32_t') +have_type('int_least64_t') +have_type('int_fast8_t') +have_type('int_fast16_t') +have_type('int_fast32_t') +have_type('int_fast64_t') +have_type('intmax_t') +have_type('sig_atomic_t', %w[signal.h]) +have_type('wchar_t') +have_type('wint_t', %w[wctype.h]) +have_type('wctrans_t', %w[wctype.h]) +have_type('wctype_t', %w[wctype.h]) +have_type('_Bool') +have_type('long double') +have_type('float _Complex') +have_type('double _Complex') +have_type('long double _Complex') +have_type('float _Imaginary') +have_type('double _Imaginary') +have_type('long double _Imaginary') +have_type('__int128') # x86_64 ABI (optional) +have_type('__float128') # x86_64 ABI (optional) +have_type('_Decimal32') # x86_64 ABI +have_type('_Decimal64') # x86_64 ABI +have_type('_Decimal128') # x86_64 ABI +have_type('__m64') # x86_64 ABI (optional) +have_type('__m128') # x86_64 ABI (optional) +have_type('__float80') # gcc x86 create_makefile('rbconfig/sizeof') -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/