File tree Expand file tree Collapse file tree 3 files changed +11
-11
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 3 files changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -280,12 +280,7 @@ def write(str)
280
280
str = String ( str )
281
281
return 0 if str . empty?
282
282
283
- if external_encoding &&
284
- external_encoding != str . encoding &&
285
- external_encoding != Encoding ::BINARY &&
286
- str . encoding != Encoding ::BINARY
287
- str = str . encode ( external_encoding )
288
- end
283
+ str = Truffle ::IOOperations . write_transcoding ( str , external_encoding )
289
284
290
285
d = @__data__
291
286
TruffleRuby . synchronized ( d ) do
Original file line number Diff line number Diff line change @@ -2324,11 +2324,7 @@ def write(*objects)
2324
2324
2325
2325
ensure_open_and_writable
2326
2326
2327
- if external_encoding && external_encoding != string . encoding && external_encoding != Encoding ::BINARY
2328
- unless string . ascii_only? && external_encoding . ascii_compatible?
2329
- string = string . encode ( external_encoding )
2330
- end
2331
- end
2327
+ string = Truffle ::IOOperations . write_transcoding ( string , external_encoding )
2332
2328
2333
2329
count = Truffle ::POSIX . write_string self , string , true
2334
2330
bytes_written += count
Original file line number Diff line number Diff line change @@ -72,6 +72,15 @@ def self.puts(io, *args)
72
72
nil
73
73
end
74
74
75
+ def self . write_transcoding ( string , external_encoding )
76
+ if external_encoding && external_encoding != string . encoding && external_encoding != Encoding ::BINARY &&
77
+ !( string . ascii_only? && external_encoding . ascii_compatible? )
78
+ string . encode ( external_encoding )
79
+ else
80
+ string
81
+ end
82
+ end
83
+
75
84
def self . dup2_with_cloexec ( old_fd , new_fd )
76
85
if new_fd < 3
77
86
# STDIO should not be made close-on-exec. `dup2` clears the close-on-exec bit for the destination FD.
You can’t perform that action at this time.
0 commit comments