Commit notifications for all Sup repositories
 help / color / mirror / Atom feed
From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [sup.git] 05/08: call setlocale() through ncurses bindings instead of fiddle
Date: Sat, 28 Nov 2026 17:13:40 +1100	[thread overview]
Message-ID: <20261128061335.A6ABB2D45D1@bl2.djc.id.au> (raw)
In-Reply-To: <179584641514.302139.17817016268117078700@bl2.djc.id.au>

New commit on branch develop:
https://supmua.dev/git/sup/commit/846f5d83619572e570304b88c57a8e69decfd495.html

commit 846f5d83619572e570304b88c57a8e69decfd495
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Nov 21 17:17:47 2026 +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.
---
 Manifest.txt                     |  2 --
 bin/sup                          | 13 +------------
 contrib/nix/Gemfile              |  1 -
 contrib/nix/Gemfile.lock         |  1 -
 contrib/nix/ruby2.4-Gemfile.lock |  2 --
 contrib/nix/ruby2.4-gemset.nix   | 10 ----------
 contrib/nix/ruby2.4-shell.nix    |  3 ---
 contrib/nix/ruby2.5-Gemfile.lock |  2 --
 contrib/nix/ruby2.5-gemset.nix   | 10 ----------
 contrib/nix/ruby2.5-shell.nix    |  3 ---
 contrib/nix/ruby2.6-Gemfile.lock |  2 --
 contrib/nix/ruby2.6-gemset.nix   | 10 ----------
 contrib/nix/ruby2.6-shell.nix    |  3 ---
 contrib/nix/ruby2.7-Gemfile.lock |  2 --
 contrib/nix/ruby2.7-gemset.nix   | 10 ----------
 contrib/nix/ruby3.0-Gemfile.lock |  2 --
 contrib/nix/ruby3.0-gemset.nix   | 10 ----------
 contrib/nix/ruby3.1-Gemfile.lock |  2 --
 contrib/nix/ruby3.1-gemset.nix   | 10 ----------
 contrib/nix/ruby3.2-Gemfile.lock |  2 --
 contrib/nix/ruby3.2-gemset.nix   | 10 ----------
 lib/sup/util/locale_fiddler.rb   | 24 ------------------------
 sup.gemspec                      |  1 -
 test/unit/test_locale_fiddler.rb | 15 ---------------
 24 files changed, 1 insertion(+), 149 deletions(-)

diff --git a/Manifest.txt b/Manifest.txt
index a523f1c5..03b5678e 100644
--- 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
index b8c0ef22..3ba9b356 100755
--- 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
index 00810768..6afd5a2f 100644
--- 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
index 107d22e0..10ad08a0 100644
--- 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
index 81bef91a..99130e4e 100644
--- 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
index f596ed0d..0e550914 100644
--- 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
index 26a479f4..3663b55a 100644
--- 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
index cb527e6f..974b47d2 100644
--- 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
index 184f3ed6..277912a3 100644
--- 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
index e98f1bd7..d80847b0 100644
--- 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
index cecf0d16..c98c8f9d 100644
--- 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
index 3dd13cfa..a6adc858 100644
--- 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
index c7423f6f..f656d3bc 100644
--- 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
index 1825f05b..f8e98b8b 100644
--- 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
index fa2012a9..3f72cb2f 100644
--- 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
index 711dd3bd..f8e98b8b 100644
--- 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
index 9c4e48ce..3f72cb2f 100644
--- 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
index bcac3866..7a0bea61 100644
--- 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
index a004cd61..abb19bc7 100644
--- 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
index bcac3866..7a0bea61 100644
--- 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
index a004cd61..abb19bc7 100644
--- 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
deleted file mode 100644
index 38d0e1ab..00000000
--- a/lib/sup/util/locale_fiddler.rb
+++ /dev/null
@@ -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
index 875b304e..c3d8b3d0 100644
--- 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
deleted file mode 100644
index 33ec634e..00000000
--- a/test/unit/test_locale_fiddler.rb
+++ /dev/null
@@ -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

  parent reply	other threads:[~2026-11-28  6:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  6:13 [sup.git] branch develop updated (ce27c933 -> 53f07beb) Dan Callaghan
2026-11-28  6:13 ` [sup.git] 01/08: delete dead report_broken_sources method Dan Callaghan
2026-11-28  6:13 ` [sup.git] 02/08: sup-sync-back-maildir: remove broken negative short options Dan Callaghan
2026-11-28  6:13 ` [sup.git] 03/08: show both raw and encoded sizes of attachments Dan Callaghan
2026-11-28  6:13 ` [sup.git] 04/08: shell escape bounce destination addresses Dan Callaghan
2026-11-28  6:13 ` Dan Callaghan [this message]
2026-11-28  6:13 ` [sup.git] 06/08: use libmagic to detect attachment MIME types Dan Callaghan
2026-11-28  6:13 ` [sup.git] 07/08: clean up directory traversal in Maildir#poll Dan Callaghan
2026-11-28  6:13 ` [sup.git] 08/08: bring back sup-recover-sources from the dead Dan Callaghan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128061335.A6ABB2D45D1@bl2.djc.id.au \
    --to=dan@bl2.djc.id.au \
    --cc=djc@djc.id.au \
    --cc=sup-commits@supmua.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox