aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--array.c21
-rw-r--r--ast.c10
-rw-r--r--bignum.c37
-rw-r--r--class.c14
-rw-r--r--compar.c5
-rw-r--r--compile.c38
-rw-r--r--complex.c16
-rw-r--r--constant.h2
-rw-r--r--cont.c20
-rw-r--r--coroutine/amd64/Context.h2
-rw-r--r--coroutine/arm32/Context.h2
-rw-r--r--coroutine/arm64/Context.h2
-rw-r--r--coroutine/ppc64le/Context.h2
-rw-r--r--coroutine/win32/Context.h2
-rw-r--r--coroutine/win64/Context.h2
-rw-r--r--coroutine/x86/Context.h2
-rw-r--r--debug.c17
-rw-r--r--dir.c80
-rw-r--r--dln.c2
-rw-r--r--dln.h1
-rw-r--r--enc/encdb.c2
-rw-r--r--encindex.h1
-rw-r--r--encoding.c18
-rw-r--r--enum.c14
-rw-r--r--enumerator.c14
-rw-r--r--error.c33
-rw-r--r--eval.c26
-rw-r--r--ext/-test-/bignum/big2str.c2
-rw-r--r--ext/-test-/bignum/bigzero.c2
-rw-r--r--ext/-test-/bignum/div.c2
-rw-r--r--ext/-test-/bignum/intpack.c2
-rw-r--r--ext/-test-/bignum/mul.c2
-rw-r--r--ext/-test-/bignum/str2big.c2
-rw-r--r--ext/-test-/integer/core_ext.c2
-rw-r--r--ext/-test-/rational/rat.c2
-rw-r--r--ext/-test-/string/capacity.c2
-rw-r--r--ext/-test-/string/cstr.c3
-rw-r--r--ext/-test-/string/normalize.c2
-rw-r--r--ext/-test-/time/leap_second.c3
-rw-r--r--ext/coverage/coverage.c4
-rw-r--r--ext/objspace/objspace.c12
-rw-r--r--ext/objspace/objspace_dump.c10
-rw-r--r--ext/pty/pty.c58
-rw-r--r--ext/socket/rubysocket.h49
-rw-r--r--file.c133
-rw-r--r--gc.c105
-rw-r--r--gc.h2
-rw-r--r--hash.c33
-rw-r--r--id_table.h2
-rw-r--r--inits.c3
-rw-r--r--internal.h102
-rw-r--r--internal/array.h2
-rw-r--r--internal/class.h9
-rw-r--r--internal/compilers.h1
-rw-r--r--internal/error.h11
-rw-r--r--internal/gc.h8
-rw-r--r--internal/hash.h10
-rw-r--r--internal/io.h3
-rw-r--r--internal/parse.h5
-rw-r--r--internal/string.h4
-rw-r--r--internal/struct.h21
-rw-r--r--internal/symbol.h4
-rw-r--r--internal/variable.h1
-rw-r--r--internal/vm.h8
-rw-r--r--io.c61
-rw-r--r--iseq.c30
-rw-r--r--iseq.h2
-rw-r--r--load.c15
-rw-r--r--marshal.c25
-rw-r--r--math.c13
-rw-r--r--method.h3
-rw-r--r--mini_builtin.c3
-rw-r--r--mjit.c12
-rw-r--r--mjit.h7
-rw-r--r--mjit_compile.c11
-rw-r--r--node.c3
-rw-r--r--numeric.c22
-rw-r--r--object.c27
-rw-r--r--pack.c14
-rw-r--r--parse.y38
-rw-r--r--proc.c9
-rw-r--r--process.c72
-rw-r--r--random.c50
-rw-r--r--range.c16
-rw-r--r--rational.c23
-rw-r--r--re.c15
-rw-r--r--ruby.c55
-rw-r--r--signal.c44
-rw-r--r--sprintf.c20
-rw-r--r--st.c3
-rw-r--r--strftime.c13
-rw-r--r--string.c47
-rw-r--r--struct.c11
-rw-r--r--symbol.c15
-rw-r--r--symbol.h1
-rw-r--r--template/prelude.c.tmpl5
-rw-r--r--thread.c35
-rw-r--r--time.c30
-rw-r--r--timev.h1
-rw-r--r--tool/mk_builtin_loader.rb9
-rw-r--r--transcode.c12
-rw-r--r--transient_heap.c14
-rw-r--r--util.c13
-rw-r--r--variable.c27
-rw-r--r--vm.c31
-rw-r--r--vm_backtrace.c10
-rw-r--r--vm_core.h62
-rw-r--r--vm_dump.c35
-rw-r--r--vm_insnhelper.c23
-rw-r--r--vm_trace.c10
-rw-r--r--win32/dir.h3
-rw-r--r--win32/file.c1
-rw-r--r--win32/win32.c4
113 files changed, 1327 insertions, 689 deletions
diff --git a/array.c b/array.c
index 28bd8c866b..9846320f00 100644
--- a/array.c
+++ b/array.c
@@ -10,14 +10,25 @@
Copyright (C) 2000 Information-technology Promotion Agency, Japan
**********************************************************************/
+
+#include "debug_counter.h"
+#include "id.h"
+#include "internal.h"
+#include "internal/array.h"
+#include "internal/compar.h"
+#include "internal/enum.h"
+#include "internal/gc.h"
+#include "internal/hash.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/proc.h"
+#include "internal/rational.h"
+#include "internal/vm.h"
+#include "probes.h"
#include "ruby/encoding.h"
-#include "ruby/util.h"
#include "ruby/st.h"
-#include "probes.h"
-#include "id.h"
-#include "debug_counter.h"
+#include "ruby/util.h"
#include "transient_heap.h"
-#include "internal.h"
#if !ARRAY_DEBUG
# define NDEBUG
diff --git a/ast.c b/ast.c
index 1133fb8a10..3f7061a7b0 100644
--- a/ast.c
+++ b/ast.c
@@ -1,11 +1,15 @@
/* indent-tabs-mode: nil */
+#include "internal.h"
+#include "internal/parse.h"
+#include "internal/symbol.h"
+#include "internal/warnings.h"
+#include "iseq.h"
+#include "node.h"
#include "ruby.h"
#include "ruby/encoding.h"
#include "ruby/util.h"
-#include "internal.h"
-#include "node.h"
#include "vm_core.h"
-#include "iseq.h"
+
#include "builtin.h"
static VALUE rb_mAST;
diff --git a/bignum.c b/bignum.c
index 3923da7d0b..8492853104 100644
--- a/bignum.c
+++ b/bignum.c
@@ -9,27 +9,40 @@
**********************************************************************/
-#include "internal.h"
-#include "ruby/thread.h"
-#include "ruby/util.h"
-#include "id.h"
+#include "ruby/config.h"
+
+#include <ctype.h>
+#include <float.h>
+#include <math.h>
#ifdef HAVE_STRINGS_H
-#include <strings.h>
+# include <strings.h>
#endif
-#include <math.h>
-#include <float.h>
-#include <ctype.h>
+
#ifdef HAVE_IEEEFP_H
-#include <ieeefp.h>
+# include <ieeefp.h>
#endif
-#include "ruby_assert.h"
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
-#define USE_GMP
-#include <gmp.h>
+# define USE_GMP
+# include <gmp.h>
#endif
+#include "id.h"
+#include "internal.h"
+#include "internal/bignum.h"
+#include "internal/complex.h"
+#include "internal/gc.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/sanitizers.h"
+#include "internal/util.h"
+#include "internal/variable.h"
+#include "internal/warnings.h"
+#include "ruby/thread.h"
+#include "ruby/util.h"
+#include "ruby_assert.h"
+
#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
#ifndef RUBY_INTEGER_UNIFICATION
diff --git a/class.c b/class.c
index c866d1d727..bc64ff7795 100644
--- a/class.c
+++ b/class.c
@@ -23,12 +23,20 @@
* \{
*/
+#include "ruby/config.h"
+#include <ctype.h>
+
+#include "constant.h"
+#include "id_table.h"
#include "internal.h"
+#include "internal/class.h"
+#include "internal/error.h"
+#include "internal/eval.h"
+#include "internal/hash.h"
+#include "internal/object.h"
+#include "internal/variable.h"
#include "ruby/st.h"
-#include "constant.h"
#include "vm_core.h"
-#include "id_table.h"
-#include <ctype.h>
#define id_attached id__attached__
diff --git a/compar.c b/compar.c
index 94072c9fc1..15ebfcdcd2 100644
--- a/compar.c
+++ b/compar.c
@@ -9,9 +9,12 @@
**********************************************************************/
-#include "ruby/ruby.h"
#include "id.h"
#include "internal.h"
+#include "internal/compar.h"
+#include "internal/error.h"
+#include "internal/vm.h"
+#include "ruby/ruby.h"
VALUE rb_mComparable;
diff --git a/compile.c b/compile.c
index 7043ba9a73..200670f826 100644
--- a/compile.c
+++ b/compile.c
@@ -9,25 +9,39 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "ruby/re.h"
-#include "ruby/util.h"
-#include "internal.h"
-#include "encindex.h"
+#include "ruby/config.h"
#include <math.h>
+#ifdef HAVE_DLADDR
+# include <dlfcn.h>
+#endif
+
+#include "encindex.h"
+#include "gc.h"
+#include "id_table.h"
+#include "internal.h"
+#include "internal/array.h"
+#include "internal/compile.h"
+#include "internal/complex.h"
+#include "internal/debug.h"
+#include "internal/encoding.h"
+#include "internal/error.h"
+#include "internal/hash.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/re.h"
+#include "internal/symbol.h"
+#include "internal/thread.h"
+#include "internal/variable.h"
+#include "iseq.h"
+#include "ruby/re.h"
+#include "ruby/util.h"
#include "vm_core.h"
#include "vm_debug.h"
+
#include "builtin.h"
-#include "iseq.h"
#include "insns.inc"
#include "insns_info.inc"
-#include "id_table.h"
-#include "gc.h"
-
-#ifdef HAVE_DLADDR
-# include <dlfcn.h>
-#endif
#undef RUBY_UNTYPED_DATA_WARNING
#define RUBY_UNTYPED_DATA_WARNING 0
diff --git a/complex.c b/complex.c
index cdd5edc50a..bce22be735 100644
--- a/complex.c
+++ b/complex.c
@@ -6,15 +6,25 @@
*/
#include "ruby/config.h"
+
#if defined _MSC_VER
/* Microsoft Visual C does not define M_PI and others by default */
# define _USE_MATH_DEFINES 1
#endif
+
+#include <ctype.h>
#include <math.h>
-#include "internal.h"
-#include "id.h"
#define NDEBUG
+#include "id.h"
+#include "internal.h"
+#include "internal/class.h"
+#include "internal/complex.h"
+#include "internal/error.h"
+#include "internal/math.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/rational.h"
#include "ruby_assert.h"
#define ZERO INT2FIX(0)
@@ -1700,8 +1710,6 @@ numeric_to_c(VALUE self)
return rb_complex_new1(self);
}
-#include <ctype.h>
-
inline static int
issign(int c)
{
diff --git a/constant.h b/constant.h
index 610bdf1dfe..1396651e21 100644
--- a/constant.h
+++ b/constant.h
@@ -10,6 +10,8 @@
**********************************************************************/
#ifndef CONSTANT_H
#define CONSTANT_H
+#include "ruby/ruby.h"
+#include "id_table.h"
typedef enum {
CONST_DEPRECATED = 0x100,
diff --git a/cont.c b/cont.c
index 793bce018b..2365406d9e 100644
--- a/cont.c
+++ b/cont.c
@@ -9,19 +9,25 @@
**********************************************************************/
-#include "internal.h"
-#include "vm_core.h"
-#include "gc.h"
-#include "eval_intern.h"
-#include "mjit.h"
-
-#include COROUTINE_H
+#include "ruby/config.h"
#ifndef _WIN32
#include <unistd.h>
#include <sys/mman.h>
#endif
+#include COROUTINE_H
+
+#include "eval_intern.h"
+#include "gc.h"
+#include "internal.h"
+#include "internal/cont.h"
+#include "internal/mjit.h"
+#include "internal/proc.h"
+#include "internal/warnings.h"
+#include "mjit.h"
+#include "vm_core.h"
+
static const int DEBUG = 0;
#define RB_PAGE_SIZE (pagesize)
diff --git a/coroutine/amd64/Context.h b/coroutine/amd64/Context.h
index 8fe323c1a1..441c4491c1 100644
--- a/coroutine/amd64/Context.h
+++ b/coroutine/amd64/Context.h
@@ -8,6 +8,8 @@
#pragma once
#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
#include <string.h>
#define COROUTINE __attribute__((noreturn)) void
diff --git a/coroutine/arm32/Context.h b/coroutine/arm32/Context.h
index e29fe1bb63..8bba8f6376 100644
--- a/coroutine/arm32/Context.h
+++ b/coroutine/arm32/Context.h
@@ -8,6 +8,8 @@
#pragma once
#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
#include <string.h>
#define COROUTINE __attribute__((noreturn)) void
diff --git a/coroutine/arm64/Context.h b/coroutine/arm64/Context.h
index a1ae921144..63170ce4cc 100644
--- a/coroutine/arm64/Context.h
+++ b/coroutine/arm64/Context.h
@@ -8,6 +8,8 @@
#pragma once
#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
#include <string.h>
#define COROUTINE __attribute__((noreturn)) void
diff --git a/coroutine/ppc64le/Context.h b/coroutine/ppc64le/Context.h
index adf21b4fd9..e36f9c3583 100644
--- a/coroutine/ppc64le/Context.h
+++ b/coroutine/ppc64le/Context.h
@@ -1,6 +1,8 @@
#pragma once
#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
#include <string.h>
#define COROUTINE __attribute__((noreturn)) void
diff --git a/coroutine/win32/Context.h b/coroutine/win32/Context.h
index 299515ed92..68a71a76fb 100644
--- a/coroutine/win32/Context.h
+++ b/coroutine/win32/Context.h
@@ -8,6 +8,8 @@
#pragma once
#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
#include <string.h>
#define COROUTINE __declspec(noreturn) void __fastcall
diff --git a/coroutine/win64/Context.h b/coroutine/win64/Context.h
index 6bf2dc5b35..659e503d21 100644
--- a/coroutine/win64/Context.h
+++ b/coroutine/win64/Context.h
@@ -8,6 +8,8 @@
#pragma once
#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
#include <string.h>
#define COROUTINE __declspec(noreturn) void
diff --git a/coroutine/x86/Context.h b/coroutine/x86/Context.h
index 6d3a56eaa6..123321ded6 100644
--- a/coroutine/x86/Context.h
+++ b/coroutine/x86/Context.h
@@ -8,6 +8,8 @@
#pragma once
#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
#include <string.h>
#define COROUTINE __attribute__((noreturn, fastcall)) void
diff --git a/debug.c b/debug.c
index 7c32f6dac0..7bb9d02052 100644
--- a/debug.c
+++ b/debug.c
@@ -9,15 +9,22 @@
**********************************************************************/
-#include "ruby/ruby.h"
+#include "ruby/config.h"
+
+#include <stdio.h>
+
+#include "eval_intern.h"
+#include "id.h"
+#include "internal/debug.h"
+#include "internal/signal.h"
+#include "internal/util.h"
#include "ruby/encoding.h"
#include "ruby/io.h"
+#include "ruby/ruby.h"
#include "ruby/util.h"
-#include "vm_debug.h"
-#include "eval_intern.h"
-#include "vm_core.h"
#include "symbol.h"
-#include "id.h"
+#include "vm_core.h"
+#include "vm_debug.h"
/* This is the only place struct RIMemo is actually used */
struct RIMemo {
diff --git a/dir.c b/dir.c
index 6a926f438c..c72011a0d9 100644
--- a/dir.c
+++ b/dir.c
@@ -11,12 +11,10 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "ruby/thread.h"
-#include "internal.h"
-#include "id.h"
-#include "encindex.h"
+#include "ruby/config.h"
+#include <ctype.h>
+#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -36,12 +34,10 @@
# define USE_OPENDIR_AT 0
# endif
#endif
+
#if USE_OPENDIR_AT
# include <fcntl.h>
#endif
-#ifndef AT_FDCWD
-# define AT_FDCWD -1
-#endif
#undef HAVE_DIRENT_NAMLEN
#if defined HAVE_DIRENT_H && !defined _WIN32
@@ -68,8 +64,6 @@
# endif
#endif
-#include <errno.h>
-
#ifndef HAVE_STDLIB_H
char *getenv();
#endif
@@ -78,28 +72,6 @@ char *getenv();
char *strchr(char*,char);
#endif
-#include <ctype.h>
-
-#include "ruby/util.h"
-
-#define vm_initialized rb_cThread
-
-/* define system APIs */
-#ifdef _WIN32
-#undef chdir
-#define chdir(p) rb_w32_uchdir(p)
-#undef mkdir
-#define mkdir(p, m) rb_w32_umkdir((p), (m))
-#undef rmdir
-#define rmdir(p) rb_w32_urmdir(p)
-#undef opendir
-#define opendir(p) rb_w32_uopendir(p)
-#define ruby_getcwd() rb_w32_ugetcwd(NULL, 0)
-#define IS_WIN32 1
-#else
-#define IS_WIN32 0
-#endif
-
#ifdef HAVE_SYS_ATTR_H
#include <sys/attr.h>
#endif
@@ -123,15 +95,51 @@ char *strchr(char*,char);
#ifdef __APPLE__
# define NORMALIZE_UTF8PATH 1
+# include <sys/param.h>
+# include <sys/mount.h>
+# include <sys/vnode.h>
#else
# define NORMALIZE_UTF8PATH 0
#endif
-#if NORMALIZE_UTF8PATH
-#include <sys/param.h>
-#include <sys/mount.h>
-#include <sys/vnode.h>
+#include "encindex.h"
+#include "id.h"
+#include "internal.h"
+#include "internal/dir.h"
+#include "internal/encoding.h"
+#include "internal/error.h"
+#include "internal/file.h"
+#include "internal/gc.h"
+#include "internal/io.h"
+#include "internal/vm.h"
+#include "ruby/encoding.h"
+#include "ruby/ruby.h"
+#include "ruby/thread.h"
+#include "ruby/util.h"
+#ifndef AT_FDCWD
+# define AT_FDCWD -1
+#endif
+
+#define vm_initialized rb_cThread
+
+/* define system APIs */
+#ifdef _WIN32
+# undef chdir
+# define chdir(p) rb_w32_uchdir(p)
+# undef mkdir
+# define mkdir(p, m) rb_w32_umkdir((p), (m))
+# undef rmdir
+# define rmdir(p) rb_w32_urmdir(p)
+# undef opendir
+# define opendir(p) rb_w32_uopendir(p)
+# define ruby_getcwd() rb_w32_ugetcwd(NULL, 0)
+# define IS_WIN32 1
+#else
+# define IS_WIN32 0
+#endif
+
+#if NORMALIZE_UTF8PATH
# if defined HAVE_FGETATTRLIST || !defined HAVE_GETATTRLIST
# define need_normalization(dirp, path) need_normalization(dirp)
# else
diff --git a/dln.c b/dln.c
index c40cbfc6ac..78c4c45a1f 100644
--- a/dln.c
+++ b/dln.c
@@ -1244,6 +1244,8 @@ rb_w32_check_imported(HMODULE ext, HMODULE mine)
#endif
#ifdef USE_DLN_DLOPEN
+# include "internal/stdbool.h"
+# include "internal/warnings.h"
COMPILER_WARNING_PUSH
#if defined(__clang__) || GCC_VERSION_SINCE(4, 2, 0)
COMPILER_WARNING_IGNORED(-Wpedantic)
diff --git a/dln.h b/dln.h
index d98b2607e2..9570de8f15 100644
--- a/dln.h
+++ b/dln.h
@@ -11,6 +11,7 @@
#ifndef DLN_H
#define DLN_H
+#include "ruby/defines.h" /* for RUBY_SYMBOL_EXPORT_BEGIN */
#ifdef __cplusplus
# ifndef HAVE_PROTOTYPES
diff --git a/enc/encdb.c b/enc/encdb.c
index a41e4edc6d..a1936df804 100644
--- a/enc/encdb.c
+++ b/enc/encdb.c
@@ -9,7 +9,7 @@
**********************************************************************/
-#include "internal.h"
+#include "internal/encoding.h"
#define ENC_REPLICATE(name, orig) rb_encdb_replicate((name), (orig))
#define ENC_ALIAS(name, orig) rb_encdb_alias((name), (orig))
diff --git a/encindex.h b/encindex.h
index 658b60a9fd..baf70735ec 100644
--- a/encindex.h
+++ b/encindex.h
@@ -11,6 +11,7 @@
#ifndef RUBY_ENCINDEX_H
#define RUBY_ENCINDEX_H 1
+#include "ruby/encoding.h" /* rb_ascii8bit_encindex etc. */
#if defined(__cplusplus)
extern "C" {
#if 0
diff --git a/encoding.c b/encoding.c
index 69015cc8fd..c50a470d05 100644
--- a/encoding.c
+++ b/encoding.c
@@ -9,14 +9,24 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "internal.h"
+#include "ruby/config.h"
+
+#include <ctype.h>
+
#include "encindex.h"
+#include "internal.h"
+#include "internal/enc.h"
+#include "internal/encoding.h"
+#include "internal/inits.h"
+#include "internal/load.h"
+#include "internal/object.h"
+#include "internal/string.h"
+#include "internal/vm.h"
#include "regenc.h"
-#include <ctype.h>
+#include "ruby/encoding.h"
#include "ruby/util.h"
-
#include "ruby_assert.h"
+
#ifndef ENC_DEBUG
#define ENC_DEBUG 0
#endif
diff --git a/enum.c b/enum.c
index cc77964ff9..867eec8f81 100644
--- a/enum.c
+++ b/enum.c
@@ -9,14 +9,20 @@
**********************************************************************/
-#include "ruby/encoding.h"
+#include "id.h"
#include "internal.h"
+#include "internal/compar.h"
+#include "internal/enum.h"
+#include "internal/hash.h"
+#include "internal/imemo.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/proc.h"
+#include "internal/rational.h"
#include "ruby/util.h"
-#include "id.h"
+#include "ruby_assert.h"
#include "symbol.h"
-#include <assert.h>
-
VALUE rb_mEnumerable;
static ID id_next;
diff --git a/enumerator.c b/enumerator.c
index 9d0547da05..790818064f 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -12,14 +12,22 @@
************************************************/
-#include "ruby/ruby.h"
-#include "internal.h"
-#include "id.h"
+#include "ruby/config.h"
#ifdef HAVE_FLOAT_H
#include <float.h>
#endif
+#include "id.h"
+#include "internal.h"
+#include "internal/enumerator.h"
+#include "internal/error.h"
+#include "internal/hash.h"
+#include "internal/imemo.h"
+#include "internal/numeric.h"
+#include "internal/range.h"
+#include "ruby/ruby.h"
+
/*
* Document-class: Enumerator
*
diff --git a/error.c b/error.c
index 9557d8552b..f99cdb6784 100644
--- a/error.c
+++ b/error.c
@@ -9,27 +9,40 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "ruby/st.h"
-#include "internal.h"
-#include "ruby_assert.h"
-#include "vm_core.h"
-#include "builtin.h"
+#include "ruby/config.h"
-#include <stdio.h>
+#include <errno.h>
#include <stdarg.h>
+#include <stdio.h>
+
#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
+# include <stdlib.h>
#endif
-#include <errno.h>
+
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
#if defined __APPLE__
# include <AvailabilityMacros.h>
#endif
+#include "internal.h"
+#include "internal/error.h"
+#include "internal/eval.h"
+#include "internal/io.h"
+#include "internal/load.h"
+#include "internal/object.h"
+#include "internal/symbol.h"
+#include "internal/thread.h"
+#include "internal/variable.h"
+#include "ruby/encoding.h"
+#include "ruby/st.h"
+#include "ruby_assert.h"
+#include "vm_core.h"
+
+#include "builtin.h"
+
/*!
* \defgroup exception Exception handlings
* \{
diff --git a/eval.c b/eval.c
index f2fde81e19..4770327a72 100644
--- a/eval.c
+++ b/eval.c
@@ -11,18 +11,30 @@
**********************************************************************/
-#include "internal.h"
+#include "ruby/config.h"
+
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
+
#include "eval_intern.h"
-#include "iseq.h"
#include "gc.h"
-#include "ruby/vm.h"
-#include "vm_core.h"
+#include "internal.h"
+#include "internal/class.h"
+#include "internal/error.h"
+#include "internal/eval.h"
+#include "internal/hash.h"
+#include "internal/inits.h"
+#include "internal/io.h"
+#include "internal/mjit.h"
+#include "internal/object.h"
+#include "internal/variable.h"
+#include "iseq.h"
#include "mjit.h"
#include "probes.h"
#include "probes_helper.h"
-#ifdef HAVE_SYS_PRCTL_H
-#include <sys/prctl.h>
-#endif
+#include "ruby/vm.h"
+#include "vm_core.h"
NORETURN(void rb_raise_jump(VALUE, VALUE));
void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec);
diff --git a/ext/-test-/bignum/big2str.c b/ext/-test-/bignum/big2str.c
index ec4bde2915..bc5a933f82 100644
--- a/ext/-test-/bignum/big2str.c
+++ b/ext/-test-/bignum/big2str.c
@@ -1,4 +1,4 @@
-#include "internal.h"
+#include "internal/bignum.h"
static VALUE
big(VALUE x)
diff --git a/ext/-test-/bignum/bigzero.c b/ext/-test-/bignum/bigzero.c
index 35117db7ae..e2bfebcd3e 100644
--- a/ext/-test-/bignum/bigzero.c
+++ b/ext/-test-/bignum/bigzero.c
@@ -1,4 +1,4 @@
-#include "internal.h"
+#include "internal/bignum.h"
static VALUE
bug_big_zero(VALUE self, VALUE length)
diff --git a/ext/-test-/bignum/div.c b/ext/-test-/bignum/div.c
index a1db21dc30..2be0d2d62a 100644
--- a/ext/-test-/bignum/div.c
+++ b/ext/-test-/bignum/div.c
@@ -1,4 +1,4 @@
-#include "internal.h"
+#include "internal/bignum.h"
static VALUE
big(VALUE x)
diff --git a/ext/-test-/bignum/intpack.c b/ext/-test-/bignum/intpack.c
index 2d19442cf2..698362f96f 100644
--- a/ext/-test-/bignum/intpack.c
+++ b/ext/-test-/bignum/intpack.c
@@ -1,4 +1,4 @@
-#include "internal.h"
+#include "internal/bignum.h"
static VALUE
rb_integer_pack_raw_m(VALUE val, VALUE buf, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags)
diff --git a/ext/-test-/bignum/mul.c b/ext/-test-/bignum/mul.c
index b922f34437..1b6eb911bd 100644
--- a/ext/-test-/bignum/mul.c
+++ b/ext/-test-/bignum/mul.c
@@ -1,4 +1,4 @@
-#include "internal.h"
+#include "internal/bignum.h"
static VALUE
big(VALUE x)
diff --git a/ext/-test-/bignum/str2big.c b/ext/-test-/bignum/str2big.c
index bc79ef0329..7dd2da9a07 100644
--- a/ext/-test-/bignum/str2big.c
+++ b/ext/-test-/bignum/str2big.c
@@ -1,4 +1,4 @@
-#include "internal.h"
+#include "internal/bignum.h"
static VALUE
str2big_poweroftwo(VALUE str, VALUE vbase, VALUE badcheck)
diff --git a/ext/-test-/integer/core_ext.c b/ext/-test-/integer/core_ext.c
index 510ba4a1e6..2062fa3afa 100644
--- a/ext/-test-/integer/core_ext.c
+++ b/ext/-test-/integer/core_ext.c
@@ -1,4 +1,4 @@
-#include "internal.h"
+#include "internal/numeric.h"
static VALUE
int_bignum_p(VALUE self)
diff --git a/ext/-test-/rational/rat.c b/ext/-test-/rational/rat.c
index 772546fca8..01388346f7 100644
--- a/ext/-test-/rational/rat.c
+++ b/ext/-test-/rational/rat.c
@@ -1,4 +1,4 @@
-#include "internal.h"
+#include "internal/rational.h"
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
static VALUE
diff --git a/ext/-test-/string/capacity.c b/ext/-test-/string/capacity.c
index f5277bf4e6..cb8d2c2b3a 100644
--- a/ext/-test-/string/capacity.c
+++ b/ext/-test-/string/capacity.c
@@ -1,5 +1,5 @@
#include "ruby.h"
-#include "internal.h"
+#include "internal/string.h"
static VALUE
bug_str_capacity(VALUE klass, VALUE str)
diff --git a/ext/-test-/string/cstr.c b/ext/-test-/string/cstr.c
index 71eafdb703..5a464451da 100644
--- a/ext/-test-/string/cstr.c
+++ b/ext/-test-/string/cstr.c
@@ -1,5 +1,6 @@
-#include "ruby/encoding.h"
#include "internal.h"
+#include "internal/error.h"
+#include "ruby/encoding.h"
static VALUE
bug_str_cstr_term(VALUE str)
diff --git a/ext/-test-/string/normalize.c b/ext/-test-/string/normalize.c
index 0ba1797631..a069288ee8 100644
--- a/ext/-test-/string/normalize.c
+++ b/ext/-test-/string/normalize.c
@@ -1,4 +1,4 @@
-#include "internal.h"
+#include "internal/file.h"
#ifdef __APPLE__
static VALUE
diff --git a/ext/-test-/time/leap_second.c b/ext/-test-/time/leap_second.c
index 7eed421b73..ccf38194f0 100644
--- a/ext/-test-/time/leap_second.c
+++ b/ext/-test-/time/leap_second.c
@@ -1,6 +1,5 @@
-#include "ruby.h"
+#include "internal/time.h"
-void ruby_reset_leap_second_info(void);
static VALUE
bug_time_s_reset_leap_second_info(VALUE klass)
{
diff --git a/ext/coverage/coverage.c b/ext/coverage/coverage.c
index 8503c9d6c6..34b0849fc4 100644
--- a/ext/coverage/coverage.c
+++ b/ext/coverage/coverage.c
@@ -8,9 +8,11 @@
************************************************/
+#include "gc.h"
+#include "internal/hash.h"
+#include "internal/thread.h"
#include "ruby.h"
#include "vm_core.h"
-#include "gc.h"
static int current_mode;
static VALUE me2counter = Qnil;
diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c
index 311e687206..6d5f6c073a 100644
--- a/ext/objspace/objspace.c
+++ b/ext/objspace/objspace.c
@@ -12,12 +12,16 @@
**********************************************************************/
-#include <ruby/io.h>
+#include "gc.h"
#include "internal.h"
-#include <ruby/st.h>
-#include <ruby/re.h>
+#include "internal/class.h"
+#include "internal/compilers.h"
+#include "internal/hash.h"
+#include "internal/imemo.h"
#include "node.h"
-#include "gc.h"
+#include "ruby/io.h"
+#include "ruby/re.h"
+#include "ruby/st.h"
#include "symbol.h"
/*
diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c
index 5fa9d98e38..d753b48a80 100644
--- a/ext/objspace/objspace_dump.c
+++ b/ext/objspace/objspace_dump.c
@@ -12,13 +12,15 @@
**********************************************************************/
-#include "ruby/io.h"
-#include "internal.h"
-#include "ruby/debug.h"
#include "gc.h"
+#include "internal.h"
+#include "internal/hash.h"
+#include "internal/string.h"
#include "node.h"
-#include "vm_core.h"
#include "objspace.h"
+#include "ruby/debug.h"
+#include "ruby/io.h"
+#include "vm_core.h"
static VALUE sym_output, sym_stdout, sym_string, sym_file;
static VALUE sym_full;
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index 4c6ae26127..485f61c304 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -1,45 +1,51 @@
-#include "ruby/config.h"
+#include "ruby/config.h"
+
#ifdef RUBY_EXTCONF_H
-#include RUBY_EXTCONF_H
+# include RUBY_EXTCONF_H
#endif
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/file.h>
-#include <fcntl.h>
-#include <errno.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+#include <fcntl.h>
+
#ifdef HAVE_PWD_H
-#include <pwd.h>
+# include <pwd.h>
#endif
+
#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
+# include <sys/ioctl.h>
#endif
+
#ifdef HAVE_LIBUTIL_H
-#include <libutil.h>
+# include <libutil.h>
#endif
+
#ifdef HAVE_UTIL_H
-#include <util.h>
+# include <util.h>
#endif
+
#ifdef HAVE_PTY_H
-#include <pty.h>
+# include <pty.h>
#endif
+
#if defined(HAVE_SYS_PARAM_H)
- /* for __FreeBSD_version */
+ /* for __FreeBSD_version */
# include <sys/param.h>
#endif
+
#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
+# include <sys/wait.h>
#else
-#define WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
+# define WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
#endif
-#include <ctype.h>
-
-#include "ruby/io.h"
-#include "internal.h"
-#include "ruby/util.h"
-#include <signal.h>
#ifdef HAVE_SYS_STROPTS_H
#include <sys/stropts.h>
#endif
@@ -48,6 +54,12 @@
#include <unistd.h>
#endif
+#include "internal.h"
+#include "internal/process.h"
+#include "internal/signal.h"
+#include "ruby/io.h"
+#include "ruby/util.h"
+
#define DEVICELEN 16
#ifndef HAVE_SETEUID
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h
index 0ce77a5f6e..5dca68a198 100644
--- a/ext/socket/rubysocket.h
+++ b/ext/socket/rubysocket.h
@@ -1,12 +1,12 @@
#ifndef RUBY_SOCKET_H
#define RUBY_SOCKET_H 1
-#include "ruby/ruby.h"
-#include "ruby/io.h"
-#include "ruby/thread.h"
-#include "ruby/util.h"
-#include "internal.h"
+#include "ruby/config.h"
+#include RUBY_EXTCONF_H
+
+#include <errno.h>
#include <stdio.h>
+
#include <sys/types.h>
#include <sys/stat.h>
@@ -56,12 +56,11 @@
#ifdef HAVE_NETPACKET_PACKET_H
# include <netpacket/packet.h>
#endif
+
#ifdef HAVE_NET_ETHERNET_H
# include <net/ethernet.h>
#endif
-#include <errno.h>
-
#ifdef HAVE_SYS_UN_H
# include <sys/un.h>
#endif
@@ -87,12 +86,15 @@
# endif
# include <ifaddrs.h>
#endif
+
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
+
#ifdef HAVE_SYS_SOCKIO_H
# include <sys/sockio.h>
#endif
+
#ifdef HAVE_NET_IF_H
# include <net/if.h>
#endif
@@ -100,16 +102,40 @@
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
+
#ifdef HAVE_SYS_UCRED_H
# include <sys/ucred.h>
#endif
+
#ifdef HAVE_UCRED_H
# include <ucred.h>
#endif
+
#ifdef HAVE_NET_IF_DL_H
# include <net/if_dl.h>
#endif
+#ifdef SOCKS5
+# include <socks.h>
+#endif
+
+#ifndef HAVE_GETADDRINFO
+# include "addrinfo.h"
+#endif
+
+#include "internal.h"
+#include "internal/array.h"
+#include "internal/error.h"
+#include "internal/gc.h"
+#include "internal/io.h"
+#include "internal/thread.h"
+#include "internal/vm.h"
+#include "ruby/io.h"
+#include "ruby/ruby.h"
+#include "ruby/thread.h"
+#include "ruby/util.h"
+#include "sockport.h"
+
#ifndef HAVE_TYPE_SOCKLEN_T
typedef int socklen_t;
#endif
@@ -143,11 +169,6 @@ unsigned int if_nametoindex(const char *);
*/
#define pseudo_AF_FTIP pseudo_AF_RTIP
-#ifndef HAVE_GETADDRINFO
-# include "addrinfo.h"
-#endif
-
-#include "sockport.h"
#ifndef NI_MAXHOST
# define NI_MAXHOST 1025
@@ -255,9 +276,7 @@ extern VALUE rb_eSocket;
#ifdef SOCKS
extern VALUE rb_cSOCKSSocket;
-# ifdef SOCKS5
-# include <socks.h>
-# else
+# ifndef SOCKS5
void SOCKSinit();
int Rconnect();
# endif
diff --git a/file.c b/file.c
index c46377b933..c267781d20 100644
--- a/file.c
+++ b/file.c
@@ -11,14 +11,22 @@
**********************************************************************/
+#include "ruby/config.h"
+
#ifdef _WIN32
-#include "missing/file.h"
+# include "missing/file.h"
+# include "ruby.h"
#endif
+
+#include <ctype.h>
+#include <time.h>
+
#ifdef __CYGWIN__
-#include <windows.h>
-#include <sys/cygwin.h>
-#include <wchar.h>
+# include <windows.h>
+# include <sys/cygwin.h>
+# include <wchar.h>
#endif
+
#ifdef __APPLE__
# if !(defined(__has_feature) && defined(__has_attribute))
/* Maybe a bug in SDK of Xcode 10.2.1 */
@@ -28,21 +36,13 @@
# define API_AVAILABLE(...)
# define API_DEPRECATED(...)
# endif
-#include <CoreFoundation/CFString.h>
+# include <CoreFoundation/CFString.h>
#endif
-#include "id.h"
-#include "ruby/encoding.h"
-#include "ruby/io.h"
-#include "ruby/util.h"
-#include "ruby/thread.h"
-#include "internal.h"
-#include "dln.h"
-#include "encindex.h"
-
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
+
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
@@ -60,77 +60,73 @@ int flock(int, int);
# define MAXPATHLEN 1024
#endif
-#include <ctype.h>
-
-#include <time.h>
-
#ifdef HAVE_UTIME_H
-#include <utime.h>
+# include <utime.h>
#elif defined HAVE_SYS_UTIME_H
-#include <sys/utime.h>
+# include <sys/utime.h>
#endif
#ifdef HAVE_PWD_H
-#include <pwd.h>
+# include <pwd.h>
#endif
#ifdef HAVE_SYS_SYSMACROS_H
-#include <sys/sysmacros.h>
+# include <sys/sysmacros.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_SYS_MKDEV_H
-#include <sys/mkdev.h>
+# include <sys/mkdev.h>
#endif
#if defined(HAVE_FCNTL_H)
-#include <fcntl.h>
+# include <fcntl.h>
#endif
#if defined(HAVE_SYS_TIME_H)
-#include <sys/time.h>
+# include <sys/time.h>
#endif
#if !defined HAVE_LSTAT && !defined lstat
-#define lstat stat
+# define lstat stat
#endif
/* define system APIs */
#ifdef _WIN32
-#include "win32/file.h"
-#define STAT(p, s) rb_w32_ustati128((p), (s))
-#undef lstat
-#define lstat(p, s) rb_w32_ulstati128((p), (s))
-#undef access
-#define access(p, m) rb_w32_uaccess((p), (m))
-#undef truncate
-#define truncate(p, n) rb_w32_utruncate((p), (n))
-#undef chmod
-#define chmod(p, m) rb_w32_uchmod((p), (m))
-#undef chown
-#define chown(p, o, g) rb_w32_uchown((p), (o), (g))
-#undef lchown
-#define lchown(p, o, g) rb_w32_ulchown((p), (o), (g))
-#undef utimensat
-#define utimensat(s, p, t, f) rb_w32_uutimensat((s), (p), (t), (f))
-#undef link
-#define link(f, t) rb_w32_ulink((f), (t))
-#undef unlink
-#define unlink(p) rb_w32_uunlink(p)
-#undef rename
-#define rename(f, t) rb_w32_urename((f), (t))
-#undef symlink
-#define symlink(s, l) rb_w32_usymlink((s), (l))
-
-#ifdef HAVE_REALPATH
+# include "win32/file.h"
+# define STAT(p, s) rb_w32_ustati128((p), (s))
+# undef lstat
+# define lstat(p, s) rb_w32_ulstati128((p), (s))
+# undef access
+# define access(p, m) rb_w32_uaccess((p), (m))
+# undef truncate
+# define truncate(p, n) rb_w32_utruncate((p), (n))
+# undef chmod
+# define chmod(p, m) rb_w32_uchmod((p), (m))
+# undef chown
+# define chown(p, o, g) rb_w32_uchown((p), (o), (g))
+# undef lchown
+# define lchown(p, o, g) rb_w32_ulchown((p), (o), (g))
+# undef utimensat
+# define utimensat(s, p, t, f) rb_w32_uutimensat((s), (p), (t), (f))
+# undef link
+# define link(f, t) rb_w32_ulink((f), (t))
+# undef unlink
+# define unlink(p) rb_w32_uunlink(p)
+# undef rename
+# define rename(f, t) rb_w32_urename((f), (t))
+# undef symlink
+# define symlink(s, l) rb_w32_usymlink((s), (l))
+
+# ifdef HAVE_REALPATH
/* Don't use native realpath(3) on Windows, as the check for
absolute paths does not work for drive letters. */
-#undef HAVE_REALPATH
-#endif
+# undef HAVE_REALPATH
+# endif
#else
-#define STAT(p, s) stat((p), (s))
+# define STAT(p, s) stat((p), (s))
#endif
#if defined _WIN32 || defined __APPLE__
@@ -143,7 +139,7 @@ int flock(int, int);
/* utime may fail if time is out-of-range for the FS [ruby-dev:38277] */
#if defined DOSISH || defined __CYGWIN__
-# define UTIME_EINVAL
+# define UTIME_EINVAL
#endif
/* Solaris 10 realpath(3) doesn't support File.realpath */
@@ -152,10 +148,29 @@ int flock(int, int);
#endif
#ifdef HAVE_REALPATH
-#include <limits.h>
-#include <stdlib.h>
+# include <limits.h>
+# include <stdlib.h>
#endif
+#include "dln.h"
+#include "encindex.h"
+#include "id.h"
+#include "internal.h"
+#include "internal/compilers.h"
+#include "internal/dir.h"
+#include "internal/error.h"
+#include "internal/file.h"
+#include "internal/io.h"
+#include "internal/load.h"
+#include "internal/object.h"
+#include "internal/process.h"
+#include "internal/thread.h"
+#include "internal/vm.h"
+#include "ruby/encoding.h"
+#include "ruby/io.h"
+#include "ruby/thread.h"
+#include "ruby/util.h"
+
VALUE rb_cFile;
VALUE rb_mFileTest;
VALUE rb_cStat;
diff --git a/gc.c b/gc.c
index 6def78a105..9747655f99 100644
--- a/gc.c
+++ b/gc.c
@@ -14,43 +14,25 @@
#define rb_data_object_alloc rb_data_object_alloc
#define rb_data_typed_object_alloc rb_data_typed_object_alloc
-#include "ruby/encoding.h"
-#include "ruby/io.h"
-#include "ruby/st.h"
-#include "ruby/re.h"
-#include "ruby/thread.h"
-#include "ruby/util.h"
-#include "ruby/debug.h"
-#include "internal.h"
-#include "eval_intern.h"
-#include "vm_core.h"
-#include "builtin.h"
-#include "gc.h"
-#include "constant.h"
-#include "ruby_atomic.h"
-#include "probes.h"
-#include "id_table.h"
-#include "symbol.h"
-#include <stdio.h>
-#include <stdarg.h>
-#include <setjmp.h>
-#include <sys/types.h>
-#include "ruby_assert.h"
-#include "debug_counter.h"
-#include "transient_heap.h"
-#include "mjit.h"
+#include "ruby/config.h"
+#ifdef _WIN32
+# include "ruby/ruby.h"
+#endif
-#undef rb_data_object_wrap
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stdio.h>
#ifndef HAVE_MALLOC_USABLE_SIZE
# ifdef _WIN32
-# define HAVE_MALLOC_USABLE_SIZE
-# define malloc_usable_size(a) _msize(a)
+# define HAVE_MALLOC_USABLE_SIZE
+# define malloc_usable_size(a) _msize(a)
# elif defined HAVE_MALLOC_SIZE
-# define HAVE_MALLOC_USABLE_SIZE
-# define malloc_usable_size(a) malloc_size(a)
+# define HAVE_MALLOC_USABLE_SIZE
+# define malloc_usable_size(a) malloc_size(a)
# endif
#endif
+
#ifdef HAVE_MALLOC_USABLE_SIZE
# ifdef RUBY_ALTERNATIVE_MALLOC_HEADER
# include RUBY_ALTERNATIVE_MALLOC_HEADER
@@ -64,28 +46,73 @@
#endif
#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
+# include <sys/time.h>
#endif
#ifdef HAVE_SYS_RESOURCE_H
-#include <sys/resource.h>
+# include <sys/resource.h>
#endif
#if defined _WIN32 || defined __CYGWIN__
-#include <windows.h>
+# include <windows.h>
#elif defined(HAVE_POSIX_MEMALIGN)
#elif defined(HAVE_MEMALIGN)
-#include <malloc.h>
+# include <malloc.h>
#endif
-#define rb_setjmp(env) RUBY_SETJMP(env)
-#define rb_jmp_buf rb_jmpbuf_t
+#include <sys/types.h>
#if defined(_MSC_VER) && defined(_WIN64)
-#include <intrin.h>
-#pragma intrinsic(_umul128)
+# include <intrin.h>
+# pragma intrinsic(_umul128)
#endif
+#include "constant.h"
+#include "debug_counter.h"
+#include "eval_intern.h"
+#include "gc.h"
+#include "id_table.h"
+#include "internal.h"
+#include "internal/class.h"
+#include "internal/complex.h"
+#include "internal/cont.h"
+#include "internal/error.h"
+#include "internal/eval.h"
+#include "internal/gc.h"
+#include "internal/hash.h"
+#include "internal/imemo.h"
+#include "internal/io.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/proc.h"
+#include "internal/rational.h"
+#include "internal/sanitizers.h"
+#include "internal/struct.h"
+#include "internal/symbol.h"
+#include "internal/thread.h"
+#include "internal/variable.h"
+#include "internal/warnings.h"
+#include "mjit.h"
+#include "probes.h"
+#include "regint.h"
+#include "ruby/debug.h"
+#include "ruby/io.h"
+#include "ruby/re.h"
+#include "ruby/st.h"
+#include "ruby/thread.h"
+#include "ruby/util.h"
+#include "ruby_assert.h"
+#include "ruby_atomic.h"
+#include "symbol.h"
+#include "transient_heap.h"
+#include "vm_core.h"
+
+#include "builtin.h"
+
+#define rb_setjmp(env) RUBY_SETJMP(env)
+#define rb_jmp_buf rb_jmpbuf_t
+#undef rb_data_object_wrap
+
/* Expecting this struct to be eliminated by function inlinings */
struct optional {
bool left;
@@ -3807,8 +3834,6 @@ rb_obj_id(VALUE obj)
return rb_find_object_id(obj, cached_object_id);
}
-#include "regint.h"
-
static size_t
obj_memsize_of(VALUE obj, int use_all_types)
{
diff --git a/gc.h b/gc.h
index cf794fa514..750d87819b 100644
--- a/gc.h
+++ b/gc.h
@@ -1,6 +1,6 @@
-
#ifndef RUBY_GC_H
#define RUBY_GC_H 1
+#include "ruby/ruby.h"
#if defined(__x86_64__) && !defined(_ILP32) && defined(__GNUC__)
#define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("movq\t%%rsp, %0" : "=r" (*(p)))
diff --git a/hash.c b/hash.c
index 44352c96f1..606d5d3930 100644
--- a/hash.c
+++ b/hash.c
@@ -11,17 +11,10 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "ruby/st.h"
-#include "ruby/util.h"
-#include "internal.h"
+#include "ruby/config.h"
+
#include <errno.h>
-#include "probes.h"
-#include "id.h"
-#include "symbol.h"
-#include "debug_counter.h"
-#include "transient_heap.h"
-#include "ruby_assert.h"
+
#ifdef __APPLE__
# ifdef HAVE_CRT_EXTERNS_H
# include <crt_externs.h>
@@ -30,6 +23,26 @@
# endif
#endif
+#include "debug_counter.h"
+#include "id.h"
+#include "internal.h"
+#include "internal/array.h"
+#include "internal/bignum.h"
+#include "internal/class.h"
+#include "internal/cont.h"
+#include "internal/error.h"
+#include "internal/hash.h"
+#include "internal/object.h"
+#include "internal/proc.h"
+#include "internal/symbol.h"
+#include "internal/vm.h"
+#include "probes.h"
+#include "ruby/st.h"
+#include "ruby/util.h"
+#include "ruby_assert.h"
+#include "symbol.h"
+#include "transient_heap.h"
+
#ifndef HASH_DEBUG
#define HASH_DEBUG 0
#endif
diff --git a/id_table.h b/id_table.h
index abd9eb5f38..8d4d991069 100644
--- a/id_table.h
+++ b/id_table.h
@@ -1,5 +1,7 @@
#ifndef RUBY_ID_TABLE_H
#define RUBY_ID_TABLE_H 1
+#include "ruby/config.h"
+#include <stddef.h>
#include "ruby/ruby.h"
struct rb_id_table;
diff --git a/inits.c b/inits.c
index 79a6cf014e..72a2a9868b 100644
--- a/inits.c
+++ b/inits.c
@@ -9,7 +9,8 @@
**********************************************************************/
-#include "internal.h"
+#include "internal/inits.h"
+#include "ruby.h"
#include "builtin.h"
#include "prelude.rbinc"
diff --git a/internal.h b/internal.h
index fa6f78b52f..7479c73563 100644
--- a/internal.h
+++ b/internal.h
@@ -18,17 +18,9 @@
# error not for C++
#endif
-#include "ruby/encoding.h"
-#include "ruby/io.h"
-#include "internal/stdbool.h"
-#include "internal/bits.h"
-
#define LIKELY(x) RB_LIKELY(x)
#define UNLIKELY(x) RB_UNLIKELY(x)
-#include "internal/compilers.h"
-#include "internal/sanitizers.h"
-
#define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
#define roomof(x, y) (((x) + (y) - 1) / (y))
#define type_roomof(x, y) roomof(sizeof(x), sizeof(y))
@@ -36,54 +28,50 @@
/* Prevent compiler from reordering access */
#define ACCESS_ONCE(type,x) (*((volatile type *)&(x)))
-#include "internal/serial.h"
-#include "internal/static_assert.h"
-#include "internal/time.h"
-#include "internal/fixnum.h"
-#include "internal/bignum.h"
-#include "internal/rational.h"
-#include "internal/numeric.h"
-#include "internal/complex.h"
-#include "internal/hash.h"
-#include "internal/missing.h"
-#include "internal/struct.h"
-#include "internal/class.h"
-#include "internal/imemo.h"
-#include "internal/compar.h"
-#include "internal/variable.h"
-#include "internal/array.h"
-#include "internal/debug.h"
-#include "internal/compile.h"
-#include "internal/cont.h"
-#include "internal/dir.h"
-#include "internal/encoding.h"
-#include "internal/enum.h"
-#include "internal/eval.h"
-#include "internal/error.h"
-#include "internal/file.h"
-#include "internal/gc.h"
-#include "internal/io.h"
-#include "internal/load.h"
-#include "internal/loadpath.h"
-#include "internal/math.h"
-#include "internal/mjit.h"
-#include "internal/object.h"
-#include "internal/parse.h"
-#include "internal/proc.h"
-#include "internal/process.h"
-#include "internal/range.h"
-#include "internal/re.h"
-#include "internal/signal.h"
-#include "internal/string.h"
-#include "internal/symbol.h"
-#include "internal/thread.h"
-#include "internal/transcode.h"
-#include "internal/enc.h"
-#include "internal/util.h"
-#include "internal/vm.h"
-#include "internal/enumerator.h"
-#include "internal/random.h"
-#include "internal/inits.h"
-#include "internal/warnings.h"
+#include "ruby/ruby.h"
+
+/* Folowing macros were formerlly defined in this header but moved to somewhere
+ * else. In order to detect them we undef here. */
+
+/* internal/error.h */
+#undef Check_Type
+
+/* internal/class.h */
+#undef RClass
+#undef RCLASS_SUPER
+
+/* internal/gc.h */
+#undef NEWOBJ_OF
+#undef RB_NEWOBJ_OF
+#undef RB_OBJ_WRITE
+
+/* internal/hash.h */
+#undef RHASH_IFNONE
+#undef RHASH_SIZE
+
+/* internal/struct.h */
+#undef RSTRUCT_LEN
+#undef RSTRUCT_PTR
+#undef RSTRUCT_SET
+#undef RSTRUCT_GET
+
+/* Also, we keep the following macros here. They are expected to be
+ * overridden in each headers. */
+
+/* internal/array.h */
+#define rb_ary_new_from_args(...) rb_nonexistent_symbol(__VA_ARGS__)
+
+/* internal/io.h */
+#define rb_io_fptr_finalize(...) rb_nonexistent_symbol(__VA_ARGS__)
+
+/* internal/string.h */
+#define rb_fstring_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
+
+/* internal/symbol.h */
+#define rb_sym_intern_ascii_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
+
+/* internal/vm.h */
+#define rb_funcallv(...) rb_nonexistent_symbol(__VA_ARGS__)
+#define rb_method_basic_definition_p(...) rb_nonexistent_symbol(__VA_ARGS__)
#endif /* RUBY_INTERNAL_H */
diff --git a/internal/array.h b/internal/array.h
index 857edacf97..1c5de4bb32 100644
--- a/internal/array.h
+++ b/internal/array.h
@@ -9,7 +9,6 @@
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
*/
-
#include "ruby/config.h"
#include <stddef.h> /* for size_t */
#include "internal/static_assert.h" /* for STATIC_ASSERT */
@@ -87,6 +86,7 @@ RARY_TRANSIENT_UNSET(VALUE ary)
#endif
}
+#undef rb_ary_new_from_args
#if defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
#define rb_ary_new_from_args(n, ...) \
__extension__ ({ \
diff --git a/internal/class.h b/internal/class.h
index 254094e038..72d3b9ea54 100644
--- a/internal/class.h
+++ b/internal/class.h
@@ -16,8 +16,13 @@
#include "ruby/intern.h" /* for rb_alloc_func_t */
#include "ruby/ruby.h" /* for struct RBasic */
-#undef RClass /* See also include/ruby/backward.h */
-#undef RCLASS_SUPER
+#ifdef RClass
+# undef RClass /* See also include/ruby/backward.h */
+#endif
+
+#ifdef RCLASS_SUPER
+# undef RCLASS_SUPER
+#endif
struct rb_deprecated_classext_struct {
char conflict[sizeof(VALUE) * 3];
diff --git a/internal/compilers.h b/internal/compilers.h
index 2b1189a670..68e2d33e28 100644
--- a/internal/compilers.h
+++ b/internal/compilers.h
@@ -9,7 +9,6 @@
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
*/
-
#include "ruby/defines.h" /* for GCC_VERSION_SINCE */
#ifdef _MSC_VER
diff --git a/internal/error.h b/internal/error.h
index 6c645b21bb..cb2f23d262 100644
--- a/internal/error.h
+++ b/internal/error.h
@@ -17,7 +17,16 @@
#include "ruby/intern.h" /* for rb_exc_raise */
#include "ruby/ruby.h" /* for enum ruby_value_type */
-#undef Check_Type /* in ruby/ruby.h */
+#ifdef Check_Type
+# undef Check_Type /* in ruby/ruby.h */
+#endif
+
+#ifdef rb_raise_static
+# undef rb_raise_static
+# undef rb_sys_fail_path
+# undef rb_syserr_fail_path
+#endif
+
#define rb_raise_static(e, m) \
rb_raise_cstr_i((e), rb_str_new_static((m), rb_strlen_lit(m)))
#ifdef RUBY_FUNCTION_NAME_STRING
diff --git a/internal/gc.h b/internal/gc.h
index 74e52187c7..36da0db53d 100644
--- a/internal/gc.h
+++ b/internal/gc.h
@@ -18,9 +18,11 @@
struct rb_execution_context_struct; /* in vm_core.h */
-#undef NEWOBJ_OF
-#undef RB_NEWOBJ_OF
-#undef RB_OBJ_WRITE
+#ifdef NEWOBJ_OF
+# undef NEWOBJ_OF
+# undef RB_NEWOBJ_OF
+# undef RB_OBJ_WRITE
+#endif
/* optimized version of NEWOBJ() */
#define RB_NEWOBJ_OF(var, T, c, f) \
diff --git a/internal/hash.h b/internal/hash.h
index 634092e4c2..90a27fd189 100644
--- a/internal/hash.h
+++ b/internal/hash.h
@@ -55,8 +55,14 @@ struct RHash {
};
#define RHASH(obj) (R_CAST(RHash)(obj))
-#undef RHASH_IFNONE
-#undef RHASH_SIZE
+
+#ifdef RHASH_IFNONE
+# undef RHASH_IFNONE
+#endif
+
+#ifdef RHASH_SIZE
+# undef RHASH_SIZE
+#endif
/* hash.c */
void rb_hash_st_table_set(VALUE hash, st_table *st);
diff --git a/internal/io.h b/internal/io.h
index e04dbcb67c..acdb4ffab7 100644
--- a/internal/io.h
+++ b/internal/io.h
@@ -19,6 +19,9 @@ VALUE rb_io_flush_raw(VALUE, int);
size_t rb_io_memsize(const rb_io_t *);
int rb_stderr_tty_p(void);
void rb_io_fptr_finalize_internal(void *ptr);
+#ifdef rb_io_fptr_finalize
+# undef rb_io_fptr_finalize
+#endif
#define rb_io_fptr_finalize rb_io_fptr_finalize_internal
RUBY_SYMBOL_EXPORT_BEGIN
diff --git a/internal/parse.h b/internal/parse.h
index bcde0fea7a..782c06a437 100644
--- a/internal/parse.h
+++ b/internal/parse.h
@@ -10,11 +10,6 @@
* file COPYING are met. Consult the file for details.
*/
#include "ruby/ruby.h" /* for VALUE */
-
-#ifndef USE_SYMBOL_GC
-# define USE_SYMBOL_GC 1
-#endif
-
struct rb_iseq_struct; /* in vm_core.h */
/* parse.y */
diff --git a/internal/string.h b/internal/string.h
index dae4f1bdc0..f585163594 100644
--- a/internal/string.h
+++ b/internal/string.h
@@ -19,6 +19,10 @@
#define STR_NOEMBED FL_USER1
#define STR_SHARED FL_USER2 /* = ELTS_SHARED */
+#ifdef rb_fstring_cstr
+# undef rb_fstring_cstr
+#endif
+
/* string.c */
VALUE rb_fstring(VALUE);
VALUE rb_fstring_cstr(const char *str);
diff --git a/internal/struct.h b/internal/struct.h
index b0f7f2eddd..f205dbd89e 100644
--- a/internal/struct.h
+++ b/internal/struct.h
@@ -12,6 +12,7 @@
#include "internal/gc.h" /* for RB_OBJ_WRITE */
#include "internal/stdbool.h" /* for bool */
#include "ruby/ruby.h" /* for struct RBasic */
+#include "internal/gc.h" /* for RB_OBJ_WRITE */
enum {
RSTRUCT_EMBED_LEN_MAX = RVALUE_EMBED_LEN_MAX,
@@ -32,10 +33,22 @@ struct RStruct {
};
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
-#undef RSTRUCT_LEN
-#undef RSTRUCT_PTR
-#undef RSTRUCT_SET
-#undef RSTRUCT_GET
+
+#ifdef RSTRUCT_LEN
+# undef RSTRUCT_LEN
+#endif
+
+#ifdef RSTRUCT_PTR
+# undef RSTRUCT_PTR
+#endif
+
+#ifdef RSTRUCT_SET
+# undef RSTRUCT_SET
+#endif
+
+#ifdef RSTRUCT_GET
+# undef RSTRUCT_GET
+#endif
/* struct.c */
VALUE rb_struct_init_copy(VALUE copy, VALUE s);
diff --git a/internal/symbol.h b/internal/symbol.h
index 0317f66561..8de6903ae2 100644
--- a/internal/symbol.h
+++ b/internal/symbol.h
@@ -13,6 +13,10 @@
#include "ruby/encoding.h" /* for rb_encoding */
#include "internal/compilers.h" /* for __has_builtin */
+#ifdef rb_sym_intern_ascii_cstr
+# undef rb_sym_intern_ascii_cstr
+#endif
+
/* symbol.c */
VALUE rb_to_symbol_type(VALUE obj);
VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc);
diff --git a/internal/variable.h b/internal/variable.h
index 1cdc06e08d..5080fc13ef 100644
--- a/internal/variable.h
+++ b/internal/variable.h
@@ -9,7 +9,6 @@
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
*/
-
#include "ruby/config.h"
#include <stddef.h> /* for size_t */
#include "constant.h" /* for rb_const_entry_t */
diff --git a/internal/vm.h b/internal/vm.h
index e9d2d09c6c..1bd7a98f7a 100644
--- a/internal/vm.h
+++ b/internal/vm.h
@@ -15,6 +15,14 @@
#include "ruby/ruby.h" /* for ID */
#include "ruby/st.h" /* for st_table */
+#ifdef rb_funcallv
+# undef rb_funcallv
+#endif
+
+#ifdef rb_method_basic_definition_p
+# undef rb_method_basic_definition_p
+#endif
+
/* I have several reasons to choose 64 here:
*
* - A cache line must be a power-of-two size.
diff --git a/io.c b/io.c
index 42528c0fd5..37109f5def 100644
--- a/io.c
+++ b/io.c
@@ -11,38 +11,31 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "ruby/io.h"
-#include "ruby/thread.h"
-#include "internal.h"
-#include "dln.h"
-#include "encindex.h"
-#include "id.h"
+#include "ruby/config.h"
+
+#ifdef _WIN32
+# include "ruby/ruby.h"
+# include "ruby/io.h"
+#endif
+
#include <ctype.h>
#include <errno.h>
-#include "ruby_atomic.h"
-#include "ccan/list/list.h"
+#include <stddef.h>
/* non-Linux poll may not work on all FDs */
#if defined(HAVE_POLL)
-# if defined(__linux__)
-# define USE_POLL 1
-# endif
-# if defined(__FreeBSD_version) && __FreeBSD_version >= 1100000
-# define USE_POLL 1
-# endif
+# if defined(__linux__)
+# define USE_POLL 1
+# endif
+# if defined(__FreeBSD_version) && __FreeBSD_version >= 1100000
+# define USE_POLL 1
+# endif
#endif
#ifndef USE_POLL
-# define USE_POLL 0
-#endif
-
-#if !USE_POLL
-# include "vm_core.h"
+# define USE_POLL 0
#endif
-#include "builtin.h"
-
#undef free
#define free(x) xfree(x)
@@ -119,7 +112,31 @@
# include <copyfile.h>
#endif
+#include "dln.h"
+#include "encindex.h"
+#include "id.h"
+#include "internal.h"
+#include "internal/encoding.h"
+#include "internal/error.h"
+#include "internal/inits.h"
+#include "internal/io.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/process.h"
+#include "internal/stdbool.h"
+#include "ccan/list/list.h"
+#include "internal/thread.h"
+#include "internal/transcode.h"
+#include "ruby/io.h"
+#include "ruby/thread.h"
#include "ruby/util.h"
+#include "ruby_atomic.h"
+
+#if !USE_POLL
+# include "vm_core.h"
+#endif
+
+#include "builtin.h"
#ifndef O_ACCMODE
#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
diff --git a/iseq.c b/iseq.c
index cbf62176bd..2f40efc77b 100644
--- a/iseq.c
+++ b/iseq.c
@@ -9,25 +9,37 @@
**********************************************************************/
-#include "internal.h"
-#include "ruby/util.h"
-#include "eval_intern.h"
+#define RUBY_VM_INSNS_INFO 1
+/* #define RUBY_MARK_FREE_DEBUG 1 */
+
+#include "ruby/config.h"
#ifdef HAVE_DLADDR
# include <dlfcn.h>
#endif
-#define RUBY_VM_INSNS_INFO 1
-/* #define RUBY_MARK_FREE_DEBUG 1 */
+#include "eval_intern.h"
#include "gc.h"
-#include "vm_core.h"
-#include "iseq.h"
#include "id_table.h"
-#include "builtin.h"
+#include "internal.h"
+#include "internal/bits.h"
+#include "internal/compile.h"
+#include "internal/error.h"
+#include "internal/file.h"
+#include "internal/hash.h"
+#include "internal/parse.h"
+#include "internal/sanitizers.h"
+#include "internal/symbol.h"
+#include "internal/thread.h"
+#include "internal/variable.h"
+#include "iseq.h"
+#include "mjit.h"
+#include "ruby/util.h"
+#include "vm_core.h"
+#include "builtin.h"
#include "insns.inc"
#include "insns_info.inc"
-#include "mjit.h"
VALUE rb_cISeq;
static VALUE iseqw_new(const rb_iseq_t *iseq);
diff --git a/iseq.h b/iseq.h
index 25c62a384f..8354a0490f 100644
--- a/iseq.h
+++ b/iseq.h
@@ -11,6 +11,8 @@
#ifndef RUBY_ISEQ_H
#define RUBY_ISEQ_H 1
+#include "internal/gc.h"
+#include "vm_core.h"
RUBY_EXTERN const int ruby_api_version[];
#define ISEQ_MAJOR_VERSION ((unsigned int)ruby_api_version[0])
diff --git a/load.c b/load.c
index fda100fb1a..70a04756c6 100644
--- a/load.c
+++ b/load.c
@@ -2,13 +2,20 @@
* load methods from eval.c
*/
-#include "ruby/encoding.h"
-#include "ruby/util.h"
-#include "internal.h"
#include "dln.h"
#include "eval_intern.h"
-#include "probes.h"
+#include "internal.h"
+#include "internal/dir.h"
+#include "internal/error.h"
+#include "internal/file.h"
+#include "internal/load.h"
+#include "internal/parse.h"
+#include "internal/thread.h"
+#include "internal/variable.h"
#include "iseq.h"
+#include "probes.h"
+#include "ruby/encoding.h"
+#include "ruby/util.h"
static VALUE ruby_dln_librefs;
diff --git a/marshal.c b/marshal.c
index df8da10b27..299902712c 100644
--- a/marshal.c
+++ b/marshal.c
@@ -9,13 +9,7 @@
**********************************************************************/
-#include "ruby/ruby.h"
-#include "ruby/io.h"
-#include "internal.h"
-#include "ruby/st.h"
-#include "ruby/util.h"
-#include "encindex.h"
-#include "id_table.h"
+#include "ruby/config.h"
#include <math.h>
#ifdef HAVE_FLOAT_H
@@ -25,6 +19,23 @@
#include <ieeefp.h>
#endif
+#include "encindex.h"
+#include "id_table.h"
+#include "internal.h"
+#include "internal/bignum.h"
+#include "internal/class.h"
+#include "internal/encoding.h"
+#include "internal/error.h"
+#include "internal/hash.h"
+#include "internal/object.h"
+#include "internal/struct.h"
+#include "internal/util.h"
+#include "internal/vm.h"
+#include "ruby/io.h"
+#include "ruby/ruby.h"
+#include "ruby/st.h"
+#include "ruby/util.h"
+
#define BITSPERSHORT (2*CHAR_BIT)
#define SHORTMASK ((1<<BITSPERSHORT)-1)
#define SHORTDN(x) RSHIFT((x),BITSPERSHORT)
diff --git a/math.c b/math.c
index d98467ca0a..7edde60270 100644
--- a/math.c
+++ b/math.c
@@ -9,13 +9,22 @@
**********************************************************************/
+#include "ruby/config.h"
+
#ifdef _MSC_VER
# define _USE_MATH_DEFINES 1
#endif
-#include "internal.h"
+
+#include <errno.h>
#include <float.h>
#include <math.h>
-#include <errno.h>
+
+#include "internal.h"
+#include "internal/bignum.h"
+#include "internal/complex.h"
+#include "internal/math.h"
+#include "internal/object.h"
+#include "internal/vm.h"
#if defined(HAVE_SIGNBIT) && defined(__GNUC__) && defined(__sun) && \
!defined(signbit)
diff --git a/method.h b/method.h
index b26caaa92d..519cc9bfc1 100644
--- a/method.h
+++ b/method.h
@@ -12,6 +12,9 @@
#define RUBY_METHOD_H 1
#include "internal.h"
+#include "internal/imemo.h"
+#include "internal/compilers.h"
+#include "internal/static_assert.h"
#ifndef END_OF_ENUMERATION
# if defined(__GNUC__) &&! defined(__STRICT_ANSI__)
diff --git a/mini_builtin.c b/mini_builtin.c
index ad289bf896..86803e1656 100644
--- a/mini_builtin.c
+++ b/mini_builtin.c
@@ -1,6 +1,7 @@
#include "internal.h"
-#include "vm_core.h"
+#include "internal/array.h"
#include "iseq.h"
+#include "vm_core.h"
#include "builtin.h"
#include "miniprelude.c"
diff --git a/mjit.c b/mjit.c
index 33abfbe3e9..5d1a182b0b 100644
--- a/mjit.c
+++ b/mjit.c
@@ -11,14 +11,20 @@
// To share variables privately, include mjit_worker.c instead of linking.
-#include "internal.h"
+#include "ruby/config.h"
#if USE_MJIT
-#include "mjit_worker.c"
-
#include "constant.h"
#include "id_table.h"
+#include "internal.h"
+#include "internal/class.h"
+#include "internal/file.h"
+#include "internal/hash.h"
+#include "internal/mjit.h"
+#include "internal/warnings.h"
+
+#include "mjit_worker.c"
// Copy ISeq's states so that race condition does not happen on compilation.
static void
diff --git a/mjit.h b/mjit.h
index 256bf65a29..44cb6571b7 100644
--- a/mjit.h
+++ b/mjit.h
@@ -9,11 +9,14 @@
#ifndef RUBY_MJIT_H
#define RUBY_MJIT_H 1
-#include "ruby.h"
-#include "debug_counter.h"
+#include "ruby/config.h"
#if USE_MJIT
+#include "debug_counter.h"
+#include "ruby.h"
+#include "vm_core.h"
+
// Special address values of a function generated from the
// corresponding iseq by MJIT:
enum rb_mjit_iseq_func {
diff --git a/mjit_compile.c b/mjit_compile.c
index f379a896a8..3218c52c4e 100644
--- a/mjit_compile.c
+++ b/mjit_compile.c
@@ -10,17 +10,22 @@
// call Ruby methods (C functions that may call rb_funcall) or trigger
// GC (using ZALLOC, xmalloc, xfree, etc.) in this file.
-#include "internal.h"
+#include "ruby/config.h"
#if USE_MJIT
+#include "internal.h"
+#include "internal/compile.h"
+#include "internal/hash.h"
+#include "internal/variable.h"
+#include "mjit.h"
#include "vm_core.h"
#include "vm_exec.h"
-#include "mjit.h"
+#include "vm_insnhelper.h"
+
#include "builtin.h"
#include "insns.inc"
#include "insns_info.inc"
-#include "vm_insnhelper.h"
// Macros to check if a position is already compiled using compile_status.stack_size_for_pos
#define NOT_COMPILED_STACK_SIZE -1
diff --git a/node.c b/node.c
index 3514060ecb..9decd803ce 100644
--- a/node.c
+++ b/node.c
@@ -9,6 +9,9 @@
**********************************************************************/
+#include "internal.h"
+#include "internal/hash.h"
+#include "internal/variable.h"
#include "ruby/ruby.h"
#include "vm_core.h"
diff --git a/numeric.c b/numeric.c
index 218dabe462..2471f9bd04 100644
--- a/numeric.c
+++ b/numeric.c
@@ -9,10 +9,8 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "ruby/util.h"
-#include "internal.h"
-#include "id.h"
+#include "ruby/config.h"
+
#include <assert.h>
#include <ctype.h>
#include <math.h>
@@ -26,6 +24,22 @@
#include <ieeefp.h>
#endif
+#include "id.h"
+#include "internal.h"
+#include "internal/array.h"
+#include "internal/compilers.h"
+#include "internal/complex.h"
+#include "internal/enumerator.h"
+#include "internal/gc.h"
+#include "internal/hash.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/rational.h"
+#include "internal/util.h"
+#include "internal/variable.h"
+#include "ruby/encoding.h"
+#include "ruby/util.h"
+
/* use IEEE 64bit values if not defined */
#ifndef FLT_RADIX
#define FLT_RADIX 2
diff --git a/object.c b/object.c
index 61be0d3862..f7bb57c13b 100644
--- a/object.c
+++ b/object.c
@@ -11,18 +11,31 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "ruby/st.h"
-#include "ruby/util.h"
-#include "internal.h"
-#include <stdio.h>
-#include <errno.h>
+#include "ruby/config.h"
+
#include <ctype.h>
-#include <math.h>
+#include <errno.h>
#include <float.h>
+#include <math.h>
+#include <stdio.h>
+
#include "constant.h"
#include "id.h"
+#include "internal.h"
+#include "internal/array.h"
+#include "internal/class.h"
+#include "internal/error.h"
+#include "internal/eval.h"
+#include "internal/inits.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/struct.h"
+#include "internal/symbol.h"
+#include "internal/variable.h"
#include "probes.h"
+#include "ruby/encoding.h"
+#include "ruby/st.h"
+#include "ruby/util.h"
/*!
* \defgroup object Core objects and their operations
diff --git a/pack.c b/pack.c
index ae5a9a18e2..8ba492fd3b 100644
--- a/pack.c
+++ b/pack.c
@@ -9,12 +9,20 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "internal.h"
-#include <sys/types.h>
+#include "ruby/config.h"
+
#include <ctype.h>
#include <errno.h>
#include <float.h>
+#include <sys/types.h>
+
+#include "internal.h"
+#include "internal/bits.h"
+#include "internal/string.h"
+#include "internal/symbol.h"
+#include "internal/util.h"
+#include "internal/variable.h"
+
#include "builtin.h"
/*
diff --git a/parse.y b/parse.y
index 1281eb6258..5f7884b5ae 100644
--- a/parse.y
+++ b/parse.y
@@ -20,18 +20,37 @@
#define YYLTYPE rb_code_location_t
#define YYLTYPE_IS_DECLARED 1
-#include "ruby/ruby.h"
-#include "ruby/st.h"
-#include "ruby/encoding.h"
+#include "ruby/config.h"
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+
#include "internal.h"
+#include "internal/compile.h"
+#include "internal/complex.h"
+#include "internal/error.h"
+#include "internal/hash.h"
+#include "internal/imemo.h"
+#include "internal/io.h"
+#include "internal/numeric.h"
+#include "internal/parse.h"
+#include "internal/rational.h"
+#include "internal/re.h"
+#include "internal/symbol.h"
+#include "internal/thread.h"
+#include "internal/util.h"
+#include "internal/variable.h"
#include "node.h"
#include "parse.h"
-#include "symbol.h"
-#include "regenc.h"
-#include <stdio.h>
-#include <errno.h>
-#include <ctype.h>
#include "probes.h"
+#include "regenc.h"
+#include "ruby/encoding.h"
+#include "ruby/regex.h"
+#include "ruby/ruby.h"
+#include "ruby/st.h"
+#include "ruby/util.h"
+#include "symbol.h"
#ifndef WARN_PAST_SCOPE
# define WARN_PAST_SCOPE 0
@@ -5531,9 +5550,6 @@ ripper_dispatch_delayed_token(struct parser_params *p, enum yytokentype t)
#define has_delayed_token(p) (!NIL_P(p->delayed.token))
#endif /* RIPPER */
-#include "ruby/regex.h"
-#include "ruby/util.h"
-
static inline int
is_identchar(const char *ptr, const char *MAYBE_UNUSED(ptr_end), rb_encoding *enc)
{
diff --git a/proc.c b/proc.c
index e7178bebf5..cb5ffdab9a 100644
--- a/proc.c
+++ b/proc.c
@@ -10,10 +10,15 @@
**********************************************************************/
#include "eval_intern.h"
-#include "internal.h"
#include "gc.h"
-#include "vm_core.h"
+#include "internal.h"
+#include "internal/class.h"
+#include "internal/error.h"
+#include "internal/object.h"
+#include "internal/proc.h"
+#include "internal/symbol.h"
#include "iseq.h"
+#include "vm_core.h"
/* Proc.new with no block will raise an exception in the future
* versions */
diff --git a/process.c b/process.c
index 3ea6eb2a1b..bb895150d8 100644
--- a/process.c
+++ b/process.c
@@ -12,82 +12,106 @@
**********************************************************************/
#include "ruby/config.h"
-#include "ruby/io.h"
-#include "internal.h"
-#include "ruby/thread.h"
-#include "ruby/util.h"
-#include "vm_core.h"
-#include "hrtime.h"
-#include <stdio.h>
+#include <ctype.h>
#include <errno.h>
#include <signal.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <time.h>
+
#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
+# include <stdlib.h>
#endif
+
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
+
#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
+# include <fcntl.h>
#endif
+
#ifdef HAVE_PROCESS_H
-#include <process.h>
+# include <process.h>
#endif
-#include <time.h>
-#include <ctype.h>
-
#ifndef EXIT_SUCCESS
-#define EXIT_SUCCESS 0
+# define EXIT_SUCCESS 0
#endif
+
#ifndef EXIT_FAILURE
-#define EXIT_FAILURE 1
+# define EXIT_FAILURE 1
#endif
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
+
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif
+
#ifdef HAVE_VFORK_H
# include <vfork.h>
#endif
+
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
+
#ifndef MAXPATHLEN
# define MAXPATHLEN 1024
#endif
-#include "ruby/st.h"
#include <sys/stat.h>
#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
+# include <sys/time.h>
#endif
+
#ifdef HAVE_SYS_TIMES_H
-#include <sys/times.h>
+# include <sys/times.h>
#endif
#ifdef HAVE_PWD_H
-#include <pwd.h>
+# include <pwd.h>
#endif
+
#ifdef HAVE_GRP_H
-#include <grp.h>
+# include <grp.h>
# ifdef __CYGWIN__
int initgroups(const char *, rb_gid_t);
# endif
#endif
+
#ifdef HAVE_SYS_ID_H
-#include <sys/id.h>
+# include <sys/id.h>
#endif
#ifdef __APPLE__
# include <mach/mach_time.h>
#endif
+#include "dln.h"
+#include "hrtime.h"
+#include "internal.h"
+#include "internal/bits.h"
+#include "internal/error.h"
+#include "internal/eval.h"
+#include "internal/hash.h"
+#include "internal/mjit.h"
+#include "internal/object.h"
+#include "internal/process.h"
+#include "internal/thread.h"
+#include "internal/variable.h"
+#include "internal/warnings.h"
+#include "ruby/io.h"
+#include "ruby/st.h"
+#include "ruby/thread.h"
+#include "ruby/util.h"
+#include "vm_core.h"
+
/* define system APIs */
#ifdef _WIN32
#undef open
@@ -317,8 +341,6 @@ close_unless_reserved(int fd)
/*#define DEBUG_REDIRECT*/
#if defined(DEBUG_REDIRECT)
-#include <stdarg.h>
-
static void
ttyprintf(const char *fmt, ...)
{
@@ -1572,8 +1594,6 @@ after_fork_ruby(void)
}
#endif
-#include "dln.h"
-
#if defined(HAVE_WORKING_FORK)
/* try_with_sh and exec_with_sh should be async-signal-safe. Actually it is.*/
diff --git a/random.c b/random.c
index d763a214cd..29ac388311 100644
--- a/random.c
+++ b/random.c
@@ -9,41 +9,59 @@
**********************************************************************/
-#include "internal.h"
+#include "ruby/config.h"
+#include <errno.h>
#include <limits.h>
+#include <math.h>
+#include <time.h>
+
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
-#include <time.h>
+
#include <sys/types.h>
#include <sys/stat.h>
+
#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
+# include <fcntl.h>
#endif
-#include <math.h>
-#include <errno.h>
+
#if defined(HAVE_SYS_TIME_H)
-#include <sys/time.h>
+# include <sys/time.h>
#endif
#ifdef HAVE_SYSCALL_H
-#include <syscall.h>
+# include <syscall.h>
#elif defined HAVE_SYS_SYSCALL_H
-#include <sys/syscall.h>
+# include <sys/syscall.h>
#endif
#ifdef _WIN32
-#include <windows.h>
-#include <wincrypt.h>
+# include <winsock2.h>
+# include <windows.h>
+# include <wincrypt.h>
#endif
-#include "ruby_atomic.h"
#ifdef __OpenBSD__
/* to define OpenBSD for version check */
-#include <sys/param.h>
+# include <sys/param.h>
+#endif
+
+#if defined HAVE_GETRANDOM
+# include <sys/random.h>
+#elif defined __linux__ && defined __NR_getrandom
+# include <linux/random.h>
#endif
+#include "internal.h"
+#include "internal/compilers.h"
+#include "internal/error.h"
+#include "internal/numeric.h"
+#include "internal/random.h"
+#include "internal/sanitizers.h"
+#include "ruby_atomic.h"
+
typedef int int_must_be_32bit_at_least[sizeof(int) * CHAR_BIT < 32 ? -1 : 1];
#include "missing/mt19937.c"
@@ -320,11 +338,7 @@ fill_random_bytes_urandom(void *seed, size_t size)
# define fill_random_bytes_urandom(seed, size) -1
#endif
-#if defined HAVE_GETRANDOM
-# include <sys/random.h>
-#elif defined __linux__ && defined __NR_getrandom
-# include <linux/random.h>
-
+#if ! defined HAVE_GETRANDOM && defined __linux__ && defined __NR_getrandom
# ifndef GRND_NONBLOCK
# define GRND_NONBLOCK 0x0001 /* not defined in musl libc */
# endif
diff --git a/range.c b/range.c
index bf14c0c7a7..e182934fa3 100644
--- a/range.c
+++ b/range.c
@@ -9,14 +9,24 @@
**********************************************************************/
-#include "internal.h"
-#include "id.h"
+#include "ruby/config.h"
+
#include <assert.h>
+#include <math.h>
#ifdef HAVE_FLOAT_H
#include <float.h>
#endif
-#include <math.h>
+
+#include "id.h"
+#include "internal.h"
+#include "internal/array.h"
+#include "internal/compar.h"
+#include "internal/enum.h"
+#include "internal/enumerator.h"
+#include "internal/error.h"
+#include "internal/numeric.h"
+#include "internal/range.h"
VALUE rb_cRange;
static ID id_beg, id_end, id_excl;
diff --git a/rational.c b/rational.c
index c606f3c625..8b4a39452c 100644
--- a/rational.c
+++ b/rational.c
@@ -5,23 +5,32 @@
which is written in ruby.
*/
-#include "internal.h"
-#include "id.h"
-#include <math.h>
+#include "ruby/config.h"
+
+#include <ctype.h>
#include <float.h>
+#include <math.h>
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
-#define NDEBUG
-#include "ruby_assert.h"
-
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
#define USE_GMP
#include <gmp.h>
#endif
+#define NDEBUG
+#include "id.h"
+#include "internal.h"
+#include "internal/complex.h"
+#include "internal/error.h"
+#include "internal/gc.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/rational.h"
+#include "ruby_assert.h"
+
#define ZERO INT2FIX(0)
#define ONE INT2FIX(1)
#define TWO INT2FIX(2)
@@ -2299,8 +2308,6 @@ float_rationalize(int argc, VALUE *argv, VALUE self)
}
}
-#include <ctype.h>
-
inline static int
issign(int c)
{
diff --git a/re.c b/re.c
index b15c3a07a8..56b5144f9f 100644
--- a/re.c
+++ b/re.c
@@ -9,13 +9,20 @@
**********************************************************************/
+#include "ruby/config.h"
+
+#include <ctype.h>
+
+#include "encindex.h"
+#include "internal.h"
+#include "internal/error.h"
+#include "internal/hash.h"
+#include "internal/imemo.h"
+#include "internal/re.h"
+#include "regint.h"
#include "ruby/encoding.h"
#include "ruby/re.h"
#include "ruby/util.h"
-#include "internal.h"
-#include "regint.h"
-#include "encindex.h"
-#include <ctype.h>
VALUE rb_eRegexpError;
diff --git a/ruby.c b/ruby.c
index 7903f583fe..2d1a437e7d 100644
--- a/ruby.c
+++ b/ruby.c
@@ -11,38 +11,57 @@
**********************************************************************/
-#ifdef __CYGWIN__
-#include <windows.h>
-#include <sys/cygwin.h>
-#endif
-#include "ruby/encoding.h"
-#include "ruby/thread.h"
-#include "ruby/version.h"
-#include "internal.h"
-#include "eval_intern.h"
-#include "dln.h"
+#include "ruby/config.h"
+
+#include <ctype.h>
#include <stdio.h>
#include <sys/types.h>
-#include <ctype.h>
+
+#ifdef __CYGWIN__
+# include <windows.h>
+# include <sys/cygwin.h>
+#endif
#ifdef __hpux
-#include <sys/pstat.h>
+# include <sys/pstat.h>
#endif
+
#if defined(LOAD_RELATIVE) && defined(HAVE_DLADDR)
-#include <dlfcn.h>
+# include <dlfcn.h>
#endif
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
+
#if defined(HAVE_FCNTL_H)
-#include <fcntl.h>
+# include <fcntl.h>
#elif defined(HAVE_SYS_FCNTL_H)
-#include <sys/fcntl.h>
+# include <sys/fcntl.h>
#endif
+
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
+
+#include "dln.h"
+#include "eval_intern.h"
+#include "internal.h"
+#include "internal/error.h"
+#include "internal/file.h"
+#include "internal/inits.h"
+#include "internal/io.h"
+#include "internal/load.h"
+#include "internal/loadpath.h"
+#include "internal/missing.h"
+#include "internal/object.h"
+#include "internal/parse.h"
+#include "mjit.h"
+#include "ruby/encoding.h"
+#include "ruby/thread.h"
+#include "ruby/util.h"
+#include "ruby/version.h"
+
#ifndef MAXPATHLEN
# define MAXPATHLEN 1024
#endif
@@ -50,10 +69,6 @@
# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
#endif
-#include "ruby/util.h"
-
-#include "mjit.h"
-
void Init_ruby_description(void);
#ifndef HAVE_STDLIB_H
diff --git a/signal.c b/signal.c
index 68d68c54bf..ab4eadc7ee 100644
--- a/signal.c
+++ b/signal.c
@@ -11,36 +11,39 @@
**********************************************************************/
-#include "internal.h"
-#include "vm_core.h"
+#include "ruby/config.h"
+
+#include <errno.h>
#include <signal.h>
#include <stdio.h>
-#include <errno.h>
-#include "ruby_atomic.h"
-#include "eval_intern.h"
+
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
+
#ifdef HAVE_SYS_UIO_H
-#include <sys/uio.h>
+# include <sys/uio.h>
#endif
+
#ifdef HAVE_UCONTEXT_H
-#include <ucontext.h>
+# include <ucontext.h>
#endif
-#ifdef HAVE_VALGRIND_MEMCHECK_H
-# include <valgrind/memcheck.h>
-# ifndef VALGRIND_MAKE_MEM_DEFINED
-# define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n))
-# endif
-# ifndef VALGRIND_MAKE_MEM_UNDEFINED
-# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n))
-# endif
-#else
-# define VALGRIND_MAKE_MEM_DEFINED(p, n) 0
-# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0
+#if HAVE_PTHREAD_H
+# include <pthread.h>
#endif
+#include "debug_counter.h"
+#include "eval_intern.h"
+#include "internal.h"
+#include "internal/eval.h"
+#include "internal/sanitizers.h"
+#include "internal/signal.h"
+#include "internal/string.h"
+#include "internal/thread.h"
+#include "ruby_atomic.h"
+#include "vm_core.h"
+
#ifdef NEED_RUBY_ATOMIC_OPS
rb_atomic_t
ruby_atomic_exchange(rb_atomic_t *ptr, rb_atomic_t val)
@@ -395,7 +398,6 @@ interrupt_init(int argc, VALUE *argv, VALUE self)
return rb_call_super(2, args);
}
-#include "debug_counter.h"
void rb_malloc_info_show_results(void); /* gc.c */
void
@@ -728,10 +730,6 @@ rb_signal_buff_size(void)
return signal_buff.size;
}
-#if HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-
static void
rb_disable_interrupt(void)
{
diff --git a/sprintf.c b/sprintf.c
index 23eb39a73b..64cfdee1a1 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -11,17 +11,27 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "ruby/re.h"
-#include "internal.h"
-#include "id.h"
+#include "ruby/config.h"
+
#include <math.h>
#include <stdarg.h>
#ifdef HAVE_IEEEFP_H
-#include <ieeefp.h>
+# include <ieeefp.h>
#endif
+#include "id.h"
+#include "internal.h"
+#include "internal/error.h"
+#include "internal/hash.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/sanitizers.h"
+#include "internal/symbol.h"
+#include "internal/util.h"
+#include "ruby/encoding.h"
+#include "ruby/re.h"
+
#define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */
static char *fmt_setup(char*,size_t,int,int,int,int);
diff --git a/st.c b/st.c
index 2b973ea75d..3d95c812d1 100644
--- a/st.c
+++ b/st.c
@@ -105,6 +105,9 @@
#include "st.h"
#else
#include "internal.h"
+#include "internal/bits.h"
+#include "internal/hash.h"
+#include "internal/sanitizers.h"
#endif
#include <stdio.h>
diff --git a/strftime.c b/strftime.c
index dd2b21f977..911bcdaf15 100644
--- a/strftime.c
+++ b/strftime.c
@@ -47,10 +47,7 @@
* January 1996
*/
-#include "ruby/ruby.h"
-#include "ruby/encoding.h"
-#include "timev.h"
-#include "internal.h"
+#include "ruby/config.h"
#ifndef GAWK
#include <stdio.h>
@@ -68,6 +65,14 @@
#endif
#include <math.h>
+#include "internal.h"
+#include "internal/string.h"
+#include "internal/util.h"
+#include "internal/vm.h"
+#include "ruby/encoding.h"
+#include "ruby/ruby.h"
+#include "timev.h"
+
/* defaults: season to taste */
#define SYSV_EXT 1 /* stuff in System V ascftime routine */
#define SUNOS_EXT 1 /* stuff in SunOS strftime routine */
diff --git a/string.c b/string.c
index d6fd73115b..c9383937ae 100644
--- a/string.c
+++ b/string.c
@@ -11,37 +11,52 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "ruby/re.h"
-#include "internal.h"
-#include "encindex.h"
-#include "probes.h"
-#include "gc.h"
-#include "ruby_assert.h"
-#include "id.h"
-#include "debug_counter.h"
-#include "ruby/util.h"
-
-#define BEG(no) (regs->beg[(no)])
-#define END(no) (regs->end[(no)])
+#include "ruby/config.h"
+#include <ctype.h>
#include <errno.h>
#include <math.h>
-#include <ctype.h>
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
#if defined HAVE_CRYPT_R
# if defined HAVE_CRYPT_H
-# include <crypt.h>
+# include <crypt.h>
# endif
#elif !defined HAVE_CRYPT
# include "missing/crypt.h"
# define HAVE_CRYPT_R 1
#endif
+#include "debug_counter.h"
+#include "encindex.h"
+#include "gc.h"
+#include "id.h"
+#include "internal.h"
+#include "internal/array.h"
+#include "internal/compar.h"
+#include "internal/compilers.h"
+#include "internal/encoding.h"
+#include "internal/error.h"
+#include "internal/gc.h"
+#include "internal/numeric.h"
+#include "internal/object.h"
+#include "internal/proc.h"
+#include "internal/re.h"
+#include "internal/sanitizers.h"
+#include "internal/string.h"
+#include "internal/transcode.h"
+#include "probes.h"
+#include "ruby/encoding.h"
+#include "ruby/re.h"
+#include "ruby/util.h"
+#include "ruby_assert.h"
+
+#define BEG(no) (regs->beg[(no)])
+#define END(no) (regs->end[(no)])
+
#undef rb_str_new
#undef rb_usascii_str_new
#undef rb_utf8_str_new
diff --git a/struct.c b/struct.c
index d1aa7c278f..79131db2bd 100644
--- a/struct.c
+++ b/struct.c
@@ -9,10 +9,17 @@
**********************************************************************/
-#include "internal.h"
-#include "vm_core.h"
#include "id.h"
+#include "internal.h"
+#include "internal/class.h"
+#include "internal/error.h"
+#include "internal/hash.h"
+#include "internal/object.h"
+#include "internal/proc.h"
+#include "internal/struct.h"
+#include "internal/symbol.h"
#include "transient_heap.h"
+#include "vm_core.h"
/* only for struct[:field] access */
enum {
diff --git a/symbol.c b/symbol.c
index 14517df01e..a0aa4cc75f 100644
--- a/symbol.c
+++ b/symbol.c
@@ -9,13 +9,22 @@
**********************************************************************/
+#include "gc.h"
+#include "internal.h"
+#include "internal/error.h"
+#include "internal/gc.h"
+#include "internal/hash.h"
+#include "internal/object.h"
+#include "internal/symbol.h"
+#include "internal/vm.h"
+#include "probes.h"
#include "ruby/encoding.h"
#include "ruby/st.h"
-#include "internal.h"
#include "symbol.h"
-#include "gc.h"
-#include "probes.h"
+#ifndef USE_SYMBOL_GC
+# define USE_SYMBOL_GC 1
+#endif
#ifndef SYMBOL_DEBUG
# define SYMBOL_DEBUG 0
#endif
diff --git a/symbol.h b/symbol.h
index 4b5c676d55..45cf1b21c9 100644
--- a/symbol.h
+++ b/symbol.h
@@ -13,6 +13,7 @@
#define RUBY_SYMBOL_H 1
#include "id.h"
+#include "ruby/encoding.h"
#define DYNAMIC_ID_P(id) (!(id&ID_STATIC_SYM)&&id>tLAST_OP_ID)
#define STATIC_ID2SYM(id) (((VALUE)(id)<<RUBY_SPECIAL_SHIFT)|SYMBOL_FLAG)
diff --git a/template/prelude.c.tmpl b/template/prelude.c.tmpl
index b582e2ddd6..a8b53d05c9 100644
--- a/template/prelude.c.tmpl
+++ b/template/prelude.c.tmpl
@@ -87,10 +87,11 @@ Prelude.new(output, ARGV, vpath).instance_eval do
sources: <%= @preludes.map {|n,*| prelude_base(n)}.join(', ') %><%=%>
*/
%unless @preludes.empty?
-#include "ruby/ruby.h"
#include "internal.h"
-#include "vm_core.h"
+#include "internal/warnings.h"
#include "iseq.h"
+#include "ruby/ruby.h"
+#include "vm_core.h"
% preludes = @preludes.values.sort
% preludes.each {|i, prelude, lines, sub|
diff --git a/thread.c b/thread.c
index da36b62f8b..73d60b0fe3 100644
--- a/thread.c
+++ b/thread.c
@@ -64,23 +64,34 @@
/* for model 2 */
#include "ruby/config.h"
-#include "ruby/io.h"
+
+#ifdef __linux__
+// Normally, gcc(1) translates calls to alloca() with inlined code. This is not done when either the -ansi, -std=c89, -std=c99, or the -std=c11 option is given and the header <alloca.h> is not included.
+# include <alloca.h>
+#endif
+
#include "eval_intern.h"
-#include "timev.h"
-#include "ruby/thread.h"
-#include "ruby/thread_native.h"
-#include "ruby/debug.h"
#include "gc.h"
+#include "hrtime.h"
#include "internal.h"
+#include "internal/class.h"
+#include "internal/error.h"
+#include "internal/hash.h"
+#include "internal/io.h"
+#include "internal/object.h"
+#include "internal/proc.h"
+#include "internal/signal.h"
+#include "internal/thread.h"
+#include "internal/time.h"
+#include "internal/warnings.h"
#include "iseq.h"
-#include "vm_core.h"
#include "mjit.h"
-#include "hrtime.h"
-
-#ifdef __linux__
-// Normally, gcc(1) translates calls to alloca() with inlined code. This is not done when either the -ansi, -std=c89, -std=c99, or the -std=c11 option is given and the header <alloca.h> is not included.
-#include <alloca.h>
-#endif
+#include "ruby/debug.h"
+#include "ruby/io.h"
+#include "ruby/thread.h"
+#include "ruby/thread_native.h"
+#include "timev.h"
+#include "vm_core.h"
#ifndef USE_NATIVE_THREAD_PRIORITY
#define USE_NATIVE_THREAD_PRIORITY 0
diff --git a/time.c b/time.c
index d71d43e058..0f7b35f824 100644
--- a/time.c
+++ b/time.c
@@ -11,29 +11,37 @@
#define _DEFAULT_SOURCE
#define _BSD_SOURCE
-#include "ruby/encoding.h"
-#include "internal.h"
-#include <sys/types.h>
-#include <time.h>
+#include "ruby/config.h"
+
#include <errno.h>
+#include <float.h>
+#include <math.h>
+#include <time.h>
+#include <sys/types.h>
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
-#include <float.h>
-#include <math.h>
-
#ifdef HAVE_STRINGS_H
-#include <strings.h>
+# include <strings.h>
#endif
#if defined(HAVE_SYS_TIME_H)
-#include <sys/time.h>
+# include <sys/time.h>
#endif
-#include "timev.h"
#include "id.h"
+#include "internal.h"
+#include "internal/array.h"
+#include "internal/compar.h"
+#include "internal/numeric.h"
+#include "internal/rational.h"
+#include "internal/string.h"
+#include "internal/time.h"
+#include "internal/variable.h"
+#include "ruby/encoding.h"
+#include "timev.h"
static ID id_submicro, id_nano_num, id_nano_den, id_offset, id_zone;
static ID id_nanosecond, id_microsecond, id_millisecond, id_nsec, id_usec;
diff --git a/timev.h b/timev.h
index 6f124aa6bf..af97ed95b5 100644
--- a/timev.h
+++ b/timev.h
@@ -1,5 +1,6 @@
#ifndef RUBY_TIMEV_H
#define RUBY_TIMEV_H
+#include "ruby/ruby.h"
#if 0
struct vtm {/* dummy for TAGS */};
diff --git a/tool/mk_builtin_loader.rb b/tool/mk_builtin_loader.rb
index dcd4b93532..3d2a3430e0 100644
--- a/tool/mk_builtin_loader.rb
+++ b/tool/mk_builtin_loader.rb
@@ -127,13 +127,18 @@ def mk_builtin_header file
f.puts "// auto-generated file"
f.puts "// by #{__FILE__}"
f.puts "// with #{file}"
+ f.puts '#include "internal/compilers.h" /* for MAYBE_UNUSED */'
+ f.puts '#include "internal/warnings.h" /* for COMPILER_WARNING_PUSH */'
+ f.puts '#include "ruby/ruby.h" /* for VALUE */'
+ f.puts '#include "builtin.h" /* for RB_BUILTIN_FUNCTION */'
+ f.puts 'struct rb_execution_context_struct; /* in vm_core.h */'
f.puts
- lineno = 6
+ lineno = 11
line_file = file.gsub('\\', '/')
inlines.each{|cfunc_name, (body_lineno, text, params, func_name)|
if String === cfunc_name
- f.puts "static VALUE #{cfunc_name}(rb_execution_context_t *ec, const VALUE self) {"
+ f.puts "static VALUE #{cfunc_name}(struct rb_execution_context_struct *ec, const VALUE self) {"
lineno += 1
params.reverse_each.with_index{|param, i|
diff --git a/transcode.c b/transcode.c
index aeab90f9e6..a336f5d9ad 100644
--- a/transcode.c
+++ b/transcode.c
@@ -9,10 +9,18 @@
**********************************************************************/
-#include "ruby/encoding.h"
+#include "ruby/config.h"
+
+#include <ctype.h>
+
#include "internal.h"
+#include "internal/inits.h"
+#include "internal/object.h"
+#include "internal/string.h"
+#include "internal/transcode.h"
+#include "ruby/encoding.h"
+
#include "transcode_data.h"
-#include <ctype.h>
#define ENABLE_ECONV_NEWLINE_OPTION 1
diff --git a/transient_heap.c b/transient_heap.c
index 6e9cf6440e..3c1d9a3986 100644
--- a/transient_heap.c
+++ b/transient_heap.c
@@ -6,14 +6,20 @@
**********************************************************************/
-#include "ruby/ruby.h"
-#include "ruby/debug.h"
-#include "vm_debug.h"
+#include "debug_counter.h"
#include "gc.h"
#include "internal.h"
+#include "internal/gc.h"
+#include "internal/hash.h"
+#include "internal/sanitizers.h"
+#include "internal/static_assert.h"
+#include "internal/struct.h"
+#include "internal/variable.h"
+#include "ruby/debug.h"
+#include "ruby/ruby.h"
#include "ruby_assert.h"
#include "transient_heap.h"
-#include "debug_counter.h"
+#include "vm_debug.h"
#if USE_TRANSIENT_HEAP /* USE_TRANSIENT_HEAP */
/*
diff --git a/util.c b/util.c
index aa8e7ef3f2..08dbed105e 100644
--- a/util.c
+++ b/util.c
@@ -10,21 +10,24 @@
**********************************************************************/
#if defined __MINGW32__ || defined __MINGW64__
-#define MINGW_HAS_SECURE_API 1
+# define MINGW_HAS_SECURE_API 1
#endif
-#include "internal.h"
+#include "ruby/config.h"
#include <ctype.h>
-#include <stdio.h>
#include <errno.h>
-#include <math.h>
#include <float.h>
+#include <math.h>
+#include <stdio.h>
#ifdef _WIN32
-#include "missing/file.h"
+# include "missing/file.h"
#endif
+#include "internal.h"
+#include "internal/sanitizers.h"
+#include "internal/util.h"
#include "ruby/util.h"
const char ruby_hexdigits[] = "0123456789abcdef0123456789ABCDEF";
diff --git a/variable.c b/variable.c
index 42c4cb7cd4..46f7dea725 100644
--- a/variable.c
+++ b/variable.c
@@ -11,19 +11,30 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "ruby/st.h"
-#include "ruby/util.h"
-#include "internal.h"
-#include "id_table.h"
+#include "ruby/config.h"
+#include <stddef.h>
#include "constant.h"
+#include "debug_counter.h"
#include "id.h"
-#include "ccan/list/list.h"
#include "id_table.h"
-#include "debug_counter.h"
-#include "vm_core.h"
+#include "internal.h"
+#include "internal/class.h"
+#include "internal/compilers.h"
+#include "internal/error.h"
+#include "internal/eval.h"
+#include "internal/hash.h"
+#include "internal/re.h"
+#include "internal/symbol.h"
+#include "internal/stdbool.h"
+#include "ccan/list/list.h"
+#include "internal/thread.h"
+#include "internal/variable.h"
+#include "ruby/encoding.h"
+#include "ruby/st.h"
+#include "ruby/util.h"
#include "transient_heap.h"
#include "variable.h"
+#include "vm_core.h"
static struct rb_id_table *rb_global_tbl;
static ID autoload, classpath, tmp_classpath;
diff --git a/vm.c b/vm.c
index bb3ffae078..d4a1d4437e 100644
--- a/vm.c
+++ b/vm.c
@@ -8,17 +8,33 @@
**********************************************************************/
-#include "internal.h"
-#include "ruby/vm.h"
-#include "ruby/st.h"
-
#define vm_exec rb_vm_exec
+#include "eval_intern.h"
#include "gc.h"
+#include "internal.h"
+#include "internal/compile.h"
+#include "internal/cont.h"
+#include "internal/debug.h"
+#include "internal/error.h"
+#include "internal/eval.h"
+#include "internal/inits.h"
+#include "internal/mjit.h"
+#include "internal/object.h"
+#include "internal/parse.h"
+#include "internal/proc.h"
+#include "internal/re.h"
+#include "internal/symbol.h"
+#include "internal/vm.h"
+#include "iseq.h"
+#include "mjit.h"
+#include "ruby/st.h"
+#include "ruby/vm.h"
#include "vm_core.h"
#include "vm_debug.h"
-#include "iseq.h"
-#include "eval_intern.h"
+#include "vm_exec.h"
+#include "vm_insnhelper.h"
+
#include "builtin.h"
#ifndef MJIT_HEADER
@@ -338,9 +354,6 @@ extern VALUE rb_vm_invoke_bmethod(rb_execution_context_t *ec, rb_proc_t *proc, V
const rb_callable_method_entry_t *me);
static VALUE vm_invoke_proc(rb_execution_context_t *ec, rb_proc_t *proc, VALUE self, int argc, const VALUE *argv, int kw_splat, VALUE block_handler);
-#include "mjit.h"
-#include "vm_insnhelper.h"
-#include "vm_exec.h"
#include "vm_insnhelper.c"
#ifndef MJIT_HEADER
diff --git a/vm_backtrace.c b/vm_backtrace.c
index 2c9649a7c2..9bc56f731e 100644
--- a/vm_backtrace.c
+++ b/vm_backtrace.c
@@ -9,13 +9,13 @@
**********************************************************************/
-#include "ruby/encoding.h"
-#include "ruby/debug.h"
-#include "internal.h"
-
-#include "vm_core.h"
#include "eval_intern.h"
+#include "internal.h"
+#include "internal/vm.h"
#include "iseq.h"
+#include "ruby/debug.h"
+#include "ruby/encoding.h"
+#include "vm_core.h"
static VALUE rb_cBacktrace;
static VALUE rb_cBacktraceLocation;
diff --git a/vm_core.h b/vm_core.h
index 12c3ac3775..8807c23b6f 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -46,6 +46,19 @@
#define VMDEBUG 3
#endif
+#include "ruby/config.h"
+
+#include <stddef.h>
+#include <signal.h>
+
+#ifdef HAVE_STDARG_PROTOTYPES
+#include <stdarg.h>
+#define va_init_list(a,b) va_start((a),(b))
+#else
+#include <varargs.h>
+#define va_init_list(a,b) va_start((a))
+#endif
+
#include "ruby_assert.h"
#if VM_CHECK_MODE > 0
@@ -57,27 +70,21 @@
#define VM_UNREACHABLE(func) UNREACHABLE
#endif
-#define RUBY_VM_THREAD_MODEL 2
-
-/*
- * implementation selector of get_insn_info algorithm
- * 0: linear search
- * 1: binary search
- * 2: succinct bitvector
- */
-#ifndef VM_INSN_INFO_TABLE_IMPL
-# define VM_INSN_INFO_TABLE_IMPL 2
-#endif
-
-#include "ruby/ruby.h"
-#include "ruby/st.h"
+#include <setjmp.h>
-#include "node.h"
-#include "vm_opts.h"
#include "id.h"
+#include "internal.h"
+#include "internal/array.h"
+#include "internal/serial.h"
+#include "internal/stdbool.h"
+#include "ccan/list/list.h"
+#include "internal/vm.h"
#include "method.h"
+#include "node.h"
+#include "ruby/ruby.h"
+#include "ruby/st.h"
#include "ruby_atomic.h"
-#include "ccan/list/list.h"
+#include "vm_opts.h"
#include "ruby/thread_native.h"
#if defined(_WIN32)
@@ -86,8 +93,17 @@
#include "thread_pthread.h"
#endif
-#include <setjmp.h>
-#include <signal.h>
+#define RUBY_VM_THREAD_MODEL 2
+
+/*
+ * implementation selector of get_insn_info algorithm
+ * 0: linear search
+ * 1: binary search
+ * 2: succinct bitvector
+ */
+#ifndef VM_INSN_INFO_TABLE_IMPL
+# define VM_INSN_INFO_TABLE_IMPL 2
+#endif
#if defined(NSIG_MAX) /* POSIX issue 8 */
# undef NSIG
@@ -123,14 +139,6 @@
/* define to 0 to test old code path */
#define WAITPID_USE_SIGCHLD (RUBY_SIGCHLD || SIGCHLD_LOSSY)
-#ifdef HAVE_STDARG_PROTOTYPES
-#include <stdarg.h>
-#define va_init_list(a,b) va_start((a),(b))
-#else
-#include <varargs.h>
-#define va_init_list(a,b) va_start((a))
-#endif
-
#if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__)
# define USE_SIGALTSTACK
void *rb_register_sigaltstack(void);
diff --git a/vm_dump.c b/vm_dump.c
index c778e1b4dd..09051cfc32 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -8,27 +8,32 @@
**********************************************************************/
-
-#include "internal.h"
-#include "addr2line.h"
-#include "vm_core.h"
-#include "iseq.h"
-#include "gc.h"
+#include "ruby/config.h"
#ifdef HAVE_UCONTEXT_H
-#include <ucontext.h>
+# include <ucontext.h>
#endif
+
#ifdef __APPLE__
-#ifdef HAVE_LIBPROC_H
-#include <libproc.h>
-#endif
-#include <mach/vm_map.h>
-#include <mach/mach_init.h>
-#ifdef __LP64__
-#define vm_region_recurse vm_region_recurse_64
-#endif
+# ifdef HAVE_LIBPROC_H
+# include <libproc.h>
+# endif
+# include <mach/vm_map.h>
+# include <mach/mach_init.h>
+# ifdef __LP64__
+# define vm_region_recurse vm_region_recurse_64
+# endif
#endif
+#include "addr2line.h"
+#include "gc.h"
+#include "internal.h"
+#include "internal/variable.h"
+#include "internal/vm.h"
+#include "iseq.h"
+#include "vm_core.h"
+
+
/* see vm_insnhelper.h for the values */
#ifndef VMDEBUG
#define VMDEBUG 0
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 0cd4bdefe9..8cc47e15af 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -8,18 +8,29 @@
**********************************************************************/
-/* finish iseq array */
-#include "insns.inc"
-#ifndef MJIT_HEADER
-#include "insns_info.inc"
-#endif
+#include "ruby/config.h"
+
#include <math.h>
+
#include "constant.h"
+#include "debug_counter.h"
#include "internal.h"
+#include "internal/class.h"
+#include "internal/compar.h"
+#include "internal/hash.h"
+#include "internal/numeric.h"
+#include "internal/proc.h"
+#include "internal/random.h"
+#include "internal/variable.h"
#include "ruby/config.h"
-#include "debug_counter.h"
#include "variable.h"
+/* finish iseq array */
+#include "insns.inc"
+#ifndef MJIT_HEADER
+#include "insns_info.inc"
+#endif
+
extern rb_method_definition_t *rb_method_definition_create(rb_method_type_t type, ID mid);
extern void rb_method_definition_set(const rb_method_entry_t *me, rb_method_definition_t *def, void *opts);
extern int rb_method_definition_eq(const rb_method_definition_t *d1, const rb_method_definition_t *d2);
diff --git a/vm_trace.c b/vm_trace.c
index 9a604814c6..079795bfc6 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -21,13 +21,15 @@
*
*/
+#include "eval_intern.h"
#include "internal.h"
+#include "internal/hash.h"
+#include "internal/symbol.h"
+#include "iseq.h"
+#include "mjit.h"
#include "ruby/debug.h"
-
#include "vm_core.h"
-#include "mjit.h"
-#include "iseq.h"
-#include "eval_intern.h"
+
#include "builtin.h"
/* (1) trace mechanisms */
diff --git a/win32/dir.h b/win32/dir.h
index 29c4c1c6d5..a0759804f6 100644
--- a/win32/dir.h
+++ b/win32/dir.h
@@ -1,5 +1,8 @@
#ifndef RUBY_WIN32_DIR_H
#define RUBY_WIN32_DIR_H
+#include <stdint.h> /* for uint8_t */
+#include <esent.h> /* for WCHAR */
+#include "ruby/encoding.h" /* for rb_encoding */
#define DT_UNKNOWN 0
#define DT_DIR (S_IFDIR>>12)
diff --git a/win32/file.c b/win32/file.c
index 9d21370019..133b5fbdb0 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -5,6 +5,7 @@
#include "ruby/ruby.h"
#include "ruby/encoding.h"
#include "internal.h"
+#include "internal/error.h"
#include <winbase.h>
#include <wchar.h>
#include <shlwapi.h>
diff --git a/win32/win32.c b/win32/win32.c
index 247ac918d4..0fa3855fb3 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -55,6 +55,10 @@
#include "win32/file.h"
#include "id.h"
#include "internal.h"
+#include "internal/enc.h"
+#include "internal/object.h"
+#include "internal/static_assert.h"
+#include "internal/stdbool.h"
#include "encindex.h"
#define isdirsep(x) ((x) == '/' || (x) == '\\')