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

in_tail: remove workaround of converting encoding #4815

Closed
wants to merge 2 commits into from

Conversation

Watson1978
Copy link
Contributor

Which issue(s) this PR fixes:
Fixes #

What this PR does / why we need it:
This PR will remove workarounds for versions earlier than Ruby 2.4.

The following code is causing SEGV in Ruby 2.3.
And I think it was workaround for SEGV.

a = open('/dev/urandom')
buf = ''.force_encoding(Encoding::UTF_16BE)
a.readpartial(2048, buf)

#1409 (comment)

I want to remove it because it works well with currently Ruby.

Docs Changes:

Release Note:

@daipom
Copy link
Contributor

daipom commented Feb 3, 2025

Awesome! Thanks! I will see this soon.

@Watson1978
Copy link
Contributor Author

Hmm, this fails CI...
I will look test codes...

@Watson1978 Watson1978 marked this pull request as draft February 3, 2025 03:07
@Watson1978
Copy link
Contributor Author

Hmm, this PR might cause a Encoding::CompatibilityError when append the chunk data...

>> @buffer = ''.force_encoding(Encoding::UTF_16LE)
=> ""
>> chunk = 'あいうえお'.force_encoding('ASCII-8BIT')
=> "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"
>> @buffer << chunk
=> "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"
>> @buffer.encoding
=> #<Encoding:BINARY (ASCII-8BIT)>
>> @buffer.force_encoding(Encoding::UTF_16LE)
=> "\u81E3\uE382\u8481\u81E3\uE386\u8881\u81E3\x8A"
>> @buffer << chunk
(irb):7:in 'String#<<': incompatible character encodings: UTF-16LE and BINARY (ASCII-8BIT) (Encoding::CompatibilityError)
	from (irb):7:in '<main>'
	from <internal:kernel>:168:in 'Kernel#loop'
	from /home/watson/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/irb-1.15.1/exe/irb:9:in '<top (required)>'
	from /home/watson/.rbenv/versions/3.4.1/bin/irb:25:in 'Kernel#load'
	from /home/watson/.rbenv/versions/3.4.1/bin/irb:25:in '<main>'

@Watson1978 Watson1978 closed this Feb 3, 2025
@Watson1978 Watson1978 deleted the in_tail branch February 3, 2025 05:33
@daipom
Copy link
Contributor

daipom commented Feb 3, 2025

I see.
Thanks for this endeavor.
Let us know if you find out anything about this.
Thanks!

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

Successfully merging this pull request may close these issues.

2 participants