summaryrefslogtreecommitdiff
path: root/lib/resolv.rb
diff options
context:
space:
mode:
authorHoneyryderChuck <[email protected]>2024-10-29 17:58:27 +0000
committergit <[email protected]>2025-04-10 15:58:04 +0000
commite3dd766e991892f1e2c0191ab6648eb0872a641c (patch)
treec04e4e9f6f9291e301e9f7f8ed6811ed2e5a58ad /lib/resolv.rb
parent54a85caed4b364df5a7dd25795957b20b8e50f8e (diff)
[ruby/resolv] refactoring class-hash to be ractor-safe
mutable constants can't be shared across ractors; this changes that design to define the required variables as constants on the Resource class, which makes them reachable using ractors; the ClassHash is kept in order not to break integrations relying on its existence, but under the hood it's doing the same thing https://github.com/ruby/resolv/commit/639c01dc7f
Diffstat (limited to 'lib/resolv.rb')
-rw-r--r--lib/resolv.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/resolv.rb b/lib/resolv.rb
index 216d5cfe2b..ca72f41c5c 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -2125,7 +2125,14 @@ class Resolv
attr_reader :ttl
- ClassHash = {} # :nodoc:
+ ClassHash = Module.new do
+ module_function
+
+ def []=(type_class_value, klass)
+ type_value, class_value = type_class_value
+ Resource.const_set(:"Type#{type_value}_Class#{class_value}", klass)
+ end
+ end
def encode_rdata(msg) # :nodoc:
raise NotImplementedError.new
@@ -2163,7 +2170,9 @@ class Resolv
end
def self.get_class(type_value, class_value) # :nodoc:
- return ClassHash[[type_value, class_value]] ||
+ cache = :"Type#{type_value}_Class#{class_value}"
+
+ return (const_defined?(cache) && const_get(cache)) ||
Generic.create(type_value, class_value)
end