commit ee1af8368d3bb27049170cc7ebb9767b4c2ca8f2
parent 1f980b5e55a25010363d2e1ee8e1f47a1d3ba21e
Author: Gaute Hope <eg@gaute.vetsj.com>
Date: Fri, 6 Feb 2015 08:21:17 +0100
Merge #360: Replace dl/import with fiddle, drop ruby 1.9.3 support
Diffstat:
5 files changed, 51 insertions(+), 26 deletions(-)
diff --git a/.travis.yml b/.travis.yml
@@ -3,7 +3,7 @@ language: ruby
rvm:
- 2.1.1
- 2.0.0
- - 1.9.3
+ - 2.2.0
before_install:
- sudo apt-get update -qq
diff --git a/bin/sup b/bin/sup
@@ -7,6 +7,7 @@ require 'rubygems'
require 'ncursesw'
require 'sup/util/ncurses'
+require 'sup/util/locale_fiddler'
no_gpgme = false
begin
@@ -102,32 +103,17 @@ global_keymap = Keymap.new do |k|
end
end
-## 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 'rbconfig'
-unless RbConfig::CONFIG['arch'] =~ /openbsd/
- require 'dl/import'
- module LibC
- extend DL.const_defined?(:Importer) ? DL::Importer : DL::Importable
- setlocale_lib = case RbConfig::CONFIG['arch']
- when /darwin/; "libc.dylib"
- when /cygwin/; "cygwin1.dll"
- when /freebsd/; "libc.so.7"
- else; "libc.so.6"
- end
- debug "dynamically loading setlocale() from #{setlocale_lib}"
- begin
- dlload setlocale_lib
- extern "void setlocale(int, const char *)"
- debug "setting locale..."
- LibC.setlocale(6, "") # LC_ALL == 6
- rescue RuntimeError => e
- warn "cannot dlload setlocale(); ncurses wide character support probably broken."
- warn "dlload error was #{e.class}: #{e.message}"
- end
+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
diff --git a/lib/sup/mbox.rb b/lib/sup/mbox.rb
@@ -180,7 +180,7 @@ class MBox < Source
time = $1
begin
## hack -- make Time.parse fail when trying to substitute values from Time.now
- Time.parse time, 0
+ Time.parse time, Time.at(0)
true
rescue NoMethodError, ArgumentError
warn "found invalid date in potential mbox split line, not splitting: #{l.inspect}"
diff --git a/lib/sup/util/locale_fiddler.rb b/lib/sup/util/locale_fiddler.rb
@@ -0,0 +1,24 @@
+## 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/test/unit/test_locale_fiddler.rb b/test/unit/test_locale_fiddler.rb
@@ -0,0 +1,15 @@
+require 'test_helper'
+require 'sup/util/locale_fiddler'
+
+class TestFiddle < ::Minitest::Unit::TestCase
+ # 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