Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support null encoding for rb_enc_interned_str_cstr #3480

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Bug fixes:

Compatibility:

* Allow null encoding pointer in `rb_enc_interned_str_cstr` (@thomasmarshall).

Performance:

Changes:
Expand Down
2 changes: 1 addition & 1 deletion lib/cext/ABI_check.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13
14
2 changes: 1 addition & 1 deletion spec/ruby/optional/capi/ext/string_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ static VALUE string_spec_rb_str_unlocktmp(VALUE self, VALUE str) {
}

static VALUE string_spec_rb_enc_interned_str_cstr(VALUE self, VALUE str, VALUE enc) {
rb_encoding *e = rb_to_encoding(enc);
rb_encoding *e = NIL_P(enc) ? 0 : rb_to_encoding(enc);
return rb_enc_interned_str_cstr(RSTRING_PTR(str), e);
}

Expand Down
8 changes: 8 additions & 0 deletions spec/ruby/optional/capi/string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,14 @@ def inspect
it "returns the same string as String#-@" do
@s.rb_enc_interned_str_cstr("hello", Encoding::UTF_8).should.equal?(-"hello")
end

ruby_bug "#20322", ""..."3.4" do
it "uses the default encoding if encoding is null" do
str = "hello"
val = @s.rb_enc_interned_str_cstr(str, nil)
val.encoding.should == Encoding::ASCII_8BIT
end
end
end

describe "rb_str_to_interned_str" do
Expand Down
2 changes: 1 addition & 1 deletion src/main/c/cext/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ long rb_str_coderange_scan_restartable(const char *s, const char *e, rb_encoding
}

VALUE rb_enc_interned_str_cstr(const char *ptr, rb_encoding *enc) {
VALUE str = rb_enc_str_new_cstr(ptr, enc);
VALUE str = rb_enc_str_new_cstr(ptr, enc ? enc : rb_ascii8bit_encoding());
return rb_str_to_interned_str(str);
}

Expand Down
Loading