From 31f51e0ba9a7b6fb5d7d6853ee91e56570294193 Mon Sep 17 00:00:00 2001 From: KJ Tsanaktsidis Date: Wed, 24 Jan 2024 10:23:15 +1100 Subject: [PATCH] Don't depend on Fiddle features which aren't in Ruby 3.0 The fiddle gem has changed more than I thought! We can't depend on CONST_STRING being available, nor the Fiddle::Type module. Thankfully, passing strings _in_ as VOIDP or CONST_STRING works the same, and we don't need to look at any string results, so we can just use the old/new types interchangeably. --- lib/mspec/runner/actions/leakchecker.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/mspec/runner/actions/leakchecker.rb b/lib/mspec/runner/actions/leakchecker.rb index 9cf5cef..71797b9 100644 --- a/lib/mspec/runner/actions/leakchecker.rb +++ b/lib/mspec/runner/actions/leakchecker.rb @@ -345,10 +345,13 @@ def disable_nss_modules begin libc = Fiddle.dlopen(nil) + # Older versions of fiddle don't have Fiddle::Type (and instead rely on Fiddle::TYPE_) + # Even older versions of fiddle don't have CONST_STRING, + string_type = defined?(Fiddle::TYPE_CONST_STRING) ? Fiddle::TYPE_CONST_STRING : Fiddle::TYPE_VOIDP nss_configure_lookup = Fiddle::Function.new( libc['__nss_configure_lookup'], - [Fiddle::Types::CONST_STRING, Fiddle::Types::CONST_STRING], - Fiddle::Types::INT + [string_type, string_type], + Fiddle::TYPE_INT ) rescue Fiddle::DLError # We're not running with glibc - no need to do this.