|
7 | 7 | require "rbconfig" |
8 | 8 | require "ffi" |
9 | 9 |
|
| 10 | +# We want to eagerly load this file if there are Ractors so that it does not get |
| 11 | +# autoloaded from within a non-main Ractor. |
| 12 | +require "prism/serialize" if defined?(Ractor) |
| 13 | + |
10 | 14 | module Prism |
11 | 15 | module LibRubyParser # :nodoc: |
12 | 16 | extend FFI::Library |
@@ -159,6 +163,9 @@ def self.with |
159 | 163 | class PrismString # :nodoc: |
160 | 164 | SIZEOF = LibRubyParser.pm_string_sizeof |
161 | 165 |
|
| 166 | + PLATFORM_EXPECTS_UTF8 = |
| 167 | + RbConfig::CONFIG["host_os"].match?(/bccwin|cygwin|djgpp|mingw|mswin|wince|darwin/i) |
| 168 | + |
162 | 169 | attr_reader :pointer, :length |
163 | 170 |
|
164 | 171 | def initialize(pointer, length, from_string) |
@@ -193,8 +200,7 @@ def self.with_file(filepath) |
193 | 200 | # On Windows and Mac, it's expected that filepaths will be encoded in |
194 | 201 | # UTF-8. If they are not, we need to convert them to UTF-8 before |
195 | 202 | # passing them into pm_string_mapped_init. |
196 | | - if RbConfig::CONFIG["host_os"].match?(/bccwin|cygwin|djgpp|mingw|mswin|wince|darwin/i) && |
197 | | - (encoding = filepath.encoding) != Encoding::ASCII_8BIT && encoding != Encoding::UTF_8 |
| 203 | + if PLATFORM_EXPECTS_UTF8 && (encoding = filepath.encoding) != Encoding::ASCII_8BIT && encoding != Encoding::UTF_8 |
198 | 204 | filepath = filepath.encode(Encoding::UTF_8) |
199 | 205 | end |
200 | 206 |
|
@@ -223,7 +229,7 @@ def self.with_file(filepath) |
223 | 229 | private_constant :LibRubyParser |
224 | 230 |
|
225 | 231 | # The version constant is set by reading the result of calling pm_version. |
226 | | - VERSION = LibRubyParser.pm_version.read_string |
| 232 | + VERSION = LibRubyParser.pm_version.read_string.freeze |
227 | 233 |
|
228 | 234 | class << self |
229 | 235 | # Mirror the Prism.dump API by using the serialization API. |
|
0 commit comments