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

jruby: Implement set_encoding_by_bom #101

Merged
merged 6 commits into from
Sep 25, 2024
Merged

Conversation

headius
Copy link
Contributor

@headius headius commented Jul 31, 2024

Fix GH-100

This better matches the CRuby logic that calls the equivalent
function and brings in BOM support.
Roughly ported from CRuby.

See ruby@b249631
@headius headius marked this pull request as ready for review August 1, 2024 12:05
@headius
Copy link
Contributor Author

headius commented Aug 1, 2024

JRuby is still not green but it reduces the failure count by 5, exactly the number of tests that failed due to missing set_encoding_by_bom.

@nobu This is ready for review and merge. I will try to get the remaining tests green some day.


// TODO: replace with EncodingUtils#extractModeEncoding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed?
It seems that we already use EncodingUtils#extractModeEncoding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in upcoming push.

Comment on lines 307 to 309
Object vmodeVperm = EncodingUtils.vmodeVperm(null, null);
int[] oflags = {0};
int[] fmode = {0};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move them to the bellow if (!options.isNil()) { ... } block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in upcoming push, and vmodeVperm and oflags are now allocated once since they are never read by StringIO.

ext/java/org/jruby/ext/stringio/StringIO.java Outdated Show resolved Hide resolved
Comment on lines 1683 to 1684
if (len < 2) break;
if (toUnsignedInt(bytes[p + 1]) == 0xBB && len > 2) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick: why len < 2?

Suggested change
if (len < 2) break;
if (toUnsignedInt(bytes[p + 1]) == 0xBB && len > 2) {
if (len < 3) break;
if (toUnsignedInt(bytes[p + 1]) == 0xBB) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original logic was ported from the C code:

https://github.com/ruby/stringio/blob/master/ext/stringio/stringio.c#L229-L230

Are you sure this should change to len < 3?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is resolved in the other comment from @kou.

headius and others added 3 commits September 21, 2024 09:18
The code does use extractModeEncoding now.
* Only prepare carrier objects if we'll make the call
* Cache the two carrier objects that are actually read
  (vmodeVperm is read inside extractModeEncoding so can't be a
  simple constant).
@kou kou changed the title Implement set_encoding_by_bom jruby: Implement set_encoding_by_bom Sep 25, 2024
@kou kou merged commit cb46167 into ruby:master Sep 25, 2024
51 checks passed
@kou
Copy link
Member

kou commented Sep 25, 2024

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

JRuby ext is missing set_encoding_by_bom
3 participants