commit 846f5d83619572e570304b88c57a8e69decfd495
parent 4480647703939e89d1cd98ff7eeb5c6eec3a7948
Author: Dan Callaghan <djc@djc.id.au>
Date: Sat, 21 Nov 2026 17:17:47 +1100
call setlocale() through ncurses bindings instead of fiddle
The approach of calling setlocale() via fiddle was problematic for a few
reasons. It hardcoded 6 for LC_ALL but this is only true on glibc, on
other platforms 6 is a different constant. And on many platforms Sup
would choose the wrong libc name or not know which name to use, see for
example PR #595.
It turns out ncurses worked fine anyway because Ruby since 1.9 already
calls setlocale(LC_CTYPE, "") at startup, which is enough for ncurses to
enable wide character support. So LocaleFiddler was not really needed on
Ruby 1.9 and above. However the call to setlocale() is still important
for gpgme message localisation. And it is expected that the main program
should call setlocale() for any libraries which use locale-aware
functions (like ncurses and gpgme do) so it's still the "proper" thing
to do.
The ncursesw gem already binds setlocale() so just call that instead of
using fiddle.
Diffstat:
24 files changed, 1 insertion(+), 149 deletions(-)
diff --git a/Manifest.txt b/Manifest.txt
@@ -131,7 +131,6 @@ lib/sup/undo.rb
lib/sup/update.rb
lib/sup/util.rb
lib/sup/util/axe.rb
-lib/sup/util/locale_fiddler.rb
lib/sup/util/ncurses.rb
lib/sup/util/path.rb
lib/sup/util/query.rb
@@ -191,7 +190,6 @@ test/unit/test_edit_message_mode.rb
test/unit/test_horizontal_selector.rb
test/unit/test_index.rb
test/unit/test_line_cursor_mode.rb
-test/unit/test_locale_fiddler.rb
test/unit/test_maildir.rb
test/unit/test_person.rb
test/unit/test_rmail_message.rb
diff --git a/bin/sup b/bin/sup
@@ -6,7 +6,6 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'ncursesw'
require 'sup/util/ncurses'
-require 'sup/util/locale_fiddler'
require 'sup/util/axe'
no_gpgme = false
@@ -106,17 +105,7 @@ end
require 'rbconfig'
-unless RbConfig::CONFIG['arch'] =~ /openbsd/
- debug "dynamically loading setlocale()"
- begin
- class LibC; extend LocaleFiddler; end
- debug "setting locale..."
- LibC.setlocale(6, "")
- rescue RuntimeError => e
- warn "cannot dlload setlocale(); ncurses wide character support probably broken."
- warn "dlload error was #{e.class}: #{e.message}"
- end
-end
+Ncurses.setlocale Ncurses::LC_ALL, ""
def start_cursing
Ncurses.initscr
diff --git a/contrib/nix/Gemfile b/contrib/nix/Gemfile
@@ -13,7 +13,6 @@ gem "unicode", "~> 0.4.4"
gem "unicode-display_width"
gem "string-scrub" if /^2\.0\./ =~ RUBY_VERSION
gem "benchmark"
-gem "fiddle"
gem "bundler", ">= 1.3", "< 3"
gem "rake"
diff --git a/contrib/nix/Gemfile.lock b/contrib/nix/Gemfile.lock
@@ -86,7 +86,6 @@ DEPENDENCIES
benchmark
bundler (>= 1.3, < 3)
chronic
- fiddle
gpgme (>= 2.0.2)
highline
locale (~> 2.0)
diff --git a/contrib/nix/ruby2.4-Gemfile.lock b/contrib/nix/ruby2.4-Gemfile.lock
@@ -5,7 +5,6 @@ GEM
benchmark (0.4.0)
chronic (0.10.2)
coderay (1.1.3)
- fiddle (1.0.9)
gpgme (2.0.20)
mini_portile2 (~> 2.3)
highline (2.0.3)
@@ -63,7 +62,6 @@ DEPENDENCIES
benchmark
bundler (>= 1.3, < 3)
chronic
- fiddle
gpgme (>= 2.0.2)
highline
locale (~> 2.0)
diff --git a/contrib/nix/ruby2.4-gemset.nix b/contrib/nix/ruby2.4-gemset.nix
@@ -39,16 +39,6 @@
};
version = "1.1.3";
};
- fiddle = {
- groups = ["default"];
- platforms = [];
- source = {
- remotes = ["https://rubygems.org"];
- sha256 = "1d2y2qh6xml4w6p15kaz1v2ryb8p3nm6yy5x5mfygdrxgpsc63rd";
- type = "gem";
- };
- version = "1.0.9";
- };
gpgme = {
dependencies = ["mini_portile2"];
groups = ["default"];
diff --git a/contrib/nix/ruby2.4-shell.nix b/contrib/nix/ruby2.4-shell.nix
@@ -11,9 +11,6 @@ let
lockfile = ./ruby2.4-Gemfile.lock;
gemset = ./ruby2.4-gemset.nix;
gemConfig = pkgs.defaultGemConfig // {
- fiddle = attrs: {
- buildInputs = [ pkgs.libffi ];
- };
# Workaround: remove rake from nativeBuildInputs, otherwise it causes
# xapian-bindings to build against the default Ruby version
# instead of our chosen version.
diff --git a/contrib/nix/ruby2.5-Gemfile.lock b/contrib/nix/ruby2.5-Gemfile.lock
@@ -5,7 +5,6 @@ GEM
benchmark (0.4.0)
chronic (0.10.2)
coderay (1.1.3)
- fiddle (1.0.9)
gpgme (2.0.20)
mini_portile2 (~> 2.3)
highline (2.0.3)
@@ -63,7 +62,6 @@ DEPENDENCIES
benchmark
bundler (>= 1.3, < 3)
chronic
- fiddle
gpgme (>= 2.0.2)
highline
locale (~> 2.0)
diff --git a/contrib/nix/ruby2.5-gemset.nix b/contrib/nix/ruby2.5-gemset.nix
@@ -39,16 +39,6 @@
};
version = "1.1.3";
};
- fiddle = {
- groups = ["default"];
- platforms = [];
- source = {
- remotes = ["https://rubygems.org"];
- sha256 = "1d2y2qh6xml4w6p15kaz1v2ryb8p3nm6yy5x5mfygdrxgpsc63rd";
- type = "gem";
- };
- version = "1.0.9";
- };
gpgme = {
dependencies = ["mini_portile2"];
groups = ["default"];
diff --git a/contrib/nix/ruby2.5-shell.nix b/contrib/nix/ruby2.5-shell.nix
@@ -11,9 +11,6 @@ let
lockfile = ./ruby2.5-Gemfile.lock;
gemset = ./ruby2.5-gemset.nix;
gemConfig = pkgs.defaultGemConfig // {
- fiddle = attrs: {
- buildInputs = [ pkgs.libffi ];
- };
# Workaround: remove rake from nativeBuildInputs, otherwise it causes
# xapian-bindings to build against the default Ruby version
# instead of our chosen version.
diff --git a/contrib/nix/ruby2.6-Gemfile.lock b/contrib/nix/ruby2.6-Gemfile.lock
@@ -5,7 +5,6 @@ GEM
benchmark (0.4.0)
chronic (0.10.2)
coderay (1.1.3)
- fiddle (1.0.9)
gpgme (2.0.23)
mini_portile2 (~> 2.7)
highline (2.0.3)
@@ -65,7 +64,6 @@ DEPENDENCIES
benchmark
bundler (>= 1.3, < 3)
chronic
- fiddle
gpgme (>= 2.0.2)
highline
locale (~> 2.0)
diff --git a/contrib/nix/ruby2.6-gemset.nix b/contrib/nix/ruby2.6-gemset.nix
@@ -39,16 +39,6 @@
};
version = "1.1.3";
};
- fiddle = {
- groups = ["default"];
- platforms = [];
- source = {
- remotes = ["https://rubygems.org"];
- sha256 = "1d2y2qh6xml4w6p15kaz1v2ryb8p3nm6yy5x5mfygdrxgpsc63rd";
- type = "gem";
- };
- version = "1.0.9";
- };
gpgme = {
dependencies = ["mini_portile2"];
groups = ["default"];
diff --git a/contrib/nix/ruby2.6-shell.nix b/contrib/nix/ruby2.6-shell.nix
@@ -11,9 +11,6 @@ let
lockfile = ./ruby2.6-Gemfile.lock;
gemset = ./ruby2.6-gemset.nix;
gemConfig = pkgs.defaultGemConfig // {
- fiddle = attrs: {
- buildInputs = [ pkgs.libffi ];
- };
# Workaround: remove rake from nativeBuildInputs, otherwise it causes
# xapian-bindings to build against the default Ruby version
# instead of our chosen version.
diff --git a/contrib/nix/ruby2.7-Gemfile.lock b/contrib/nix/ruby2.7-Gemfile.lock
@@ -5,7 +5,6 @@ GEM
benchmark (0.4.0)
chronic (0.10.2)
coderay (1.1.3)
- fiddle (1.0.9)
gpgme (2.0.24)
mini_portile2 (~> 2.7)
highline (3.0.1)
@@ -69,7 +68,6 @@ DEPENDENCIES
benchmark
bundler (>= 1.3, < 3)
chronic
- fiddle
gpgme (>= 2.0.2)
highline
locale (~> 2.0)
diff --git a/contrib/nix/ruby2.7-gemset.nix b/contrib/nix/ruby2.7-gemset.nix
@@ -39,16 +39,6 @@
};
version = "1.1.3";
};
- fiddle = {
- groups = ["default"];
- platforms = [];
- source = {
- remotes = ["https://rubygems.org"];
- sha256 = "1d2y2qh6xml4w6p15kaz1v2ryb8p3nm6yy5x5mfygdrxgpsc63rd";
- type = "gem";
- };
- version = "1.0.9";
- };
gpgme = {
dependencies = ["mini_portile2"];
groups = ["default"];
diff --git a/contrib/nix/ruby3.0-Gemfile.lock b/contrib/nix/ruby3.0-Gemfile.lock
@@ -5,7 +5,6 @@ GEM
benchmark (0.4.0)
chronic (0.10.2)
coderay (1.1.3)
- fiddle (1.1.6)
gpgme (2.0.24)
mini_portile2 (~> 2.7)
highline (3.0.1)
@@ -69,7 +68,6 @@ DEPENDENCIES
benchmark
bundler (>= 1.3, < 3)
chronic
- fiddle
gpgme (>= 2.0.2)
highline
locale (~> 2.0)
diff --git a/contrib/nix/ruby3.0-gemset.nix b/contrib/nix/ruby3.0-gemset.nix
@@ -39,16 +39,6 @@
};
version = "1.1.3";
};
- fiddle = {
- groups = ["default"];
- platforms = [];
- source = {
- remotes = ["https://rubygems.org"];
- sha256 = "1as92bp6pgkab73kj3mh5d1idjr9wykczz7r9i1pkn82wq4xks3r";
- type = "gem";
- };
- version = "1.1.6";
- };
gpgme = {
dependencies = ["mini_portile2"];
groups = ["default"];
diff --git a/contrib/nix/ruby3.1-Gemfile.lock b/contrib/nix/ruby3.1-Gemfile.lock
@@ -5,7 +5,6 @@ GEM
benchmark (0.4.0)
chronic (0.10.2)
coderay (1.1.3)
- fiddle (1.1.6)
gpgme (2.0.24)
mini_portile2 (~> 2.7)
highline (3.1.2)
@@ -79,7 +78,6 @@ DEPENDENCIES
benchmark
bundler (>= 1.3, < 3)
chronic
- fiddle
gpgme (>= 2.0.2)
highline
locale (~> 2.0)
diff --git a/contrib/nix/ruby3.1-gemset.nix b/contrib/nix/ruby3.1-gemset.nix
@@ -39,16 +39,6 @@
};
version = "1.1.3";
};
- fiddle = {
- groups = ["default"];
- platforms = [];
- source = {
- remotes = ["https://rubygems.org"];
- sha256 = "1as92bp6pgkab73kj3mh5d1idjr9wykczz7r9i1pkn82wq4xks3r";
- type = "gem";
- };
- version = "1.1.6";
- };
gpgme = {
dependencies = ["mini_portile2"];
groups = ["default"];
diff --git a/contrib/nix/ruby3.2-Gemfile.lock b/contrib/nix/ruby3.2-Gemfile.lock
@@ -5,7 +5,6 @@ GEM
benchmark (0.4.0)
chronic (0.10.2)
coderay (1.1.3)
- fiddle (1.1.6)
gpgme (2.0.24)
mini_portile2 (~> 2.7)
highline (3.1.2)
@@ -79,7 +78,6 @@ DEPENDENCIES
benchmark
bundler (>= 1.3, < 3)
chronic
- fiddle
gpgme (>= 2.0.2)
highline
locale (~> 2.0)
diff --git a/contrib/nix/ruby3.2-gemset.nix b/contrib/nix/ruby3.2-gemset.nix
@@ -39,16 +39,6 @@
};
version = "1.1.3";
};
- fiddle = {
- groups = ["default"];
- platforms = [];
- source = {
- remotes = ["https://rubygems.org"];
- sha256 = "1as92bp6pgkab73kj3mh5d1idjr9wykczz7r9i1pkn82wq4xks3r";
- type = "gem";
- };
- version = "1.1.6";
- };
gpgme = {
dependencies = ["mini_portile2"];
groups = ["default"];
diff --git a/lib/sup/util/locale_fiddler.rb b/lib/sup/util/locale_fiddler.rb
@@ -1,24 +0,0 @@
-## the following magic enables wide characters when used with a ruby
-## ncurses.so that's been compiled against libncursesw. (note the w.) why
-## this works, i have no idea. much like pretty much every aspect of
-## dealing with curses. cargo cult programming at its best.
-require 'fiddle'
-require 'fiddle/import'
-
-module LocaleFiddler
- extend Fiddle::Importer
-
- SETLOCALE_LIB = case RbConfig::CONFIG['arch']
- when /darwin/; "libc.dylib"
- when /cygwin/; "cygwin1.dll"
- when /freebsd/; "libc.so.7"
- else; "libc.so.6"
- end
-
- dlload SETLOCALE_LIB
- extern "char *setlocale(int, char const *)"
-
- def setlocale(type, string)
- LocaleFiddler.setlocale(type, string)
- end
-end
diff --git a/sup.gemspec b/sup.gemspec
@@ -62,7 +62,6 @@ SUP: please note that our old mailing lists have been shut down,
s.add_runtime_dependency "unicode-display_width"
s.add_runtime_dependency "string-scrub" if /^2\.0\./ =~ RUBY_VERSION
s.add_runtime_dependency "benchmark"
- s.add_runtime_dependency "fiddle"
s.add_development_dependency "bundler", ">= 1.3", "< 3"
s.add_development_dependency "rake"
diff --git a/test/unit/test_locale_fiddler.rb b/test/unit/test_locale_fiddler.rb
@@ -1,15 +0,0 @@
-require 'test_helper'
-require 'sup/util/locale_fiddler'
-
-class TestFiddle < Minitest::Test
- # TODO this is a silly test
- def test_fiddle_set_locale
- before = LocaleDummy.setlocale(6, nil).to_s
- after = LocaleDummy.setlocale(6, "").to_s
- assert(before != after, "Expected locale to be fiddled with")
- end
-end
-
-class LocaleDummy
- extend LocaleFiddler
-end