summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--ChangeLog5
-rw-r--r--common.mk9
-rw-r--r--miniinit.c6
-rw-r--r--sizes.c55
-rw-r--r--template/sizes.c.tmpl30
6 files changed, 49 insertions, 57 deletions
diff --git a/.gitignore b/.gitignore
index 4a4465094f..7c537ee37f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -82,6 +82,7 @@ y.tab.c
/rubicon
/ruby
/ruby-man.rd.gz
+/sizes.c
/test.rb
/tmp
/transdb.h
diff --git a/ChangeLog b/ChangeLog
index ce854a8603..2edb7ddf7e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Aug 26 12:37:10 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * template/sizes.c.tmpl: generate automatically by extracting
+ RUBY_CHECK_SIZEOF from configure.in.
+
Mon Aug 26 10:16:59 2013 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* process.c (gcd_timetick_int): Renamed from gcd_timtick_int.
diff --git a/common.mk b/common.mk
index 939b81fc5e..f295fb596c 100644
--- a/common.mk
+++ b/common.mk
@@ -95,7 +95,6 @@ COMMONOBJS = array.$(OBJEXT) \
vm_trace.$(OBJEXT) \
thread.$(OBJEXT) \
cont.$(OBJEXT) \
- sizes.$(OBJEXT) \
$(BUILTIN_ENCOBJS) \
$(BUILTIN_TRANSOBJS) \
$(MISSING)
@@ -103,6 +102,7 @@ COMMONOBJS = array.$(OBJEXT) \
EXPORTOBJS = $(DLNOBJ) \
localeinit.$(OBJEXT) \
loadpath.$(OBJEXT) \
+ sizes.$(OBJEXT) \
$(COMMONOBJS)
OBJS = $(EXPORTOBJS) prelude.$(OBJEXT)
@@ -883,7 +883,7 @@ INSNS2VMOPT = --srcdir="$(srcdir)"
{$(VPATH)}vm.inc: $(srcdir)/template/vm.inc.tmpl
-srcs: {$(VPATH)}parse.c {$(VPATH)}lex.c {$(VPATH)}newline.c {$(VPATH)}id.c srcs-ext srcs-enc
+srcs: {$(VPATH)}parse.c {$(VPATH)}lex.c {$(VPATH)}newline.c {$(VPATH)}id.c {$(VPATH)}sizes.c srcs-ext srcs-enc
EXT_SRCS = $(srcdir)/ext/ripper/ripper.c $(srcdir)/ext/json/parser/parser.c \
$(srcdir)/ext/dl/callback/callback.c
@@ -910,6 +910,11 @@ id.c: $(srcdir)/tool/generic_erb.rb $(srcdir)/template/id.c.tmpl $(srcdir)/defs/
$(Q) $(BASERUBY) $(srcdir)/tool/generic_erb.rb --output=$@ \
$(srcdir)/template/id.c.tmpl
+sizes.c: $(srcdir)/tool/generic_erb.rb $(srcdir)/template/sizes.c.tmpl $(srcdir)/configure.in
+ $(ECHO) generating $@
+ $(Q) $(BASERUBY) $(srcdir)/tool/generic_erb.rb --output=$@ \
+ $(srcdir)/template/sizes.c.tmpl $(srcdir)/configure.in
+
node_name.inc: {$(VPATH)}node.h
$(ECHO) generating $@
$(Q) $(BASERUBY) -n $(srcdir)/tool/node_name.rb < $? > $@
diff --git a/miniinit.c b/miniinit.c
index bc6138a774..6d285aea64 100644
--- a/miniinit.c
+++ b/miniinit.c
@@ -28,3 +28,9 @@ Init_enc_set_filesystem_encoding(void)
{
return rb_enc_to_index(rb_default_external_encoding());
}
+
+/* sizes.c */
+void
+Init_sizes(void)
+{
+}
diff --git a/sizes.c b/sizes.c
deleted file mode 100644
index 629978dc00..0000000000
--- a/sizes.c
+++ /dev/null
@@ -1,55 +0,0 @@
-#include "ruby/ruby.h"
-
-void
-Init_sizes(void)
-{
- VALUE s = rb_hash_new();
- 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));
-
-#if SIZEOF_INT != 0
- DEFINE(int, INT);
-#endif
-#if SIZEOF_SHORT != 0
- DEFINE(short, SHORT);
-#endif
-#if SIZEOF_LONG != 0
- DEFINE(long, LONG);
-#endif
-#if SIZEOF_LONG_LONG != 0 && defined(HAVE_TRUE_LONG_LONG)
- DEFINE(long long, LONG_LONG);
-#endif
-#if SIZEOF___INT64 != 0
- DEFINE(__int64, __INT64);
-#endif
-#if SIZEOF___INT128 != 0
- DEFINE(__int128, __INT128);
-#endif
-#if SIZEOF_OFF_T != 0
- DEFINE(off_t, OFF_T);
-#endif
-#if SIZEOF_VOIDP != 0
- DEFINE(void*, VOIDP);
-#endif
-#if SIZEOF_FLOAT != 0
- DEFINE(float, FLOAT);
-#endif
-#if SIZEOF_DOUBLE != 0
- DEFINE(double, DOUBLE);
-#endif
-#if SIZEOF_TIME_T != 0
- DEFINE(time_t, TIME_T);
-#endif
-#if SIZEOF_CLOCK_T != 0
- DEFINE(clock_t, CLOCK_T);
-#endif
-#if SIZEOF_SIZE_T != 0
- DEFINE(size_t, SIZE_T);
-#endif
-#if SIZEOF_PTRDIFF_T != 0
- DEFINE(ptrdiff_t, PTRDIFF_T);
-#endif
-
-#undef DEFINE
-}
diff --git a/template/sizes.c.tmpl b/template/sizes.c.tmpl
new file mode 100644
index 0000000000..e47eadebb7
--- /dev/null
+++ b/template/sizes.c.tmpl
@@ -0,0 +1,30 @@
+%# -*- c -*-
+#include "ruby/ruby.h"
+<%
+class String
+ def tr_cpp
+ strip.upcase.tr_s("^A-Z0-9_*", "_").tr_s("*", "P")
+ end
+end
+types = ARGF.grep(/^\s*RUBY_CHECK_SIZEOF\((\w[^\[\],#]*)[^#]*\)/) {$1}
+conditions = {
+ "long long" => 'defined(HAVE_TRUE_LONG_LONG)',
+}
+%>
+void
+Init_sizes(void)
+{
+ VALUE s = rb_hash_new();
+ 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));
+
+% types.each do |type|
+% cond = conditions[type]
+#if SIZEOF_<%= type.tr_cpp %> != 0<%= " && #{cond}" if cond %>
+ DEFINE(<%= type %>, <%= type.tr_cpp %>);
+#endif
+% end
+
+#undef DEFINE
+}