Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ractor compat #62

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -998,13 +998,13 @@ def Config.parse_resolv_conf(filename)
next unless keyword
case keyword
when 'nameserver'
nameserver.concat(args)
nameserver.concat(args.each(&:freeze))
when 'domain'
next if args.empty?
search = [args[0]]
search = [args[0].freeze]
when 'search'
next if args.empty?
search = args
search = args.each(&:freeze)
when 'options'
args.each {|arg|
case arg
Expand All @@ -1015,22 +1015,22 @@ def Config.parse_resolv_conf(filename)
end
}
}
return { :nameserver => nameserver, :search => search, :ndots => ndots }
return { :nameserver => nameserver.freeze, :search => search.freeze, :ndots => ndots.freeze }.freeze
end

def Config.default_config_hash(filename="/etc/resolv.conf")
if File.exist? filename
config_hash = Config.parse_resolv_conf(filename)
Config.parse_resolv_conf(filename)
elsif WINDOWS
require 'win32/resolv'
search, nameserver = Win32::Resolv.get_resolv_info
config_hash = {}
config_hash[:nameserver] = nameserver if nameserver
config_hash[:search] = [search].flatten if search
config_hash
else
if WINDOWS
require 'win32/resolv'
search, nameserver = Win32::Resolv.get_resolv_info
config_hash = {}
config_hash[:nameserver] = nameserver if nameserver
config_hash[:search] = [search].flatten if search
end
{}
end
config_hash || {}
end

def lazy_initialize
Expand Down Expand Up @@ -2125,7 +2125,14 @@ class Resource < Query

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
Expand Down Expand Up @@ -2163,7 +2170,9 @@ def hash # :nodoc:
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

Expand Down
Loading