From 0745dc9b0d8d20f1184db1893fc61947bcbd39f1 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 4 Aug 2025 15:21:59 +0200 Subject: [PATCH] Fix some constants to be frozen and usable in a Ractor Freeze some constants to make them available in a Ractor context. --- lib/pg.rb | 1 + lib/pg/version.rb | 1 + spec/pg_spec.rb | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/lib/pg.rb b/lib/pg.rb index 73f2f894c..557f81728 100644 --- a/lib/pg.rb +++ b/lib/pg.rb @@ -21,6 +21,7 @@ module PG POSTGRESQL_LIB_PATH = false end end + POSTGRESQL_LIB_PATH.freeze add_dll_path = proc do |path, &block| if RUBY_PLATFORM =~/(mswin|mingw)/i && path diff --git a/lib/pg/version.rb b/lib/pg/version.rb index 579dbe2b8..d37ddd956 100644 --- a/lib/pg/version.rb +++ b/lib/pg/version.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module PG # Library version VERSION = '1.6.1' diff --git a/spec/pg_spec.rb b/spec/pg_spec.rb index dc7b3e2b4..b24d3c1bf 100644 --- a/spec/pg_spec.rb +++ b/spec/pg_spec.rb @@ -57,4 +57,14 @@ expect( bres ).to eq( 55 ) end + + it "should provide constants in a Ractor", :ractor do + vals = Ractor.new(@conninfo) do |conninfo| + [PG.library_version, PG.version_string, PG.threadsafe?, PG::VERSION, PG::POSTGRESQL_LIB_PATH] + end.value + + expect( vals ).to eq( + [PG.library_version, PG.version_string, PG.threadsafe?, PG::VERSION, PG::POSTGRESQL_LIB_PATH] + ) + end end