diff options
author | Kevin Newton <[email protected]> | 2025-03-12 13:16:38 -0400 |
---|---|---|
committer | git <[email protected]> | 2025-03-12 19:15:03 +0000 |
commit | 242e99eb0f32e1705413d084126be4ae6525a804 (patch) | |
tree | cc05ec6908dbb7bdf0f2bbc6f5d28fcf18f6eefc /lib | |
parent | 08b3a45bc97c835b4677bf76dbce68fd51d81897 (diff) |
[ruby/prism] Mark extension as Ractor-safe
https://github.com/ruby/prism/commit/10e5431b38
Diffstat (limited to 'lib')
-rw-r--r-- | lib/prism/ffi.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/prism/ffi.rb b/lib/prism/ffi.rb index 35b91e41b2..a0da0b6195 100644 --- a/lib/prism/ffi.rb +++ b/lib/prism/ffi.rb @@ -7,6 +7,10 @@ require "rbconfig" require "ffi" +# We want to eagerly load this file if there are Ractors so that it does not get +# autoloaded from within a non-main Ractor. +require "prism/serialize" if defined?(Ractor) + module Prism module LibRubyParser # :nodoc: extend FFI::Library @@ -159,6 +163,9 @@ module Prism class PrismString # :nodoc: SIZEOF = LibRubyParser.pm_string_sizeof + PLATFORM_EXPECTS_UTF8 = + RbConfig::CONFIG["host_os"].match?(/bccwin|cygwin|djgpp|mingw|mswin|wince|darwin/i) + attr_reader :pointer, :length def initialize(pointer, length, from_string) @@ -193,8 +200,7 @@ module Prism # On Windows and Mac, it's expected that filepaths will be encoded in # UTF-8. If they are not, we need to convert them to UTF-8 before # passing them into pm_string_mapped_init. - if RbConfig::CONFIG["host_os"].match?(/bccwin|cygwin|djgpp|mingw|mswin|wince|darwin/i) && - (encoding = filepath.encoding) != Encoding::ASCII_8BIT && encoding != Encoding::UTF_8 + if PLATFORM_EXPECTS_UTF8 && (encoding = filepath.encoding) != Encoding::ASCII_8BIT && encoding != Encoding::UTF_8 filepath = filepath.encode(Encoding::UTF_8) end @@ -223,7 +229,7 @@ module Prism private_constant :LibRubyParser # The version constant is set by reading the result of calling pm_version. - VERSION = LibRubyParser.pm_version.read_string + VERSION = LibRubyParser.pm_version.read_string.freeze class << self # Mirror the Prism.dump API by using the serialization API. |