Repository navigation
Remove get_actual_encoding() and the dynamic endian detection for dummy UTF-16/UTF-32 - #6322
Conversation
3d3243d to
2d42bf9
Compare
|
At that comment, you wrote:
Why deprecating these encodings themselves? |
From https://github.com/ruby/dev-meeting-log/blob/master/DevMeeting-2022-08-18.md#feature-18949-deprecate-and-remove-replicate-and-dummy-encodings-eregon :
My understanding of this, is we don't need the dummy UTF-16/32 encodings (unnecessary, no actual use case), i.e., we don't need that feature and users can specify the endian explicitly from the start instead ("People should convert the string first."). This will also remove a lot of unnecessary complexity. |
My comment ("it doesn't have actual use case") is about " the dynamic UTF-16/32 endian detection". Removing UTF-16/32 dummy encoding itself is not accepted.
Your understanding of character encoding is based on Universal Character Set Normalization model. In the UCS model, all strings are converted into the UCS to handle as a string. I think you can read the log carefully. It says "Conclusion: Just remove the dynamic UTF-16/32 endian detection. People should convert the string first.". I think there are no ambiguously. |
|
Oh, OK, thank you for clarifying. I did read it carefully multiple times, for me "remove the dynamic UTF-16/32 endian detection" means remove dummy UTF encodings. I misunderstood the "dynamic" I think, where you mean "detecting it on each string operation vs once" and I thought it means "automatic, based on the string first bytes". "People should convert the string first.". also clearly means for me they should "attach/decide" BE/LE when creating the string/when giving it an encoding (so not give it a dummy unicode encoding but a BE or LE encoding). Re UCS vs CSI, I am well aware Ruby is M17N and has strings of multiple encodings in the same process. I will deprecate and remove the dummy UTF-16/32 encodings in TruffleRuby (currently they behave the same as -BE variants), because I believe they are not worth the complexity and nobody uses them in the real world (or they could very easily use UTF-16/32-BE/LE instead). I wish we could do the same in CRuby for better compatibility between implementations, but it seems Ruby core is not ready for that yet, alright. @nurse Could you clarify this: |
No. The current consensus is...
|
|
Ah, so that basically (almost) means |
No. After the change, Encoding::UTF_32 won't provide any string operation like Encoding::ISO_2022_JP |
|
Ah yes, it will be like "any other dummy encoding". |
|
@nurse Because of Lines 4 to 5 in c22a668 For example: Is that OK? |
…my UTF-16/UTF-32 * And simplify callers of get_actual_encoding(). * See [Feature ruby#18949]. * See ruby#6322 (comment)
2d42bf9 to
de32eca
Compare
|
I think it makes more sense to have them as regular dummy encodings and use ENC_DUMMY (i.e., undo 3a2aca5) |
…my UTF-16/UTF-32 * And simplify callers of get_actual_encoding(). * See [Feature ruby#18949]. * See ruby#6322 (comment)
de32eca to
d9b88c7
Compare
| #define ENC_DEFINE(name) rb_encdb_declare(name) | ||
| #define ENC_SET_BASE(name, orig) rb_enc_set_base((name), (orig)) | ||
| #define ENC_SET_DUMMY(name, orig) rb_enc_set_dummy(name) | ||
| #define ENC_DUMMY_UNICODE(name) rb_encdb_set_unicode(rb_enc_set_dummy(ENC_REPLICATE((name), name "BE"))) |
There was a problem hiding this comment.
Removing rb_encdb_set_unicode() is necessary here, so that:
> "\u3042".encode("UTF-32BE").force_encoding("UTF-32")
=> "\x00\x00\x30\x42"
> "\u3042".encode("UTF-32BE").force_encoding("ISO-2022-JP")
=> "\x00\x00\x30\x42"
and not:
s = "\u3042".encode("UTF-32BE")
s.dup.force_encoding("UTF-32").inspect
=> "\"\\u0000\\u00000B\""
irb(main):005:0> s.dup.force_encoding("UTF-16").inspect
=> "\"\\u0000\\u00000B\""
Since the latter seems quite wrong (interpreting single bytes as unicode/ASCII characters in UTF-16/32)
|
This is now ready for review. The dummy UTF-16 and UTF-32 encodings are now exactly like all other dummy encodings. |
nurse
left a comment
There was a problem hiding this comment.
Looks good! Thank for the change!
https://bugs.ruby-lang.org/issues/18949#note-29