JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6808

org.jruby.ext.ffi.Platform does not determineCPU or determineOS properly on Turkish

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.7, JRuby 1.7.0.pre1
    • Fix Version/s: JRuby 1.7.0.pre2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Turkish Windows 2008
    • Number of attachments :
      0

      Description

      I had problems loading the ffi library in jruby on Turkish Windows, and was directed to checkout org/jruyb/ext/ffi/Platform.java, and it is indeed here that the problem is coming from. It is using the turkish "i" (without a dot) in place of the regular "i" (with a dot) in "i386", and thus cannot find the right library to load.

      Output of determineOS() and determineCPU()
      OS : unknown
      CPU: ı386

      I suspect the problem is depending on the value of toLowerCase() here:

      public enum OS_TYPE {
      DARWIN,
      FREEBSD,
      NETBSD,
      OPENBSD,
      LINUX,
      SOLARIS,
      AIX,
      WINDOWS,

      UNKNOWN;
      @Override
      public String toString()

      { return name().toLowerCase(); }

      }

        Activity

        Hide
        Matt Hauck added a comment -

        Note the following output of toLowerCase from irb on this system:

        irb(main):005:0> java.lang.String.new("I").toLowerCase
        => "\304\261"

        Show
        Matt Hauck added a comment - Note the following output of toLowerCase from irb on this system: irb(main):005:0> java.lang.String.new("I").toLowerCase => "\304\261"
        Hide
        Matt Hauck added a comment -

        Okay, looks like this code does it:

        irb(main):009:0> java.lang.String.new("I").toLowerCase(Locale::ENGLISH)
        => "i"

        (cf. http://lotusnotus.com/lotusnotus_en.nsf/dx/dotless-i-tolowercase-and-touppercase-functions-use-responsibly.htm)

        Show
        Matt Hauck added a comment - Okay, looks like this code does it: irb(main):009:0> java.lang.String.new("I").toLowerCase(Locale::ENGLISH) => "i" (cf. http://lotusnotus.com/lotusnotus_en.nsf/dx/dotless-i-tolowercase-and-touppercase-functions-use-responsibly.htm )
        Hide
        Matt Hauck added a comment - - edited

        The following monkey-patch almost works...

        class Platform
        class CPU_TYPE
        def toString
        java.lang.String.new(name).toLowerCase(java.util.Locale::ENGLISH)
        end
        end
        class OS_TYPE
        def toString
        java.lang.String.new(name).toLowerCase(java.util.Locale::ENGLISH)
        end
        end
        end

        except that the determineOS and determineCPU functions themselves call toLowerCase() in a way that would be difficult to patch on the fly...

        Show
        Matt Hauck added a comment - - edited The following monkey-patch almost works... class Platform class CPU_TYPE def toString java.lang.String.new(name).toLowerCase(java.util.Locale::ENGLISH) end end class OS_TYPE def toString java.lang.String.new(name).toLowerCase(java.util.Locale::ENGLISH) end end end except that the determineOS and determineCPU functions themselves call toLowerCase() in a way that would be difficult to patch on the fly...
        Hide
        Matt Hauck added a comment - - edited

        Okay, I've gotten this far, which works, but when i require 'ffi' after this patch, it appears to clobber my patch. =( Is there any workaround for this?

        require 'java'
        java_import 'java.lang.System'
        java_import 'java.util.Locale'

        FixFFIPlatform = Java::OrgJrubyExtFfi::Platform

        class FixFFIPlatform
        class CPU_TYPE
        def toString
        java.lang.String.new(name).toLowerCase(java.util.Locale::ENGLISH)
        end
        end
        class OS_TYPE
        def toString
        java.lang.String.new(name).toLowerCase(java.util.Locale::ENGLISH)
        end
        end

        def self.determineOS
        os_name = java.lang.String.new(System.getProperty('os.name').split(' ')[0]).toLowerCase(Locale::ENGLISH)
        if os_name =~ /^mac/ || os_name =~ /^darwin/
        return FixFFIPlatform::OS_TYPE::DARWIN
        elsif os_name =~ /^sunos/ || os_name =~ /solaris/
        return FixFFIPlatform::OS_TYPE::SOLARIS
        end
        FixFFIPlatform::OS_TYPE.values.each do |os|
        if os_name =~ /^#

        {os.toString}

        /
        return os
        end
        end

        FixFFIPlatform::OS_TYPE::UNKNOWN
        end
        end

        puts "OS : #

        {Java::OrgJrubyExtFfi::Platform.determineOS.toString}

        "
        puts "CPU: #

        {Java::OrgJrubyExtFfi::Platform.determineCPU.toString}

        "

        Show
        Matt Hauck added a comment - - edited Okay, I've gotten this far, which works, but when i require 'ffi' after this patch, it appears to clobber my patch. =( Is there any workaround for this? require 'java' java_import 'java.lang.System' java_import 'java.util.Locale' FixFFIPlatform = Java::OrgJrubyExtFfi::Platform class FixFFIPlatform class CPU_TYPE def toString java.lang.String.new(name).toLowerCase(java.util.Locale::ENGLISH) end end class OS_TYPE def toString java.lang.String.new(name).toLowerCase(java.util.Locale::ENGLISH) end end def self.determineOS os_name = java.lang.String.new(System.getProperty('os.name').split(' ') [0] ).toLowerCase(Locale::ENGLISH) if os_name =~ /^mac/ || os_name =~ /^darwin/ return FixFFIPlatform::OS_TYPE::DARWIN elsif os_name =~ /^sunos/ || os_name =~ /solaris/ return FixFFIPlatform::OS_TYPE::SOLARIS end FixFFIPlatform::OS_TYPE.values.each do |os| if os_name =~ /^# {os.toString} / return os end end FixFFIPlatform::OS_TYPE::UNKNOWN end end puts "OS : # {Java::OrgJrubyExtFfi::Platform.determineOS.toString} " puts "CPU: # {Java::OrgJrubyExtFfi::Platform.determineCPU.toString} "
        Hide
        Matt Hauck added a comment -

        It may be a good idea to generalize this bug and fix all these toLowerCase() errors throughout jruby otherwise they will just keep popping up in Turkish one by one...

        Show
        Matt Hauck added a comment - It may be a good idea to generalize this bug and fix all these toLowerCase() errors throughout jruby otherwise they will just keep popping up in Turkish one by one...
        Hide
        Wayne Meissner added a comment -

        I did a sweep of jffi, jnr-ffi and jruby ffi, and they should all be using Locale.ENGLISH to do case conversions now.

        Can you try the latest jruby-master again?

        Show
        Wayne Meissner added a comment - I did a sweep of jffi, jnr-ffi and jruby ffi, and they should all be using Locale.ENGLISH to do case conversions now. Can you try the latest jruby-master again?
        Hide
        Matt Hauck added a comment -

        Okay, that worked, I can require 'ffi' now in Turkish.

        Show
        Matt Hauck added a comment - Okay, that worked, I can require 'ffi' now in Turkish.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Matt Hauck
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: