1%# -*- c -*- 2#include "ruby/ruby.h" 3<% 4class String 5 def tr_cpp 6 strip.upcase.tr_s("^A-Z0-9_*", "_").tr_s("*", "P") 7 end 8end 9headers = Hash.new {[]} 10sizes = {} 11types = ARGF.grep(/^\s*RUBY_CHECK_SIZEOF\((\w[^\[\],#]*)[^#]*\)| 12 ^\s*RUBY_DEFINT\((\w[^\[\],#]*)[^#]*\)| 13 ^\s*have_type\('(.+?)'(?:,\s*%w\[(.+)\])?\)/x) do 14 sizes[type = $3] = true 15 hdrs = $4 and hdrs.split.each {|h| headers[h] <<= type} 16 type || $+ 17end 18conditions = { 19 "long long" => 'defined(HAVE_TRUE_LONG_LONG)', 20} 21%> 22% headers.each do |h, type| 23#if <%= type.map {|t| "defined(HAVE_TYPE_#{t.tr_cpp})"}.join(' || ') %> 24# include <<%= h %>> 25#endif 26 27% end 28extern void Init_limits(void); 29void 30Init_sizeof(void) 31{ 32 VALUE s = rb_hash_new(); 33 rb_define_const(rb_define_module("RbConfig"), "SIZEOF", s); 34 35#define DEFINE(type, size) rb_hash_aset(s, rb_str_new_cstr(#type), INT2FIX(SIZEOF_##size)) 36#define DEFINE_SIZE(type) rb_hash_aset(s, rb_str_new_cstr(#type), INT2FIX(sizeof(type))) 37 38% types.each do |type| 39% if sizes[type] 40#ifdef HAVE_TYPE_<%= type.tr_cpp %> 41 DEFINE_SIZE(<%= type %>); 42#endif 43% next 44% end 45% cond = conditions[type] 46#if SIZEOF_<%= type.tr_cpp %> != 0<%= " && #{cond}" if cond %> 47 DEFINE(<%= type %>, <%= type.tr_cpp %>); 48#endif 49% end 50 OBJ_FREEZE(s); 51 52#undef DEFINE 53 Init_limits(); 54} 55