Follow the code style about else

This commit is contained in:
Satoshi Tagomori 2025-05-08 23:38:00 +09:00
parent 90e5ce6132
commit 294b52fb9b
7 changed files with 110 additions and 57 deletions

View File

@ -55,7 +55,8 @@ load_with_builtin_functions(const char *feature_name, const struct rb_builtin_fu
// exec // exec
if (rb_namespace_available() && rb_mNamespaceRefiner) { if (rb_namespace_available() && rb_mNamespaceRefiner) {
rb_iseq_eval_with_refinement(rb_iseq_check(iseq), rb_mNamespaceRefiner); rb_iseq_eval_with_refinement(rb_iseq_check(iseq), rb_mNamespaceRefiner);
} else { }
else {
rb_iseq_eval(rb_iseq_check(iseq)); rb_iseq_eval(rb_iseq_check(iseq));
} }

93
class.c
View File

@ -274,7 +274,8 @@ class_duplicate_iclass_classext(VALUE iclass, rb_classext_t *mod_ext, const rb_n
// See also: rb_include_class_new() // See also: rb_include_class_new()
if (RCLASSEXT_ICLASS_IS_ORIGIN(src) && !RCLASSEXT_ICLASS_ORIGIN_SHARED_MTBL(src)) { if (RCLASSEXT_ICLASS_IS_ORIGIN(src) && !RCLASSEXT_ICLASS_ORIGIN_SHARED_MTBL(src)) {
RCLASSEXT_M_TBL(ext) = duplicate_classext_m_tbl(RCLASSEXT_M_TBL(src), iclass, true); RCLASSEXT_M_TBL(ext) = duplicate_classext_m_tbl(RCLASSEXT_M_TBL(src), iclass, true);
} else { }
else {
RCLASSEXT_M_TBL(ext) = RCLASSEXT_M_TBL(mod_ext); RCLASSEXT_M_TBL(ext) = RCLASSEXT_M_TBL(mod_ext);
} }
RCLASSEXT_FIELDS(ext) = (VALUE *)st_init_numtable(); RCLASSEXT_FIELDS(ext) = (VALUE *)st_init_numtable();
@ -318,14 +319,16 @@ rb_class_duplicate_classext(rb_classext_t *orig, VALUE klass, const rb_namespace
if (RCLASSEXT_FIELDS(orig)) { if (RCLASSEXT_FIELDS(orig)) {
RCLASSEXT_FIELDS(ext) = (VALUE *)st_copy((st_table *)RCLASSEXT_FIELDS(orig)); RCLASSEXT_FIELDS(ext) = (VALUE *)st_copy((st_table *)RCLASSEXT_FIELDS(orig));
rb_autoload_copy_table_for_namespace((st_table *)RCLASSEXT_FIELDS(ext), ns); rb_autoload_copy_table_for_namespace((st_table *)RCLASSEXT_FIELDS(ext), ns);
} else { }
else {
RCLASSEXT_FIELDS(ext) = (VALUE *)st_init_numtable(); RCLASSEXT_FIELDS(ext) = (VALUE *)st_init_numtable();
} }
if (RCLASSEXT_SHARED_CONST_TBL(orig)) { if (RCLASSEXT_SHARED_CONST_TBL(orig)) {
RCLASSEXT_CONST_TBL(ext) = RCLASSEXT_CONST_TBL(orig); RCLASSEXT_CONST_TBL(ext) = RCLASSEXT_CONST_TBL(orig);
RCLASSEXT_SHARED_CONST_TBL(ext) = true; RCLASSEXT_SHARED_CONST_TBL(ext) = true;
} else { }
else {
RCLASSEXT_CONST_TBL(ext) = duplicate_classext_const_tbl(RCLASSEXT_CONST_TBL(orig), klass); RCLASSEXT_CONST_TBL(ext) = duplicate_classext_const_tbl(RCLASSEXT_CONST_TBL(orig), klass);
RCLASSEXT_SHARED_CONST_TBL(ext) = false; RCLASSEXT_SHARED_CONST_TBL(ext) = false;
} }
@ -544,16 +547,19 @@ debug_dump_super_chain(rb_classext_t *ext, const rb_namespace_t *ns)
rb_str_cat_cstr(result, " -> "); rb_str_cat_cstr(result, " -> ");
if (ns) { if (ns) {
s = RCLASSEXT_SUPER(RCLASS_EXT_READABLE_IN_NS(s, ns)); s = RCLASSEXT_SUPER(RCLASS_EXT_READABLE_IN_NS(s, ns));
} else { }
else {
s = RCLASSEXT_SUPER(RCLASS_EXT_PRIME(s)); s = RCLASSEXT_SUPER(RCLASS_EXT_PRIME(s));
} }
} else { }
else {
chaining = false; chaining = false;
} }
} }
if (count >= 100) { if (count >= 100) {
rb_str_cat_cstr(result, " -> ... (chain size >= 100)\n"); rb_str_cat_cstr(result, " -> ... (chain size >= 100)\n");
} else { }
else {
rb_str_cat_cstr(result, "\n"); rb_str_cat_cstr(result, "\n");
} }
return result; return result;
@ -571,9 +577,11 @@ debug_dump_ivars_foreach_i(st_data_t k, st_data_t v, st_data_t arg)
// to suppress the very long Gem ivar values // to suppress the very long Gem ivar values
if (key == rb_intern("@loaded_specs")) { if (key == rb_intern("@loaded_specs")) {
rb_str_cat_cstr(result, "[ ... ]"); rb_str_cat_cstr(result, "[ ... ]");
} else if (key == rb_intern("@path_to_default_spec_map")) { }
else if (key == rb_intern("@path_to_default_spec_map")) {
rb_str_cat_cstr(result, "{ ... }"); rb_str_cat_cstr(result, "{ ... }");
} else { }
else {
rb_str_concat(result, debug_dump_inspect_or_return_type(value)); rb_str_concat(result, debug_dump_inspect_or_return_type(value));
} }
rb_str_cat_cstr(result, "\n"); rb_str_cat_cstr(result, "\n");
@ -607,7 +615,8 @@ debug_dump_sorted_methods_i(ID key, VALUE value, void *data)
// snprintf(buf, 2048, "%s[%p](*)", rb_id2name(key), me); // snprintf(buf, 2048, "%s[%p](*)", rb_id2name(key), me);
snprintf(buf, 2048, "%s(*)", rb_id2name(key)); snprintf(buf, 2048, "%s(*)", rb_id2name(key));
rb_ary_push(ary, rb_str_new_cstr(buf)); rb_ary_push(ary, rb_str_new_cstr(buf));
} else { }
else {
// snprintf(buf, 2048, "%s[%p]", rb_id2name(key), me); // snprintf(buf, 2048, "%s[%p]", rb_id2name(key), me);
snprintf(buf, 2048, "%s", rb_id2name(key)); snprintf(buf, 2048, "%s", rb_id2name(key));
rb_ary_push(ary, rb_str_new_cstr(buf)); rb_ary_push(ary, rb_str_new_cstr(buf));
@ -666,10 +675,12 @@ debug_dump_classext(rb_classext_t *ext, VALUE klass, const rb_namespace_t *ns)
} else { } else {
if (!RCLASSEXT_FIELDS(ext)) { if (!RCLASSEXT_FIELDS(ext)) {
rb_str_cat_cstr(result, "Ivars: NONE\n"); rb_str_cat_cstr(result, "Ivars: NONE\n");
} else if (st_table_size((st_table *)RCLASSEXT_FIELDS(ext)) == 0) { }
else if (st_table_size((st_table *)RCLASSEXT_FIELDS(ext)) == 0) {
snprintf(buf, 2048, "IVars: NONE (%p)\n", (void *)RCLASSEXT_FIELDS(ext)); snprintf(buf, 2048, "IVars: NONE (%p)\n", (void *)RCLASSEXT_FIELDS(ext));
rb_str_cat_cstr(result, buf); rb_str_cat_cstr(result, buf);
} else { }
else {
snprintf(buf, 2048, "IVars: %zu (%p)\n", st_table_size((st_table *)RCLASSEXT_FIELDS(ext)), (void *)RCLASSEXT_FIELDS(ext)); snprintf(buf, 2048, "IVars: %zu (%p)\n", st_table_size((st_table *)RCLASSEXT_FIELDS(ext)), (void *)RCLASSEXT_FIELDS(ext));
rb_str_cat_cstr(result, buf); rb_str_cat_cstr(result, buf);
st_foreach((st_table *)RCLASSEXT_FIELDS(ext), debug_dump_ivars_foreach_i, (st_data_t)result); st_foreach((st_table *)RCLASSEXT_FIELDS(ext), debug_dump_ivars_foreach_i, (st_data_t)result);
@ -677,7 +688,8 @@ debug_dump_classext(rb_classext_t *ext, VALUE klass, const rb_namespace_t *ns)
} }
if (!RCLASSEXT_CONST_TBL(ext) || rb_id_table_size(RCLASSEXT_CONST_TBL(ext)) == 0) { if (!RCLASSEXT_CONST_TBL(ext) || rb_id_table_size(RCLASSEXT_CONST_TBL(ext)) == 0) {
rb_str_cat_cstr(result, "Constants: NONE\n"); rb_str_cat_cstr(result, "Constants: NONE\n");
} else { }
else {
snprintf(buf, 2048, "Constants: %zu\n ", rb_id_table_size(RCLASSEXT_CONST_TBL(ext))); snprintf(buf, 2048, "Constants: %zu\n ", rb_id_table_size(RCLASSEXT_CONST_TBL(ext)));
rb_str_cat_cstr(result, buf); rb_str_cat_cstr(result, buf);
rb_str_concat(result, debug_dump_sorted_constants(RCLASSEXT_CONST_TBL(ext))); rb_str_concat(result, debug_dump_sorted_constants(RCLASSEXT_CONST_TBL(ext)));
@ -685,7 +697,8 @@ debug_dump_classext(rb_classext_t *ext, VALUE klass, const rb_namespace_t *ns)
} }
if (!RCLASSEXT_M_TBL(ext) || rb_id_table_size(RCLASSEXT_M_TBL(ext)) == 0) { if (!RCLASSEXT_M_TBL(ext) || rb_id_table_size(RCLASSEXT_M_TBL(ext)) == 0) {
rb_str_cat_cstr(result, "Methods: NONE\n"); rb_str_cat_cstr(result, "Methods: NONE\n");
} else { }
else {
snprintf(buf, 2048, "Methods: %zu\n ", rb_id_table_size(RCLASSEXT_M_TBL(ext))); snprintf(buf, 2048, "Methods: %zu\n ", rb_id_table_size(RCLASSEXT_M_TBL(ext)));
rb_str_cat_cstr(result, buf); rb_str_cat_cstr(result, buf);
rb_str_concat(result, debug_dump_sorted_methods(RCLASSEXT_M_TBL(ext))); rb_str_concat(result, debug_dump_sorted_methods(RCLASSEXT_M_TBL(ext)));
@ -693,7 +706,8 @@ debug_dump_classext(rb_classext_t *ext, VALUE klass, const rb_namespace_t *ns)
} }
if (!RCLASSEXT_CALLABLE_M_TBL(ext) || rb_id_table_size(RCLASSEXT_CALLABLE_M_TBL(ext)) == 0) { if (!RCLASSEXT_CALLABLE_M_TBL(ext) || rb_id_table_size(RCLASSEXT_CALLABLE_M_TBL(ext)) == 0) {
rb_str_cat_cstr(result, "Callable Methods: NONE\n"); rb_str_cat_cstr(result, "Callable Methods: NONE\n");
} else { }
else {
snprintf(buf, 2048, "Callable Methods: %zu\n ", rb_id_table_size(RCLASSEXT_CALLABLE_M_TBL(ext))); snprintf(buf, 2048, "Callable Methods: %zu\n ", rb_id_table_size(RCLASSEXT_CALLABLE_M_TBL(ext)));
rb_str_cat_cstr(result, buf); rb_str_cat_cstr(result, buf);
rb_str_concat(result, debug_dump_sorted_list_of_id_table_keys(RCLASSEXT_CALLABLE_M_TBL(ext))); rb_str_concat(result, debug_dump_sorted_list_of_id_table_keys(RCLASSEXT_CALLABLE_M_TBL(ext)));
@ -701,7 +715,8 @@ debug_dump_classext(rb_classext_t *ext, VALUE klass, const rb_namespace_t *ns)
} }
if (!RCLASSEXT_CC_TBL(ext) || rb_id_table_size(RCLASSEXT_CC_TBL(ext)) == 0) { if (!RCLASSEXT_CC_TBL(ext) || rb_id_table_size(RCLASSEXT_CC_TBL(ext)) == 0) {
rb_str_cat_cstr(result, "Call Caches: NONE\n"); rb_str_cat_cstr(result, "Call Caches: NONE\n");
} else { }
else {
snprintf(buf, 2048, "Call Caches: %zu\n ", rb_id_table_size(RCLASSEXT_CC_TBL(ext))); snprintf(buf, 2048, "Call Caches: %zu\n ", rb_id_table_size(RCLASSEXT_CC_TBL(ext)));
rb_str_cat_cstr(result, buf); rb_str_cat_cstr(result, buf);
rb_str_concat(result, debug_dump_sorted_list_of_id_table_keys(RCLASSEXT_CC_TBL(ext))); rb_str_concat(result, debug_dump_sorted_list_of_id_table_keys(RCLASSEXT_CC_TBL(ext)));
@ -709,7 +724,8 @@ debug_dump_classext(rb_classext_t *ext, VALUE klass, const rb_namespace_t *ns)
} }
if (!RCLASSEXT_CVC_TBL(ext) || rb_id_table_size(RCLASSEXT_CVC_TBL(ext)) == 0) { if (!RCLASSEXT_CVC_TBL(ext) || rb_id_table_size(RCLASSEXT_CVC_TBL(ext)) == 0) {
rb_str_cat_cstr(result, "CVar Caches: NONE\n"); rb_str_cat_cstr(result, "CVar Caches: NONE\n");
} else { }
else {
snprintf(buf, 2048, "CVar Caches: %zu\n ", rb_id_table_size(RCLASSEXT_CVC_TBL(ext))); snprintf(buf, 2048, "CVar Caches: %zu\n ", rb_id_table_size(RCLASSEXT_CVC_TBL(ext)));
rb_str_cat_cstr(result, buf); rb_str_cat_cstr(result, buf);
rb_str_concat(result, debug_dump_sorted_list_of_id_table_keys(RCLASSEXT_CVC_TBL(ext))); rb_str_concat(result, debug_dump_sorted_list_of_id_table_keys(RCLASSEXT_CVC_TBL(ext)));
@ -717,7 +733,8 @@ debug_dump_classext(rb_classext_t *ext, VALUE klass, const rb_namespace_t *ns)
} }
if (RCLASSEXT_SUPERCLASS_DEPTH(ext) == 0) { if (RCLASSEXT_SUPERCLASS_DEPTH(ext) == 0) {
rb_str_cat_cstr(result, "Superclasses: NONE\n"); rb_str_cat_cstr(result, "Superclasses: NONE\n");
} else { }
else {
rb_str_cat_cstr(result, "Superclasses: "); rb_str_cat_cstr(result, "Superclasses: ");
len = (int)RCLASSEXT_SUPERCLASS_DEPTH(ext); len = (int)RCLASSEXT_SUPERCLASS_DEPTH(ext);
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
@ -732,7 +749,8 @@ debug_dump_classext(rb_classext_t *ext, VALUE klass, const rb_namespace_t *ns)
rb_str_cat_cstr(result, buf); rb_str_cat_cstr(result, buf);
if (!RCLASSEXT_SUBCLASSES(ext)) { if (!RCLASSEXT_SUBCLASSES(ext)) {
rb_str_cat_cstr(result, "Subclasses: NONE\n"); rb_str_cat_cstr(result, "Subclasses: NONE\n");
} else { }
else {
rb_str_cat_cstr(result, "Subclasses: "); rb_str_cat_cstr(result, "Subclasses: ");
subclass = RCLASSEXT_SUBCLASSES(ext)->head; subclass = RCLASSEXT_SUBCLASSES(ext)->head;
while (subclass->next) { while (subclass->next) {
@ -746,26 +764,30 @@ debug_dump_classext(rb_classext_t *ext, VALUE klass, const rb_namespace_t *ns)
} }
if (!RCLASSEXT_NS_SUPER_SUBCLASSES(ext)) { if (!RCLASSEXT_NS_SUPER_SUBCLASSES(ext)) {
rb_str_cat_cstr(result, "Namespace Super Subclass Table: NONE\n"); rb_str_cat_cstr(result, "Namespace Super Subclass Table: NONE\n");
} else { }
else {
snprintf(buf, 2048, "Namespace Super Subclass Table: %p\n", (void *)RCLASSEXT_NS_SUPER_SUBCLASSES(ext)); snprintf(buf, 2048, "Namespace Super Subclass Table: %p\n", (void *)RCLASSEXT_NS_SUPER_SUBCLASSES(ext));
rb_str_cat_cstr(result, buf); rb_str_cat_cstr(result, buf);
} }
if (!RCLASSEXT_NS_MODULE_SUBCLASSES(ext)) { if (!RCLASSEXT_NS_MODULE_SUBCLASSES(ext)) {
rb_str_cat_cstr(result, "Namespace Module Subclass Table: NONE\n"); rb_str_cat_cstr(result, "Namespace Module Subclass Table: NONE\n");
} else { }
else {
snprintf(buf, 2048, "Namespace Module Subclass Table: %p\n", (void *)RCLASSEXT_NS_MODULE_SUBCLASSES(ext)); snprintf(buf, 2048, "Namespace Module Subclass Table: %p\n", (void *)RCLASSEXT_NS_MODULE_SUBCLASSES(ext));
rb_str_cat_cstr(result, buf); rb_str_cat_cstr(result, buf);
} }
if (!RCLASSEXT_ORIGIN(ext)) { if (!RCLASSEXT_ORIGIN(ext)) {
rb_str_cat_cstr(result, "Origin: NONE\n"); rb_str_cat_cstr(result, "Origin: NONE\n");
} else { }
else {
rb_str_cat_cstr(result, "Origin: "); rb_str_cat_cstr(result, "Origin: ");
rb_str_concat(result, debug_dump_inspect_or_return_type(RCLASSEXT_ORIGIN(ext))); rb_str_concat(result, debug_dump_inspect_or_return_type(RCLASSEXT_ORIGIN(ext)));
rb_str_cat_cstr(result, "\n"); rb_str_cat_cstr(result, "\n");
} }
if (!RCLASSEXT_INCLUDER(ext)) { if (!RCLASSEXT_INCLUDER(ext)) {
rb_str_cat_cstr(result, "Includer: NONE\n"); rb_str_cat_cstr(result, "Includer: NONE\n");
} else { }
else {
rb_str_cat_cstr(result, "Includer: "); rb_str_cat_cstr(result, "Includer: ");
rb_str_concat(result, debug_dump_inspect_or_return_type(RCLASSEXT_INCLUDER(ext))); rb_str_concat(result, debug_dump_inspect_or_return_type(RCLASSEXT_INCLUDER(ext)));
rb_str_cat_cstr(result, "\n"); rb_str_cat_cstr(result, "\n");
@ -818,13 +840,15 @@ rb_class_debug_dump_all_classext(VALUE klass)
rb_str_cat_cstr(r, "klass: "); rb_str_cat_cstr(r, "klass: ");
if (METACLASS_OF(klass)) { if (METACLASS_OF(klass)) {
rb_str_concat(r, debug_dump_inspect_or_return_type(METACLASS_OF(klass))); rb_str_concat(r, debug_dump_inspect_or_return_type(METACLASS_OF(klass)));
} else { }
else {
rb_str_cat_cstr(r, "NONE\n"); rb_str_cat_cstr(r, "NONE\n");
} }
rb_str_cat_cstr(r, "\n"); rb_str_cat_cstr(r, "\n");
if (RCLASS_SINGLETON_P(klass)) { if (RCLASS_SINGLETON_P(klass)) {
rb_str_cat_cstr(r, "singleton class: true\n"); rb_str_cat_cstr(r, "singleton class: true\n");
} else { }
else {
rb_str_cat_cstr(r, "singleton class: false\n"); rb_str_cat_cstr(r, "singleton class: false\n");
} }
snprintf(buf, 2048, snprintf(buf, 2048,
@ -866,7 +890,8 @@ rb_class_debug_print_classext(const char *label, const char *opt, VALUE klass)
VALUE d = rb_class_debug_dump_all_classext(klass); VALUE d = rb_class_debug_dump_all_classext(klass);
if (opt) { if (opt) {
fprintf(stderr, "***** %s (%s)\n%s", label, opt, StringValueCStr(d)); fprintf(stderr, "***** %s (%s)\n%s", label, opt, StringValueCStr(d));
} else { }
else {
fprintf(stderr, "***** %s\n%s", label, StringValueCStr(d)); fprintf(stderr, "***** %s\n%s", label, StringValueCStr(d));
} }
} }
@ -930,7 +955,8 @@ push_subclass_entry_to_list(VALUE super, VALUE klass, bool is_module)
if (is_module) { if (is_module) {
RCLASS_WRITE_NS_MODULE_SUBCLASSES(klass, anchor->ns_subclasses); RCLASS_WRITE_NS_MODULE_SUBCLASSES(klass, anchor->ns_subclasses);
} else { }
else {
RCLASS_WRITE_NS_SUPER_SUBCLASSES(klass, anchor->ns_subclasses); RCLASS_WRITE_NS_SUPER_SUBCLASSES(klass, anchor->ns_subclasses);
} }
} }
@ -989,13 +1015,15 @@ remove_class_from_subclasses(struct st_table *tbl, VALUE ns_id, VALUE klass)
if (first_entry) { if (first_entry) {
if (next) { if (next) {
st_insert(tbl, ns_id, (st_data_t)next); st_insert(tbl, ns_id, (st_data_t)next);
} else { }
else {
// no subclass entries in this ns // no subclass entries in this ns
st_delete(tbl, &ns_id, NULL); st_delete(tbl, &ns_id, NULL);
} }
} }
break; break;
} else if (first_entry) { }
else if (first_entry) {
first_entry = false; first_entry = false;
} }
entry = entry->next; entry = entry->next;
@ -1174,7 +1202,8 @@ class_associate_super(VALUE klass, VALUE super, bool init)
} }
if (init) { if (init) {
RCLASS_SET_SUPER(klass, super); RCLASS_SET_SUPER(klass, super);
} else { }
else {
RCLASS_WRITE_SUPER(klass, super); RCLASS_WRITE_SUPER(klass, super);
} }
rb_class_update_superclasses(klass); rb_class_update_superclasses(klass);
@ -1274,7 +1303,8 @@ rb_class_update_superclasses(VALUE klass)
super_depth = RCLASS_SUPERCLASS_DEPTH(super); super_depth = RCLASS_SUPERCLASS_DEPTH(super);
if (RCLASS_SUPERCLASSES_WITH_SELF_P(super)) { if (RCLASS_SUPERCLASSES_WITH_SELF_P(super)) {
superclasses = RCLASS_SUPERCLASSES(super); superclasses = RCLASS_SUPERCLASSES(super);
} else { }
else {
superclasses = class_superclasses_including_self(super); superclasses = class_superclasses_including_self(super);
RCLASS_WRITE_SUPERCLASSES(super, super_depth, superclasses, true, true); RCLASS_WRITE_SUPERCLASSES(super, super_depth, superclasses, true, true);
} }
@ -2117,7 +2147,8 @@ rb_include_class_new(VALUE module, VALUE super)
RUBY_ASSERT(!RB_TYPE_P(module, T_ICLASS)); RUBY_ASSERT(!RB_TYPE_P(module, T_ICLASS));
if (RCLASS_WRITABLE_CONST_TBL(module)) { if (RCLASS_WRITABLE_CONST_TBL(module)) {
RCLASS_SET_CONST_TBL(klass, RCLASS_WRITABLE_CONST_TBL(module), true); RCLASS_SET_CONST_TBL(klass, RCLASS_WRITABLE_CONST_TBL(module), true);
} else { }
else {
RCLASS_WRITE_CONST_TBL(module, rb_id_table_create(0), false); RCLASS_WRITE_CONST_TBL(module, rb_id_table_create(0), false);
RCLASS_SET_CONST_TBL(klass, RCLASS_WRITABLE_CONST_TBL(module), true); RCLASS_SET_CONST_TBL(klass, RCLASS_WRITABLE_CONST_TBL(module), true);
} }

6
gc.c
View File

@ -2243,7 +2243,8 @@ rb_obj_memsize_of(VALUE obj)
if (rb_shape_obj_too_complex_p(obj)) { if (rb_shape_obj_too_complex_p(obj)) {
rb_class_classext_foreach(obj, classext_fields_hash_memsize, (void *)&size); rb_class_classext_foreach(obj, classext_fields_hash_memsize, (void *)&size);
} else { }
else {
// class IV sizes are allocated as powers of two // class IV sizes are allocated as powers of two
size += SIZEOF_VALUE << bit_length(RCLASS_FIELDS_COUNT(obj)); size += SIZEOF_VALUE << bit_length(RCLASS_FIELDS_COUNT(obj));
} }
@ -3746,7 +3747,8 @@ update_classext(rb_classext_t *ext, bool is_prime, VALUE namespace, void *arg)
if (args->obj_too_complex) { if (args->obj_too_complex) {
gc_ref_update_table_values_only((st_table *)RCLASSEXT_FIELDS(ext)); gc_ref_update_table_values_only((st_table *)RCLASSEXT_FIELDS(ext));
} else { }
else {
// Classext is not copied in this case // Classext is not copied in this case
for (attr_index_t i = 0; i < RCLASS_FIELDS_COUNT(klass); i++) { for (attr_index_t i = 0; i < RCLASS_FIELDS_COUNT(klass); i++) {
UPDATE_IF_MOVED(objspace, RCLASSEXT_FIELDS(RCLASS_EXT_PRIME(klass))[i]); UPDATE_IF_MOVED(objspace, RCLASSEXT_FIELDS(RCLASS_EXT_PRIME(klass))[i]);

12
load.c
View File

@ -798,7 +798,8 @@ iseq_eval_in_namespace(VALUE arg)
struct iseq_eval_in_namespace_data *data = (struct iseq_eval_in_namespace_data *)arg; struct iseq_eval_in_namespace_data *data = (struct iseq_eval_in_namespace_data *)arg;
if (rb_namespace_available() && data->in_builtin) { if (rb_namespace_available() && data->in_builtin) {
return rb_iseq_eval_with_refinement(data->iseq, rb_mNamespaceRefiner); return rb_iseq_eval_with_refinement(data->iseq, rb_mNamespaceRefiner);
} else { }
else {
return rb_iseq_eval(data->iseq); return rb_iseq_eval(data->iseq);
} }
} }
@ -865,7 +866,8 @@ load_iseq_eval(rb_execution_context_t *ec, VALUE fname)
.in_builtin = NAMESPACE_BUILTIN_P(loading_ns), .in_builtin = NAMESPACE_BUILTIN_P(loading_ns),
}; };
rb_namespace_exec(loading_ns, iseq_eval_in_namespace, (VALUE)&arg); rb_namespace_exec(loading_ns, iseq_eval_in_namespace, (VALUE)&arg);
} else { }
else {
rb_iseq_eval(iseq); rb_iseq_eval(iseq);
} }
} }
@ -891,7 +893,8 @@ load_wrapping(rb_execution_context_t *ec, VALUE fname, VALUE load_wrapper)
ns->top_self = rb_obj_clone(rb_vm_top_self()); ns->top_self = rb_obj_clone(rb_vm_top_self());
} }
th->top_self = ns->top_self; th->top_self = ns->top_self;
} else { }
else {
th->top_self = rb_obj_clone(rb_vm_top_self()); th->top_self = rb_obj_clone(rb_vm_top_self());
} }
th->top_wrapper = load_wrapper; th->top_wrapper = load_wrapper;
@ -1441,7 +1444,8 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
// check with NAMESPACE_OPTIONAL_P (not NAMESPACE_USER_P) for NS1::xxx naming // check with NAMESPACE_OPTIONAL_P (not NAMESPACE_USER_P) for NS1::xxx naming
// it is not expected for the main namespace // it is not expected for the main namespace
load_wrapping(saved.ec, path, vm_ns->ns->ns_object); load_wrapping(saved.ec, path, vm_ns->ns->ns_object);
} else { }
else {
load_iseq_eval(saved.ec, path); load_iseq_eval(saved.ec, path);
} }
break; break;

View File

@ -111,7 +111,8 @@ rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin
const rb_iseq_t *iseq; const rb_iseq_t *iseq;
if (rb_namespace_available() && rb_mNamespaceRefiner) { if (rb_namespace_available() && rb_mNamespaceRefiner) {
load_with_builtin_functions(feature_name, table); load_with_builtin_functions(feature_name, table);
} else { }
else {
iseq = builtin_iseq_load(feature_name, table); iseq = builtin_iseq_load(feature_name, table);
rb_iseq_eval(iseq); rb_iseq_eval(iseq);
} }

View File

@ -149,11 +149,13 @@ namespace_ignore_builtin_primitive_methods_p(const rb_namespace_t *ns, rb_method
) { ) {
return true; return true;
} }
} else if (strcmp(path, "<internal:warning>") == 0) { }
else if (strcmp(path, "<internal:warning>") == 0) {
if (mid == rb_intern("warn")) { if (mid == rb_intern("warn")) {
return true; return true;
} }
} else if (strcmp(path, "<internal:marshal>") == 0) { }
else if (strcmp(path, "<internal:marshal>") == 0) {
if (mid == rb_intern("load")) if (mid == rb_intern("load"))
return true; return true;
} }
@ -220,7 +222,8 @@ current_namespace(bool permit_calling_builtin)
} }
} }
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
} else { }
else {
calling = 0; calling = 0;
} }
} }
@ -349,21 +352,24 @@ rb_current_namespace_details(VALUE opt)
rb_str_cat_cstr(str, buf); rb_str_cat_cstr(str, buf);
calling = 0; calling = 0;
break; break;
} else { }
else {
snprintf(buf, 2048, " cfp cme->def id:%s, ns:%s, exprim:f, path:%s\n", snprintf(buf, 2048, " cfp cme->def id:%s, ns:%s, exprim:f, path:%s\n",
rb_id2name(cme->def->original_id), rb_id2name(cme->def->original_id),
RSTRING_PTR(part), RSTRING_PTR(part),
path); path);
rb_str_cat_cstr(str, buf); rb_str_cat_cstr(str, buf);
} }
} else { }
else {
snprintf(buf, 2048, " cfp cme->def id:%s, ns:null, path:%s\n", snprintf(buf, 2048, " cfp cme->def id:%s, ns:null, path:%s\n",
rb_id2name(cme->def->original_id), rb_id2name(cme->def->original_id),
path); path);
rb_str_cat_cstr(str, buf); rb_str_cat_cstr(str, buf);
} }
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
} else { }
else {
calling = 0; calling = 0;
} }
} }
@ -750,11 +756,13 @@ copy_ext_file(char *src_path, char *dst_path)
if (ferror(dst)) { if (ferror(dst)) {
retvalue = 4; retvalue = 4;
break; break;
} else { // partial write }
else { // partial write
clean_read = 0; clean_read = 0;
written += wrote; written += wrote;
} }
} else { // Wrote the entire buffer to dst, next read is clean one }
else { // Wrote the entire buffer to dst, next read is clean one
clean_read = 1; clean_read = 1;
} }
} }
@ -762,7 +770,8 @@ copy_ext_file(char *src_path, char *dst_path)
if (clean_read && feof(src)) { if (clean_read && feof(src)) {
// If it's not clean, buffer should have bytes not written yet. // If it's not clean, buffer should have bytes not written yet.
eof = 1; eof = 1;
} else if (ferror(src)) { }
else if (ferror(src)) {
retvalue = 3; retvalue = 3;
// Writes could be partial/dirty, but this load is failure anyway // Writes could be partial/dirty, but this load is failure anyway
break; break;
@ -852,7 +861,8 @@ namespace_push(rb_thread_t *th, VALUE namespace)
{ {
if (RTEST(th->namespaces)) { if (RTEST(th->namespaces)) {
rb_ary_push(th->namespaces, namespace); rb_ary_push(th->namespaces, namespace);
} else { }
else {
th->namespaces = rb_ary_new_from_args(1, namespace); th->namespaces = rb_ary_new_from_args(1, namespace);
} }
th->ns = rb_get_namespace_t(namespace); th->ns = rb_get_namespace_t(namespace);
@ -873,7 +883,8 @@ namespace_pop(VALUE th_value)
if (stack_len == 0) { if (stack_len == 0) {
th->namespaces = 0; th->namespaces = 0;
th->ns = main_namespace; th->ns = main_namespace;
} else { }
else {
upper_ns = RARRAY_AREF(namespaces, stack_len-1); upper_ns = RARRAY_AREF(namespaces, stack_len-1);
th->ns = rb_get_namespace_t(upper_ns); th->ns = rb_get_namespace_t(upper_ns);
} }
@ -990,7 +1001,8 @@ rb_namespace_inspect(VALUE obj)
} }
if (NAMESPACE_MAIN_P(ns)) { if (NAMESPACE_MAIN_P(ns)) {
rb_str_cat_cstr(r, ",main"); rb_str_cat_cstr(r, ",main");
} else if (NAMESPACE_OPTIONAL_P(ns)) { }
else if (NAMESPACE_OPTIONAL_P(ns)) {
rb_str_cat_cstr(r, ",optional"); rb_str_cat_cstr(r, ",optional");
} }
rb_str_cat_cstr(r, ">"); rb_str_cat_cstr(r, ">");

View File

@ -1009,7 +1009,8 @@ rb_gvar_set(ID id, VALUE val)
rb_hash_aset(ns->gvar_tbl, rb_id2sym(entry->id), val); rb_hash_aset(ns->gvar_tbl, rb_id2sym(entry->id), val);
retval = val; retval = val;
// TODO: think about trace // TODO: think about trace
} else { }
else {
retval = rb_gvar_set_entry(entry, val); retval = rb_gvar_set_entry(entry, val);
} }
return retval; return retval;
@ -1034,14 +1035,16 @@ rb_gvar_get(ID id)
key = rb_id2sym(entry->id); key = rb_id2sym(entry->id);
if (RTEST(rb_hash_has_key(gvars, key))) { // this gvar is already cached if (RTEST(rb_hash_has_key(gvars, key))) { // this gvar is already cached
retval = rb_hash_aref(gvars, key); retval = rb_hash_aref(gvars, key);
} else { }
else {
retval = (*var->getter)(entry->id, var->data); retval = (*var->getter)(entry->id, var->data);
if (rb_obj_respond_to(retval, rb_intern("clone"), 1)) { if (rb_obj_respond_to(retval, rb_intern("clone"), 1)) {
retval = rb_funcall(retval, rb_intern("clone"), 0); retval = rb_funcall(retval, rb_intern("clone"), 0);
} }
rb_hash_aset(gvars, key, retval); rb_hash_aset(gvars, key, retval);
} }
} else { }
else {
retval = (*var->getter)(entry->id, var->data); retval = (*var->getter)(entry->id, var->data);
} }
return retval; return retval;
@ -3787,11 +3790,10 @@ rb_const_remove(VALUE mod, ID id)
val = Qnil; val = Qnil;
} }
if (ce == const_lookup(RCLASS_PRIME_CONST_TBL(mod), id)) { if (ce != const_lookup(RCLASS_PRIME_CONST_TBL(mod), id)) {
// skip free'ing the ce because it still exists in the prime classext
} else {
ruby_xfree(ce); ruby_xfree(ce);
} }
// else - skip free'ing the ce because it still exists in the prime classext
return val; return val;
} }