summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatoshi Tagomori <s-tagomori@sakura.ad.jp>2025-11-05 16:09:45 +0900
committerSatoshi Tagomori <tagomoris@gmail.com>2025-11-07 13:14:54 +0900
commitd2a587c79156275f66035d60bcc69882be61a3e1 (patch)
tree03d02d662031aa77e1445704c5f01e45bd2baa14
parentaaa1234702f0186b1cd7d2cea136eee20fc82153 (diff)
renaming internal data structures and functions from namespace to box
-rw-r--r--box.c589
-rw-r--r--builtin.c2
-rw-r--r--class.c212
-rw-r--r--dln.c2
-rw-r--r--eval.c4
-rw-r--r--eval_intern.h10
-rw-r--r--gc.c20
-rw-r--r--inits.c2
-rw-r--r--insns.def4
-rw-r--r--internal/box.h72
-rw-r--r--internal/class.h176
-rw-r--r--internal/inits.h10
-rw-r--r--internal/variable.h4
-rw-r--r--iseq.c2
-rw-r--r--load.c269
-rw-r--r--method.h2
-rw-r--r--mini_builtin.c2
-rw-r--r--proc.c22
-rw-r--r--ruby.c24
-rw-r--r--shape.c2
-rw-r--r--shape.h4
-rw-r--r--variable.c80
-rw-r--r--vm.c166
-rw-r--r--vm_core.h30
-rw-r--r--vm_dump.c76
-rw-r--r--vm_eval.c16
-rw-r--r--vm_method.c4
27 files changed, 900 insertions, 906 deletions
diff --git a/box.c b/box.c
index a9368ca744..f1290f60aa 100644
--- a/box.c
+++ b/box.c
@@ -24,7 +24,7 @@ VALUE rb_cNamespace = 0;
VALUE rb_cNamespaceEntry = 0;
VALUE rb_mNamespaceLoader = 0;
-static rb_namespace_t root_namespace_data = {
+static rb_box_t root_box_data = {
/* Initialize values lazily in Init_namespace() */
(VALUE)NULL, 0,
(VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL,
@@ -32,12 +32,12 @@ static rb_namespace_t root_namespace_data = {
false, false
};
-static rb_namespace_t * root_namespace = &root_namespace_data;
-static rb_namespace_t * main_namespace = 0;
+static rb_box_t * root_box = &root_box_data;
+static rb_box_t * main_box = 0;
static char *tmp_dir;
static bool tmp_dir_has_dirsep;
-#define NAMESPACE_TMP_PREFIX "_ruby_ns_"
+#define BOX_TMP_PREFIX "_ruby_box_"
#ifndef MAXPATHLEN
# define MAXPATHLEN 1024
@@ -49,156 +49,156 @@ static bool tmp_dir_has_dirsep;
# define DIRSEP "/"
#endif
-bool ruby_namespace_enabled = false; // extern
-bool ruby_namespace_init_done = false; // extern
-bool ruby_namespace_crashed = false; // extern, changed only in vm.c
+bool ruby_box_enabled = false; // extern
+bool ruby_box_init_done = false; // extern
+bool ruby_box_crashed = false; // extern, changed only in vm.c
VALUE rb_resolve_feature_path(VALUE klass, VALUE fname);
-static VALUE rb_namespace_inspect(VALUE obj);
+static VALUE rb_box_inspect(VALUE obj);
void
-rb_namespace_init_done(void)
+rb_box_init_done(void)
{
- ruby_namespace_init_done = true;
+ ruby_box_init_done = true;
}
-const rb_namespace_t *
-rb_root_namespace(void)
+const rb_box_t *
+rb_root_box(void)
{
- return root_namespace;
+ return root_box;
}
-const rb_namespace_t *
-rb_main_namespace(void)
+const rb_box_t *
+rb_main_box(void)
{
- return main_namespace;
+ return main_box;
}
-const rb_namespace_t *
-rb_current_namespace(void)
+const rb_box_t *
+rb_current_box(void)
{
/*
- * If RUBY_NAMESPACE is not set, the root namespace is the only available one.
+ * If RUBY_NAMESPACE is not set, the root box is the only available one.
*
- * Until the main_namespace is not initialized, the root namespace is
- * the only valid namespace.
+ * Until the main_box is not initialized, the root box is
+ * the only valid box.
* This early return is to avoid accessing EC before its setup.
*/
- if (!main_namespace)
- return root_namespace;
+ if (!main_box)
+ return root_box;
- return rb_vm_current_namespace(GET_EC());
+ return rb_vm_current_box(GET_EC());
}
-const rb_namespace_t *
-rb_loading_namespace(void)
+const rb_box_t *
+rb_loading_box(void)
{
- if (!main_namespace)
- return root_namespace;
+ if (!main_box)
+ return root_box;
- return rb_vm_loading_namespace(GET_EC());
+ return rb_vm_loading_box(GET_EC());
}
-const rb_namespace_t *
-rb_current_namespace_in_crash_report(void)
+const rb_box_t *
+rb_current_box_in_crash_report(void)
{
- if (ruby_namespace_crashed)
+ if (ruby_box_crashed)
return NULL;
- return rb_current_namespace();
+ return rb_current_box();
}
-static long namespace_id_counter = 0;
+static long box_id_counter = 0;
static long
-namespace_generate_id(void)
+box_generate_id(void)
{
long id;
RB_VM_LOCKING() {
- id = ++namespace_id_counter;
+ id = ++box_id_counter;
}
return id;
}
static VALUE
-namespace_main_to_s(VALUE obj)
+box_main_to_s(VALUE obj)
{
return rb_str_new2("main");
}
static void
-namespace_entry_initialize(rb_namespace_t *ns)
+box_entry_initialize(rb_box_t *box)
{
- const rb_namespace_t *root = rb_root_namespace();
+ const rb_box_t *root = rb_root_box();
// These will be updated immediately
- ns->ns_object = 0;
- ns->ns_id = 0;
-
- ns->top_self = rb_obj_alloc(rb_cObject);
- rb_define_singleton_method(ns->top_self, "to_s", namespace_main_to_s, 0);
- rb_define_alias(rb_singleton_class(ns->top_self), "inspect", "to_s");
- ns->load_path = rb_ary_dup(root->load_path);
- ns->expanded_load_path = rb_ary_dup(root->expanded_load_path);
- ns->load_path_snapshot = rb_ary_new();
- ns->load_path_check_cache = 0;
- ns->loaded_features = rb_ary_dup(root->loaded_features);
- ns->loaded_features_snapshot = rb_ary_new();
- ns->loaded_features_index = st_init_numtable();
- ns->loaded_features_realpaths = rb_hash_dup(root->loaded_features_realpaths);
- ns->loaded_features_realpath_map = rb_hash_dup(root->loaded_features_realpath_map);
- ns->loading_table = st_init_strtable();
- ns->ruby_dln_libmap = rb_hash_new_with_size(0);
- ns->gvar_tbl = rb_hash_new_with_size(0);
-
- ns->is_user = true;
- ns->is_optional = true;
+ box->box_object = 0;
+ box->box_id = 0;
+
+ box->top_self = rb_obj_alloc(rb_cObject);
+ rb_define_singleton_method(box->top_self, "to_s", box_main_to_s, 0);
+ rb_define_alias(rb_singleton_class(box->top_self), "inspect", "to_s");
+ box->load_path = rb_ary_dup(root->load_path);
+ box->expanded_load_path = rb_ary_dup(root->expanded_load_path);
+ box->load_path_snapshot = rb_ary_new();
+ box->load_path_check_cache = 0;
+ box->loaded_features = rb_ary_dup(root->loaded_features);
+ box->loaded_features_snapshot = rb_ary_new();
+ box->loaded_features_index = st_init_numtable();
+ box->loaded_features_realpaths = rb_hash_dup(root->loaded_features_realpaths);
+ box->loaded_features_realpath_map = rb_hash_dup(root->loaded_features_realpath_map);
+ box->loading_table = st_init_strtable();
+ box->ruby_dln_libmap = rb_hash_new_with_size(0);
+ box->gvar_tbl = rb_hash_new_with_size(0);
+
+ box->is_user = true;
+ box->is_optional = true;
}
void
-rb_namespace_gc_update_references(void *ptr)
+rb_box_gc_update_references(void *ptr)
{
- rb_namespace_t *ns = (rb_namespace_t *)ptr;
- if (!ns) return;
-
- if (ns->ns_object)
- ns->ns_object = rb_gc_location(ns->ns_object);
- if (ns->top_self)
- ns->top_self = rb_gc_location(ns->top_self);
- ns->load_path = rb_gc_location(ns->load_path);
- ns->expanded_load_path = rb_gc_location(ns->expanded_load_path);
- ns->load_path_snapshot = rb_gc_location(ns->load_path_snapshot);
- if (ns->load_path_check_cache) {
- ns->load_path_check_cache = rb_gc_location(ns->load_path_check_cache);
+ rb_box_t *box = (rb_box_t *)ptr;
+ if (!box) return;
+
+ if (box->box_object)
+ box->box_object = rb_gc_location(box->box_object);
+ if (box->top_self)
+ box->top_self = rb_gc_location(box->top_self);
+ box->load_path = rb_gc_location(box->load_path);
+ box->expanded_load_path = rb_gc_location(box->expanded_load_path);
+ box->load_path_snapshot = rb_gc_location(box->load_path_snapshot);
+ if (box->load_path_check_cache) {
+ box->load_path_check_cache = rb_gc_location(box->load_path_check_cache);
}
- ns->loaded_features = rb_gc_location(ns->loaded_features);
- ns->loaded_features_snapshot = rb_gc_location(ns->loaded_features_snapshot);
- ns->loaded_features_realpaths = rb_gc_location(ns->loaded_features_realpaths);
- ns->loaded_features_realpath_map = rb_gc_location(ns->loaded_features_realpath_map);
- ns->ruby_dln_libmap = rb_gc_location(ns->ruby_dln_libmap);
- ns->gvar_tbl = rb_gc_location(ns->gvar_tbl);
+ box->loaded_features = rb_gc_location(box->loaded_features);
+ box->loaded_features_snapshot = rb_gc_location(box->loaded_features_snapshot);
+ box->loaded_features_realpaths = rb_gc_location(box->loaded_features_realpaths);
+ box->loaded_features_realpath_map = rb_gc_location(box->loaded_features_realpath_map);
+ box->ruby_dln_libmap = rb_gc_location(box->ruby_dln_libmap);
+ box->gvar_tbl = rb_gc_location(box->gvar_tbl);
}
void
-rb_namespace_entry_mark(void *ptr)
+rb_box_entry_mark(void *ptr)
{
- const rb_namespace_t *ns = (rb_namespace_t *)ptr;
- if (!ns) return;
-
- rb_gc_mark(ns->ns_object);
- rb_gc_mark(ns->top_self);
- rb_gc_mark(ns->load_path);
- rb_gc_mark(ns->expanded_load_path);
- rb_gc_mark(ns->load_path_snapshot);
- rb_gc_mark(ns->load_path_check_cache);
- rb_gc_mark(ns->loaded_features);
- rb_gc_mark(ns->loaded_features_snapshot);
- rb_gc_mark(ns->loaded_features_realpaths);
- rb_gc_mark(ns->loaded_features_realpath_map);
- if (ns->loading_table) {
- rb_mark_tbl(ns->loading_table);
+ const rb_box_t *box = (rb_box_t *)ptr;
+ if (!box) return;
+
+ rb_gc_mark(box->box_object);
+ rb_gc_mark(box->top_self);
+ rb_gc_mark(box->load_path);
+ rb_gc_mark(box->expanded_load_path);
+ rb_gc_mark(box->load_path_snapshot);
+ rb_gc_mark(box->load_path_check_cache);
+ rb_gc_mark(box->loaded_features);
+ rb_gc_mark(box->loaded_features_snapshot);
+ rb_gc_mark(box->loaded_features_realpaths);
+ rb_gc_mark(box->loaded_features_realpath_map);
+ if (box->loading_table) {
+ rb_mark_tbl(box->loading_table);
}
- rb_gc_mark(ns->ruby_dln_libmap);
- rb_gc_mark(ns->gvar_tbl);
+ rb_gc_mark(box->ruby_dln_libmap);
+ rb_gc_mark(box->gvar_tbl);
}
static int
@@ -218,186 +218,185 @@ free_loaded_feature_index_i(st_data_t key, st_data_t value, st_data_t arg)
}
static void
-namespace_root_free(void *ptr)
+box_root_free(void *ptr)
{
- rb_namespace_t *ns = (rb_namespace_t *)ptr;
- if (ns->loading_table) {
- st_foreach(ns->loading_table, free_loading_table_entry, 0);
- st_free_table(ns->loading_table);
- ns->loading_table = 0;
+ rb_box_t *box = (rb_box_t *)ptr;
+ if (box->loading_table) {
+ st_foreach(box->loading_table, free_loading_table_entry, 0);
+ st_free_table(box->loading_table);
+ box->loading_table = 0;
}
- if (ns->loaded_features_index) {
- st_foreach(ns->loaded_features_index, free_loaded_feature_index_i, 0);
- st_free_table(ns->loaded_features_index);
+ if (box->loaded_features_index) {
+ st_foreach(box->loaded_features_index, free_loaded_feature_index_i, 0);
+ st_free_table(box->loaded_features_index);
}
}
static void
-namespace_entry_free(void *ptr)
+box_entry_free(void *ptr)
{
- namespace_root_free(ptr);
+ box_root_free(ptr);
xfree(ptr);
}
static size_t
-namespace_entry_memsize(const void *ptr)
+box_entry_memsize(const void *ptr)
{
- const rb_namespace_t *ns = (const rb_namespace_t *)ptr;
- return sizeof(rb_namespace_t) + \
- rb_st_memsize(ns->loaded_features_index) + \
- rb_st_memsize(ns->loading_table);
+ const rb_box_t *box = (const rb_box_t *)ptr;
+ return sizeof(rb_box_t) + \
+ rb_st_memsize(box->loaded_features_index) + \
+ rb_st_memsize(box->loading_table);
}
-const rb_data_type_t rb_namespace_data_type = {
+const rb_data_type_t rb_box_data_type = {
"Namespace::Entry",
{
- rb_namespace_entry_mark,
- namespace_entry_free,
- namespace_entry_memsize,
- rb_namespace_gc_update_references,
+ rb_box_entry_mark,
+ box_entry_free,
+ box_entry_memsize,
+ rb_box_gc_update_references,
},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY // TODO: enable RUBY_TYPED_WB_PROTECTED when inserting write barriers
};
-const rb_data_type_t rb_root_namespace_data_type = {
+const rb_data_type_t rb_root_box_data_type = {
"Namespace::Root",
{
- rb_namespace_entry_mark,
- namespace_root_free,
- namespace_entry_memsize,
- rb_namespace_gc_update_references,
+ rb_box_entry_mark,
+ box_root_free,
+ box_entry_memsize,
+ rb_box_gc_update_references,
},
- &rb_namespace_data_type, 0, RUBY_TYPED_FREE_IMMEDIATELY // TODO: enable RUBY_TYPED_WB_PROTECTED when inserting write barriers
+ &rb_box_data_type, 0, RUBY_TYPED_FREE_IMMEDIATELY // TODO: enable RUBY_TYPED_WB_PROTECTED when inserting write barriers
};
VALUE
-rb_namespace_entry_alloc(VALUE klass)
+rb_box_entry_alloc(VALUE klass)
{
- rb_namespace_t *entry;
- VALUE obj = TypedData_Make_Struct(klass, rb_namespace_t, &rb_namespace_data_type, entry);
- namespace_entry_initialize(entry);
+ rb_box_t *entry;
+ VALUE obj = TypedData_Make_Struct(klass, rb_box_t, &rb_box_data_type, entry);
+ box_entry_initialize(entry);
return obj;
}
-static rb_namespace_t *
-get_namespace_struct_internal(VALUE entry)
+static rb_box_t *
+get_box_struct_internal(VALUE entry)
{
- rb_namespace_t *sval;
- TypedData_Get_Struct(entry, rb_namespace_t, &rb_namespace_data_type, sval);
+ rb_box_t *sval;
+ TypedData_Get_Struct(entry, rb_box_t, &rb_box_data_type, sval);
return sval;
}
-rb_namespace_t *
-rb_get_namespace_t(VALUE namespace)
+rb_box_t *
+rb_get_box_t(VALUE box)
{
VALUE entry;
- ID id_namespace_entry;
+ ID id_box_entry;
- VM_ASSERT(namespace);
+ VM_ASSERT(box);
- if (NIL_P(namespace))
- return root_namespace;
+ if (NIL_P(box))
+ return root_box;
- VM_ASSERT(NAMESPACE_OBJ_P(namespace));
+ VM_ASSERT(BOX_OBJ_P(box));
- CONST_ID(id_namespace_entry, "__namespace_entry__");
- entry = rb_attr_get(namespace, id_namespace_entry);
- return get_namespace_struct_internal(entry);
+ CONST_ID(id_box_entry, "__box_entry__");
+ entry = rb_attr_get(box, id_box_entry);
+ return get_box_struct_internal(entry);
}
VALUE
-rb_get_namespace_object(rb_namespace_t *ns)
+rb_get_box_object(rb_box_t *box)
{
- VM_ASSERT(ns && ns->ns_object);
- return ns->ns_object;
+ VM_ASSERT(box && box->box_object);
+ return box->box_object;
}
/*
* call-seq:
- * Namespace.new -> new_namespace
+ * Namespace.new -> new_box
*
- * Returns a new Namespace object.
+ * Returns a new Ruby::Box object.
*/
static VALUE
-namespace_initialize(VALUE namespace)
+box_initialize(VALUE box_value)
{
- rb_namespace_t *ns;
+ rb_box_t *box;
rb_classext_t *object_classext;
VALUE entry;
- ID id_namespace_entry;
- CONST_ID(id_namespace_entry, "__namespace_entry__");
+ ID id_box_entry;
+ CONST_ID(id_box_entry, "__box_entry__");
- if (!rb_namespace_available()) {
+ if (!rb_box_available()) {
rb_raise(rb_eRuntimeError, "Namespace is disabled. Set RUBY_NAMESPACE=1 environment variable to use Namespace.");
}
entry = rb_class_new_instance_pass_kw(0, NULL, rb_cNamespaceEntry);
- ns = get_namespace_struct_internal(entry);
+ box = get_box_struct_internal(entry);
- ns->ns_object = namespace;
- ns->ns_id = namespace_generate_id();
- rb_define_singleton_method(ns->load_path, "resolve_feature_path", rb_resolve_feature_path, 1);
+ box->box_object = box_value;
+ box->box_id = box_generate_id();
+ rb_define_singleton_method(box->load_path, "resolve_feature_path", rb_resolve_feature_path, 1);
- // Set the Namespace object unique/consistent from any namespaces to have just single
- // constant table from any view of every (including main) namespace.
- // If a code in the namespace adds a constant, the constant will be visible even from root/main.
- RCLASS_SET_PRIME_CLASSEXT_WRITABLE(namespace, true);
+ // Set the Ruby::Box object unique/consistent from any boxes to have just single
+ // constant table from any view of every (including main) box.
+ // If a code in the box adds a constant, the constant will be visible even from root/main.
+ RCLASS_SET_PRIME_CLASSEXT_WRITABLE(box_value, true);
// Get a clean constant table of Object even by writable one
// because ns was just created, so it has not touched any constants yet.
- object_classext = RCLASS_EXT_WRITABLE_IN_NS(rb_cObject, ns);
- RCLASS_SET_CONST_TBL(namespace, RCLASSEXT_CONST_TBL(object_classext), true);
+ object_classext = RCLASS_EXT_WRITABLE_IN_BOX(rb_cObject, box);
+ RCLASS_SET_CONST_TBL(box_value, RCLASSEXT_CONST_TBL(object_classext), true);
- rb_ivar_set(namespace, id_namespace_entry, entry);
+ rb_ivar_set(box_value, id_box_entry, entry);
- return namespace;
+ return box_value;
}
/*
* call-seq:
* Namespace.enabled? -> true or false
*
- * Returns +true+ if namespace is enabled.
+ * Returns +true+ if Ruby::Box is enabled.
*/
static VALUE
-rb_namespace_s_getenabled(VALUE recv)
+rb_box_s_getenabled(VALUE recv)
{
- return RBOOL(rb_namespace_available());
+ return RBOOL(rb_box_available());
}
/*
* call-seq:
- * Namespace.current -> namespace, nil or false
+ * Namespace.current -> box, nil or false
*
- * Returns the current namespace.
- * Returns +nil+ if it is the built-in namespace.
- * Returns +false+ if namespace is not enabled.
+ * Returns the current box.
+ * Returns +nil+ if Ruby Box is not enabled.
*/
static VALUE
-rb_namespace_s_current(VALUE recv)
+rb_box_s_current(VALUE recv)
{
- const rb_namespace_t *ns;
+ const rb_box_t *box;
- if (!rb_namespace_available())
+ if (!rb_box_available())
return Qnil;
- ns = rb_vm_current_namespace(GET_EC());
- VM_ASSERT(ns && ns->ns_object);
- return ns->ns_object;
+ box = rb_vm_current_box(GET_EC());
+ VM_ASSERT(box && box->box_object);
+ return box->box_object;
}
/*
* call-seq:
* load_path -> array
*
- * Returns namespace local load path.
+ * Returns box local load path.
*/
static VALUE
-rb_namespace_load_path(VALUE namespace)
+rb_box_load_path(VALUE box)
{
- VM_ASSERT(NAMESPACE_OBJ_P(namespace));
- return rb_get_namespace_t(namespace)->load_path;
+ VM_ASSERT(BOX_OBJ_P(box));
+ return rb_get_box_t(box)->load_path;
}
#ifdef _WIN32
@@ -480,12 +479,12 @@ system_tmpdir(void)
/* end of copy */
static int
-sprint_ext_filename(char *str, size_t size, long namespace_id, const char *prefix, const char *basename)
+sprint_ext_filename(char *str, size_t size, long box_id, const char *prefix, const char *basename)
{
if (tmp_dir_has_dirsep) {
- return snprintf(str, size, "%s%sp%"PRI_PIDT_PREFIX"u_%ld_%s", tmp_dir, prefix, getpid(), namespace_id, basename);
+ return snprintf(str, size, "%s%sp%"PRI_PIDT_PREFIX"u_%ld_%s", tmp_dir, prefix, getpid(), box_id, basename);
}
- return snprintf(str, size, "%s%s%sp%"PRI_PIDT_PREFIX"u_%ld_%s", tmp_dir, DIRSEP, prefix, getpid(), namespace_id, basename);
+ return snprintf(str, size, "%s%s%sp%"PRI_PIDT_PREFIX"u_%ld_%s", tmp_dir, DIRSEP, prefix, getpid(), box_id, basename);
}
#ifdef _WIN32
@@ -661,19 +660,19 @@ escaped_basename(const char *path, const char *fname, char *rvalue, size_t rsize
}
VALUE
-rb_namespace_local_extension(VALUE namespace, VALUE fname, VALUE path)
+rb_box_local_extension(VALUE box_value, VALUE fname, VALUE path)
{
char ext_path[MAXPATHLEN], fname2[MAXPATHLEN], basename[MAXPATHLEN];
int copy_error, wrote;
char *src_path = RSTRING_PTR(path), *fname_ptr = RSTRING_PTR(fname);
- rb_namespace_t *ns = rb_get_namespace_t(namespace);
+ rb_box_t *box = rb_get_box_t(box_value);
fname_without_suffix(fname_ptr, fname2, sizeof(fname2));
escaped_basename(src_path, fname2, basename, sizeof(basename));
- wrote = sprint_ext_filename(ext_path, sizeof(ext_path), ns->ns_id, NAMESPACE_TMP_PREFIX, basename);
+ wrote = sprint_ext_filename(ext_path, sizeof(ext_path), box->box_id, BOX_TMP_PREFIX, basename);
if (wrote >= (int)sizeof(ext_path)) {
- rb_bug("Extension file path in namespace was too long");
+ rb_bug("Extension file path in the box was too long");
}
copy_error = copy_ext_file(src_path, ext_path);
if (copy_error) {
@@ -683,7 +682,7 @@ rb_namespace_local_extension(VALUE namespace, VALUE fname, VALUE path)
#else
copy_ext_file_error(message, sizeof(message), copy_error, src_path, ext_path);
#endif
- rb_raise(rb_eLoadError, "can't prepare the extension file for namespaces (%s from %s): %s", ext_path, src_path, message);
+ rb_raise(rb_eLoadError, "can't prepare the extension file for Ruby Box (%s from %s): %s", ext_path, src_path, message);
}
// TODO: register the path to be clean-uped
return rb_str_new_cstr(ext_path);
@@ -694,40 +693,40 @@ rb_namespace_local_extension(VALUE namespace, VALUE fname, VALUE path)
// And it requires calling dlclose before deleting it.
static VALUE
-rb_namespace_load(int argc, VALUE *argv, VALUE namespace)
+rb_box_load(int argc, VALUE *argv, VALUE box)
{
VALUE fname, wrap;
rb_scan_args(argc, argv, "11", &fname, &wrap);
- rb_vm_frame_flag_set_ns_require(GET_EC());
+ rb_vm_frame_flag_set_box_require(GET_EC());
VALUE args = rb_ary_new_from_args(2, fname, wrap);
return rb_load_entrypoint(args);
}
static VALUE
-rb_namespace_require(VALUE namespace, VALUE fname)
+rb_box_require(VALUE box, VALUE fname)
{
- rb_vm_frame_flag_set_ns_require(GET_EC());
+ rb_vm_frame_flag_set_box_require(GET_EC());
return rb_require_string(fname);
}
static VALUE
-rb_namespace_require_relative(VALUE namespace, VALUE fname)
+rb_box_require_relative(VALUE box, VALUE fname)
{
- rb_vm_frame_flag_set_ns_require(GET_EC());
+ rb_vm_frame_flag_set_box_require(GET_EC());
return rb_require_relative_entrypoint(fname);
}
static void
-initialize_root_namespace(void)
+initialize_root_box(void)
{
- VALUE root_namespace, entry;
- ID id_namespace_entry;
+ VALUE root_box, entry;
+ ID id_box_entry;
rb_vm_t *vm = GET_VM();
- rb_namespace_t *root = (rb_namespace_t *)rb_root_namespace();
+ rb_box_t *root = (rb_box_t *)rb_root_box();
root->load_path = rb_ary_new();
root->expanded_load_path = rb_ary_hidden_new(0);
@@ -746,98 +745,98 @@ initialize_root_namespace(void)
root->ruby_dln_libmap = rb_hash_new_with_size(0);
root->gvar_tbl = rb_hash_new_with_size(0);
- vm->root_namespace = root;
+ vm->root_box = root;
- if (rb_namespace_available()) {
- CONST_ID(id_namespace_entry, "__namespace_entry__");
+ if (rb_box_available()) {
+ CONST_ID(id_box_entry, "__box_entry__");
- root_namespace = rb_obj_alloc(rb_cNamespace);
- RCLASS_SET_PRIME_CLASSEXT_WRITABLE(root_namespace, true);
- RCLASS_SET_CONST_TBL(root_namespace, RCLASSEXT_CONST_TBL(RCLASS_EXT_PRIME(rb_cObject)), true);
+ root_box = rb_obj_alloc(rb_cNamespace);
+ RCLASS_SET_PRIME_CLASSEXT_WRITABLE(root_box, true);
+ RCLASS_SET_CONST_TBL(root_box, RCLASSEXT_CONST_TBL(RCLASS_EXT_PRIME(rb_cObject)), true);
- root->ns_id = namespace_generate_id();
- root->ns_object = root_namespace;
+ root->box_id = box_generate_id();
+ root->box_object = root_box;
- entry = TypedData_Wrap_Struct(rb_cNamespaceEntry, &rb_root_namespace_data_type, root);
- rb_ivar_set(root_namespace, id_namespace_entry, entry);
+ entry = TypedData_Wrap_Struct(rb_cNamespaceEntry, &rb_root_box_data_type, root);
+ rb_ivar_set(root_box, id_box_entry, entry);
}
else {
- root->ns_id = 1;
- root->ns_object = Qnil;
+ root->box_id = 1;
+ root->box_object = Qnil;
}
}
static VALUE
-rb_namespace_eval(VALUE namespace, VALUE str)
+rb_box_eval(VALUE box_value, VALUE str)
{
const rb_iseq_t *iseq;
- const rb_namespace_t *ns;
+ const rb_box_t *box;
StringValue(str);
iseq = rb_iseq_compile_iseq(str, rb_str_new_cstr("eval"));
VM_ASSERT(iseq);
- ns = (const rb_namespace_t *)rb_get_namespace_t(namespace);
+ box = (const rb_box_t *)rb_get_box_t(box_value);
- return rb_iseq_eval(iseq, ns);
+ return rb_iseq_eval(iseq, box);
}
-static int namespace_experimental_warned = 0;
+static int box_experimental_warned = 0;
void
-rb_initialize_main_namespace(void)
+rb_initialize_main_box(void)
{
- rb_namespace_t *ns;
- VALUE main_ns;
+ rb_box_t *box;
+ VALUE main_box_value;
rb_vm_t *vm = GET_VM();
- VM_ASSERT(rb_namespace_available());
+ VM_ASSERT(rb_box_available());
- if (!namespace_experimental_warned) {
+ if (!box_experimental_warned) {
rb_category_warn(RB_WARN_CATEGORY_EXPERIMENTAL,
- "Namespace is experimental, and the behavior may change in the future!\n"
- "See doc/namespace.md for known issues, etc.");
- namespace_experimental_warned = 1;
+ "Ruby::Box is experimental, and the behavior may change in the future!\n"
+ "See doc/box.md for known issues, etc.");
+ box_experimental_warned = 1;
}
- main_ns = rb_class_new_instance(0, NULL, rb_cNamespace);
- VM_ASSERT(NAMESPACE_OBJ_P(main_ns));
- ns = rb_get_namespace_t(main_ns);
- ns->ns_object = main_ns;
- ns->is_user = true;
- ns->is_optional = false;
+ main_box_value = rb_class_new_instance(0, NULL, rb_cNamespace);
+ VM_ASSERT(BOX_OBJ_P(main_box_value));
+ box = rb_get_box_t(main_box_value);
+ box->box_object = main_box_value;
+ box->is_user = true;
+ box->is_optional = false;
- rb_const_set(rb_cNamespace, rb_intern("MAIN"), main_ns);
+ rb_const_set(rb_cNamespace, rb_intern("MAIN"), main_box_value);
- vm->main_namespace = main_namespace = ns;
+ vm->main_box = main_box = box;
// create the writable classext of ::Object explicitly to finalize the set of visible top-level constants
- RCLASS_EXT_WRITABLE_IN_NS(rb_cObject, ns);
+ RCLASS_EXT_WRITABLE_IN_BOX(rb_cObject, box);
}
static VALUE
-rb_namespace_inspect(VALUE obj)
+rb_box_inspect(VALUE obj)
{
- rb_namespace_t *ns;
+ rb_box_t *box;
VALUE r;
if (obj == Qfalse) {
r = rb_str_new_cstr("#<Namespace:root>");
return r;
}
- ns = rb_get_namespace_t(obj);
+ box = rb_get_box_t(obj);
r = rb_str_new_cstr("#<Namespace:");
- rb_str_concat(r, rb_funcall(LONG2NUM(ns->ns_id), rb_intern("to_s"), 0));
- if (NAMESPACE_ROOT_P(ns)) {
+ rb_str_concat(r, rb_funcall(LONG2NUM(box->box_id), rb_intern("to_s"), 0));
+ if (BOX_ROOT_P(box)) {
rb_str_cat_cstr(r, ",root");
}
- if (NAMESPACE_USER_P(ns)) {
+ if (BOX_USER_P(box)) {
rb_str_cat_cstr(r, ",user");
}
- if (NAMESPACE_MAIN_P(ns)) {
+ if (BOX_MAIN_P(box)) {
rb_str_cat_cstr(r, ",main");
}
- else if (NAMESPACE_OPTIONAL_P(ns)) {
+ else if (BOX_OPTIONAL_P(box)) {
rb_str_cat_cstr(r, ",optional");
}
rb_str_cat_cstr(r, ">");
@@ -845,65 +844,65 @@ rb_namespace_inspect(VALUE obj)
}
static VALUE
-rb_namespace_loading_func(int argc, VALUE *argv, VALUE _self)
+rb_box_loading_func(int argc, VALUE *argv, VALUE _self)
{
- rb_vm_frame_flag_set_ns_require(GET_EC());
+ rb_vm_frame_flag_set_box_require(GET_EC());
return rb_call_super(argc, argv);
}
static void
-namespace_define_loader_method(const char *name)
+box_define_loader_method(const char *name)
{
- rb_define_private_method(rb_mNamespaceLoader, name, rb_namespace_loading_func, -1);
- rb_define_singleton_method(rb_mNamespaceLoader, name, rb_namespace_loading_func, -1);
+ rb_define_private_method(rb_mNamespaceLoader, name, rb_box_loading_func, -1);
+ rb_define_singleton_method(rb_mNamespaceLoader, name, rb_box_loading_func, -1);
}
void
-Init_root_namespace(void)
+Init_root_box(void)
{
- root_namespace->loading_table = st_init_strtable();
+ root_box->loading_table = st_init_strtable();
}
void
-Init_enable_namespace(void)
+Init_enable_box(void)
{
const char *env = getenv("RUBY_NAMESPACE");
if (env && strlen(env) == 1 && env[0] == '1') {
- ruby_namespace_enabled = true;
+ ruby_box_enabled = true;
}
else {
- ruby_namespace_init_done = true;
+ ruby_box_init_done = true;
}
}
/* :nodoc: */
static VALUE
-rb_namespace_s_root(VALUE recv)
+rb_box_s_root(VALUE recv)
{
- return root_namespace->ns_object;
+ return root_box->box_object;
}
/* :nodoc: */
static VALUE
-rb_namespace_s_main(VALUE recv)
+rb_box_s_main(VALUE recv)
{
- return main_namespace->ns_object;
+ return main_box->box_object;
}
/* :nodoc: */
static VALUE
-rb_namespace_root_p(VALUE namespace)
+rb_box_root_p(VALUE box_value)
{
- const rb_namespace_t *ns = (const rb_namespace_t *)rb_get_namespace_t(namespace);
- return RBOOL(NAMESPACE_ROOT_P(ns));
+ const rb_box_t *box = (const rb_box_t *)rb_get_box_t(box_value);
+ return RBOOL(BOX_ROOT_P(box));
}
/* :nodoc: */
static VALUE
-rb_namespace_main_p(VALUE namespace)
+rb_box_main_p(VALUE box_value)
{
- const rb_namespace_t *ns = (const rb_namespace_t *)rb_get_namespace_t(namespace);
- return RBOOL(NAMESPACE_MAIN_P(ns));
+ const rb_box_t *box = (const rb_box_t *)rb_get_box_t(box_value);
+ return RBOOL(BOX_MAIN_P(box));
}
#if RUBY_DEBUG
@@ -940,14 +939,14 @@ dump_classext_constants_i(ID mid, VALUE _val, void *data)
}
static void
-dump_classext_i(rb_classext_t *ext, bool is_prime, VALUE _ns, void *data)
+dump_classext_i(rb_classext_t *ext, bool is_prime, VALUE _recv, void *data)
{
char buf[4096];
struct rb_id_table *tbl;
VALUE ary, res = (VALUE)data;
- snprintf(buf, 4096, "Namespace %ld:%s classext %p\n",
- RCLASSEXT_NS(ext)->ns_id, is_prime ? " prime" : "", (void *)ext);
+ snprintf(buf, 4096, "Ruby::Box %ld:%s classext %p\n",
+ RCLASSEXT_BOX(ext)->box_id, is_prime ? " prime" : "", (void *)ext);
rb_str_cat_cstr(res, buf);
snprintf(buf, 2048, " Super: %s\n", classname(RCLASSEXT_SUPER(ext)));
@@ -989,13 +988,13 @@ rb_f_dump_classext(VALUE recv, VALUE klass)
/*
* The desired output String value is:
* Class: 0x88800932 (String) [singleton]
- * Prime classext namespace(2,main), readable(t), writable(f)
+ * Prime classext box(2,main), readable(t), writable(f)
* Non-prime classexts: 3
- * Namespace 2: prime classext 0x88800933
+ * Box 2: prime classext 0x88800933
* Super: Object
* Methods(43): aaaaa, bbbb, cccc, dddd, eeeee, ffff, gggg, hhhhh, ...
* Constants(12): FOO, Bar, ...
- * Namespace 5: classext 0x88800934
+ * Box 5: classext 0x88800934
* Super: Object
* Methods(43): aaaaa, bbbb, cccc, dddd, eeeee, ffff, gggg, hhhhh, ...
* Constants(12): FOO, Bar, ...
@@ -1003,7 +1002,7 @@ rb_f_dump_classext(VALUE recv, VALUE klass)
char buf[2048];
VALUE res;
const rb_classext_t *ext;
- const rb_namespace_t *ns;
+ const rb_box_t *box;
st_table *classext_tbl;
if (!(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_MODULE))) {
@@ -1021,10 +1020,10 @@ rb_f_dump_classext(VALUE recv, VALUE klass)
res = rb_str_new_cstr(buf);
ext = RCLASS_EXT_PRIME(klass);
- ns = RCLASSEXT_NS(ext);
- snprintf(buf, 2048, "Prime classext namespace(%ld,%s), readable(%s), writable(%s)\n",
- ns->ns_id,
- NAMESPACE_ROOT_P(ns) ? "root" : (NAMESPACE_MAIN_P(ns) ? "main" : "optional"),
+ box = RCLASSEXT_BOX(ext);
+ snprintf(buf, 2048, "Prime classext box(%ld,%s), readable(%s), writable(%s)\n",
+ box->box_id,
+ BOX_ROOT_P(box) ? "root" : (BOX_MAIN_P(box) ? "main" : "optional"),
RCLASS_PRIME_CLASSEXT_READABLE_P(klass) ? "t" : "f",
RCLASS_PRIME_CLASSEXT_WRITABLE_P(klass) ? "t" : "f");
rb_str_cat_cstr(res, buf);
@@ -1046,54 +1045,54 @@ rb_f_dump_classext(VALUE recv, VALUE klass)
#endif /* RUBY_DEBUG */
/*
- * Document-class: Namespace
+ * Document-class: Ruby::Box
*
- * Namespace is designed to provide separated spaces in a Ruby
+ * Ruby::Box is designed to provide separated spaces in a Ruby
* process, to isolate applications and libraries.
- * See {Namespace}[rdoc-ref:namespace.md].
+ * See {Ruby::Box}[rdoc-ref:box.md].
*/
void
-Init_Namespace(void)
+Init_Box(void)
{
tmp_dir = system_tmpdir();
tmp_dir_has_dirsep = (strcmp(tmp_dir + (strlen(tmp_dir) - strlen(DIRSEP)), DIRSEP) == 0);
rb_cNamespace = rb_define_class("Namespace", rb_cModule);
- rb_define_method(rb_cNamespace, "initialize", namespace_initialize, 0);
+ rb_define_method(rb_cNamespace, "initialize", box_initialize, 0);
/* :nodoc: */
rb_cNamespaceEntry = rb_define_class_under(rb_cNamespace, "Entry", rb_cObject);
- rb_define_alloc_func(rb_cNamespaceEntry, rb_namespace_entry_alloc);
+ rb_define_alloc_func(rb_cNamespaceEntry, rb_box_entry_alloc);
- initialize_root_namespace();
+ initialize_root_box();
/* :nodoc: */
rb_mNamespaceLoader = rb_define_module_under(rb_cNamespace, "Loader");
- namespace_define_loader_method("require");
- namespace_define_loader_method("require_relative");
- namespace_define_loader_method("load");
+ box_define_loader_method("require");
+ box_define_loader_method("require_relative");
+ box_define_loader_method("load");
- if (rb_namespace_available()) {
+ if (rb_box_available()) {
rb_include_module(rb_cObject, rb_mNamespaceLoader);
- rb_define_singleton_method(rb_cNamespace, "root", rb_namespace_s_root, 0);
- rb_define_singleton_method(rb_cNamespace, "main", rb_namespace_s_main, 0);
- rb_define_method(rb_cNamespace, "root?", rb_namespace_root_p, 0);
- rb_define_method(rb_cNamespace, "main?", rb_namespace_main_p, 0);
+ rb_define_singleton_method(rb_cNamespace, "root", rb_box_s_root, 0);
+ rb_define_singleton_method(rb_cNamespace, "main", rb_box_s_main, 0);
+ rb_define_method(rb_cNamespace, "root?", rb_box_root_p, 0);
+ rb_define_method(rb_cNamespace, "main?", rb_box_main_p, 0);
#if RUBY_DEBUG
rb_define_global_function("dump_classext", rb_f_dump_classext, 1);
#endif
}
- rb_define_singleton_method(rb_cNamespace, "enabled?", rb_namespace_s_getenabled, 0);
- rb_define_singleton_method(rb_cNamespace, "current", rb_namespace_s_current, 0);
+ rb_define_singleton_method(rb_cNamespace, "enabled?", rb_box_s_getenabled, 0);
+ rb_define_singleton_method(rb_cNamespace, "current", rb_box_s_current, 0);
- rb_define_method(rb_cNamespace, "load_path", rb_namespace_load_path, 0);
- rb_define_method(rb_cNamespace, "load", rb_namespace_load, -1);
- rb_define_method(rb_cNamespace, "require", rb_namespace_require, 1);
- rb_define_method(rb_cNamespace, "require_relative", rb_namespace_require_relative, 1);
- rb_define_method(rb_cNamespace, "eval", rb_namespace_eval, 1);
+ rb_define_method(rb_cNamespace, "load_path", rb_box_load_path, 0);
+ rb_define_method(rb_cNamespace, "load", rb_box_load, -1);
+ rb_define_method(rb_cNamespace, "require", rb_box_require, 1);
+ rb_define_method(rb_cNamespace, "require_relative", rb_box_require_relative, 1);
+ rb_define_method(rb_cNamespace, "eval", rb_box_eval, 1);
- rb_define_method(rb_cNamespace, "inspect", rb_namespace_inspect, 0);
+ rb_define_method(rb_cNamespace, "inspect", rb_box_inspect, 0);
}
diff --git a/builtin.c b/builtin.c
index 657143a739..6cc9790466 100644
--- a/builtin.c
+++ b/builtin.c
@@ -51,7 +51,7 @@ load_with_builtin_functions(const char *feature_name, const struct rb_builtin_fu
vm->builtin_function_table = NULL;
// exec
- rb_iseq_eval(rb_iseq_check(iseq), rb_root_namespace()); // builtin functions are loaded in the root namespace
+ rb_iseq_eval(rb_iseq_check(iseq), rb_root_box()); // builtin functions are loaded in the root box
}
void
diff --git a/class.c b/class.c
index 8c3c91cf7a..16ebd3b889 100644
--- a/class.c
+++ b/class.c
@@ -41,21 +41,21 @@
* 1: RUBY_FL_SINGLETON
* This class is a singleton class.
* 2: RCLASS_PRIME_CLASSEXT_PRIME_WRITABLE
- * This class's prime classext is the only classext and writable from any namespaces.
- * If unset, the prime classext is writable only from the root namespace.
+ * This class's prime classext is the only classext and writable from any boxes.
+ * If unset, the prime classext is writable only from the root box.
* 3: RCLASS_IS_INITIALIZED
* Class has been initialized.
- * 4: RCLASS_NAMESPACEABLE
- * Is a builtin class that may be namespaced. It larger than a normal class.
+ * 4: RCLASS_BOXABLE
+ * Is a builtin class that may be boxed. It larger than a normal class.
*/
/* Flags of T_ICLASS
*
* 2: RCLASS_PRIME_CLASSEXT_PRIME_WRITABLE
- * This module's prime classext is the only classext and writable from any namespaces.
- * If unset, the prime classext is writable only from the root namespace.
- * 4: RCLASS_NAMESPACEABLE
- * Is a builtin class that may be namespaced. It larger than a normal class.
+ * This module's prime classext is the only classext and writable from any boxes.
+ * If unset, the prime classext is writable only from the root box.
+ * 4: RCLASS_BOXABLE
+ * Is a builtin class that may be boxed. It larger than a normal class.
*/
/* Flags of T_MODULE
@@ -66,12 +66,12 @@
* 1: <reserved>
* Ensures that RUBY_FL_SINGLETON is never set on a T_MODULE. See `rb_class_real`.
* 2: RCLASS_PRIME_CLASSEXT_PRIME_WRITABLE
- * This module's prime classext is the only classext and writable from any namespaces.
- * If unset, the prime classext is writable only from the root namespace.
+ * This module's prime classext is the only classext and writable from any boxes.
+ * If unset, the prime classext is writable only from the root box.
* 3: RCLASS_IS_INITIALIZED
* Module has been initialized.
- * 4: RCLASS_NAMESPACEABLE
- * Is a builtin class that may be namespaced. It larger than a normal class.
+ * 4: RCLASS_BOXABLE
+ * Is a builtin class that may be boxed. It larger than a normal class.
* 5: RMODULE_IS_REFINEMENT
* Module is used for refinements.
*/
@@ -150,15 +150,15 @@ iclass_free_orphan_classext(VALUE klass, rb_classext_t *ext)
xfree(ext);
}
-struct rb_class_set_namespace_classext_args {
+struct rb_class_set_box_classext_args {
VALUE obj;
rb_classext_t *ext;
};
static int
-rb_class_set_namespace_classext_update(st_data_t *key_ptr, st_data_t *val_ptr, st_data_t a, int existing)
+rb_class_set_box_classext_update(st_data_t *key_ptr, st_data_t *val_ptr, st_data_t a, int existing)
{
- struct rb_class_set_namespace_classext_args *args = (struct rb_class_set_namespace_classext_args *)a;
+ struct rb_class_set_box_classext_args *args = (struct rb_class_set_box_classext_args *)a;
if (existing) {
if (LIKELY(BUILTIN_TYPE(args->obj) == T_ICLASS)) {
@@ -175,14 +175,14 @@ rb_class_set_namespace_classext_update(st_data_t *key_ptr, st_data_t *val_ptr, s
}
void
-rb_class_set_namespace_classext(VALUE obj, const rb_namespace_t *ns, rb_classext_t *ext)
+rb_class_set_box_classext(VALUE obj, const rb_box_t *box, rb_classext_t *ext)
{
- struct rb_class_set_namespace_classext_args args = {
+ struct rb_class_set_box_classext_args args = {
.obj = obj,
.ext = ext,
};
- st_update(RCLASS_CLASSEXT_TBL(obj), (st_data_t)ns->ns_object, rb_class_set_namespace_classext_update, (st_data_t)&args);
+ st_update(RCLASS_CLASSEXT_TBL(obj), (st_data_t)box->box_object, rb_class_set_box_classext_update, (st_data_t)&args);
}
RUBY_EXTERN rb_serial_t ruby_vm_global_cvar_state;
@@ -289,12 +289,12 @@ duplicate_classext_const_tbl(struct rb_id_table *src, VALUE klass)
}
static VALUE
-namespace_subclasses_tbl_key(const rb_namespace_t *ns)
+box_subclasses_tbl_key(const rb_box_t *box)
{
- if (!ns){
+ if (!box){
return 0;
}
- return (VALUE)ns->ns_id;
+ return (VALUE)box->box_id;
}
static void
@@ -302,16 +302,16 @@ duplicate_classext_subclasses(rb_classext_t *orig, rb_classext_t *copy)
{
rb_subclass_anchor_t *anchor, *orig_anchor;
rb_subclass_entry_t *head, *cur, *cdr, *entry, *first = NULL;
- rb_ns_subclasses_t *ns_subclasses;
+ rb_box_subclasses_t *box_subclasses;
struct st_table *tbl;
if (RCLASSEXT_SUBCLASSES(orig)) {
orig_anchor = RCLASSEXT_SUBCLASSES(orig);
- ns_subclasses = orig_anchor->ns_subclasses;
- tbl = ((rb_ns_subclasses_t *)ns_subclasses)->tbl;
+ box_subclasses = orig_anchor->box_subclasses;
+ tbl = ((rb_box_subclasses_t *)box_subclasses)->tbl;
anchor = ZALLOC(rb_subclass_anchor_t);
- anchor->ns_subclasses = rb_ns_subclasses_ref_inc(ns_subclasses);
+ anchor->box_subclasses = rb_box_subclasses_ref_inc(box_subclasses);
head = ZALLOC(rb_subclass_entry_t);
anchor->head = head;
@@ -333,28 +333,28 @@ duplicate_classext_subclasses(rb_classext_t *orig, rb_classext_t *copy)
cdr->prev = cur;
cur->next = cdr;
if (!first) {
- VALUE ns_id = namespace_subclasses_tbl_key(RCLASSEXT_NS(copy));
+ VALUE box_id = box_subclasses_tbl_key(RCLASSEXT_BOX(copy));
first = cdr;
- st_insert(tbl, ns_id, (st_data_t)first);
+ st_insert(tbl, box_id, (st_data_t)first);
}
cur = cdr;
entry = entry->next;
}
}
- if (RCLASSEXT_NS_SUPER_SUBCLASSES(orig))
- RCLASSEXT_NS_SUPER_SUBCLASSES(copy) = rb_ns_subclasses_ref_inc(RCLASSEXT_NS_SUPER_SUBCLASSES(orig));
- if (RCLASSEXT_NS_MODULE_SUBCLASSES(orig))
- RCLASSEXT_NS_MODULE_SUBCLASSES(copy) = rb_ns_subclasses_ref_inc(RCLASSEXT_NS_MODULE_SUBCLASSES(orig));
+ if (RCLASSEXT_BOX_SUPER_SUBCLASSES(orig))
+ RCLASSEXT_BOX_SUPER_SUBCLASSES(copy) = rb_box_subclasses_ref_inc(RCLASSEXT_BOX_SUPER_SUBCLASSES(orig));
+ if (RCLASSEXT_BOX_MODULE_SUBCLASSES(orig))
+ RCLASSEXT_BOX_MODULE_SUBCLASSES(copy) = rb_box_subclasses_ref_inc(RCLASSEXT_BOX_MODULE_SUBCLASSES(orig));
}
static void
-class_duplicate_iclass_classext(VALUE iclass, rb_classext_t *mod_ext, const rb_namespace_t *ns)
+class_duplicate_iclass_classext(VALUE iclass, rb_classext_t *mod_ext, const rb_box_t *box)
{
RUBY_ASSERT(RB_TYPE_P(iclass, T_ICLASS));
rb_classext_t *src = RCLASS_EXT_PRIME(iclass);
- rb_classext_t *ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(iclass, ns);
+ rb_classext_t *ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(iclass, box);
int first_set = 0;
if (ext) {
@@ -364,7 +364,7 @@ class_duplicate_iclass_classext(VALUE iclass, rb_classext_t *mod_ext, const rb_n
ext = ZALLOC(rb_classext_t);
- RCLASSEXT_NS(ext) = ns;
+ RCLASSEXT_BOX(ext) = box;
RCLASSEXT_SUPER(ext) = RCLASSEXT_SUPER(src);
@@ -383,7 +383,7 @@ class_duplicate_iclass_classext(VALUE iclass, rb_classext_t *mod_ext, const rb_n
// RCLASSEXT_CALLABLE_M_TBL(ext) = NULL;
// RCLASSEXT_CC_TBL(ext) = NULL;
- // subclasses, namespace_super_subclasses_tbl, namespace_module_subclasses_tbl
+ // subclasses, box_super_subclasses_tbl, box_module_subclasses_tbl
duplicate_classext_subclasses(src, ext);
RCLASSEXT_SET_ORIGIN(ext, iclass, RCLASSEXT_ORIGIN(src));
@@ -392,23 +392,23 @@ class_duplicate_iclass_classext(VALUE iclass, rb_classext_t *mod_ext, const rb_n
RCLASSEXT_SET_INCLUDER(ext, iclass, RCLASSEXT_INCLUDER(src));
- VM_ASSERT(FL_TEST_RAW(iclass, RCLASS_NAMESPACEABLE));
+ VM_ASSERT(FL_TEST_RAW(iclass, RCLASS_BOXABLE));
- first_set = RCLASS_SET_NAMESPACE_CLASSEXT(iclass, ns, ext);
+ first_set = RCLASS_SET_BOX_CLASSEXT(iclass, box, ext);
if (first_set) {
RCLASS_SET_PRIME_CLASSEXT_WRITABLE(iclass, false);
}
}
rb_classext_t *
-rb_class_duplicate_classext(rb_classext_t *orig, VALUE klass, const rb_namespace_t *ns)
+rb_class_duplicate_classext(rb_classext_t *orig, VALUE klass, const rb_box_t *box)
{
VM_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_MODULE) || RB_TYPE_P(klass, T_ICLASS));
rb_classext_t *ext = ZALLOC(rb_classext_t);
bool dup_iclass = RB_TYPE_P(klass, T_MODULE) ? true : false;
- RCLASSEXT_NS(ext) = ns;
+ RCLASSEXT_BOX(ext) = box;
RCLASSEXT_SUPER(ext) = RCLASSEXT_SUPER(orig);
@@ -433,7 +433,7 @@ rb_class_duplicate_classext(rb_classext_t *orig, VALUE klass, const rb_namespace
* so initially, it can be NULL and let it be created lazily.
* RCLASSEXT_CALLABLE_M_TBL(ext) = NULL;
*
- * cc_tbl is for method inline cache, and method calls from different namespaces never occur on
+ * cc_tbl is for method inline cache, and method calls from different boxes never occur on
* the same code, so the copied classext should have a different cc_tbl from the prime one.
* RCLASSEXT_CC_TBL(copy) = NULL
*/
@@ -445,7 +445,7 @@ rb_class_duplicate_classext(rb_classext_t *orig, VALUE klass, const rb_namespace
RCLASSEXT_SET_ORIGIN(ext, klass, RCLASSEXT_ORIGIN(orig));
/*
- * Members not copied to namespace classext values
+ * Members not copied to box's classext values
* * refined_class
* * as.class.allocator / as.singleton_class.attached_object
* * includer
@@ -463,7 +463,7 @@ rb_class_duplicate_classext(rb_classext_t *orig, VALUE klass, const rb_namespace
/*
* ICLASS has the same m_tbl/const_tbl/cvc_tbl with the included module.
* So the module's classext is copied, its tables should be also referred
- * by the ICLASS's classext for the namespace.
+ * by the ICLASS's classext for the box.
*/
rb_subclass_anchor_t *anchor = RCLASSEXT_SUBCLASSES(ext);
rb_subclass_entry_t *subclass_entry = anchor->head;
@@ -472,9 +472,9 @@ rb_class_duplicate_classext(rb_classext_t *orig, VALUE klass, const rb_namespace
iclass = subclass_entry->klass;
if (RBASIC_CLASS(iclass) == klass) {
// Is the subclass an ICLASS including this module into another class
- // If so we need to re-associate it under our namespace with the new ext
- VM_ASSERT(FL_TEST_RAW(iclass, RCLASS_NAMESPACEABLE));
- class_duplicate_iclass_classext(iclass, ext, ns);
+ // If so we need to re-associate it under our box with the new ext
+ VM_ASSERT(FL_TEST_RAW(iclass, RCLASS_BOXABLE));
+ class_duplicate_iclass_classext(iclass, ext, box);
}
}
subclass_entry = subclass_entry->next;
@@ -541,9 +541,9 @@ push_subclass_entry_to_list(VALUE super, VALUE klass, bool is_module)
{
rb_subclass_entry_t *entry, *head;
rb_subclass_anchor_t *anchor;
- rb_ns_subclasses_t *ns_subclasses;
+ rb_box_subclasses_t *box_subclasses;
struct st_table *tbl;
- const rb_namespace_t *ns = rb_current_namespace();
+ const rb_box_t *box = rb_current_box();
entry = ZALLOC(rb_subclass_entry_t);
entry->klass = klass;
@@ -551,9 +551,9 @@ push_subclass_entry_to_list(VALUE super, VALUE klass, bool is_module)
RB_VM_LOCKING() {
anchor = RCLASS_WRITABLE_SUBCLASSES(super);
VM_ASSERT(anchor);
- ns_subclasses = (rb_ns_subclasses_t *)anchor->ns_subclasses;
- VM_ASSERT(ns_subclasses);
- tbl = ns_subclasses->tbl;
+ box_subclasses = (rb_box_subclasses_t *)anchor->box_subclasses;
+ VM_ASSERT(box_subclasses);
+ tbl = box_subclasses->tbl;
VM_ASSERT(tbl);
head = anchor->head;
@@ -563,14 +563,14 @@ push_subclass_entry_to_list(VALUE super, VALUE klass, bool is_module)
}
head->next = entry;
entry->prev = head;
- st_insert(tbl, namespace_subclasses_tbl_key(ns), (st_data_t)entry);
+ st_insert(tbl, box_subclasses_tbl_key(box), (st_data_t)entry);
}
if (is_module) {
- RCLASS_WRITE_NS_MODULE_SUBCLASSES(klass, anchor->ns_subclasses);
+ RCLASS_WRITE_BOX_MODULE_SUBCLASSES(klass, anchor->box_subclasses);
}
else {
- RCLASS_WRITE_NS_SUPER_SUBCLASSES(klass, anchor->ns_subclasses);
+ RCLASS_WRITE_BOX_SUPER_SUBCLASSES(klass, anchor->box_subclasses);
}
}
@@ -598,10 +598,10 @@ rb_class_remove_subclass_head(VALUE klass)
}
static struct rb_subclass_entry *
-class_get_subclasses_for_ns(struct st_table *tbl, VALUE ns_id)
+class_get_subclasses_for_ns(struct st_table *tbl, VALUE box_id)
{
st_data_t value;
- if (st_lookup(tbl, (st_data_t)ns_id, &value)) {
+ if (st_lookup(tbl, (st_data_t)box_id, &value)) {
return (struct rb_subclass_entry *)value;
}
return NULL;
@@ -615,9 +615,9 @@ remove_class_from_subclasses_replace_first_entry(st_data_t *key, st_data_t *valu
}
static void
-remove_class_from_subclasses(struct st_table *tbl, VALUE ns_id, VALUE klass)
+remove_class_from_subclasses(struct st_table *tbl, VALUE box_id, VALUE klass)
{
- rb_subclass_entry_t *entry = class_get_subclasses_for_ns(tbl, ns_id);
+ rb_subclass_entry_t *entry = class_get_subclasses_for_ns(tbl, box_id);
bool first_entry = true;
while (entry) {
if (entry->klass == klass) {
@@ -632,11 +632,11 @@ remove_class_from_subclasses(struct st_table *tbl, VALUE ns_id, VALUE klass)
if (first_entry) {
if (next) {
- st_update(tbl, ns_id, remove_class_from_subclasses_replace_first_entry, (st_data_t)next);
+ st_update(tbl, box_id, remove_class_from_subclasses_replace_first_entry, (st_data_t)next);
}
else {
// no subclass entries in this ns after the deletion
- st_delete(tbl, &ns_id, NULL);
+ st_delete(tbl, &box_id, NULL);
}
}
@@ -655,32 +655,32 @@ void
rb_class_remove_from_super_subclasses(VALUE klass)
{
rb_classext_t *ext = RCLASS_EXT_WRITABLE(klass);
- rb_ns_subclasses_t *ns_subclasses = RCLASSEXT_NS_SUPER_SUBCLASSES(ext);
+ rb_box_subclasses_t *box_subclasses = RCLASSEXT_BOX_SUPER_SUBCLASSES(ext);
- if (!ns_subclasses) return;
- remove_class_from_subclasses(ns_subclasses->tbl, namespace_subclasses_tbl_key(RCLASSEXT_NS(ext)), klass);
- rb_ns_subclasses_ref_dec(ns_subclasses);
- RCLASSEXT_NS_SUPER_SUBCLASSES(ext) = 0;
+ if (!box_subclasses) return;
+ remove_class_from_subclasses(box_subclasses->tbl, box_subclasses_tbl_key(RCLASSEXT_BOX(ext)), klass);
+ rb_box_subclasses_ref_dec(box_subclasses);
+ RCLASSEXT_BOX_SUPER_SUBCLASSES(ext) = 0;
}
void
rb_class_remove_from_module_subclasses(VALUE klass)
{
rb_classext_t *ext = RCLASS_EXT_WRITABLE(klass);
- rb_ns_subclasses_t *ns_subclasses = RCLASSEXT_NS_MODULE_SUBCLASSES(ext);
+ rb_box_subclasses_t *box_subclasses = RCLASSEXT_BOX_MODULE_SUBCLASSES(ext);
- if (!ns_subclasses) return;
- remove_class_from_subclasses(ns_subclasses->tbl, namespace_subclasses_tbl_key(RCLASSEXT_NS(ext)), klass);
- rb_ns_subclasses_ref_dec(ns_subclasses);
- RCLASSEXT_NS_MODULE_SUBCLASSES(ext) = 0;
+ if (!box_subclasses) return;
+ remove_class_from_subclasses(box_subclasses->tbl, box_subclasses_tbl_key(RCLASSEXT_BOX(ext)), klass);
+ rb_box_subclasses_ref_dec(box_subclasses);
+ RCLASSEXT_BOX_MODULE_SUBCLASSES(ext) = 0;
}
void
rb_class_classext_free_subclasses(rb_classext_t *ext, VALUE klass, bool replacing)
{
rb_subclass_anchor_t *anchor = RCLASSEXT_SUBCLASSES(ext);
- struct st_table *tbl = anchor->ns_subclasses->tbl;
- VALUE ns_id = namespace_subclasses_tbl_key(RCLASSEXT_NS(ext));
+ struct st_table *tbl = anchor->box_subclasses->tbl;
+ VALUE box_id = box_subclasses_tbl_key(RCLASSEXT_BOX(ext));
rb_subclass_entry_t *next, *entry = anchor->head;
while (entry) {
@@ -689,21 +689,21 @@ rb_class_classext_free_subclasses(rb_classext_t *ext, VALUE klass, bool replacin
entry = next;
}
VM_ASSERT(
- rb_ns_subclasses_ref_count(anchor->ns_subclasses) > 0,
- "ns_subclasses refcount (%p) %d", anchor->ns_subclasses, rb_ns_subclasses_ref_count(anchor->ns_subclasses));
- st_delete(tbl, &ns_id, NULL);
- rb_ns_subclasses_ref_dec(anchor->ns_subclasses);
+ rb_box_subclasses_ref_count(anchor->box_subclasses) > 0,
+ "box_subclasses refcount (%p) %d", anchor->box_subclasses, rb_box_subclasses_ref_count(anchor->box_subclasses));
+ st_delete(tbl, &box_id, NULL);
+ rb_box_subclasses_ref_dec(anchor->box_subclasses);
xfree(anchor);
- if (!replacing && RCLASSEXT_NS_SUPER_SUBCLASSES(ext)) {
- rb_ns_subclasses_t *ns_sub = RCLASSEXT_NS_SUPER_SUBCLASSES(ext);
- remove_class_from_subclasses(ns_sub->tbl, ns_id, klass);
- rb_ns_subclasses_ref_dec(ns_sub);
+ if (!replacing && RCLASSEXT_BOX_SUPER_SUBCLASSES(ext)) {
+ rb_box_subclasses_t *box_sub = RCLASSEXT_BOX_SUPER_SUBCLASSES(ext);
+ remove_class_from_subclasses(box_sub->tbl, box_id, klass);
+ rb_box_subclasses_ref_dec(box_sub);
}
- if (!replacing && RCLASSEXT_NS_MODULE_SUBCLASSES(ext)) {
- rb_ns_subclasses_t *ns_sub = RCLASSEXT_NS_MODULE_SUBCLASSES(ext);
- remove_class_from_subclasses(ns_sub->tbl, ns_id, klass);
- rb_ns_subclasses_ref_dec(ns_sub);
+ if (!replacing && RCLASSEXT_BOX_MODULE_SUBCLASSES(ext)) {
+ rb_box_subclasses_t *box_sub = RCLASSEXT_BOX_MODULE_SUBCLASSES(ext);
+ remove_class_from_subclasses(box_sub->tbl, box_id, klass);
+ rb_box_subclasses_ref_dec(box_sub);
}
}
@@ -766,19 +766,19 @@ class_switch_superclass(VALUE super, VALUE klass)
* @note this function is not Class#allocate.
*/
static VALUE
-class_alloc0(enum ruby_value_type type, VALUE klass, bool namespaceable)
+class_alloc0(enum ruby_value_type type, VALUE klass, bool boxable)
{
- rb_ns_subclasses_t *ns_subclasses;
+ rb_box_subclasses_t *box_subclasses;
rb_subclass_anchor_t *anchor;
- const rb_namespace_t *ns = rb_current_namespace();
+ const rb_box_t *box = rb_current_box();
- if (!ruby_namespace_init_done) {
- namespaceable = true;
+ if (!ruby_box_init_done) {
+ boxable = true;
}
size_t alloc_size = sizeof(struct RClass_and_rb_classext_t);
- if (namespaceable) {
- alloc_size = sizeof(struct RClass_namespaceable);
+ if (boxable) {
+ alloc_size = sizeof(struct RClass_boxable);
}
// class_alloc is supposed to return a new object that is not promoted yet.
@@ -787,18 +787,18 @@ class_alloc0(enum ruby_value_type type, VALUE klass, bool namespaceable)
//
// TODO: Note that this could cause memory leak.
// If NEWOBJ_OF fails with out of memory, these buffers will leak.
- ns_subclasses = ZALLOC(rb_ns_subclasses_t);
- ns_subclasses->refcount = 1;
- ns_subclasses->tbl = st_init_numtable();
+ box_subclasses = ZALLOC(rb_box_subclasses_t);
+ box_subclasses->refcount = 1;
+ box_subclasses->tbl = st_init_numtable();
anchor = ZALLOC(rb_subclass_anchor_t);
- anchor->ns_subclasses = ns_subclasses;
+ anchor->box_subclasses = box_subclasses;
anchor->head = ZALLOC(rb_subclass_entry_t);
RUBY_ASSERT(type == T_CLASS || type == T_ICLASS || type == T_MODULE);
VALUE flags = type | FL_SHAREABLE;
if (RGENGC_WB_PROTECTED_CLASS) flags |= FL_WB_PROTECTED;
- if (namespaceable) flags |= RCLASS_NAMESPACEABLE;
+ if (boxable) flags |= RCLASS_BOXABLE;
NEWOBJ_OF(obj, struct RClass, klass, flags, alloc_size, 0);
@@ -813,14 +813,14 @@ class_alloc0(enum ruby_value_type type, VALUE klass, bool namespaceable)
RCLASS_SET_SUPER((VALUE)obj, 0);
*/
- if (namespaceable) {
- ((struct RClass_namespaceable *)obj)->ns_classext_tbl = NULL;
+ if (boxable) {
+ ((struct RClass_boxable *)obj)->box_classext_tbl = NULL;
}
- RCLASS_PRIME_NS((VALUE)obj) = ns;
- // Classes/Modules defined in user namespaces are
- // writable directly because it exists only in a namespace.
- RCLASS_SET_PRIME_CLASSEXT_WRITABLE((VALUE)obj, !namespaceable || NAMESPACE_USER_P(ns));
+ RCLASS_PRIME_BOX((VALUE)obj) = box;
+ // Classes/Modules defined in user boxes are
+ // writable directly because it exists only in a box.
+ RCLASS_SET_PRIME_CLASSEXT_WRITABLE((VALUE)obj, !boxable || BOX_USER_P(box));
RCLASS_SET_ORIGIN((VALUE)obj, (VALUE)obj);
RCLASS_SET_REFINED_CLASS((VALUE)obj, Qnil);
@@ -872,9 +872,9 @@ class_clear_method_table(VALUE c)
}
static VALUE
-class_boot_namespaceable(VALUE super, bool namespaceable)
+class_boot_boxable(VALUE super, bool boxable)
{
- VALUE klass = class_alloc0(T_CLASS, rb_cClass, namespaceable);
+ VALUE klass = class_alloc0(T_CLASS, rb_cClass, boxable);
// initialize method table prior to class_associate_super()
// because class_associate_super() may cause GC and promote klass
@@ -900,7 +900,7 @@ class_boot_namespaceable(VALUE super, bool namespaceable)
VALUE
rb_class_boot(VALUE super)
{
- return class_boot_namespaceable(super, false);
+ return class_boot_boxable(super, false);
}
static VALUE *
@@ -1387,7 +1387,7 @@ static inline VALUE
make_metaclass(VALUE klass)
{
VALUE super;
- VALUE metaclass = class_boot_namespaceable(Qundef, FL_TEST_RAW(klass, RCLASS_NAMESPACEABLE));
+ VALUE metaclass = class_boot_boxable(Qundef, FL_TEST_RAW(klass, RCLASS_BOXABLE));
FL_SET(metaclass, FL_SINGLETON);
rb_singleton_class_attached(metaclass, klass);
@@ -1423,7 +1423,7 @@ static inline VALUE
make_singleton_class(VALUE obj)
{
VALUE orig_class = METACLASS_OF(obj);
- VALUE klass = class_boot_namespaceable(orig_class, FL_TEST_RAW(orig_class, RCLASS_NAMESPACEABLE));
+ VALUE klass = class_boot_boxable(orig_class, FL_TEST_RAW(orig_class, RCLASS_BOXABLE));
FL_SET(klass, FL_SINGLETON);
RBASIC_SET_CLASS(obj, klass);
diff --git a/dln.c b/dln.c
index 6bc4ef199e..2549f03183 100644
--- a/dln.c
+++ b/dln.c
@@ -389,7 +389,7 @@ dln_open(const char *file)
# endif
/* Load file */
- int mode = rb_namespace_available() ? RTLD_LAZY|RTLD_LOCAL : RTLD_LAZY|RTLD_GLOBAL;
+ int mode = rb_box_available() ? RTLD_LAZY|RTLD_LOCAL : RTLD_LAZY|RTLD_GLOBAL;
handle = dlopen(file, mode);
if (handle == NULL) {
error = dln_strerror();
diff --git a/eval.c b/eval.c
index 0ff59efd98..4fbb0e7997 100644
--- a/eval.c
+++ b/eval.c
@@ -78,9 +78,9 @@ ruby_setup(void)
#endif
Init_BareVM();
rb_vm_encoded_insn_data_table_init();
- Init_enable_namespace();
+ Init_enable_box();
Init_vm_objects();
- Init_root_namespace();
+ Init_root_box();
Init_fstring_table();
EC_PUSH_TAG(GET_EC());
diff --git a/eval_intern.h b/eval_intern.h
index 4ac950e238..91808f1f29 100644
--- a/eval_intern.h
+++ b/eval_intern.h
@@ -296,11 +296,11 @@ VALUE rb_vm_make_jump_tag_but_local_jump(enum ruby_tag_type state, VALUE val);
rb_cref_t *rb_vm_cref(void);
rb_cref_t *rb_vm_cref_replace_with_duplicated_cref(void);
VALUE rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, VALUE block_handler, VALUE filename);
-VALUE rb_vm_call_cfunc_in_namespace(VALUE recv, VALUE (*func)(VALUE, VALUE), VALUE arg1, VALUE arg2, VALUE filename, const rb_namespace_t *ns);
-void rb_vm_frame_flag_set_ns_require(const rb_execution_context_t *ec);
-const rb_namespace_t *rb_vm_current_namespace(const rb_execution_context_t *ec);
-const rb_namespace_t *rb_vm_caller_namespace(const rb_execution_context_t *ec);
-const rb_namespace_t *rb_vm_loading_namespace(const rb_execution_context_t *ec);
+VALUE rb_vm_call_cfunc_in_box(VALUE recv, VALUE (*func)(VALUE, VALUE), VALUE arg1, VALUE arg2, VALUE filename, const rb_box_t *box);
+void rb_vm_frame_flag_set_box_require(const rb_execution_context_t *ec);
+const rb_box_t *rb_vm_current_box(const rb_execution_context_t *ec);
+const rb_box_t *rb_vm_caller_box(const rb_execution_context_t *ec);
+const rb_box_t *rb_vm_loading_box(const rb_execution_context_t *ec);
void rb_vm_set_progname(VALUE filename);
VALUE rb_vm_cbase(void);
diff --git a/gc.c b/gc.c
index d1e542de2c..92ba02809a 100644
--- a/gc.c
+++ b/gc.c
@@ -1228,7 +1228,7 @@ struct classext_foreach_args {
};
static void
-classext_free(rb_classext_t *ext, bool is_prime, VALUE namespace, void *arg)
+classext_free(rb_classext_t *ext, bool is_prime, VALUE box_value, void *arg)
{
struct classext_foreach_args *args = (struct classext_foreach_args *)arg;
@@ -1236,7 +1236,7 @@ classext_free(rb_classext_t *ext, bool is_prime, VALUE namespace, void *arg)
}
static void
-classext_iclass_free(rb_classext_t *ext, bool is_prime, VALUE namespace, void *arg)
+classext_iclass_free(rb_classext_t *ext, bool is_prime, VALUE box_value, void *arg)
{
struct classext_foreach_args *args = (struct classext_foreach_args *)arg;
@@ -1918,8 +1918,8 @@ object_id(VALUE obj)
switch (BUILTIN_TYPE(obj)) {
case T_CLASS:
case T_MODULE:
- // With namespaces, classes and modules have different fields
- // in different namespaces, so we cannot store the object id
+ // With Ruby Box, classes and modules have different fields
+ // in different boxes, so we cannot store the object id
// in fields.
return class_object_id(obj);
case T_IMEMO:
@@ -2271,7 +2271,7 @@ rb_gc_after_updating_jit_code(void)
}
static void
-classext_memsize(rb_classext_t *ext, bool prime, VALUE namespace, void *arg)
+classext_memsize(rb_classext_t *ext, bool prime, VALUE box_value, void *arg)
{
size_t *size = (size_t *)arg;
size_t s = 0;
@@ -2295,7 +2295,7 @@ classext_memsize(rb_classext_t *ext, bool prime, VALUE namespace, void *arg)
}
static void
-classext_superclasses_memsize(rb_classext_t *ext, bool prime, VALUE namespace, void *arg)
+classext_superclasses_memsize(rb_classext_t *ext, bool prime, VALUE box_value, void *arg)
{
size_t *size = (size_t *)arg;
size_t array_size;
@@ -3075,7 +3075,7 @@ struct gc_mark_classext_foreach_arg {
};
static void
-gc_mark_classext_module(rb_classext_t *ext, bool prime, VALUE namespace, void *arg)
+gc_mark_classext_module(rb_classext_t *ext, bool prime, VALUE box_value, void *arg)
{
struct gc_mark_classext_foreach_arg *foreach_arg = (struct gc_mark_classext_foreach_arg *)arg;
rb_objspace_t *objspace = foreach_arg->objspace;
@@ -3100,7 +3100,7 @@ gc_mark_classext_module(rb_classext_t *ext, bool prime, VALUE namespace, void *a
}
static void
-gc_mark_classext_iclass(rb_classext_t *ext, bool prime, VALUE namespace, void *arg)
+gc_mark_classext_iclass(rb_classext_t *ext, bool prime, VALUE box_value, void *arg)
{
struct gc_mark_classext_foreach_arg *foreach_arg = (struct gc_mark_classext_foreach_arg *)arg;
rb_objspace_t *objspace = foreach_arg->objspace;
@@ -3774,7 +3774,7 @@ update_classext_values(rb_objspace_t *objspace, rb_classext_t *ext, bool is_icla
}
static void
-update_classext(rb_classext_t *ext, bool is_prime, VALUE namespace, void *arg)
+update_classext(rb_classext_t *ext, bool is_prime, VALUE box_value, void *arg)
{
struct classext_foreach_args *args = (struct classext_foreach_args *)arg;
rb_objspace_t *objspace = args->objspace;
@@ -3798,7 +3798,7 @@ update_classext(rb_classext_t *ext, bool is_prime, VALUE namespace, void *arg)
}
static void
-update_iclass_classext(rb_classext_t *ext, bool is_prime, VALUE namespace, void *arg)
+update_iclass_classext(rb_classext_t *ext, bool is_prime, VALUE box_value, void *arg)
{
struct classext_foreach_args *args = (struct classext_foreach_args *)arg;
rb_objspace_t *objspace = args->objspace;
diff --git a/inits.c b/inits.c
index 5209e429f9..4569362b95 100644
--- a/inits.c
+++ b/inits.c
@@ -52,7 +52,7 @@ rb_call_inits(void)
CALL(Time);
CALL(Random);
CALL(load);
- CALL(Namespace);
+ CALL(Box);
CALL(Proc);
CALL(Binding);
CALL(Math);
diff --git a/insns.def b/insns.def
index 8c16a67717..f282b5a8e7 100644
--- a/insns.def
+++ b/insns.def
@@ -803,13 +803,13 @@ defineclass
(VALUE val)
{
VALUE klass = vm_find_or_create_class_by_id(id, flags, cbase, super);
- const rb_namespace_t *ns = rb_current_namespace();
+ const rb_box_t *box = rb_current_box();
rb_iseq_check(class_iseq);
/* enter scope */
vm_push_frame(ec, class_iseq, VM_FRAME_MAGIC_CLASS | VM_ENV_FLAG_LOCAL, klass,
- GC_GUARDED_PTR(ns),
+ GC_GUARDED_PTR(box),
(VALUE)vm_cref_push(ec, klass, NULL, FALSE, FALSE),
ISEQ_BODY(class_iseq)->iseq_encoded, GET_SP(),
ISEQ_BODY(class_iseq)->local_table_size,
diff --git a/internal/box.h b/internal/box.h
index c5a495fdf0..36844ebf19 100644
--- a/internal/box.h
+++ b/internal/box.h
@@ -1,5 +1,5 @@
-#ifndef INTERNAL_NAMESPACE_H /*-*-C-*-vi:se ft=c:*/
-#define INTERNAL_NAMESPACE_H
+#ifndef INTERNAL_BOX_H /*-*-C-*-vi:se ft=c:*/
+#define INTERNAL_BOX_H
#include "ruby/ruby.h" /* for VALUE */
@@ -9,15 +9,15 @@
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
- * @brief Internal header for Namespace.
+ * @brief Internal header for Ruby Box.
*/
-struct rb_namespace_struct {
+struct rb_box_struct {
/*
- * To retrieve Namespace object that provides #require and so on.
- * That is used from load.c, etc., that uses rb_namespace_t internally.
+ * To retrieve Ruby::Box object that provides #require and so on.
+ * That is used from load.c, etc., that uses rb_box_t internally.
*/
- VALUE ns_object;
- long ns_id; // namespace id to generate ext filenames
+ VALUE box_object;
+ long box_id; // box_id to generate ext filenames
VALUE top_self;
@@ -38,44 +38,44 @@ struct rb_namespace_struct {
bool is_user;
bool is_optional;
};
-typedef struct rb_namespace_struct rb_namespace_t;
+typedef struct rb_box_struct rb_box_t;
-#define NAMESPACE_OBJ_P(obj) (rb_obj_class(obj) == rb_cNamespace)
+#define BOX_OBJ_P(obj) (rb_obj_class(obj) == rb_cNamespace)
-#define NAMESPACE_ROOT_P(ns) (ns && !ns->is_user)
-#define NAMESPACE_USER_P(ns) (ns && ns->is_user)
-#define NAMESPACE_OPTIONAL_P(ns) (ns && ns->is_optional)
-#define NAMESPACE_MAIN_P(ns) (ns && ns->is_user && !ns->is_optional)
+#define BOX_ROOT_P(box) (box && !box->is_user)
+#define BOX_USER_P(box) (box && box->is_user)
+#define BOX_OPTIONAL_P(box) (box && box->is_optional)
+#define BOX_MAIN_P(box) (box && box->is_user && !box->is_optional)
-#define NAMESPACE_METHOD_DEFINITION(mdef) (mdef ? mdef->ns : NULL)
-#define NAMESPACE_METHOD_ENTRY(me) (me ? NAMESPACE_METHOD_DEFINITION(me->def) : NULL)
-#define NAMESPACE_CC(cc) (cc ? NAMESPACE_METHOD_ENTRY(cc->cme_) : NULL)
-#define NAMESPACE_CC_ENTRIES(ccs) (ccs ? NAMESPACE_METHOD_ENTRY(ccs->cme) : NULL)
+#define BOX_METHOD_DEFINITION(mdef) (mdef ? mdef->ns : NULL)
+#define BOX_METHOD_ENTRY(me) (me ? BOX_METHOD_DEFINITION(me->def) : NULL)
+#define BOX_CC(cc) (cc ? BOX_METHOD_ENTRY(cc->cme_) : NULL)
+#define BOX_CC_ENTRIES(ccs) (ccs ? BOX_METHOD_ENTRY(ccs->cme) : NULL)
-RUBY_EXTERN bool ruby_namespace_enabled;
-RUBY_EXTERN bool ruby_namespace_init_done;
-RUBY_EXTERN bool ruby_namespace_crashed;
+RUBY_EXTERN bool ruby_box_enabled;
+RUBY_EXTERN bool ruby_box_init_done;
+RUBY_EXTERN bool ruby_box_crashed;
static inline bool
-rb_namespace_available(void)
+rb_box_available(void)
{
- return ruby_namespace_enabled;
+ return ruby_box_enabled;
}
-const rb_namespace_t * rb_root_namespace(void);
-const rb_namespace_t * rb_main_namespace(void);
-const rb_namespace_t * rb_current_namespace(void);
-const rb_namespace_t * rb_loading_namespace(void);
-const rb_namespace_t * rb_current_namespace_in_crash_report(void);
+const rb_box_t * rb_root_box(void);
+const rb_box_t * rb_main_box(void);
+const rb_box_t * rb_current_box(void);
+const rb_box_t * rb_loading_box(void);
+const rb_box_t * rb_current_box_in_crash_report(void);
-void rb_namespace_entry_mark(void *);
-void rb_namespace_gc_update_references(void *ptr);
+void rb_box_entry_mark(void *);
+void rb_box_gc_update_references(void *ptr);
-rb_namespace_t * rb_get_namespace_t(VALUE ns);
-VALUE rb_get_namespace_object(rb_namespace_t *ns);
+rb_box_t * rb_get_box_t(VALUE ns);
+VALUE rb_get_box_object(rb_box_t *ns);
-VALUE rb_namespace_local_extension(VALUE namespace, VALUE fname, VALUE path);
+VALUE rb_box_local_extension(VALUE box, VALUE fname, VALUE path);
-void rb_initialize_main_namespace(void);
-void rb_namespace_init_done(void);
-#endif /* INTERNAL_NAMESPACE_H */
+void rb_initialize_main_box(void);
+void rb_box_init_done(void);
+#endif /* INTERNAL_BOX_H */
diff --git a/internal/class.h b/internal/class.h
index 19393eb7c3..04d2849656 100644
--- a/internal/class.h
+++ b/internal/class.h
@@ -10,7 +10,7 @@
*/
#include "id.h"
#include "id_table.h" /* for struct rb_id_table */
-#include "internal/box.h" /* for rb_current_namespace */
+#include "internal/box.h"
#include "internal/serial.h" /* for rb_serial_t */
#include "internal/static_assert.h"
#include "internal/variable.h" /* for rb_class_ivar_set */
@@ -27,37 +27,37 @@
# undef RCLASS_SUPER
#endif
-struct rb_ns_subclasses {
+struct rb_box_subclasses {
rb_atomic_t refcount;
struct st_table *tbl;
};
-typedef struct rb_ns_subclasses rb_ns_subclasses_t;
+typedef struct rb_box_subclasses rb_box_subclasses_t;
static inline rb_atomic_t
-rb_ns_subclasses_ref_count(rb_ns_subclasses_t *ns_sub)
+rb_box_subclasses_ref_count(rb_box_subclasses_t *box_sub)
{
- return ATOMIC_LOAD_RELAXED(ns_sub->refcount);
+ return ATOMIC_LOAD_RELAXED(box_sub->refcount);
}
-static inline rb_ns_subclasses_t *
-rb_ns_subclasses_ref_inc(rb_ns_subclasses_t *ns_sub)
+static inline rb_box_subclasses_t *
+rb_box_subclasses_ref_inc(rb_box_subclasses_t *box_sub)
{
- RUBY_ATOMIC_FETCH_ADD(ns_sub->refcount, 1);
- return ns_sub;
+ RUBY_ATOMIC_FETCH_ADD(box_sub->refcount, 1);
+ return box_sub;
}
static inline void
-rb_ns_subclasses_ref_dec(rb_ns_subclasses_t *ns_sub)
+rb_box_subclasses_ref_dec(rb_box_subclasses_t *box_sub)
{
- rb_atomic_t was = RUBY_ATOMIC_FETCH_SUB(ns_sub->refcount, 1);
+ rb_atomic_t was = RUBY_ATOMIC_FETCH_SUB(box_sub->refcount, 1);
if (was == 1) {
- st_free_table(ns_sub->tbl);
- xfree(ns_sub);
+ st_free_table(box_sub->tbl);
+ xfree(box_sub);
}
}
struct rb_subclass_anchor {
- rb_ns_subclasses_t *ns_subclasses;
+ rb_box_subclasses_t *box_subclasses;
struct rb_subclass_entry *head;
};
typedef struct rb_subclass_anchor rb_subclass_anchor_t;
@@ -77,7 +77,7 @@ struct rb_cvar_class_tbl_entry {
};
struct rb_classext_struct {
- const rb_namespace_t *ns;
+ const rb_box_t *box;
VALUE super;
VALUE fields_obj; // Fields are either ivar or other internal properties stored inline
struct rb_id_table *m_tbl;
@@ -92,19 +92,19 @@ struct rb_classext_struct {
*/
struct rb_subclass_anchor *subclasses;
/**
- * The `ns_super_subclasses` points the `ns_subclasses` struct to retreive the subclasses
- * of the super class in a specific namespace.
+ * The `box_super_subclasses` points the `box_subclasses` struct to retreive the subclasses
+ * of the super class in a specific box.
* In compaction GCs, collecting a classext should trigger the deletion of a rb_subclass_entry
* from the super's subclasses. But it may be prevented by the read barrier.
* Fetching the super's subclasses for a ns is to avoid the read barrier in that process.
*/
- rb_ns_subclasses_t *ns_super_subclasses;
+ rb_box_subclasses_t *box_super_subclasses;
/**
- * In the case that this is an `ICLASS`, `ns_module_subclasses` points to the link
+ * In the case that this is an `ICLASS`, `box_module_subclasses` points to the link
* in the module's `subclasses` list that indicates that the klass has been
* included. Hopefully that makes sense.
*/
- rb_ns_subclasses_t *ns_module_subclasses;
+ rb_box_subclasses_t *box_module_subclasses;
const VALUE origin_;
const VALUE refined_class;
@@ -138,7 +138,7 @@ struct RClass {
struct RBasic basic;
VALUE object_id;
/*
- * If ns_classext_tbl is NULL, then the prime classext is readable (because no other classext exists).
+ * If box_classext_tbl is NULL, then the prime classext is readable (because no other classext exists).
* For the check whether writable or not, check flag RCLASS_PRIME_CLASSEXT_WRITABLE
*/
};
@@ -154,9 +154,9 @@ struct RClass_and_rb_classext_t {
STATIC_ASSERT(sizeof_rb_classext_t, sizeof(struct RClass_and_rb_classext_t) <= 4 * RVALUE_SIZE);
#endif
-struct RClass_namespaceable {
+struct RClass_boxable {
struct RClass_and_rb_classext_t base;
- st_table *ns_classext_tbl; // ns_object -> (rb_classext_t *)
+ st_table *box_classext_tbl; // box_object -> (rb_classext_t *)
};
static const uint16_t RCLASS_MAX_SUPERCLASS_DEPTH = ((uint16_t)-1);
@@ -170,13 +170,13 @@ static inline void RCLASS_SET_PRIME_CLASSEXT_WRITABLE(VALUE obj, bool writable);
#define RCLASS_EXT_PRIME(c) (&((struct RClass_and_rb_classext_t*)(c))->classext)
#define RCLASS_EXT_PRIME_P(ext, c) (&((struct RClass_and_rb_classext_t*)(c))->classext == ext)
-static inline rb_classext_t * RCLASS_EXT_READABLE_IN_NS(VALUE obj, const rb_namespace_t *ns);
+static inline rb_classext_t * RCLASS_EXT_READABLE_IN_BOX(VALUE obj, const rb_box_t *box);
static inline rb_classext_t * RCLASS_EXT_READABLE(VALUE obj);
-static inline rb_classext_t * RCLASS_EXT_WRITABLE_IN_NS(VALUE obj, const rb_namespace_t *ns);
+static inline rb_classext_t * RCLASS_EXT_WRITABLE_IN_BOX(VALUE obj, const rb_box_t *box);
static inline rb_classext_t * RCLASS_EXT_WRITABLE(VALUE obj);
// Raw accessor
-#define RCLASSEXT_NS(ext) (ext->ns)
+#define RCLASSEXT_BOX(ext) (ext->box)
#define RCLASSEXT_SUPER(ext) (ext->super)
#define RCLASSEXT_FIELDS(ext) (ext->fields_obj ? ROBJECT_FIELDS(ext->fields_obj) : NULL)
#define RCLASSEXT_FIELDS_OBJ(ext) (ext->fields_obj)
@@ -188,8 +188,8 @@ static inline rb_classext_t * RCLASS_EXT_WRITABLE(VALUE obj);
#define RCLASSEXT_SUPERCLASS_DEPTH(ext) (ext->superclass_depth)
#define RCLASSEXT_SUPERCLASSES(ext) (ext->superclasses)
#define RCLASSEXT_SUBCLASSES(ext) (ext->subclasses)
-#define RCLASSEXT_NS_SUPER_SUBCLASSES(ext) (ext->ns_super_subclasses)
-#define RCLASSEXT_NS_MODULE_SUBCLASSES(ext) (ext->ns_module_subclasses)
+#define RCLASSEXT_BOX_SUPER_SUBCLASSES(ext) (ext->box_super_subclasses)
+#define RCLASSEXT_BOX_MODULE_SUBCLASSES(ext) (ext->box_module_subclasses)
#define RCLASSEXT_ORIGIN(ext) (ext->origin_)
#define RCLASSEXT_REFINED_CLASS(ext) (ext->refined_class)
// class.allocator/singleton_class.attached_object are not accessed directly via RCLASSEXT_*
@@ -206,7 +206,7 @@ static inline void RCLASSEXT_SET_ORIGIN(rb_classext_t *ext, VALUE klass, VALUE o
static inline void RCLASSEXT_SET_INCLUDER(rb_classext_t *ext, VALUE klass, VALUE includer);
/* Prime classext entry accessor for very specific reason */
-#define RCLASS_PRIME_NS(c) (RCLASS_EXT_PRIME(c)->ns)
+#define RCLASS_PRIME_BOX(c) (RCLASS_EXT_PRIME(c)->box)
// To invalidate CC by inserting&invalidating method entry into tables containing the target cme
// See clear_method_cache_by_id_in_class()
#define RCLASS_PRIME_FIELDS_OBJ(c) (RCLASS_EXT_PRIME(c)->fields_obj)
@@ -218,7 +218,7 @@ static inline void RCLASSEXT_SET_INCLUDER(rb_classext_t *ext, VALUE klass, VALUE
#define RCLASS_CALLABLE_M_TBL_NOT_PRIME_P(c, tbl) (RCLASS_EXT_PRIME(c)->callable_m_tbl != tbl)
#define RCLASS_CC_TBL_NOT_PRIME_P(c, tbl) (RCLASS_EXT_PRIME(c)->cc_tbl != tbl)
-// Read accessor, regarding namespaces
+// Read accessor, regarding box
#define RCLASS_SUPER(c) (RCLASS_EXT_READABLE(c)->super)
#define RCLASS_M_TBL(c) (RCLASS_EXT_READABLE(c)->m_tbl)
#define RCLASS_CONST_TBL(c) (RCLASS_EXT_READABLE(c)->const_tbl)
@@ -240,12 +240,12 @@ static inline void RCLASSEXT_SET_INCLUDER(rb_classext_t *ext, VALUE klass, VALUE
#define RCLASS_SUPERCLASSES(c) (RCLASS_EXT_PRIME(c)->superclasses)
#define RCLASS_SUPERCLASSES_WITH_SELF_P(c) (RCLASS_EXT_PRIME(c)->superclasses_with_self)
-// namespaces don't make changes on these refined_class/attached_object/includer
+// Ruby Box doesn't make changes on these refined_class/attached_object/includer
#define RCLASS_REFINED_CLASS(c) (RCLASS_EXT_PRIME(c)->refined_class)
#define RCLASS_ATTACHED_OBJECT(c) (RCLASS_EXT_PRIME(c)->as.singleton_class.attached_object)
#define RCLASS_INCLUDER(c) (RCLASS_EXT_PRIME(c)->as.iclass.includer)
-// max IV count and variation count are just hints, so they don't need to be per-namespace
+// max IV count and variation count are just hints, so they don't need to be per-box
#define RCLASS_MAX_IV_COUNT(ext) (RCLASS_EXT_PRIME(ext)->max_iv_count)
#define RCLASS_VARIATION_COUNT(ext) (RCLASS_EXT_PRIME(ext)->variation_count)
@@ -268,8 +268,8 @@ static inline void RCLASS_WRITE_CVC_TBL(VALUE klass, struct rb_id_table *table);
static inline void RCLASS_WRITE_SUPERCLASSES(VALUE klass, size_t depth, VALUE *superclasses, bool with_self);
static inline void RCLASS_SET_SUBCLASSES(VALUE klass, rb_subclass_anchor_t *anchor);
-static inline void RCLASS_WRITE_NS_SUPER_SUBCLASSES(VALUE klass, rb_ns_subclasses_t *ns_subclasses);
-static inline void RCLASS_WRITE_NS_MODULE_SUBCLASSES(VALUE klass, rb_ns_subclasses_t *ns_subclasses);
+static inline void RCLASS_WRITE_BOX_SUPER_SUBCLASSES(VALUE klass, rb_box_subclasses_t *box_subclasses);
+static inline void RCLASS_WRITE_BOX_MODULE_SUBCLASSES(VALUE klass, rb_box_subclasses_t *box_subclasses);
static inline void RCLASS_SET_ORIGIN(VALUE klass, VALUE origin);
static inline void RCLASS_WRITE_ORIGIN(VALUE klass, VALUE origin);
@@ -293,14 +293,14 @@ static inline void RCLASS_WRITE_CLASSPATH(VALUE klass, VALUE classpath, bool per
#define RCLASS_PRIME_CLASSEXT_WRITABLE FL_USER2
#define RCLASS_IS_INITIALIZED FL_USER3
// 3 is RMODULE_IS_REFINEMENT for RMODULE
-#define RCLASS_NAMESPACEABLE FL_USER4
+#define RCLASS_BOXABLE FL_USER4
static inline st_table *
RCLASS_CLASSEXT_TBL(VALUE klass)
{
- if (FL_TEST_RAW(klass, RCLASS_NAMESPACEABLE)) {
- struct RClass_namespaceable *ns_klass = (struct RClass_namespaceable *)klass;
- return ns_klass->ns_classext_tbl;
+ if (FL_TEST_RAW(klass, RCLASS_BOXABLE)) {
+ struct RClass_boxable *box_klass = (struct RClass_boxable *)klass;
+ return box_klass->box_classext_tbl;
}
return NULL;
}
@@ -308,25 +308,25 @@ RCLASS_CLASSEXT_TBL(VALUE klass)
static inline void
RCLASS_SET_CLASSEXT_TBL(VALUE klass, st_table *tbl)
{
- RUBY_ASSERT(FL_TEST_RAW(klass, RCLASS_NAMESPACEABLE));
- struct RClass_namespaceable *ns_klass = (struct RClass_namespaceable *)klass;
- ns_klass->ns_classext_tbl = tbl;
+ RUBY_ASSERT(FL_TEST_RAW(klass, RCLASS_BOXABLE));
+ struct RClass_boxable *box_klass = (struct RClass_boxable *)klass;
+ box_klass->box_classext_tbl = tbl;
}
/* class.c */
-rb_classext_t * rb_class_duplicate_classext(rb_classext_t *orig, VALUE obj, const rb_namespace_t *ns);
+rb_classext_t * rb_class_duplicate_classext(rb_classext_t *orig, VALUE obj, const rb_box_t *box);
void rb_class_ensure_writable(VALUE obj);
-void rb_class_set_namespace_classext(VALUE obj, const rb_namespace_t *ns, rb_classext_t *ext);
+void rb_class_set_box_classext(VALUE obj, const rb_box_t *box, rb_classext_t *ext);
static inline int
-RCLASS_SET_NAMESPACE_CLASSEXT(VALUE obj, const rb_namespace_t *ns, rb_classext_t *ext)
+RCLASS_SET_BOX_CLASSEXT(VALUE obj, const rb_box_t *box, rb_classext_t *ext)
{
int first_set = 0;
st_table *tbl = RCLASS_CLASSEXT_TBL(obj);
- VM_ASSERT(NAMESPACE_USER_P(ns)); // non-prime classext is only for user namespace, with ns_object
- VM_ASSERT(ns->ns_object);
- VM_ASSERT(RCLASSEXT_NS(ext) == ns);
+ VM_ASSERT(BOX_USER_P(box)); // non-prime classext is only for user box, with box_object
+ VM_ASSERT(box->box_object);
+ VM_ASSERT(RCLASSEXT_BOX(ext) == box);
if (!tbl) {
tbl = st_init_numtable_with_size(1);
RCLASS_SET_CLASSEXT_TBL(obj, tbl);
@@ -335,28 +335,28 @@ RCLASS_SET_NAMESPACE_CLASSEXT(VALUE obj, const rb_namespace_t *ns, rb_classext_t
first_set = 1;
}
- rb_class_set_namespace_classext(obj, ns, ext);
+ rb_class_set_box_classext(obj, box, ext);
return first_set;
}
-#define VM_ASSERT_NAMESPACEABLE_TYPE(klass) \
- VM_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_MODULE) || RB_TYPE_P(klass, T_ICLASS), "%s is not namespaceable type", rb_type_str(BUILTIN_TYPE(klass)))
+#define VM_ASSERT_BOXABLE_TYPE(klass) \
+ VM_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_MODULE) || RB_TYPE_P(klass, T_ICLASS), "%s is not boxable type", rb_type_str(BUILTIN_TYPE(klass)))
static inline bool
RCLASS_PRIME_CLASSEXT_READABLE_P(VALUE klass)
{
VM_ASSERT(klass != 0, "klass should be a valid object");
- VM_ASSERT_NAMESPACEABLE_TYPE(klass);
+ VM_ASSERT_BOXABLE_TYPE(klass);
// if the lookup table exists, then it means the prime classext is NOT directly readable.
- return !FL_TEST_RAW(klass, RCLASS_NAMESPACEABLE) || RCLASS_CLASSEXT_TBL(klass) == NULL;
+ return !FL_TEST_RAW(klass, RCLASS_BOXABLE) || RCLASS_CLASSEXT_TBL(klass) == NULL;
}
static inline bool
RCLASS_PRIME_CLASSEXT_WRITABLE_P(VALUE klass)
{
VM_ASSERT(klass != 0, "klass should be a valid object");
- VM_ASSERT_NAMESPACEABLE_TYPE(klass);
+ VM_ASSERT_BOXABLE_TYPE(klass);
return FL_TEST(klass, RCLASS_PRIME_CLASSEXT_WRITABLE);
}
@@ -364,7 +364,7 @@ static inline void
RCLASS_SET_PRIME_CLASSEXT_WRITABLE(VALUE klass, bool writable)
{
VM_ASSERT(klass != 0, "klass should be a valid object");
- VM_ASSERT_NAMESPACEABLE_TYPE(klass);
+ VM_ASSERT_BOXABLE_TYPE(klass);
if (writable) {
FL_SET(klass, RCLASS_PRIME_CLASSEXT_WRITABLE);
}
@@ -374,12 +374,12 @@ RCLASS_SET_PRIME_CLASSEXT_WRITABLE(VALUE klass, bool writable)
}
static inline rb_classext_t *
-RCLASS_EXT_TABLE_LOOKUP_INTERNAL(VALUE obj, const rb_namespace_t *ns)
+RCLASS_EXT_TABLE_LOOKUP_INTERNAL(VALUE obj, const rb_box_t *box)
{
st_data_t classext_ptr;
st_table *classext_tbl = RCLASS_CLASSEXT_TBL(obj);
if (classext_tbl) {
- if (rb_st_lookup(classext_tbl, (st_data_t)ns->ns_object, &classext_ptr)) {
+ if (rb_st_lookup(classext_tbl, (st_data_t)box->box_object, &classext_ptr)) {
return (rb_classext_t *)classext_ptr;
}
}
@@ -387,9 +387,9 @@ RCLASS_EXT_TABLE_LOOKUP_INTERNAL(VALUE obj, const rb_namespace_t *ns)
}
static inline rb_classext_t *
-RCLASS_EXT_READABLE_LOOKUP(VALUE obj, const rb_namespace_t *ns)
+RCLASS_EXT_READABLE_LOOKUP(VALUE obj, const rb_box_t *box)
{
- rb_classext_t *ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(obj, ns);
+ rb_classext_t *ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(obj, box);
if (ext)
return ext;
// Classext for the ns not found. Refer the prime one instead.
@@ -397,46 +397,46 @@ RCLASS_EXT_READABLE_LOOKUP(VALUE obj, const rb_namespace_t *ns)
}
static inline rb_classext_t *
-RCLASS_EXT_READABLE_IN_NS(VALUE obj, const rb_namespace_t *ns)
+RCLASS_EXT_READABLE_IN_BOX(VALUE obj, const rb_box_t *box)
{
- if (NAMESPACE_ROOT_P(ns)
+ if (BOX_ROOT_P(box)
|| RCLASS_PRIME_CLASSEXT_READABLE_P(obj)) {
return RCLASS_EXT_PRIME(obj);
}
- return RCLASS_EXT_READABLE_LOOKUP(obj, ns);
+ return RCLASS_EXT_READABLE_LOOKUP(obj, box);
}
static inline rb_classext_t *
RCLASS_EXT_READABLE(VALUE obj)
{
- const rb_namespace_t *ns;
+ const rb_box_t *box;
if (RCLASS_PRIME_CLASSEXT_READABLE_P(obj)) {
return RCLASS_EXT_PRIME(obj);
}
- // delay determining the current namespace to optimize for unmodified classes
- ns = rb_current_namespace();
- if (NAMESPACE_ROOT_P(ns)) {
+ // delay determining the current box to optimize for unmodified classes
+ box = rb_current_box();
+ if (BOX_ROOT_P(box)) {
return RCLASS_EXT_PRIME(obj);
}
- return RCLASS_EXT_READABLE_LOOKUP(obj, ns);
+ return RCLASS_EXT_READABLE_LOOKUP(obj, box);
}
static inline rb_classext_t *
-RCLASS_EXT_WRITABLE_LOOKUP(VALUE obj, const rb_namespace_t *ns)
+RCLASS_EXT_WRITABLE_LOOKUP(VALUE obj, const rb_box_t *box)
{
rb_classext_t *ext;
int first_set = 0;
- ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(obj, ns);
+ ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(obj, box);
if (ext)
return ext;
RB_VM_LOCKING() {
// re-check the classext is not created to avoid the multi-thread race
- ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(obj, ns);
+ ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(obj, box);
if (!ext) {
- ext = rb_class_duplicate_classext(RCLASS_EXT_PRIME(obj), obj, ns);
- first_set = RCLASS_SET_NAMESPACE_CLASSEXT(obj, ns, ext);
+ ext = rb_class_duplicate_classext(RCLASS_EXT_PRIME(obj), obj, box);
+ first_set = RCLASS_SET_BOX_CLASSEXT(obj, box, ext);
if (first_set) {
// TODO: are there any case that a class/module become non-writable after its birthtime?
RCLASS_SET_PRIME_CLASSEXT_WRITABLE(obj, false);
@@ -447,28 +447,28 @@ RCLASS_EXT_WRITABLE_LOOKUP(VALUE obj, const rb_namespace_t *ns)
}
static inline rb_classext_t *
-RCLASS_EXT_WRITABLE_IN_NS(VALUE obj, const rb_namespace_t *ns)
+RCLASS_EXT_WRITABLE_IN_BOX(VALUE obj, const rb_box_t *box)
{
- if (NAMESPACE_ROOT_P(ns)
+ if (BOX_ROOT_P(box)
|| RCLASS_PRIME_CLASSEXT_WRITABLE_P(obj)) {
return RCLASS_EXT_PRIME(obj);
}
- return RCLASS_EXT_WRITABLE_LOOKUP(obj, ns);
+ return RCLASS_EXT_WRITABLE_LOOKUP(obj, box);
}
static inline rb_classext_t *
RCLASS_EXT_WRITABLE(VALUE obj)
{
- const rb_namespace_t *ns;
+ const rb_box_t *box;
if (LIKELY(RCLASS_PRIME_CLASSEXT_WRITABLE_P(obj))) {
return RCLASS_EXT_PRIME(obj);
}
- // delay determining the current namespace to optimize for unmodified classes
- ns = rb_current_namespace();
- if (NAMESPACE_ROOT_P(ns)) {
+ // delay determining the current box to optimize for unmodified classes
+ box = rb_current_box();
+ if (BOX_ROOT_P(box)) {
return RCLASS_EXT_PRIME(obj);
}
- return RCLASS_EXT_WRITABLE_LOOKUP(obj, ns);
+ return RCLASS_EXT_WRITABLE_LOOKUP(obj, box);
}
static inline void
@@ -485,7 +485,7 @@ RCLASSEXT_SET_INCLUDER(rb_classext_t *ext, VALUE klass, VALUE includer)
}
/* class.c */
-typedef void rb_class_classext_foreach_callback_func(rb_classext_t *classext, bool is_prime, VALUE namespace, void *arg);
+typedef void rb_class_classext_foreach_callback_func(rb_classext_t *classext, bool is_prime, VALUE box_value, void *arg);
void rb_class_classext_foreach(VALUE klass, rb_class_classext_foreach_callback_func *func, void *arg);
void rb_class_subclass_add(VALUE super, VALUE klass);
void rb_class_remove_from_super_subclasses(VALUE);
@@ -739,21 +739,21 @@ RCLASS_SET_SUBCLASSES(VALUE klass, struct rb_subclass_anchor *anchor)
}
static inline void
-RCLASS_WRITE_NS_SUPER_SUBCLASSES(VALUE klass, rb_ns_subclasses_t *ns_subclasses)
+RCLASS_WRITE_BOX_SUPER_SUBCLASSES(VALUE klass, rb_box_subclasses_t *box_subclasses)
{
rb_classext_t *ext = RCLASS_EXT_WRITABLE(klass);
- if (RCLASSEXT_NS_SUPER_SUBCLASSES(ext))
- rb_ns_subclasses_ref_dec(RCLASSEXT_NS_SUPER_SUBCLASSES(ext));
- RCLASSEXT_NS_SUPER_SUBCLASSES(ext) = rb_ns_subclasses_ref_inc(ns_subclasses);
+ if (RCLASSEXT_BOX_SUPER_SUBCLASSES(ext))
+ rb_box_subclasses_ref_dec(RCLASSEXT_BOX_SUPER_SUBCLASSES(ext));
+ RCLASSEXT_BOX_SUPER_SUBCLASSES(ext) = rb_box_subclasses_ref_inc(box_subclasses);
}
static inline void
-RCLASS_WRITE_NS_MODULE_SUBCLASSES(VALUE klass, rb_ns_subclasses_t *ns_subclasses)
+RCLASS_WRITE_BOX_MODULE_SUBCLASSES(VALUE klass, rb_box_subclasses_t *box_subclasses)
{
rb_classext_t *ext = RCLASS_EXT_WRITABLE(klass);
- if (RCLASSEXT_NS_MODULE_SUBCLASSES(ext))
- rb_ns_subclasses_ref_dec(RCLASSEXT_NS_MODULE_SUBCLASSES(ext));
- RCLASSEXT_NS_MODULE_SUBCLASSES(ext) = rb_ns_subclasses_ref_inc(ns_subclasses);
+ if (RCLASSEXT_BOX_MODULE_SUBCLASSES(ext))
+ rb_box_subclasses_ref_dec(RCLASSEXT_BOX_MODULE_SUBCLASSES(ext));
+ RCLASSEXT_BOX_MODULE_SUBCLASSES(ext) = rb_box_subclasses_ref_inc(box_subclasses);
}
static inline void
diff --git a/internal/inits.h b/internal/inits.h
index c1cf3db94d..dee818285c 100644
--- a/internal/inits.h
+++ b/internal/inits.h
@@ -9,6 +9,10 @@
* @brief Internal header aggregating init functions.
*/
+/* box.c */
+void Init_enable_box(void);
+void Init_root_box(void);
+
/* class.c */
void Init_class_hierarchy(void);
@@ -25,16 +29,10 @@ int Init_enc_set_filesystem_encoding(void);
/* newline.c */
void Init_newline(void);
-/* namespace.c */
-void Init_enable_namespace(void);
-
/* vm.c */
void Init_BareVM(void);
void Init_vm_objects(void);
-/* namespace.c */
-void Init_root_namespace(void);
-
/* vm_backtrace.c */
void Init_vm_backtrace(void);
diff --git a/internal/variable.h b/internal/variable.h
index 5e2bcceb61..ca5e189c90 100644
--- a/internal/variable.h
+++ b/internal/variable.h
@@ -22,13 +22,13 @@ VALUE rb_search_class_path(VALUE);
VALUE rb_attr_delete(VALUE, ID);
void rb_autoload_str(VALUE mod, ID id, VALUE file);
VALUE rb_autoload_at_p(VALUE, ID, int);
-void rb_autoload_copy_table_for_namespace(st_table *, const rb_namespace_t *);
+void rb_autoload_copy_table_for_box(st_table *, const rb_box_t *);
NORETURN(VALUE rb_mod_const_missing(VALUE,VALUE));
rb_gvar_getter_t *rb_gvar_getter_function_of(ID);
rb_gvar_setter_t *rb_gvar_setter_function_of(ID);
void rb_gvar_readonly_setter(VALUE v, ID id, VALUE *_);
void rb_gvar_ractor_local(const char *name);
-void rb_gvar_namespace_ready(const char *name);
+void rb_gvar_box_ready(const char *name);
/**
* Sets the name of a module.
diff --git a/iseq.c b/iseq.c
index df849d0521..9bf56ad655 100644
--- a/iseq.c
+++ b/iseq.c
@@ -2003,7 +2003,7 @@ iseqw_eval(VALUE self)
if (0 == ISEQ_BODY(iseq)->iseq_size) {
rb_raise(rb_eTypeError, "attempt to evaluate dummy InstructionSequence");
}
- return rb_iseq_eval(iseq, rb_current_namespace());
+ return rb_iseq_eval(iseq, rb_current_box());
}
/*
diff --git a/load.c b/load.c
index c38a5fbd32..69f1d365f2 100644
--- a/load.c
+++ b/load.c
@@ -65,10 +65,10 @@ enum expand_type {
string objects in $LOAD_PATH are frozen.
*/
static void
-rb_construct_expanded_load_path(rb_namespace_t *ns, enum expand_type type, int *has_relative, int *has_non_cache)
+rb_construct_expanded_load_path(rb_box_t *box, enum expand_type type, int *has_relative, int *has_non_cache)
{
- VALUE load_path = ns->load_path;
- VALUE expanded_load_path = ns->expanded_load_path;
+ VALUE load_path = box->load_path;
+ VALUE expanded_load_path = box->expanded_load_path;
VALUE snapshot;
VALUE ary;
long i;
@@ -108,39 +108,39 @@ rb_construct_expanded_load_path(rb_namespace_t *ns, enum expand_type type, int *
rb_ary_push(ary, rb_fstring(expanded_path));
}
rb_ary_freeze(ary);
- ns->expanded_load_path = ary;
- snapshot = ns->load_path_snapshot;
- load_path = ns->load_path;
+ box->expanded_load_path = ary;
+ snapshot = box->load_path_snapshot;
+ load_path = box->load_path;
rb_ary_replace(snapshot, load_path);
}
static VALUE
-get_expanded_load_path(rb_namespace_t *ns)
+get_expanded_load_path(rb_box_t *box)
{
VALUE check_cache;
const VALUE non_cache = Qtrue;
- const VALUE load_path_snapshot = ns->load_path_snapshot;
- const VALUE load_path = ns->load_path;
+ const VALUE load_path_snapshot = box->load_path_snapshot;
+ const VALUE load_path = box->load_path;
if (!rb_ary_shared_with_p(load_path_snapshot, load_path)) {
/* The load path was modified. Rebuild the expanded load path. */
int has_relative = 0, has_non_cache = 0;
- rb_construct_expanded_load_path(ns, EXPAND_ALL, &has_relative, &has_non_cache);
+ rb_construct_expanded_load_path(box, EXPAND_ALL, &has_relative, &has_non_cache);
if (has_relative) {
- ns->load_path_check_cache = rb_dir_getwd_ospath();
+ box->load_path_check_cache = rb_dir_getwd_ospath();
}
else if (has_non_cache) {
/* Non string object. */
- ns->load_path_check_cache = non_cache;
+ box->load_path_check_cache = non_cache;
}
else {
- ns->load_path_check_cache = 0;
+ box->load_path_check_cache = 0;
}
}
- else if ((check_cache = ns->load_path_check_cache) == non_cache) {
+ else if ((check_cache = box->load_path_check_cache) == non_cache) {
int has_relative = 1, has_non_cache = 1;
/* Expand only non-cacheable objects. */
- rb_construct_expanded_load_path(ns, EXPAND_NON_CACHE,
+ rb_construct_expanded_load_path(box, EXPAND_NON_CACHE,
&has_relative, &has_non_cache);
}
else if (check_cache) {
@@ -149,49 +149,49 @@ get_expanded_load_path(rb_namespace_t *ns)
if (!rb_str_equal(check_cache, cwd)) {
/* Current working directory or filesystem encoding was changed.
Expand relative load path and non-cacheable objects again. */
- ns->load_path_check_cache = cwd;
- rb_construct_expanded_load_path(ns, EXPAND_RELATIVE,
+ box->load_path_check_cache = cwd;
+ rb_construct_expanded_load_path(box, EXPAND_RELATIVE,
&has_relative, &has_non_cache);
}
else {
/* Expand only tilde (User HOME) and non-cacheable objects. */
- rb_construct_expanded_load_path(ns, EXPAND_HOME,
+ rb_construct_expanded_load_path(box, EXPAND_HOME,
&has_relative, &has_non_cache);
}
}
- return ns->expanded_load_path;
+ return box->expanded_load_path;
}
VALUE
rb_get_expanded_load_path(void)
{
- return get_expanded_load_path((rb_namespace_t *)rb_loading_namespace());
+ return get_expanded_load_path((rb_box_t *)rb_loading_box());
}
static VALUE
load_path_getter(ID _x, VALUE * _y)
{
- return rb_loading_namespace()->load_path;
+ return rb_loading_box()->load_path;
}
static VALUE
get_LOADED_FEATURES(ID _x, VALUE *_y)
{
- return rb_loading_namespace()->loaded_features;
+ return rb_loading_box()->loaded_features;
}
static void
-reset_loaded_features_snapshot(const rb_namespace_t *ns)
+reset_loaded_features_snapshot(const rb_box_t *box)
{
- VALUE snapshot = ns->loaded_features_snapshot;
- VALUE loaded_features = ns->loaded_features;
+ VALUE snapshot = box->loaded_features_snapshot;
+ VALUE loaded_features = box->loaded_features;
rb_ary_replace(snapshot, loaded_features);
}
static struct st_table *
-get_loaded_features_index_raw(const rb_namespace_t *ns)
+get_loaded_features_index_raw(const rb_box_t *box)
{
- return ns->loaded_features_index;
+ return box->loaded_features_index;
}
static st_data_t
@@ -212,7 +212,7 @@ is_rbext_path(VALUE feature_path)
typedef rb_darray(long) feature_indexes_t;
struct features_index_add_single_args {
- const rb_namespace_t *ns;
+ const rb_box_t *box;
VALUE offset;
bool rb;
};
@@ -221,7 +221,7 @@ static int
features_index_add_single_callback(st_data_t *key, st_data_t *value, st_data_t raw_args, int existing)
{
struct features_index_add_single_args *args = (struct features_index_add_single_args *)raw_args;
- const rb_namespace_t *ns = args->ns;
+ const rb_box_t *box = args->box;
VALUE offset = args->offset;
bool rb = args->rb;
@@ -229,7 +229,7 @@ features_index_add_single_callback(st_data_t *key, st_data_t *value, st_data_t r
VALUE this_feature_index = *value;
if (FIXNUM_P(this_feature_index)) {
- VALUE loaded_features = ns->loaded_features;
+ VALUE loaded_features = box->loaded_features;
VALUE this_feature_path = RARRAY_AREF(loaded_features, FIX2LONG(this_feature_index));
feature_indexes_t feature_indexes;
@@ -249,7 +249,7 @@ features_index_add_single_callback(st_data_t *key, st_data_t *value, st_data_t r
long pos = -1;
if (rb) {
- VALUE loaded_features = ns->loaded_features;
+ VALUE loaded_features = box->loaded_features;
for (size_t i = 0; i < rb_darray_size(feature_indexes); ++i) {
long idx = rb_darray_get(feature_indexes, i);
VALUE this_feature_path = RARRAY_AREF(loaded_features, idx);
@@ -281,7 +281,7 @@ features_index_add_single_callback(st_data_t *key, st_data_t *value, st_data_t r
}
static void
-features_index_add_single(const rb_namespace_t *ns, const char* str, size_t len, VALUE offset, bool rb)
+features_index_add_single(const rb_box_t *box, const char* str, size_t len, VALUE offset, bool rb)
{
struct st_table *features_index;
st_data_t short_feature_key;
@@ -289,10 +289,10 @@ features_index_add_single(const rb_namespace_t *ns, const char* str, size_t len,
Check_Type(offset, T_FIXNUM);
short_feature_key = feature_key(str, len);
- features_index = get_loaded_features_index_raw(ns);
+ features_index = get_loaded_features_index_raw(box);
struct features_index_add_single_args args = {
- .ns = ns,
+ .box = box,
.offset = offset,
.rb = rb,
};
@@ -309,7 +309,7 @@ features_index_add_single(const rb_namespace_t *ns, const char* str, size_t len,
relies on for its fast lookup.
*/
static void
-features_index_add(const rb_namespace_t *ns, VALUE feature, VALUE offset)
+features_index_add(const rb_box_t *box, VALUE feature, VALUE offset)
{
RUBY_ASSERT(rb_ractor_main_p());
@@ -337,14 +337,14 @@ features_index_add(const rb_namespace_t *ns, VALUE feature, VALUE offset)
if (p < feature_str)
break;
/* Now *p == '/'. We reach this point for every '/' in `feature`. */
- features_index_add_single(ns, p + 1, feature_end - p - 1, offset, false);
+ features_index_add_single(box, p + 1, feature_end - p - 1, offset, false);
if (ext) {
- features_index_add_single(ns, p + 1, ext - p - 1, offset, rb);
+ features_index_add_single(box, p + 1, ext - p - 1, offset, rb);
}
}
- features_index_add_single(ns, feature_str, feature_end - feature_str, offset, false);
+ features_index_add_single(box, feature_str, feature_end - feature_str, offset, false);
if (ext) {
- features_index_add_single(ns, feature_str, ext - feature_str, offset, rb);
+ features_index_add_single(box, feature_str, ext - feature_str, offset, rb);
}
}
@@ -359,19 +359,19 @@ loaded_features_index_clear_i(st_data_t key, st_data_t val, st_data_t arg)
}
static st_table *
-get_loaded_features_index(const rb_namespace_t *ns)
+get_loaded_features_index(const rb_box_t *box)
{
int i;
- VALUE features = ns->loaded_features;
- const VALUE snapshot = ns->loaded_features_snapshot;
+ VALUE features = box->loaded_features;
+ const VALUE snapshot = box->loaded_features_snapshot;
if (!rb_ary_shared_with_p(snapshot, features)) {
/* The sharing was broken; something (other than us in rb_provide_feature())
modified loaded_features. Rebuild the index. */
- st_foreach(ns->loaded_features_index, loaded_features_index_clear_i, 0);
+ st_foreach(box->loaded_features_index, loaded_features_index_clear_i, 0);
- VALUE realpaths = ns->loaded_features_realpaths;
- VALUE realpath_map = ns->loaded_features_realpath_map;
+ VALUE realpaths = box->loaded_features_realpaths;
+ VALUE realpath_map = box->loaded_features_realpath_map;
VALUE previous_realpath_map = rb_hash_dup(realpath_map);
rb_hash_clear(realpaths);
rb_hash_clear(realpath_map);
@@ -387,15 +387,15 @@ get_loaded_features_index(const rb_namespace_t *ns)
as_str = rb_fstring(as_str);
if (as_str != entry)
rb_ary_store(features, i, as_str);
- features_index_add(ns, as_str, INT2FIX(i));
+ features_index_add(box, as_str, INT2FIX(i));
}
/* The user modified $LOADED_FEATURES, so we should restore the changes. */
- if (!rb_ary_shared_with_p(features, ns->loaded_features)) {
- rb_ary_replace(ns->loaded_features, features);
+ if (!rb_ary_shared_with_p(features, box->loaded_features)) {
+ rb_ary_replace(box->loaded_features, features);
}
- reset_loaded_features_snapshot(ns);
+ reset_loaded_features_snapshot(box);
- features = ns->loaded_features_snapshot;
+ features = box->loaded_features_snapshot;
long j = RARRAY_LEN(features);
for (i = 0; i < j; i++) {
VALUE as_str = rb_ary_entry(features, i);
@@ -409,7 +409,7 @@ get_loaded_features_index(const rb_namespace_t *ns)
rb_hash_aset(realpath_map, as_str, realpath);
}
}
- return ns->loaded_features_index;
+ return box->loaded_features_index;
}
/* This searches `load_path` for a value such that
@@ -494,7 +494,7 @@ loaded_feature_path_i(st_data_t v, st_data_t b, st_data_t f)
* 'u': unsuffixed
*/
static int
-rb_feature_p(const rb_namespace_t *ns, const char *feature, const char *ext, int rb, int expanded, const char **fn)
+rb_feature_p(const rb_box_t *box, const char *feature, const char *ext, int rb, int expanded, const char **fn)
{
VALUE features, this_feature_index = Qnil, v, p, load_path = 0;
const char *f, *e;
@@ -515,8 +515,8 @@ rb_feature_p(const rb_namespace_t *ns, const char *feature, const char *ext, int
elen = 0;
type = 0;
}
- features = ns->loaded_features;
- features_index = get_loaded_features_index(ns);
+ features = box->loaded_features;
+ features_index = get_loaded_features_index(box);
key = feature_key(feature, strlen(feature));
/* We search `features` for an entry such that either
@@ -564,7 +564,7 @@ rb_feature_p(const rb_namespace_t *ns, const char *feature, const char *ext, int
if ((n = RSTRING_LEN(v)) < len) continue;
if (strncmp(f, feature, len) != 0) {
if (expanded) continue;
- if (!load_path) load_path = get_expanded_load_path((rb_namespace_t *)ns);
+ if (!load_path) load_path = get_expanded_load_path((rb_box_t *)box);
if (!(p = loaded_feature_path(f, n, feature, len, type, load_path)))
continue;
expanded = 1;
@@ -584,14 +584,14 @@ rb_feature_p(const rb_namespace_t *ns, const char *feature, const char *ext, int
}
}
- loading_tbl = ns->loading_table;
+ loading_tbl = box->loading_table;
f = 0;
if (!expanded && !rb_is_absolute_path(feature)) {
struct loaded_feature_searching fs;
fs.name = feature;
fs.len = len;
fs.type = type;
- fs.load_path = load_path ? load_path : get_expanded_load_path((rb_namespace_t *)ns);
+ fs.load_path = load_path ? load_path : get_expanded_load_path((rb_box_t *)box);
fs.result = 0;
st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
if ((f = fs.result) != 0) {
@@ -646,7 +646,7 @@ rb_provided(const char *feature)
}
static int
-feature_provided(rb_namespace_t *ns, const char *feature, const char **loading)
+feature_provided(rb_box_t *box, const char *feature, const char **loading)
{
const char *ext = strrchr(feature, '.');
VALUE fullpath = 0;
@@ -658,15 +658,15 @@ feature_provided(rb_namespace_t *ns, const char *feature, const char **loading)
}
if (ext && !strchr(ext, '/')) {
if (IS_RBEXT(ext)) {
- if (rb_feature_p(ns, feature, ext, TRUE, FALSE, loading)) return TRUE;
+ if (rb_feature_p(box, feature, ext, TRUE, FALSE, loading)) return TRUE;
return FALSE;
}
else if (IS_SOEXT(ext) || IS_DLEXT(ext)) {
- if (rb_feature_p(ns, feature, ext, FALSE, FALSE, loading)) return TRUE;
+ if (rb_feature_p(box, feature, ext, FALSE, FALSE, loading)) return TRUE;
return FALSE;
}
}
- if (rb_feature_p(ns, feature, 0, TRUE, FALSE, loading))
+ if (rb_feature_p(box, feature, 0, TRUE, FALSE, loading))
return TRUE;
RB_GC_GUARD(fullpath);
return FALSE;
@@ -675,40 +675,40 @@ feature_provided(rb_namespace_t *ns, const char *feature, const char **loading)
int
rb_feature_provided(const char *feature, const char **loading)
{
- rb_namespace_t *ns = (rb_namespace_t *)rb_current_namespace();
- return feature_provided(ns, feature, loading);
+ rb_box_t *box = (rb_box_t *)rb_current_box();
+ return feature_provided(box, feature, loading);
}
static void
-rb_provide_feature(const rb_namespace_t *ns, VALUE feature)
+rb_provide_feature(const rb_box_t *box, VALUE feature)
{
VALUE features;
- features = ns->loaded_features;
+ features = box->loaded_features;
if (OBJ_FROZEN(features)) {
rb_raise(rb_eRuntimeError,
"$LOADED_FEATURES is frozen; cannot append feature");
}
feature = rb_fstring(feature);
- get_loaded_features_index(ns);
+ get_loaded_features_index(box);
// If loaded_features and loaded_features_snapshot share the same backing
// array, pushing into it would cause the whole array to be copied.
// To avoid this we first clear loaded_features_snapshot.
- rb_ary_clear(ns->loaded_features_snapshot);
+ rb_ary_clear(box->loaded_features_snapshot);
rb_ary_push(features, feature);
- features_index_add(ns, feature, INT2FIX(RARRAY_LEN(features)-1));
- reset_loaded_features_snapshot(ns);
+ features_index_add(box, feature, INT2FIX(RARRAY_LEN(features)-1));
+ reset_loaded_features_snapshot(box);
}
void
rb_provide(const char *feature)
{
/*
- * rb_provide() must use rb_current_namespace to store provided features
- * in the current namespace's loaded_features, etc.
+ * rb_provide() must use rb_current_box to store provided features
+ * in the current box's loaded_features, etc.
*/
- rb_provide_feature(rb_current_namespace(), rb_fstring_cstr(feature));
+ rb_provide_feature(rb_current_box(), rb_fstring_cstr(feature));
}
NORETURN(static void load_failed(VALUE));
@@ -729,14 +729,14 @@ realpath_internal_cached(VALUE hash, VALUE path)
static inline void
load_iseq_eval(rb_execution_context_t *ec, VALUE fname)
{
- const rb_namespace_t *ns = rb_loading_namespace();
+ const rb_box_t *box = rb_loading_box();
const rb_iseq_t *iseq = rb_iseq_load_iseq(fname);
if (!iseq) {
rb_execution_context_t *ec = GET_EC();
VALUE v = rb_vm_push_frame_fname(ec, fname);
- VALUE realpath_map = ns->loaded_features_realpath_map;
+ VALUE realpath_map = box->loaded_features_realpath_map;
if (rb_ruby_prism_p()) {
pm_parse_result_t result = { 0 };
@@ -781,14 +781,14 @@ load_iseq_eval(rb_execution_context_t *ec, VALUE fname)
}
rb_exec_event_hook_script_compiled(ec, iseq, Qnil);
- rb_iseq_eval(iseq, ns);
+ rb_iseq_eval(iseq, box);
}
static inline enum ruby_tag_type
load_wrapping(rb_execution_context_t *ec, VALUE fname, VALUE load_wrapper)
{
enum ruby_tag_type state;
- rb_namespace_t *ns;
+ rb_box_t *box;
rb_thread_t *th = rb_ec_thread_ptr(ec);
volatile VALUE wrapper = th->top_wrapper;
volatile VALUE self = th->top_self;
@@ -799,12 +799,12 @@ load_wrapping(rb_execution_context_t *ec, VALUE fname, VALUE load_wrapper)
ec->errinfo = Qnil; /* ensure */
/* load in module as toplevel */
- if (NAMESPACE_OBJ_P(load_wrapper)) {
- ns = rb_get_namespace_t(load_wrapper);
- if (!ns->top_self) {
- ns->top_self = rb_obj_clone(rb_vm_top_self());
+ if (BOX_OBJ_P(load_wrapper)) {
+ box = rb_get_box_t(load_wrapper);
+ if (!box->top_self) {
+ box->top_self = rb_obj_clone(rb_vm_top_self());
}
- th->top_self = ns->top_self;
+ th->top_self = box->top_self;
}
else {
th->top_self = rb_obj_clone(rb_vm_top_self());
@@ -843,9 +843,9 @@ raise_load_if_failed(rb_execution_context_t *ec, enum ruby_tag_type state)
static void
rb_load_internal(VALUE fname, VALUE wrap)
{
- VALUE namespace;
+ VALUE box_value;
rb_execution_context_t *ec = GET_EC();
- const rb_namespace_t *ns = rb_loading_namespace();
+ const rb_box_t *box = rb_loading_box();
enum ruby_tag_type state = TAG_NONE;
if (RTEST(wrap)) {
if (!RB_TYPE_P(wrap, T_MODULE)) {
@@ -853,9 +853,9 @@ rb_load_internal(VALUE fname, VALUE wrap)
}
state = load_wrapping(ec, fname, wrap);
}
- else if (NAMESPACE_OPTIONAL_P(ns)) {
- namespace = ns->ns_object;
- state = load_wrapping(ec, fname, namespace);
+ else if (BOX_OPTIONAL_P(box)) {
+ box_value = box->box_object;
+ state = load_wrapping(ec, fname, box_value);
}
else {
load_iseq_eval(ec, fname);
@@ -958,10 +958,10 @@ rb_f_load(int argc, VALUE *argv, VALUE _)
}
static char *
-load_lock(const rb_namespace_t *ns, const char *ftptr, bool warn)
+load_lock(const rb_box_t *box, const char *ftptr, bool warn)
{
st_data_t data;
- st_table *loading_tbl = ns->loading_table;
+ st_table *loading_tbl = box->loading_table;
if (!st_lookup(loading_tbl, (st_data_t)ftptr, &data)) {
/* partial state */
@@ -1003,11 +1003,11 @@ release_thread_shield(st_data_t *key, st_data_t *value, st_data_t done, int exis
}
static void
-load_unlock(const rb_namespace_t *ns, const char *ftptr, int done)
+load_unlock(const rb_box_t *box, const char *ftptr, int done)
{
if (ftptr) {
st_data_t key = (st_data_t)ftptr;
- st_table *loading_tbl = ns->loading_table;
+ st_table *loading_tbl = box->loading_table;
st_update(loading_tbl, key, release_thread_shield, done);
}
@@ -1055,8 +1055,6 @@ static VALUE rb_require_string_internal(VALUE fname, bool resurrect);
VALUE
rb_f_require(VALUE obj, VALUE fname)
{
- // const rb_namespace_t *ns = rb_loading_namespace();
- // printf("F:current loading ns: %ld\n", ns->ns_id);
return rb_require_string(fname);
}
@@ -1086,10 +1084,10 @@ rb_f_require_relative(VALUE obj, VALUE fname)
return rb_require_relative_entrypoint(fname);
}
-typedef int (*feature_func)(const rb_namespace_t *ns, const char *feature, const char *ext, int rb, int expanded, const char **fn);
+typedef int (*feature_func)(const rb_box_t *box, const char *feature, const char *ext, int rb, int expanded, const char **fn);
static int
-search_required(const rb_namespace_t *ns, VALUE fname, volatile VALUE *path, feature_func rb_feature_p)
+search_required(const rb_box_t *box, VALUE fname, volatile VALUE *path, feature_func rb_feature_p)
{
VALUE tmp;
char *ext, *ftptr;
@@ -1100,20 +1098,20 @@ search_required(const rb_namespace_t *ns, VALUE fname, volatile VALUE *path, fea
ext = strrchr(ftptr = RSTRING_PTR(fname), '.');
if (ext && !strchr(ext, '/')) {
if (IS_RBEXT(ext)) {
- if (rb_feature_p(ns, ftptr, ext, TRUE, FALSE, &loading)) {
+ if (rb_feature_p(box, ftptr, ext, TRUE, FALSE, &loading)) {
if (loading) *path = rb_filesystem_str_new_cstr(loading);
return 'r';
}
if ((tmp = rb_find_file(fname)) != 0) {
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
- if (!rb_feature_p(ns, ftptr, ext, TRUE, TRUE, &loading) || loading)
+ if (!rb_feature_p(box, ftptr, ext, TRUE, TRUE, &loading) || loading)
*path = tmp;
return 'r';
}
return 0;
}
else if (IS_SOEXT(ext)) {
- if (rb_feature_p(ns, ftptr, ext, FALSE, FALSE, &loading)) {
+ if (rb_feature_p(box, ftptr, ext, FALSE, FALSE, &loading)) {
if (loading) *path = rb_filesystem_str_new_cstr(loading);
return 's';
}
@@ -1122,25 +1120,25 @@ search_required(const rb_namespace_t *ns, VALUE fname, volatile VALUE *path, fea
OBJ_FREEZE(tmp);
if ((tmp = rb_find_file(tmp)) != 0) {
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
- if (!rb_feature_p(ns, ftptr, ext, FALSE, TRUE, &loading) || loading)
+ if (!rb_feature_p(box, ftptr, ext, FALSE, TRUE, &loading) || loading)
*path = tmp;
return 's';
}
}
else if (IS_DLEXT(ext)) {
- if (rb_feature_p(ns, ftptr, ext, FALSE, FALSE, &loading)) {
+ if (rb_feature_p(box, ftptr, ext, FALSE, FALSE, &loading)) {
if (loading) *path = rb_filesystem_str_new_cstr(loading);
return 's';
}
if ((tmp = rb_find_file(fname)) != 0) {
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
- if (!rb_feature_p(ns, ftptr, ext, FALSE, TRUE, &loading) || loading)
+ if (!rb_feature_p(box, ftptr, ext, FALSE, TRUE, &loading) || loading)
*path = tmp;
return 's';
}
}
}
- else if ((ft = rb_feature_p(ns, ftptr, 0, FALSE, FALSE, &loading)) == 'r') {
+ else if ((ft = rb_feature_p(box, ftptr, 0, FALSE, FALSE, &loading)) == 'r') {
if (loading) *path = rb_filesystem_str_new_cstr(loading);
return 'r';
}
@@ -1174,7 +1172,7 @@ search_required(const rb_namespace_t *ns, VALUE fname, volatile VALUE *path, fea
if (ft)
goto feature_present;
ftptr = RSTRING_PTR(tmp);
- return rb_feature_p(ns, ftptr, 0, FALSE, TRUE, 0);
+ return rb_feature_p(box, ftptr, 0, FALSE, TRUE, 0);
default:
if (ft) {
@@ -1183,7 +1181,7 @@ search_required(const rb_namespace_t *ns, VALUE fname, volatile VALUE *path, fea
/* fall through */
case loadable_ext_rb:
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
- if (rb_feature_p(ns, ftptr, ext, type == loadable_ext_rb, TRUE, &loading) && !loading)
+ if (rb_feature_p(box, ftptr, ext, type == loadable_ext_rb, TRUE, &loading) && !loading)
break;
*path = tmp;
}
@@ -1204,9 +1202,9 @@ static VALUE
load_ext(VALUE path, VALUE fname)
{
VALUE loaded = path;
- const rb_namespace_t *ns = rb_loading_namespace();
- if (NAMESPACE_USER_P(ns)) {
- loaded = rb_namespace_local_extension(ns->ns_object, fname, path);
+ const rb_box_t *box = rb_loading_box();
+ if (BOX_USER_P(box)) {
+ loaded = rb_box_local_extension(box->box_object, fname, path);
}
rb_scope_visibility_set(METHOD_VISI_PUBLIC);
return (VALUE)dln_load_feature(RSTRING_PTR(loaded), RSTRING_PTR(fname));
@@ -1228,7 +1226,7 @@ run_static_ext_init(VALUE vm_ptr, VALUE feature_value)
}
static int
-no_feature_p(const rb_namespace_t *ns, const char *feature, const char *ext, int rb, int expanded, const char **fn)
+no_feature_p(const rb_box_t *box, const char *feature, const char *ext, int rb, int expanded, const char **fn)
{
return 0;
}
@@ -1240,11 +1238,11 @@ rb_resolve_feature_path(VALUE klass, VALUE fname)
VALUE path;
int found;
VALUE sym;
- const rb_namespace_t *ns = rb_loading_namespace();
+ const rb_box_t *box = rb_loading_box();
fname = rb_get_path(fname);
path = rb_str_encode_ospath(fname);
- found = search_required(ns, path, &path, no_feature_p);
+ found = search_required(box, path, &path, no_feature_p);
switch (found) {
case 'r':
@@ -1291,22 +1289,22 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
{
volatile int result = -1;
rb_thread_t *th = rb_ec_thread_ptr(ec);
- const rb_namespace_t *ns = rb_loading_namespace();
+ const rb_box_t *box = rb_loading_box();
volatile const struct {
VALUE wrapper, self, errinfo;
rb_execution_context_t *ec;
- const rb_namespace_t *ns;
+ const rb_box_t *box;
} saved = {
th->top_wrapper, th->top_self, ec->errinfo,
- ec, ns,
+ ec, box,
};
enum ruby_tag_type state;
char *volatile ftptr = 0;
VALUE path;
volatile VALUE saved_path;
volatile VALUE realpath = 0;
- VALUE realpaths = ns->loaded_features_realpaths;
- VALUE realpath_map = ns->loaded_features_realpath_map;
+ VALUE realpaths = box->loaded_features_realpaths;
+ VALUE realpath_map = box->loaded_features_realpath_map;
volatile bool reset_ext_config = false;
volatile struct rb_ext_config prev_ext_config;
@@ -1322,18 +1320,18 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
int found;
RUBY_DTRACE_HOOK(FIND_REQUIRE_ENTRY, RSTRING_PTR(fname));
- found = search_required(ns, path, &saved_path, rb_feature_p);
+ found = search_required(box, path, &saved_path, rb_feature_p);
RUBY_DTRACE_HOOK(FIND_REQUIRE_RETURN, RSTRING_PTR(fname));
path = saved_path;
if (found) {
- if (!path || !(ftptr = load_lock(ns, RSTRING_PTR(path), warn))) {
+ if (!path || !(ftptr = load_lock(box, RSTRING_PTR(path), warn))) {
result = 0;
}
else if (!*ftptr) {
result = TAG_RETURN;
}
- else if (found == 's' && RTEST(rb_vm_call_cfunc_in_namespace(Qnil, run_static_ext_init, (VALUE)th->vm, path, path, ns))) {
+ else if (found == 's' && RTEST(rb_vm_call_cfunc_in_box(Qnil, run_static_ext_init, (VALUE)th->vm, path, path, box))) {
result = TAG_RETURN;
}
else if (RTEST(rb_hash_aref(realpaths,
@@ -1343,11 +1341,12 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
else {
switch (found) {
case 'r':
- // iseq_eval_in_namespace will be called with the loading namespace eventually
- if (NAMESPACE_OPTIONAL_P(ns)) {
- // check with NAMESPACE_OPTIONAL_P (not NAMESPACE_USER_P) for NS1::xxx naming
- // it is not expected for the main namespace
- load_wrapping(saved.ec, path, ns->ns_object);
+ // iseq_eval_in_box will be called with the loading box eventually
+ if (BOX_OPTIONAL_P(box)) {
+ // check with BOX_OPTIONAL_P (not BOX_USER_P) for NS1::xxx naming
+ // it is not expected for the main box
+ // TODO: no need to use load_wrapping() here?
+ load_wrapping(saved.ec, path, box->box_object);
}
else {
load_iseq_eval(saved.ec, path);
@@ -1357,8 +1356,8 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
case 's':
reset_ext_config = true;
ext_config_push(th, &prev_ext_config);
- handle = rb_vm_call_cfunc_in_namespace(ns->top_self, load_ext, path, fname, path, ns);
- rb_hash_aset(ns->ruby_dln_libmap, path, SVALUE2NUM((SIGNED_VALUE)handle));
+ handle = rb_vm_call_cfunc_in_box(box->top_self, load_ext, path, fname, path, box);
+ rb_hash_aset(box->ruby_dln_libmap, path, SVALUE2NUM((SIGNED_VALUE)handle));
break;
}
result = TAG_RETURN;
@@ -1368,14 +1367,14 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
EC_POP_TAG();
ec = saved.ec;
- ns = saved.ns;
+ box = saved.box;
rb_thread_t *th2 = rb_ec_thread_ptr(ec);
th2->top_self = saved.self;
th2->top_wrapper = saved.wrapper;
if (reset_ext_config) ext_config_pop(th2, &prev_ext_config);
path = saved_path;
- if (ftptr) load_unlock(ns, RSTRING_PTR(path), !state);
+ if (ftptr) load_unlock(box, RSTRING_PTR(path), !state);
if (state) {
if (state == TAG_FATAL || state == TAG_THROW) {
@@ -1401,7 +1400,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
}
if (result == TAG_RETURN) {
- rb_provide_feature(ns, path);
+ rb_provide_feature(box, path);
VALUE real = realpath;
if (real) {
real = rb_fstring(real);
@@ -1505,9 +1504,9 @@ ruby_init_ext(const char *name, void (*init)(void))
{
st_table *inits_table;
rb_vm_t *vm = GET_VM();
- const rb_namespace_t *ns = rb_loading_namespace();
+ const rb_box_t *box = rb_loading_box();
- if (feature_provided((rb_namespace_t *)ns, name, 0))
+ if (feature_provided((rb_box_t *)box, name, 0))
return;
inits_table = vm->static_ext_inits;
@@ -1658,7 +1657,7 @@ rb_ext_resolve_symbol(const char* fname, const char* symbol)
VALUE path;
char *ext;
VALUE fname_str = rb_str_new_cstr(fname);
- const rb_namespace_t *ns = rb_loading_namespace();
+ const rb_box_t *box = rb_loading_box();
resolved = rb_resolve_feature_path((VALUE)NULL, fname_str);
if (NIL_P(resolved)) {
@@ -1666,7 +1665,7 @@ rb_ext_resolve_symbol(const char* fname, const char* symbol)
if (!ext || !IS_SOEXT(ext)) {
rb_str_cat_cstr(fname_str, ".so");
}
- if (rb_feature_p(ns, fname, 0, FALSE, FALSE, 0)) {
+ if (rb_feature_p(box, fname, 0, FALSE, FALSE, 0)) {
return dln_symbol(NULL, symbol);
}
return NULL;
@@ -1675,7 +1674,7 @@ rb_ext_resolve_symbol(const char* fname, const char* symbol)
return NULL;
}
path = rb_ary_entry(resolved, 1);
- handle = rb_hash_lookup(ns->ruby_dln_libmap, path);
+ handle = rb_hash_lookup(box->ruby_dln_libmap, path);
if (NIL_P(handle)) {
return NULL;
}
@@ -1689,14 +1688,14 @@ Init_load(void)
ID id_load_path = rb_intern2(var_load_path, sizeof(var_load_path)-1);
rb_define_hooked_variable(var_load_path, 0, load_path_getter, rb_gvar_readonly_setter);
- rb_gvar_namespace_ready(var_load_path);
+ rb_gvar_box_ready(var_load_path);
rb_alias_variable(rb_intern_const("$-I"), id_load_path);
rb_alias_variable(rb_intern_const("$LOAD_PATH"), id_load_path);
rb_define_virtual_variable("$\"", get_LOADED_FEATURES, 0);
- rb_gvar_namespace_ready("$\"");
+ rb_gvar_box_ready("$\"");
rb_define_virtual_variable("$LOADED_FEATURES", get_LOADED_FEATURES, 0); // TODO: rb_alias_variable ?
- rb_gvar_namespace_ready("$LOADED_FEATURES");
+ rb_gvar_box_ready("$LOADED_FEATURES");
rb_define_global_function("load", rb_f_load, -1);
rb_define_global_function("require", rb_f_require, 1);
diff --git a/method.h b/method.h
index 9e2fd24968..87fb2498a0 100644
--- a/method.h
+++ b/method.h
@@ -204,7 +204,7 @@ struct rb_method_definition_struct {
ID original_id;
uintptr_t method_serial;
- const rb_namespace_t *ns;
+ const rb_box_t *box;
};
struct rb_id_table;
diff --git a/mini_builtin.c b/mini_builtin.c
index 3ff3dc5c1d..48f401e78a 100644
--- a/mini_builtin.c
+++ b/mini_builtin.c
@@ -100,5 +100,5 @@ void
rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table)
{
const rb_iseq_t *iseq = builtin_iseq_load(feature_name, table);
- rb_iseq_eval(iseq, rb_root_namespace());
+ rb_iseq_eval(iseq, rb_root_box());
}
diff --git a/proc.c b/proc.c
index 9c1a7a7fff..2b14c38938 100644
--- a/proc.c
+++ b/proc.c
@@ -735,7 +735,6 @@ sym_proc_new(VALUE klass, VALUE sym)
GetProcPtr(procval, proc);
vm_block_type_set(&proc->block, block_type_symbol);
- // No namespace specified: similar to built-in methods
proc->is_lambda = TRUE;
RB_OBJ_WRITE(procval, &proc->block.as.symbol, sym);
return procval;
@@ -2029,23 +2028,22 @@ method_owner(VALUE obj)
/*
* call-see:
- * meth.namespace -> namespace or nil
+ * meth.box -> box or nil
*
- * Returns the namespace where +meth+ is defined in.
+ * Returns the Ruby::Box where +meth+ is defined in.
*/
static VALUE
-method_namespace(VALUE obj)
+method_box(VALUE obj)
{
struct METHOD *data;
- const rb_namespace_t *ns;
+ const rb_box_t *box;
TypedData_Get_Struct(obj, struct METHOD, &method_data_type, data);
- ns = data->me->def->ns;
- if (!ns) return Qfalse;
- if (ns->ns_object) return ns->ns_object;
- // This should not happen
- rb_bug("Unexpected namespace on the method definition: %p", (void*) ns);
- return Qtrue;
+ box = data->me->def->box;
+ if (!box) return Qnil;
+ if (box->box_object) return box->box_object;
+ rb_bug("Unexpected box on the method definition: %p", (void*) box);
+ UNREACHABLE_RETURN(Qnil);
}
void
@@ -4520,7 +4518,7 @@ Init_Proc(void)
rb_define_method(rb_mKernel, "public_method", rb_obj_public_method, 1);
rb_define_method(rb_mKernel, "singleton_method", rb_obj_singleton_method, 1);
- rb_define_method(rb_cMethod, "namespace", method_namespace, 0);
+ rb_define_method(rb_cMethod, "box", method_box, 0);
/* UnboundMethod */
rb_cUnboundMethod = rb_define_class("UnboundMethod", rb_cObject);
diff --git a/ruby.c b/ruby.c
index 0f5e6d60f7..c319fd1237 100644
--- a/ruby.c
+++ b/ruby.c
@@ -449,7 +449,7 @@ ruby_push_include(const char *path, VALUE (*filter)(VALUE))
{
const char sep = PATH_SEP_CHAR;
const char *p, *s;
- VALUE load_path = rb_root_namespace()->load_path;
+ VALUE load_path = rb_root_box()->load_path;
#ifdef __CYGWIN__
char rubylib[FILENAME_MAX];
VALUE buf = 0;
@@ -754,7 +754,7 @@ ruby_init_loadpath(void)
rb_gc_register_address(&ruby_archlibdir_path);
ruby_archlibdir_path = archlibdir;
- load_path = rb_root_namespace()->load_path;
+ load_path = rb_root_box()->load_path;
ruby_push_include(getenv("RUBYLIB"), identical_path);
@@ -1831,11 +1831,11 @@ ruby_opt_init(ruby_cmdline_options_t *opt)
ruby_init_prelude();
- /* Initialize the main namespace after loading libraries (including rubygems)
+ /* Initialize the main box after loading libraries (including rubygems)
* to enable those in both root and main */
- if (rb_namespace_available())
- rb_initialize_main_namespace();
- rb_namespace_init_done();
+ if (rb_box_available())
+ rb_initialize_main_box();
+ rb_box_init_done();
// Initialize JITs after ruby_init_prelude() because JITing prelude is typically not optimal.
#if USE_YJIT
@@ -2334,8 +2334,8 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
char fbuf[MAXPATHLEN];
int i = (int)proc_options(argc, argv, opt, 0);
unsigned int dump = opt->dump & dump_exit_bits;
- const rb_namespace_t *ns = rb_root_namespace();
- const long loaded_before_enc = RARRAY_LEN(ns->loaded_features);
+ const rb_box_t *box = rb_root_box();
+ const long loaded_before_enc = RARRAY_LEN(box->loaded_features);
if (opt->dump & (DUMP_BIT(usage)|DUMP_BIT(help))) {
const char *const progname =
@@ -2483,7 +2483,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
rb_obj_freeze(opt->script_name);
if (IF_UTF8_PATH(uenc != lenc, 1)) {
long i;
- VALUE load_path = ns->load_path;
+ VALUE load_path = box->load_path;
const ID id_initial_load_path_mark = INITIAL_LOAD_PATH_MARK;
int modifiable = FALSE;
@@ -2506,11 +2506,11 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
RARRAY_ASET(load_path, i, path);
}
if (modifiable) {
- rb_ary_replace(ns->load_path_snapshot, load_path);
+ rb_ary_replace(box->load_path_snapshot, load_path);
}
}
{
- VALUE loaded_features = ns->loaded_features;
+ VALUE loaded_features = box->loaded_features;
bool modified = false;
for (long i = loaded_before_enc; i < RARRAY_LEN(loaded_features); ++i) {
VALUE path = RARRAY_AREF(loaded_features, i);
@@ -2522,7 +2522,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
RARRAY_ASET(loaded_features, i, path);
}
if (modified) {
- rb_ary_replace(ns->loaded_features_snapshot, loaded_features);
+ rb_ary_replace(box->loaded_features_snapshot, loaded_features);
}
}
diff --git a/shape.c b/shape.c
index d6b5c30408..7acfe72930 100644
--- a/shape.c
+++ b/shape.c
@@ -744,7 +744,7 @@ rb_shape_transition_heap(VALUE obj, size_t heap_index)
}
void
-rb_set_namespaced_class_shape_id(VALUE obj, shape_id_t shape_id)
+rb_set_boxed_class_shape_id(VALUE obj, shape_id_t shape_id)
{
RBASIC_SET_SHAPE_ID(RCLASS_WRITABLE_ENSURE_FIELDS_OBJ(obj), shape_id);
// FIXME: How to do multi-shape?
diff --git a/shape.h b/shape.h
index a20da1baa5..6e4a1f079b 100644
--- a/shape.h
+++ b/shape.h
@@ -177,7 +177,7 @@ RBASIC_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id)
RUBY_ASSERT(rb_shape_verify_consistency(obj, shape_id));
}
-void rb_set_namespaced_class_shape_id(VALUE obj, shape_id_t shape_id);
+void rb_set_boxed_class_shape_id(VALUE obj, shape_id_t shape_id);
static inline void
RB_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id)
@@ -185,7 +185,7 @@ RB_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id)
switch (BUILTIN_TYPE(obj)) {
case T_CLASS:
case T_MODULE:
- rb_set_namespaced_class_shape_id(obj, shape_id);
+ rb_set_boxed_class_shape_id(obj, shape_id);
break;
default:
RBASIC_SET_SHAPE_ID(obj, shape_id);
diff --git a/variable.c b/variable.c
index 5a58f7ed63..d7e04265c4 100644
--- a/variable.c
+++ b/variable.c
@@ -533,7 +533,7 @@ struct rb_global_variable {
rb_gvar_marker_t *marker;
rb_gvar_compact_t *compactor;
struct trace_var *trace;
- bool namespace_ready;
+ bool box_ready;
};
struct rb_global_entry {
@@ -612,10 +612,10 @@ rb_gvar_ractor_local(const char *name)
}
void
-rb_gvar_namespace_ready(const char *name)
+rb_gvar_box_ready(const char *name)
{
struct rb_global_entry *entry = rb_find_global_entry(rb_intern(name));
- entry->var->namespace_ready = true;
+ entry->var->box_ready = true;
}
static void
@@ -645,7 +645,7 @@ rb_global_entry(ID id)
var->block_trace = 0;
var->trace = 0;
- var->namespace_ready = false;
+ var->box_ready = false;
rb_id_table_insert(rb_global_tbl, id, (VALUE)entry);
}
}
@@ -1000,30 +1000,30 @@ rb_gvar_set_entry(struct rb_global_entry *entry, VALUE val)
return val;
}
-#define USE_NAMESPACE_GVAR_TBL(ns,entry) \
- (NAMESPACE_USER_P(ns) && \
- (!entry || !entry->var->namespace_ready || entry->var->setter != rb_gvar_readonly_setter))
+#define USE_BOX_GVAR_TBL(ns,entry) \
+ (BOX_USER_P(ns) && \
+ (!entry || !entry->var->box_ready || entry->var->setter != rb_gvar_readonly_setter))
VALUE
rb_gvar_set(ID id, VALUE val)
{
VALUE retval;
struct rb_global_entry *entry;
- const rb_namespace_t *ns = rb_current_namespace();
- bool use_namespace_tbl = false;
+ const rb_box_t *box = rb_current_box();
+ bool use_box_tbl = false;
RB_VM_LOCKING() {
entry = rb_global_entry(id);
- if (USE_NAMESPACE_GVAR_TBL(ns, entry)) {
- use_namespace_tbl = true;
- rb_hash_aset(ns->gvar_tbl, rb_id2sym(entry->id), val);
+ if (USE_BOX_GVAR_TBL(box, entry)) {
+ use_box_tbl = true;
+ rb_hash_aset(box->gvar_tbl, rb_id2sym(entry->id), val);
retval = val;
// TODO: think about trace
}
}
- if (!use_namespace_tbl) {
+ if (!use_box_tbl) {
retval = rb_gvar_set_entry(entry, val);
}
return retval;
@@ -1039,8 +1039,8 @@ VALUE
rb_gvar_get(ID id)
{
VALUE retval, gvars, key;
- const rb_namespace_t *ns = rb_current_namespace();
- bool use_namespace_tbl = false;
+ const rb_box_t *box = rb_current_box();
+ bool use_box_tbl = false;
struct rb_global_entry *entry;
struct rb_global_variable *var;
// TODO: use lock-free rb_id_table when it's available for use (doesn't yet exist)
@@ -1048,9 +1048,9 @@ rb_gvar_get(ID id)
entry = rb_global_entry(id);
var = entry->var;
- if (USE_NAMESPACE_GVAR_TBL(ns, entry)) {
- use_namespace_tbl = true;
- gvars = ns->gvar_tbl;
+ if (USE_BOX_GVAR_TBL(box, entry)) {
+ use_box_tbl = true;
+ gvars = box->gvar_tbl;
key = rb_id2sym(entry->id);
if (RTEST(rb_hash_has_key(gvars, key))) { // this gvar is already cached
retval = rb_hash_aref(gvars, key);
@@ -1068,7 +1068,7 @@ rb_gvar_get(ID id)
}
}
}
- if (!use_namespace_tbl) {
+ if (!use_box_tbl) {
retval = (*var->getter)(entry->id, var->data);
}
return retval;
@@ -1125,7 +1125,7 @@ rb_f_global_variables(void)
if (!rb_ractor_main_p()) {
rb_raise(rb_eRactorIsolationError, "can not access global variables from non-main Ractors");
}
- /* gvar access (get/set) in namespaces creates gvar entries globally */
+ /* gvar access (get/set) in boxes creates gvar entries globally */
rb_id_table_foreach(rb_global_tbl, gvar_i, (void *)ary);
if (!NIL_P(backref)) {
@@ -2619,9 +2619,9 @@ struct autoload_const {
// The shared "autoload_data" if multiple constants are defined from the same feature.
VALUE autoload_data_value;
- // The namespace object when the autoload is called in a user namespace
- // Otherwise, Qnil means the builtin namespace, Qfalse means unspecified.
- VALUE namespace;
+ // The box object when the autoload is called in a user box
+ // Otherwise, Qnil means the root box
+ VALUE box_value;
// The module we are loading a constant into.
VALUE module;
@@ -2698,7 +2698,7 @@ autoload_const_mark_and_move(void *ptr)
rb_gc_mark_and_move(&ac->autoload_data_value);
rb_gc_mark_and_move(&ac->value);
rb_gc_mark_and_move(&ac->file);
- rb_gc_mark_and_move(&ac->namespace);
+ rb_gc_mark_and_move(&ac->box_value);
}
static size_t
@@ -2744,17 +2744,17 @@ get_autoload_data(VALUE autoload_const_value, struct autoload_const **autoload_c
struct autoload_copy_table_data {
VALUE dst_tbl_value;
struct st_table *dst_tbl;
- const rb_namespace_t *ns;
+ const rb_box_t *box;
};
static int
-autoload_copy_table_for_namespace_i(st_data_t key, st_data_t value, st_data_t arg)
+autoload_copy_table_for_box_i(st_data_t key, st_data_t value, st_data_t arg)
{
struct autoload_const *autoload_const;
struct autoload_copy_table_data *data = (struct autoload_copy_table_data *)arg;
struct st_table *tbl = data->dst_tbl;
VALUE tbl_value = data->dst_tbl_value;
- const rb_namespace_t *ns = data->ns;
+ const rb_box_t *box = data->box;
VALUE src_value = (VALUE)value;
struct autoload_const *src_const = rb_check_typeddata(src_value, &autoload_const_type);
@@ -2763,7 +2763,7 @@ autoload_copy_table_for_namespace_i(st_data_t key, st_data_t value, st_data_t ar
struct autoload_data *autoload_data = rb_check_typeddata(autoload_data_value, &autoload_data_type);
VALUE new_value = TypedData_Make_Struct(0, struct autoload_const, &autoload_const_type, autoload_const);
- autoload_const->namespace = rb_get_namespace_object((rb_namespace_t *)ns);
+ autoload_const->box_value = rb_get_box_object((rb_box_t *)box);
autoload_const->module = src_const->module;
autoload_const->name = src_const->name;
autoload_const->value = src_const->value;
@@ -2778,7 +2778,7 @@ autoload_copy_table_for_namespace_i(st_data_t key, st_data_t value, st_data_t ar
}
void
-rb_autoload_copy_table_for_namespace(st_table *iv_ptr, const rb_namespace_t *ns)
+rb_autoload_copy_table_for_box(st_table *iv_ptr, const rb_box_t *box)
{
struct st_table *src_tbl, *dst_tbl;
VALUE src_tbl_value, dst_tbl_value;
@@ -2798,10 +2798,10 @@ rb_autoload_copy_table_for_namespace(st_table *iv_ptr, const rb_namespace_t *ns)
struct autoload_copy_table_data data = {
.dst_tbl_value = dst_tbl_value,
.dst_tbl = dst_tbl,
- .ns = ns,
+ .box = box,
};
- st_foreach(src_tbl, autoload_copy_table_for_namespace_i, (st_data_t)&data);
+ st_foreach(src_tbl, autoload_copy_table_for_box_i, (st_data_t)&data);
st_insert(iv_ptr, (st_data_t)autoload, (st_data_t)dst_tbl_value);
}
@@ -2822,7 +2822,7 @@ struct autoload_arguments {
VALUE module;
ID name;
VALUE feature;
- VALUE namespace;
+ VALUE box_value;
};
static VALUE
@@ -2892,7 +2892,7 @@ autoload_synchronized(VALUE _arguments)
{
struct autoload_const *autoload_const;
VALUE autoload_const_value = TypedData_Make_Struct(0, struct autoload_const, &autoload_const_type, autoload_const);
- autoload_const->namespace = arguments->namespace;
+ autoload_const->box_value = arguments->box_value;
autoload_const->module = arguments->module;
autoload_const->name = arguments->name;
autoload_const->value = Qundef;
@@ -2909,8 +2909,8 @@ autoload_synchronized(VALUE _arguments)
void
rb_autoload_str(VALUE module, ID name, VALUE feature)
{
- const rb_namespace_t *ns = rb_current_namespace();
- VALUE current_namespace = rb_get_namespace_object((rb_namespace_t *)ns);
+ const rb_box_t *box = rb_current_box();
+ VALUE current_box_value = rb_get_box_object((rb_box_t *)box);
if (!rb_is_const_id(name)) {
rb_raise(rb_eNameError, "autoload must be constant name: %"PRIsVALUE"", QUOTE_ID(name));
@@ -2925,7 +2925,7 @@ rb_autoload_str(VALUE module, ID name, VALUE feature)
.module = module,
.name = name,
.feature = feature,
- .namespace = current_namespace,
+ .box_value = current_box_value,
};
VALUE result = rb_mutex_synchronize(autoload_mutex, autoload_synchronized, (VALUE)&arguments);
@@ -3192,17 +3192,17 @@ autoload_feature_require(VALUE _arguments)
struct autoload_load_arguments *arguments = (struct autoload_load_arguments*)_arguments;
struct autoload_const *autoload_const = arguments->autoload_const;
- VALUE autoload_namespace = autoload_const->namespace;
+ VALUE autoload_box_value = autoload_const->box_value;
// We save this for later use in autoload_apply_constants:
arguments->autoload_data = rb_check_typeddata(autoload_const->autoload_data_value, &autoload_data_type);
- if (rb_namespace_available() && NAMESPACE_OBJ_P(autoload_namespace))
- receiver = autoload_namespace;
+ if (rb_box_available() && BOX_OBJ_P(autoload_box_value))
+ receiver = autoload_box_value;
/*
* Clear the global cc cache table because the require method can be different from the current
- * namespace's one and it may cause inconsistent cc-cme states.
+ * box's one and it may cause inconsistent cc-cme states.
* For example, the assertion below may fail in gccct_method_search();
* VM_ASSERT(vm_cc_check_cme(cc, rb_callable_method_entry(klass, mid)))
*/
diff --git a/vm.c b/vm.c
index 351951408d..4bd6147fc5 100644
--- a/vm.c
+++ b/vm.c
@@ -98,19 +98,19 @@ rb_vm_search_cf_from_ep(const rb_execution_context_t *ec, const rb_control_frame
}
#if VM_CHECK_MODE > 0
-// ruby_namespace_crashed defined in internal/box.h
-#define VM_NAMESPACE_CRASHED() {ruby_namespace_crashed = true;}
-#define VM_NAMESPACE_ASSERT(expr, msg) \
- if (!(expr)) { ruby_namespace_crashed = true; rb_bug(msg); }
+// ruby_box_crashed defined in internal/box.h
+#define VM_BOX_CRASHED() {ruby_box_crashed = true;}
+#define VM_BOX_ASSERT(expr, msg) \
+ if (!(expr)) { ruby_box_crashed = true; rb_bug(msg); }
#else
-#define VM_NAMESPACE_CRASHED() {}
-#define VM_NAMESPACE_ASSERT(expr, msg) ((void)0)
+#define VM_BOX_CRASHED() {}
+#define VM_BOX_ASSERT(expr, msg) ((void)0)
#endif
static const VALUE *
VM_EP_RUBY_LEP(const rb_execution_context_t *ec, const rb_control_frame_t *current_cfp)
{
- // rb_vmdebug_namespace_env_dump_raw() simulates this function
+ // rb_vmdebug_box_env_dump_raw() simulates this function
const VALUE *ep = current_cfp->ep;
const rb_control_frame_t * const eocfp = RUBY_VM_END_CONTROL_FRAME(ec); /* end of control frame pointer */
const rb_control_frame_t *cfp = current_cfp;
@@ -120,20 +120,20 @@ VM_EP_RUBY_LEP(const rb_execution_context_t *ec, const rb_control_frame_t *curre
/**
* Returns CFUNC frame only in this case.
*
- * Usually CFUNC frame doesn't represent the current namespace and it should operate
- * the caller namespace. See the example:
+ * Usually CFUNC frame doesn't represent the current box and it should operate
+ * the caller box. See the example:
*
- * # in the main namespace
+ * # in the main box
* module Kernel
* def foo = "foo"
* module_function :foo
* end
*
- * In the case above, `module_function` is defined in the root namespace.
- * If `module_function` worked in the root namespace, `Kernel#foo` is invisible
+ * In the case above, `module_function` is defined in the root box.
+ * If `module_function` worked in the root box, `Kernel#foo` is invisible
* from it and it causes NameError: undefined method `foo` for module `Kernel`.
*
- * But in cases of IFUNC (blocks written in C), IFUNC doesn't have its own namespace
+ * But in cases of IFUNC (blocks written in C), IFUNC doesn't have its own box
* and its local env frame will be CFUNC frame.
* For example, `Enumerator#chunk` calls IFUNC blocks, written as `chunk_i` function.
*
@@ -142,7 +142,7 @@ VM_EP_RUBY_LEP(const rb_execution_context_t *ec, const rb_control_frame_t *curre
* Before calling the Ruby block `{ it.even? }`, `#chunk` calls `chunk_i` as IFUNC
* to iterate the array's members (it's just like `#each`).
* We expect that `chunk_i` works as expected by the implementation of `#chunk`
- * without any overwritten definitions from namespaces.
+ * without any overwritten definitions from boxes.
* So the definitions on IFUNC frames should be equal to the caller CFUNC.
*/
VM_ASSERT(VM_ENV_FRAME_TYPE_P(ep, VM_FRAME_MAGIC_CFUNC));
@@ -152,13 +152,13 @@ VM_EP_RUBY_LEP(const rb_execution_context_t *ec, const rb_control_frame_t *curre
while (VM_ENV_FRAME_TYPE_P(ep, VM_FRAME_MAGIC_CFUNC)) {
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
- VM_NAMESPACE_ASSERT(cfp, "CFUNC should have a valid previous control frame");
- VM_NAMESPACE_ASSERT(cfp < eocfp, "CFUNC should have a valid caller frame");
+ VM_BOX_ASSERT(cfp, "CFUNC should have a valid previous control frame");
+ VM_BOX_ASSERT(cfp < eocfp, "CFUNC should have a valid caller frame");
if (!cfp || cfp >= eocfp) {
return NULL;
}
- VM_NAMESPACE_ASSERT(cfp->ep, "CFUNC should have a valid caller frame with env");
+ VM_BOX_ASSERT(cfp->ep, "CFUNC should have a valid caller frame with env");
ep = cfp->ep;
if (!ep) {
return NULL;
@@ -196,10 +196,10 @@ static inline VALUE
VM_CF_BLOCK_HANDLER(const rb_control_frame_t * const cfp)
{
const VALUE *ep;
- if (VM_ENV_NAMESPACED_P(cfp->ep)) {
+ if (VM_ENV_BOXED_P(cfp->ep)) {
VM_ASSERT(VM_ENV_LOCAL_P(cfp->ep));
/* Never set black_handler for VM_FRAME_MAGIC_TOP or VM_FRAME_MAGIC_CLASS
- * and the specval is used for namespace (rb_namespace_t) in these case
+ * and the specval is used for boxes (rb_box_t) in these case
*/
return VM_BLOCK_HANDLER_NONE;
}
@@ -882,7 +882,7 @@ vm_stat(int argc, VALUE *argv, VALUE self)
/* control stack frame */
static void
-vm_set_top_stack(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_namespace_t *ns)
+vm_set_top_stack(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_box_t *box)
{
if (ISEQ_BODY(iseq)->type != ISEQ_TYPE_TOP) {
rb_raise(rb_eTypeError, "Not a toplevel InstructionSequence");
@@ -891,7 +891,7 @@ vm_set_top_stack(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_nam
/* for return */
vm_push_frame(ec, iseq, VM_FRAME_MAGIC_TOP | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH,
rb_ec_thread_ptr(ec)->top_self,
- GC_GUARDED_PTR(ns),
+ GC_GUARDED_PTR(box),
(VALUE)vm_cref_new_toplevel(ec), /* cref or me */
ISEQ_BODY(iseq)->iseq_encoded, ec->cfp->sp,
ISEQ_BODY(iseq)->local_table_size, ISEQ_BODY(iseq)->stack_max);
@@ -3032,11 +3032,11 @@ vm_exec_handle_exception(rb_execution_context_t *ec, enum ruby_tag_type state, V
/* misc */
VALUE
-rb_iseq_eval(const rb_iseq_t *iseq, const rb_namespace_t *ns)
+rb_iseq_eval(const rb_iseq_t *iseq, const rb_box_t *box)
{
rb_execution_context_t *ec = GET_EC();
VALUE val;
- vm_set_top_stack(ec, iseq, ns);
+ vm_set_top_stack(ec, iseq, box);
val = vm_exec(ec);
return val;
}
@@ -3086,11 +3086,11 @@ rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg,
rb_execution_context_t *ec = GET_EC();
const rb_control_frame_t *reg_cfp = ec->cfp;
const rb_iseq_t *iseq = rb_iseq_new(Qnil, filename, filename, Qnil, 0, ISEQ_TYPE_TOP);
- const rb_namespace_t *ns = rb_current_namespace();
+ const rb_box_t *box = rb_current_box();
VALUE val;
vm_push_frame(ec, iseq, VM_FRAME_MAGIC_TOP | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH,
- recv, GC_GUARDED_PTR(ns),
+ recv, GC_GUARDED_PTR(box),
(VALUE)vm_cref_new_toplevel(ec), /* cref or me */
0, reg_cfp->sp, 0, 0);
@@ -3100,11 +3100,11 @@ rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg,
return val;
}
-/* namespace */
+/* Ruby::Box */
VALUE
-rb_vm_call_cfunc_in_namespace(VALUE recv, VALUE (*func)(VALUE, VALUE), VALUE arg1, VALUE arg2,
- VALUE filename, const rb_namespace_t *ns)
+rb_vm_call_cfunc_in_box(VALUE recv, VALUE (*func)(VALUE, VALUE), VALUE arg1, VALUE arg2,
+ VALUE filename, const rb_box_t *box)
{
rb_execution_context_t *ec = GET_EC();
const rb_control_frame_t *reg_cfp = ec->cfp;
@@ -3112,7 +3112,7 @@ rb_vm_call_cfunc_in_namespace(VALUE recv, VALUE (*func)(VALUE, VALUE), VALUE arg
VALUE val;
vm_push_frame(ec, iseq, VM_FRAME_MAGIC_TOP | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH,
- recv, GC_GUARDED_PTR(ns),
+ recv, GC_GUARDED_PTR(box),
(VALUE)vm_cref_new_toplevel(ec), /* cref or me */
0, reg_cfp->sp, 0, 0);
@@ -3123,50 +3123,50 @@ rb_vm_call_cfunc_in_namespace(VALUE recv, VALUE (*func)(VALUE, VALUE), VALUE arg
}
void
-rb_vm_frame_flag_set_ns_require(const rb_execution_context_t *ec)
+rb_vm_frame_flag_set_box_require(const rb_execution_context_t *ec)
{
- VM_ASSERT(rb_namespace_available());
- VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_NS_REQUIRE);
+ VM_ASSERT(rb_box_available());
+ VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_BOX_REQUIRE);
}
-static const rb_namespace_t *
-current_namespace_on_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
+static const rb_box_t *
+current_box_on_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
{
rb_callable_method_entry_t *cme;
- const rb_namespace_t *ns;
+ const rb_box_t *box;
const VALUE *lep = VM_EP_RUBY_LEP(ec, cfp);
- VM_NAMESPACE_ASSERT(lep, "lep should be valid");
- VM_NAMESPACE_ASSERT(rb_namespace_available(), "namespace should be available here");
+ VM_BOX_ASSERT(lep, "lep should be valid");
+ VM_BOX_ASSERT(rb_box_available(), "box should be available here");
if (VM_ENV_FRAME_TYPE_P(lep, VM_FRAME_MAGIC_METHOD) || VM_ENV_FRAME_TYPE_P(lep, VM_FRAME_MAGIC_CFUNC)) {
cme = check_method_entry(lep[VM_ENV_DATA_INDEX_ME_CREF], TRUE);
- VM_NAMESPACE_ASSERT(cme, "cme should be valid");
- VM_NAMESPACE_ASSERT(cme->def, "cme->def shold be valid");
- return cme->def->ns;
+ VM_BOX_ASSERT(cme, "cme should be valid");
+ VM_BOX_ASSERT(cme->def, "cme->def shold be valid");
+ return cme->def->box;
}
else if (VM_ENV_FRAME_TYPE_P(lep, VM_FRAME_MAGIC_TOP) || VM_ENV_FRAME_TYPE_P(lep, VM_FRAME_MAGIC_CLASS)) {
- VM_NAMESPACE_ASSERT(VM_ENV_LOCAL_P(lep), "lep should be local on MAGIC_TOP or MAGIC_CLASS frames");
- return VM_ENV_NAMESPACE(lep);
+ VM_BOX_ASSERT(VM_ENV_LOCAL_P(lep), "lep should be local on MAGIC_TOP or MAGIC_CLASS frames");
+ return VM_ENV_BOX(lep);
}
else if (VM_ENV_FRAME_TYPE_P(lep, VM_FRAME_MAGIC_DUMMY)) {
// No valid local ep found (just after process boot?)
- // return the root namespace (the only valid namespace) until the main is initialized
- ns = rb_main_namespace();
- if (ns)
- return ns;
- return rb_root_namespace();
+ // return the root box (the only valid box) until the main is initialized
+ box = rb_main_box();
+ if (box)
+ return box;
+ return rb_root_box();
}
else {
- VM_NAMESPACE_CRASHED();
- rb_bug("BUG: Local ep without cme/namespace, flags: %08lX", (unsigned long)lep[VM_ENV_DATA_INDEX_FLAGS]);
+ VM_BOX_CRASHED();
+ rb_bug("BUG: Local ep without cme/box, flags: %08lX", (unsigned long)lep[VM_ENV_DATA_INDEX_FLAGS]);
}
UNREACHABLE_RETURN(0);
}
-const rb_namespace_t *
-rb_vm_current_namespace(const rb_execution_context_t *ec)
+const rb_box_t *
+rb_vm_current_box(const rb_execution_context_t *ec)
{
- return current_namespace_on_cfp(ec, ec->cfp);
+ return current_box_on_cfp(ec, ec->cfp);
}
static const rb_control_frame_t *
@@ -3175,7 +3175,7 @@ find_loader_control_frame(const rb_execution_context_t *ec, const rb_control_fra
while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
if (!VM_ENV_FRAME_TYPE_P(cfp->ep, VM_FRAME_MAGIC_CFUNC))
break;
- if (!NAMESPACE_ROOT_P(current_namespace_on_cfp(ec, cfp)))
+ if (!BOX_ROOT_P(current_box_on_cfp(ec, cfp)))
break;
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
}
@@ -3183,32 +3183,32 @@ find_loader_control_frame(const rb_execution_context_t *ec, const rb_control_fra
return cfp;
}
-const rb_namespace_t *
-rb_vm_loading_namespace(const rb_execution_context_t *ec)
+const rb_box_t *
+rb_vm_loading_box(const rb_execution_context_t *ec)
{
const rb_control_frame_t *cfp, *current_cfp, *end_cfp;
- if (!rb_namespace_available() || !ec)
- return rb_root_namespace();
+ if (!rb_box_available() || !ec)
+ return rb_root_box();
cfp = ec->cfp;
current_cfp = cfp;
end_cfp = RUBY_VM_END_CONTROL_FRAME(ec);
while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
- if (VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_NS_REQUIRE)) {
- if (RTEST(cfp->self) && NAMESPACE_OBJ_P(cfp->self)) {
- // Namespace#require, #require_relative, #load
- return rb_get_namespace_t(cfp->self);
+ if (VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_BOX_REQUIRE)) {
+ if (RTEST(cfp->self) && BOX_OBJ_P(cfp->self)) {
+ // Box#require, #require_relative, #load
+ return rb_get_box_t(cfp->self);
}
// Kernel#require, #require_relative, #load
cfp = find_loader_control_frame(ec, cfp, end_cfp);
- return current_namespace_on_cfp(ec, cfp);
+ return current_box_on_cfp(ec, cfp);
}
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
}
- // no require/load with explicit namespaces.
- return current_namespace_on_cfp(ec, current_cfp);
+ // no require/load with explicit boxes.
+ return current_box_on_cfp(ec, current_cfp);
}
/* vm */
@@ -3223,10 +3223,10 @@ rb_vm_update_references(void *ptr)
vm->mark_object_ary = rb_gc_location(vm->mark_object_ary);
vm->orig_progname = rb_gc_location(vm->orig_progname);
- if (vm->root_namespace)
- rb_namespace_gc_update_references(vm->root_namespace);
- if (vm->main_namespace)
- rb_namespace_gc_update_references(vm->main_namespace);
+ if (vm->root_box)
+ rb_box_gc_update_references(vm->root_box);
+ if (vm->main_box)
+ rb_box_gc_update_references(vm->main_box);
rb_gc_update_values(RUBY_NSIG, vm->trap_list.cmd);
@@ -3299,11 +3299,11 @@ rb_vm_mark(void *ptr)
rb_gc_mark_movable(vm->self);
- if (vm->root_namespace) {
- rb_namespace_entry_mark(vm->root_namespace);
+ if (vm->root_box) {
+ rb_box_entry_mark(vm->root_box);
}
- if (vm->main_namespace) {
- rb_namespace_entry_mark(vm->main_namespace);
+ if (vm->main_box) {
+ rb_box_entry_mark(vm->main_box);
}
rb_gc_mark_movable(vm->mark_object_ary);
@@ -3886,7 +3886,7 @@ rb_ec_clear_vm_stack(rb_execution_context_t *ec)
static void
th_init(rb_thread_t *th, VALUE self, rb_vm_t *vm)
{
- const rb_namespace_t *ns = rb_current_namespace();
+ const rb_box_t *box = rb_current_box();
th->self = self;
@@ -3911,8 +3911,8 @@ th_init(rb_thread_t *th, VALUE self, rb_vm_t *vm)
th->status = THREAD_RUNNABLE;
th->last_status = Qnil;
th->top_wrapper = 0;
- if (ns->top_self) {
- th->top_self = ns->top_self;
+ if (box->top_self) {
+ th->top_self = box->top_self;
}
else {
th->top_self = 0;
@@ -4745,20 +4745,20 @@ main_to_s(VALUE obj)
VALUE
rb_vm_top_self(void)
{
- const rb_namespace_t *ns = rb_current_namespace();
- VM_ASSERT(ns);
- VM_ASSERT(ns->top_self);
- return ns->top_self;
+ const rb_box_t *box = rb_current_box();
+ VM_ASSERT(box);
+ VM_ASSERT(box->top_self);
+ return box->top_self;
}
void
Init_top_self(void)
{
rb_vm_t *vm = GET_VM();
- vm->root_namespace = (rb_namespace_t *)rb_root_namespace();
- vm->root_namespace->top_self = rb_obj_alloc(rb_cObject);
- rb_define_singleton_method(vm->root_namespace->top_self, "to_s", main_to_s, 0);
- rb_define_alias(rb_singleton_class(vm->root_namespace->top_self), "inspect", "to_s");
+ vm->root_box = (rb_box_t *)rb_root_box();
+ vm->root_box->top_self = rb_obj_alloc(rb_cObject);
+ rb_define_singleton_method(vm->root_box->top_self, "to_s", main_to_s, 0);
+ rb_define_alias(rb_singleton_class(vm->root_box->top_self), "inspect", "to_s");
}
VALUE *
diff --git a/vm_core.h b/vm_core.h
index 599c7ada9f..79d12f9ee4 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -754,9 +754,9 @@ typedef struct rb_vm_struct {
struct global_object_list *global_object_list;
const VALUE special_exceptions[ruby_special_error_count];
- /* namespace */
- rb_namespace_t *root_namespace;
- rb_namespace_t *main_namespace;
+ /* Ruby Box */
+ rb_box_t *root_box;
+ rb_box_t *main_box;
/* load */
// For running the init function of statically linked
@@ -1389,7 +1389,7 @@ enum vm_frame_env_flags {
VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM = 0x0200,
VM_FRAME_FLAG_CFRAME_KW = 0x0400,
VM_FRAME_FLAG_PASSED = 0x0800,
- VM_FRAME_FLAG_NS_REQUIRE = 0x1000,
+ VM_FRAME_FLAG_BOX_REQUIRE = 0x1000,
/* env flag */
VM_ENV_FLAG_LOCAL = 0x0002,
@@ -1528,7 +1528,7 @@ VM_FRAME_RUBYFRAME_P_UNCHECKED(const rb_control_frame_t *cfp)
static inline int
VM_FRAME_NS_REQUIRE_P(const rb_control_frame_t *cfp)
{
- return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_NS_REQUIRE) != 0;
+ return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_BOX_REQUIRE) != 0;
}
#define RUBYVM_CFUNC_FRAME_P(cfp) \
@@ -1563,7 +1563,7 @@ VM_ENV_PREV_EP(const VALUE *ep)
}
static inline bool
-VM_ENV_NAMESPACED_P(const VALUE *ep)
+VM_ENV_BOXED_P(const VALUE *ep)
{
return VM_ENV_FRAME_TYPE_P(ep, VM_FRAME_MAGIC_CLASS) || VM_ENV_FRAME_TYPE_P(ep, VM_FRAME_MAGIC_TOP);
}
@@ -1571,7 +1571,7 @@ VM_ENV_NAMESPACED_P(const VALUE *ep)
static inline VALUE
VM_ENV_BLOCK_HANDLER(const VALUE *ep)
{
- if (VM_ENV_NAMESPACED_P(ep)) {
+ if (VM_ENV_BOXED_P(ep)) {
VM_ASSERT(VM_ENV_LOCAL_P(ep));
return VM_BLOCK_HANDLER_NONE;
}
@@ -1580,18 +1580,18 @@ VM_ENV_BLOCK_HANDLER(const VALUE *ep)
return ep[VM_ENV_DATA_INDEX_SPECVAL];
}
-static inline const rb_namespace_t *
-VM_ENV_NAMESPACE(const VALUE *ep)
+static inline const rb_box_t *
+VM_ENV_BOX(const VALUE *ep)
{
- VM_ASSERT(VM_ENV_NAMESPACED_P(ep));
+ VM_ASSERT(VM_ENV_BOXED_P(ep));
VM_ASSERT(VM_ENV_LOCAL_P(ep));
- return (const rb_namespace_t *)GC_GUARDED_PTR_REF(ep[VM_ENV_DATA_INDEX_SPECVAL]);
+ return (const rb_box_t *)GC_GUARDED_PTR_REF(ep[VM_ENV_DATA_INDEX_SPECVAL]);
}
-static inline const rb_namespace_t *
-VM_ENV_NAMESPACE_UNCHECKED(const VALUE *ep)
+static inline const rb_box_t *
+VM_ENV_BOX_UNCHECKED(const VALUE *ep)
{
- return (const rb_namespace_t *)GC_GUARDED_PTR_REF(ep[VM_ENV_DATA_INDEX_SPECVAL]);
+ return (const rb_box_t *)GC_GUARDED_PTR_REF(ep[VM_ENV_DATA_INDEX_SPECVAL]);
}
#if VM_CHECK_MODE > 0
@@ -1914,7 +1914,7 @@ NORETURN(void rb_bug_for_fatal_signal(ruby_sighandler_t default_sighandler, int
/* functions about thread/vm execution */
RUBY_SYMBOL_EXPORT_BEGIN
-VALUE rb_iseq_eval(const rb_iseq_t *iseq, const rb_namespace_t *ns);
+VALUE rb_iseq_eval(const rb_iseq_t *iseq, const rb_box_t *box);
VALUE rb_iseq_eval_main(const rb_iseq_t *iseq);
VALUE rb_iseq_path(const rb_iseq_t *iseq);
VALUE rb_iseq_realpath(const rb_iseq_t *iseq);
diff --git a/vm_dump.c b/vm_dump.c
index 2ed1f955b3..ece04f563e 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -62,7 +62,7 @@ control_frame_dump(const rb_execution_context_t *ec, const rb_control_frame_t *c
VALUE tmp;
const rb_iseq_t *iseq = NULL;
const rb_callable_method_entry_t *me = rb_vm_frame_method_entry_unchecked(cfp);
- const rb_namespace_t *ns = NULL;
+ const rb_box_t *box = NULL;
if (ep < 0 || (size_t)ep > ec->vm_stack_size) {
ep = (ptrdiff_t)cfp->ep;
@@ -72,17 +72,17 @@ control_frame_dump(const rb_execution_context_t *ec, const rb_control_frame_t *c
switch (VM_FRAME_TYPE_UNCHECKED(cfp)) {
case VM_FRAME_MAGIC_TOP:
magic = "TOP";
- ns = VM_ENV_NAMESPACE_UNCHECKED(cfp->ep);
+ box = VM_ENV_BOX_UNCHECKED(cfp->ep);
break;
case VM_FRAME_MAGIC_METHOD:
magic = "METHOD";
if (me) {
- ns = me->def->ns;
+ box = me->def->box;
}
break;
case VM_FRAME_MAGIC_CLASS:
magic = "CLASS";
- ns = VM_ENV_NAMESPACE_UNCHECKED(cfp->ep);
+ box = VM_ENV_BOX_UNCHECKED(cfp->ep);
break;
case VM_FRAME_MAGIC_BLOCK:
magic = "BLOCK";
@@ -163,11 +163,11 @@ control_frame_dump(const rb_execution_context_t *ec, const rb_control_frame_t *c
kprintf("s:%04"PRIdPTRDIFF" ", cfp->sp - ec->vm_stack);
kprintf(ep_in_heap == ' ' ? "e:%06"PRIdPTRDIFF" " : "E:%06"PRIxPTRDIFF" ", ep % 10000);
kprintf("l:%s ", VM_ENV_LOCAL_P(cfp->ep) ? "y" : "n");
- if (ns) {
- kprintf("n:%04ld ", ns->ns_id % 10000);
+ if (box) {
+ kprintf("b:%04ld ", box->box_id % 10000);
}
else {
- kprintf("n:---- ");
+ kprintf("b:---- ");
}
kprintf("%-6s", magic);
if (line) {
@@ -274,7 +274,7 @@ vmdebug_frame_method_entry_unchecked(const VALUE *ep)
}
static bool
-namespace_env_dump(const rb_execution_context_t *ec, const VALUE *env, const rb_control_frame_t *checkpoint_cfp, FILE *errout)
+box_env_dump(const rb_execution_context_t *ec, const VALUE *env, const rb_control_frame_t *checkpoint_cfp, FILE *errout)
{
ptrdiff_t pc = -1;
ptrdiff_t ep = env - ec->vm_stack;
@@ -284,7 +284,7 @@ namespace_env_dump(const rb_execution_context_t *ec, const VALUE *env, const rb_
const char *magic, *iseq_name = "-";
VALUE tmp;
const rb_iseq_t *iseq = NULL;
- const rb_namespace_t *ns = NULL;
+ const rb_box_t *box = NULL;
const rb_control_frame_t *cfp = vmdebug_search_cf_from_ep(ec, checkpoint_cfp, env);
const rb_callable_method_entry_t *me = vmdebug_frame_method_entry_unchecked(env);
@@ -298,17 +298,17 @@ namespace_env_dump(const rb_execution_context_t *ec, const VALUE *env, const rb_
switch (VM_ENV_FLAGS_UNCHECKED(env, VM_FRAME_MAGIC_MASK)) {
case VM_FRAME_MAGIC_TOP:
magic = "TOP";
- ns = VM_ENV_NAMESPACE_UNCHECKED(env);
+ box = VM_ENV_BOX_UNCHECKED(env);
break;
case VM_FRAME_MAGIC_METHOD:
magic = "METHOD";
if (me) {
- ns = me->def->ns;
+ box = me->def->box;
}
break;
case VM_FRAME_MAGIC_CLASS:
magic = "CLASS";
- ns = VM_ENV_NAMESPACE_UNCHECKED(env);
+ box = VM_ENV_BOX_UNCHECKED(env);
break;
case VM_FRAME_MAGIC_BLOCK:
magic = "BLOCK";
@@ -316,7 +316,7 @@ namespace_env_dump(const rb_execution_context_t *ec, const VALUE *env, const rb_
case VM_FRAME_MAGIC_CFUNC:
magic = "CFUNC";
if (me) {
- ns = me->def->ns;
+ box = me->def->box;
}
break;
case VM_FRAME_MAGIC_IFUNC:
@@ -382,11 +382,11 @@ namespace_env_dump(const rb_execution_context_t *ec, const VALUE *env, const rb_
}
kprintf(ep_in_heap == ' ' ? "e:%06"PRIdPTRDIFF" " : "E:%06"PRIxPTRDIFF" ", ep % 10000);
kprintf("l:%s ", VM_ENV_LOCAL_P(env) ? "y" : "n");
- if (ns) {
- kprintf("n:%04ld ", ns->ns_id % 10000);
+ if (box) {
+ kprintf("b:%04ld ", box->box_id % 10000);
}
else {
- kprintf("n:---- ");
+ kprintf("b:---- ");
}
kprintf("%-6s", magic);
if (line) {
@@ -402,36 +402,36 @@ namespace_env_dump(const rb_execution_context_t *ec, const VALUE *env, const rb_
}
static bool
-namespace_env_dump_unchecked(const rb_execution_context_t *ec, const VALUE *env, const rb_control_frame_t *checkpoint_cfp, FILE *errout)
+box_env_dump_unchecked(const rb_execution_context_t *ec, const VALUE *env, const rb_control_frame_t *checkpoint_cfp, FILE *errout)
{
if (env == NULL) {
- kprintf("c:---- e:000000 l:- n:---- (none)\n");
+ kprintf("c:---- e:000000 l:- b:---- (none)\n");
return true;
}
else {
- return namespace_env_dump(ec, env, checkpoint_cfp, errout);
+ return box_env_dump(ec, env, checkpoint_cfp, errout);
}
error:
return false;
}
bool
-rb_vmdebug_namespace_env_dump_raw(const rb_execution_context_t *ec, const rb_control_frame_t *current_cfp, FILE *errout)
+rb_vmdebug_box_env_dump_raw(const rb_execution_context_t *ec, const rb_control_frame_t *current_cfp, FILE *errout)
{
// See VM_EP_RUBY_LEP for the original logic
const VALUE *ep = current_cfp->ep;
const rb_control_frame_t * const eocfp = RUBY_VM_END_CONTROL_FRAME(ec); /* end of control frame pointer */
const rb_control_frame_t *cfp = current_cfp, *checkpoint_cfp = current_cfp;
- kprintf("-- Namespace detection information "
+ kprintf("-- Ruby Box detection information "
"-----------------------------------------\n");
- namespace_env_dump_unchecked(ec, ep, checkpoint_cfp, errout);
+ box_env_dump_unchecked(ec, ep, checkpoint_cfp, errout);
if (VM_ENV_FRAME_TYPE_P(ep, VM_FRAME_MAGIC_IFUNC)) {
while (!VM_ENV_LOCAL_P(ep)) {
ep = VM_ENV_PREV_EP(ep);
- namespace_env_dump_unchecked(ec, ep, checkpoint_cfp, errout);
+ box_env_dump_unchecked(ec, ep, checkpoint_cfp, errout);
}
goto stop;
}
@@ -446,7 +446,7 @@ rb_vmdebug_namespace_env_dump_raw(const rb_execution_context_t *ec, const rb_con
goto stop;
}
ep = cfp->ep;
- namespace_env_dump_unchecked(ec, ep, checkpoint_cfp, errout);
+ box_env_dump_unchecked(ec, ep, checkpoint_cfp, errout);
if (!ep) {
goto stop;
}
@@ -454,7 +454,7 @@ rb_vmdebug_namespace_env_dump_raw(const rb_execution_context_t *ec, const rb_con
while (!VM_ENV_LOCAL_P(ep)) {
ep = VM_ENV_PREV_EP(ep);
- namespace_env_dump_unchecked(ec, ep, checkpoint_cfp, errout);
+ box_env_dump_unchecked(ec, ep, checkpoint_cfp, errout);
}
stop:
@@ -1408,21 +1408,21 @@ rb_vm_bugreport(const void *ctx, FILE *errout)
enum {other_runtime_info = 0};
#endif
const rb_vm_t *const vm = GET_VM();
- const rb_namespace_t *current_ns = rb_current_namespace_in_crash_report();
+ const rb_box_t *current_box = rb_current_box_in_crash_report();
const rb_execution_context_t *ec = rb_current_execution_context(false);
VALUE loaded_features;
- if (current_ns) {
- loaded_features = current_ns->loaded_features;
+ if (current_box) {
+ loaded_features = current_box->loaded_features;
}
else {
- loaded_features = rb_root_namespace()->loaded_features;
+ loaded_features = rb_root_box()->loaded_features;
}
if (vm && ec) {
rb_vmdebug_stack_dump_raw(ec, ec->cfp, errout);
if (ns_env) {
- rb_vmdebug_namespace_env_dump_raw(ec, ec->cfp, errout);
+ rb_vmdebug_box_env_dump_raw(ec, ec->cfp, errout);
}
rb_backtrace_print_as_bugreport(errout);
kputs("\n");
@@ -1468,19 +1468,19 @@ rb_vm_bugreport(const void *ctx, FILE *errout)
LIMITED_NAME_LENGTH(name), RSTRING_PTR(name));
kprintf("\n");
}
- if (rb_namespace_available()) {
- kprintf("* Namespace: enabled\n");
- if (current_ns) {
- kprintf("* Current namespace id: %ld, type: %s\n",
- current_ns->ns_id,
- NAMESPACE_USER_P(current_ns) ? (NAMESPACE_MAIN_P(current_ns) ? "main" : "user") : "root");
+ if (rb_box_available()) {
+ kprintf("* Ruby Box: enabled\n");
+ if (current_box) {
+ kprintf("* Current box id: %ld, type: %s\n",
+ current_box->box_id,
+ BOX_USER_P(current_box) ? (BOX_MAIN_P(current_box) ? "main" : "user") : "root");
}
else {
- kprintf("* Current namespace: NULL (crashed)\n");
+ kprintf("* Current box: NULL (crashed)\n");
}
}
else {
- kprintf("* Namespace: disabled\n");
+ kprintf("* Ruby Box: disabled\n");
}
if (loaded_features) {
kprintf("* Loaded features:\n\n");
diff --git a/vm_eval.c b/vm_eval.c
index cd3f1bbafa..281d63a1b8 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -400,9 +400,9 @@ static inline const rb_callable_method_entry_t *rb_search_method_entry(VALUE rec
static inline enum method_missing_reason rb_method_call_status(rb_execution_context_t *ec, const rb_callable_method_entry_t *me, call_type scope, VALUE self);
static VALUE
-gccct_hash(VALUE klass, VALUE namespace, ID mid)
+gccct_hash(VALUE klass, VALUE box_value, ID mid)
{
- return ((klass ^ namespace) >> 3) ^ (VALUE)mid;
+ return ((klass ^ box_value) >> 3) ^ (VALUE)mid;
}
NOINLINE(static const struct rb_callcache *gccct_method_search_slowpath(rb_vm_t *vm, VALUE klass, unsigned int index, const struct rb_callinfo * ci));
@@ -447,8 +447,8 @@ scope_to_ci(call_type scope, ID mid, int argc, struct rb_callinfo *ci)
static inline const struct rb_callcache *
gccct_method_search(rb_execution_context_t *ec, VALUE recv, ID mid, const struct rb_callinfo *ci)
{
- VALUE klass, ns_value;
- const rb_namespace_t *ns = rb_current_namespace();
+ VALUE klass, box_value;
+ const rb_box_t *box = rb_current_box();
if (!SPECIAL_CONST_P(recv)) {
klass = RBASIC_CLASS(recv);
@@ -458,14 +458,14 @@ gccct_method_search(rb_execution_context_t *ec, VALUE recv, ID mid, const struct
klass = CLASS_OF(recv);
}
- if (NAMESPACE_USER_P(ns)) {
- ns_value = ns->ns_object;
+ if (BOX_USER_P(box)) {
+ box_value = box->box_object;
}
else {
- ns_value = 0;
+ box_value = 0;
}
// search global method cache
- unsigned int index = (unsigned int)(gccct_hash(klass, ns_value, mid) % VM_GLOBAL_CC_CACHE_TABLE_SIZE);
+ unsigned int index = (unsigned int)(gccct_hash(klass, box_value, mid) % VM_GLOBAL_CC_CACHE_TABLE_SIZE);
rb_vm_t *vm = rb_ec_vm_ptr(ec);
const struct rb_callcache *cc = vm->global_cc_cache_table[index];
diff --git a/vm_method.c b/vm_method.c
index f5ad38e07c..506a2919b7 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -384,7 +384,7 @@ struct invalidate_callable_method_entry_foreach_arg {
};
static void
-invalidate_callable_method_entry_in_every_m_table_i(rb_classext_t *ext, bool is_prime, VALUE namespace, void *data)
+invalidate_callable_method_entry_in_every_m_table_i(rb_classext_t *ext, bool is_prime, VALUE box_value, void *data)
{
st_data_t me;
struct invalidate_callable_method_entry_foreach_arg *arg = (struct invalidate_callable_method_entry_foreach_arg *)data;
@@ -1089,7 +1089,7 @@ rb_method_definition_create(rb_method_type_t type, ID mid)
def->type = type;
def->original_id = mid;
def->method_serial = (uintptr_t)RUBY_ATOMIC_FETCH_ADD(method_serial, 1);
- def->ns = rb_current_namespace();
+ def->box = rb_current_box();
return def;
}