-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rb_interned_str_* functions to not assume static strings
Fixes [Feature #13381] When passed a `fake_str`, `register_fstring` would create new strings with `str_new_static`. That's not what was expected, and answer almost no use cases.
- Loading branch information
Showing
3 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "ruby.h" | ||
|
||
static VALUE | ||
bug_rb_interned_str_dup(VALUE self, VALUE str) | ||
{ | ||
rb_check_type(str, T_STRING); | ||
return rb_interned_str(RSTRING_PTR(str), RSTRING_LEN(str)); | ||
} | ||
|
||
void | ||
Init_string_rb_interned_str(VALUE klass) | ||
{ | ||
rb_define_singleton_method(klass, "rb_interned_str_dup", bug_rb_interned_str_dup, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'test/unit' | ||
require '-test-/string' | ||
|
||
class Test_RbInternedStr < Test::Unit::TestCase | ||
def test_interned_str | ||
src = "a" * 20 | ||
interned_str = Bug::String.rb_interned_str_dup(src) | ||
src.clear | ||
src << "b" * 20 | ||
assert_equal "a" * 20, interned_str | ||
end | ||
end |