Environment
- Ruby: 4.0.3
- ruby-oci8: 2.2.14
- Oracle Instant Client: 19.23
- OS: Debian Trixie (Docker)
Problem
bundle install fails when compiling ruby-oci8 on Ruby 4.0.
Ruby 4.0 changed mkmf.rb's try_constant method — Integer(f.gets) at line 833 now raises TypeError when f.gets returns nil, instead of returning nil gracefully as in Ruby 3.x.
Error:
/usr/local/lib/ruby/4.0.0/mkmf.rb:833:in 'Kernel#Integer': can't convert nil into Integer (TypeError)
return Integer(f.gets)
^^^^^^
from /usr/local/lib/ruby/4.0.0/mkmf.rb:833:in 'block in MakeMakefile#try_constant'
from extconf.rb:34:in 'block in
'
Root Cause
In ext/oci8/extconf.rb line 33-34:
oci_major_version = checking_for 'OCI_MAJOR_VERSION in oci.h', fmt do
try_constant('OCI_MAJOR_VERSION', 'oci.h')
end
try_constant compiles a small C program that prints the constant value. When the program produces no output, f.gets returns nil. In Ruby 3.x, Integer(nil) returned nil. In Ruby 4.0, it raises TypeError.
Suggested Fix:
Wrap try_constant calls in a rescue:
oci_major_version = checking_for 'OCI_MAJOR_VERSION in oci.h', fmt do
begin; try_constant('OCI_MAJOR_VERSION', 'oci.h'); rescue TypeError; nil; end
end
if oci_major_version
oci_minor_version = checking_for 'OCI_MINOR_VERSION in oci.h', fmt do
begin; try_constant('OCI_MINOR_VERSION', 'oci.h'); rescue TypeError; nil; end
end
ruby
This allows the existing fallback detection logic (have_func('OCILobGetLength2')) to work as intended.
Current Workaround
Patch mkmf.rb before bundle install:
sed -i 's/return Integer(f.gets)/return Integer(f.gets) rescue nil/' /usr/local/lib/ruby/4.0.0/mkmf.rb
Environment
Problem
bundle installfails when compiling ruby-oci8 on Ruby 4.0.Ruby 4.0 changed
mkmf.rb'stry_constantmethod —Integer(f.gets)at line 833 now raisesTypeErrorwhenf.getsreturnsnil, instead of returningnilgracefully as in Ruby 3.x.Error:
/usr/local/lib/ruby/4.0.0/mkmf.rb:833:in 'Kernel#Integer': can't convert nil into Integer (TypeError)
from /usr/local/lib/ruby/4.0.0/mkmf.rb:833:in 'block in MakeMakefile#try_constant'
'from extconf.rb:34:in 'block in
Root Cause
In
ext/oci8/extconf.rbline 33-34: