Skip to content

Commit 9bef946

Browse files
committed
[GR-17457] Fix rb_uv_to_utf8() spec
PullRequest: truffleruby/3322
2 parents a432c1f + 6a5d6be commit 9bef946

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

spec/ruby/core/dir/foreach_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141

4242
it "accepts an encoding keyword for the encoding of the entries" do
4343
dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").to_a.sort
44-
dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
44+
dirs.each { |dir| dir.encoding.should == Encoding::UTF_8 }
4545

46-
dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::UTF_16LE).to_a.sort
47-
dirs.each {|dir| dir.encoding.should == Encoding::UTF_16LE}
46+
dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::ISO_8859_1).to_a.sort
47+
dirs.each { |dir| dir.encoding.should == Encoding::ISO_8859_1 }
4848

49-
Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::UTF_16LE) do |f|
50-
f.encoding.should == Encoding::UTF_16LE
49+
Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::ISO_8859_1) do |f|
50+
f.encoding.should == Encoding::ISO_8859_1
5151
end
5252
end
5353

spec/ruby/optional/capi/encoding_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -613,15 +613,15 @@
613613
it 'converts a Unicode codepoint to a UTF-8 C string' do
614614
str = ' ' * 6
615615
{
616-
0 => "\x01",
617-
0x7f => "\xC2\x80",
618-
0x7ff => "\xE0\xA0\x80",
619-
0xffff => "\xF0\x90\x80\x80",
620-
0x1fffff => "\xF8\x88\x80\x80\x80",
621-
0x3ffffff => "\xFC\x84\x80\x80\x80\x80",
616+
1 => "\x01",
617+
0x80 => "\xC2\x80",
618+
0x800 => "\xE0\xA0\x80",
619+
0x10000 => "\xF0\x90\x80\x80",
620+
0x200000 => "\xF8\x88\x80\x80\x80",
621+
0x4000000 => "\xFC\x84\x80\x80\x80\x80",
622622
}.each do |num, result|
623-
len = @s.rb_uv_to_utf8(str, num + 1)
624-
str[0..len-1].should == result
623+
len = @s.rb_uv_to_utf8(str, num)
624+
str.byteslice(0, len).should == result
625625
end
626626
end
627627
end

spec/ruby/optional/capi/ext/encoding_spec.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ static VALUE encoding_spec_rb_enc_str_asciionly_p(VALUE self, VALUE str) {
275275
}
276276

277277
static VALUE encoding_spec_rb_uv_to_utf8(VALUE self, VALUE buf, VALUE num) {
278-
return INT2NUM(rb_uv_to_utf8(RSTRING_PTR(buf), NUM2INT(num)));
278+
int len = rb_uv_to_utf8(RSTRING_PTR(buf), NUM2INT(num));
279+
RB_ENC_CODERANGE_CLEAR(buf);
280+
return INT2NUM(len);
279281
}
280282

281283
static VALUE encoding_spec_ONIGENC_MBC_CASE_FOLD(VALUE self, VALUE str) {

src/main/java/org/truffleruby/core/hash/HashNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ protected Object set(RubyHash hash, Object key, Object value,
257257
@ImportStatic(HashGuards.class)
258258
public abstract static class ClearNode extends CoreMethodArrayArgumentsNode {
259259

260-
@Specialization(limit = "2")
260+
@Specialization(limit = "hashStrategyLimit()")
261261
protected RubyHash clear(RubyHash hash,
262262
@CachedLibrary("hash.store") HashStoreLibrary hashes) {
263263
hashes.clear(hash.store, hash);

src/main/java/org/truffleruby/core/hash/library/PackedHashStoreLibrary.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ protected static Object lookupOrDefault(
165165
return lookupPackedEntryNode.execute(frame, hash, key, hashed, defaultNode);
166166
}
167167

168+
@ImportStatic(HashGuards.class)
168169
@ExportMessage
169170
protected static class Set {
170171
@Specialization(guards = "hash.size == 0")
@@ -190,7 +191,7 @@ protected static boolean set(Object[] store, RubyHash hash, Object key, Object v
190191
@Cached @Shared("propagateKey") PropagateSharingNode propagateSharingKey,
191192
@Cached @Shared("propagateValue") PropagateSharingNode propagateSharingValue,
192193
@Cached @Shared("compareHashKeys") CompareHashKeysNode compareHashKeys,
193-
@CachedLibrary(limit = "2") HashStoreLibrary hashes,
194+
@CachedLibrary(limit = "hashStrategyLimit()") HashStoreLibrary hashes,
194195
@Cached ConditionProfile withinCapacity) {
195196

196197
assert verify(store, hash);

0 commit comments

Comments
 (0)