Bug #18189
closed`rb_cString` can be NULL during `Init_Object`
Description
It's possible for rb_cString to be NULL during Init_Object and thus Init_class_hierarchy which means that rb_fstring_lit, which invokes setup_fake_str, invokes RBASIC_SET_CLASS_RAW(..., NULL) (or possibly just something totally random if it's not zero initialized!).
Later on in register_fstring we have an assertion which also fails to detect the abnormality:
Because both are NULL. Oops.
It seems that later on, rb_cString is set on that specific fstring. But in my own usage of rb_define_module_under during InitVM_Object, this creates invalid class names which fail when passed into Ruby land.
Updated by ioquatix (Samuel Williams) almost 5 years ago
- Description updated (diff)
Updated by ioquatix (Samuel Williams) almost 5 years ago
Updated by ioquatix (Samuel Williams) almost 5 years ago
Updated by nobu (Nobuyoshi Nakada) almost 5 years ago
Updated by ioquatix (Samuel Williams) almost 5 years ago
@nobu (Nobuyoshi Nakada) with your changes you made, please try running make test. It fails.
Then, use the sample I gave:
> ./ruby -e 'p Immutable::Object.to_s'
-e:1:in `p': method `inspect' called on hidden T_STRING object (0x0000000108b6fa90 flags=0x844005) (NotImplementedError)
from -e:1:in `<main>'
This seems invalid, no?
Updated by nobu (Nobuyoshi Nakada) almost 5 years ago
I see.
diff --git i/variable.c w/variable.c
index aa1fdd022eb..c6e1012bddc 100644
--- i/variable.c
+++ w/variable.c
@@ -202,8 +202,7 @@ build_const_pathname(VALUE head, VALUE tail)
VALUE path = rb_str_dup(head);
rb_str_cat2(path, "::");
rb_str_append(path, tail);
- OBJ_FREEZE(path);
- return path;
+ return rb_fstring(path);
}
static VALUE
Updated by ioquatix (Samuel Williams) almost 5 years ago
@nobu (Nobuyoshi Nakada) that makes total sense.
I also had one other idea.
We obviously have a lot of:
We initialize this dynamically.
Why not initialize it statically?
It seems (1) performance improvement and (2) more predictable usage at least for strings.
Updated by ioquatix (Samuel Williams) almost 5 years ago
Thanks to @nobu's suggestion here is a PR: https://github.com/ruby/ruby/pull/4892/commits/f0be5d27d5dde1b6dfeb174f00fcac66d9a0184d
Updated by ioquatix (Samuel Williams) almost 5 years ago
- Status changed from Open to Closed
It's fixed.