Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.5.1
    • Fix Version/s: JRuby 1.6RC1
    • Component/s: None
    • Labels:
      None
    • Environment:
      OS: OSX 10.5.8
      Jruby Version: 1.5.1
      FFI gem version: 0.6.3
    • Number of attachments :
      1

      Description

      Attempting to require 'pty' fails, with a "LoadError: no library specified" when using jruby 1.5.1 ('ffi' gem 0.6.3).

      irb(main):001:0> require "rubygems"
      => true
      irb(main):002:0> require "ffi"
      => true
      irb(main):003:0> require "pty"
      LoadError: no library specified
      	from /jruby/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/library.rb:46:in `ffi_libraries'
      	from /jruby/jruby-1.5.1/lib/ruby/site_ruby/shared/ffi/library.rb:96:in `attach_function'
      	from /jruby/jruby-1.5.1/lib/ruby/site_ruby/shared/pty.rb:11
      	from /jruby/jruby-1.5.1/lib/ruby/site_ruby/shared/pty.rb:31:in `require'
      	from /jruby/jruby-1.5.1/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
      	from (irb):3
      

        Activity

        Hide
        Hiro Asari added a comment -

        Edited for readability.

        Also, you don't need rubygems to see this problem. (Note that JRuby's 'pty' requires the internal 'ffi'.)

        $ jruby -vrpty -e 'p 0'
        jruby 1.6.0.dev (ruby 1.8.7 patchlevel 249) (2010-07-21 81de866) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_20) [amd64-java]
        /home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/ffi/library.rb:46:in `ffi_libraries': no library specified (LoadError)
        	from /home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/ffi/library.rb:96:in `attach_function'
        	from /home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:15
        	from /home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:1
        	...internal jruby stack elided...
        	from FFI::Library.ffi_libraries(/home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/ffi/library.rb:96)
        	from FFI::Library.attach_function(/home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:15)
        	from (unknown).(unknown)(/home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:1)
        	from (unknown).(unknown)(/home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:1)
        	from (unknown).(unknown)(/home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:1)
        	from (unknown).(unknown)(:1)
        

        It appears that, when extending FFI::Library, it is expected that there is a call to ffi_lib listing the libraries you'd want to load. In pty's case, it is 'libc', so on my MacBook Pro, the following makes the code go:

        diff --git a/lib/ruby/site_ruby/shared/pty.rb b/lib/ruby/site_ruby/shared/pty.rb
        index 04d7bdc..d3a0cb6 100644
        --- a/lib/ruby/site_ruby/shared/pty.rb
        +++ b/lib/ruby/site_ruby/shared/pty.rb
        @@ -4,6 +4,7 @@ module PTY
           private
           module LibUtil
             extend FFI::Library
        +    ffi_lib 'libc'
             # forkpty(3) is in libutil on linux, libc on MacOS/BSD
             if FFI::Platform.linux?
               ffi_lib 'libutil'
        @@ -12,6 +13,7 @@ module PTY
           end
           module LibC
             extend FFI::Library
        +    ffi_lib 'libc'
             attach_function :close, [ :int ], :int
             attach_function :strerror, [ :int ], :string
             attach_function :execv, [ :string, :buffer_in ], :int
        

        Not sure if this is the best solution, however. In fact, on Ubuntu, it appears that libc.so FFI would load is a linker script, so this won't do.

        Wayne might have a better idea.

        Show
        Hiro Asari added a comment - Edited for readability. Also, you don't need rubygems to see this problem. (Note that JRuby's 'pty' requires the internal 'ffi'.) $ jruby -vrpty -e 'p 0' jruby 1.6.0.dev (ruby 1.8.7 patchlevel 249) (2010-07-21 81de866) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_20) [amd64-java] /home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/ffi/library.rb:46:in `ffi_libraries': no library specified (LoadError) from /home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/ffi/library.rb:96:in `attach_function' from /home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:15 from /home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:1 ...internal jruby stack elided... from FFI::Library.ffi_libraries(/home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/ffi/library.rb:96) from FFI::Library.attach_function(/home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:15) from (unknown).(unknown)(/home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:1) from (unknown).(unknown)(/home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:1) from (unknown).(unknown)(/home/asari/Development/src/jruby/lib/ruby/site_ruby/shared/pty.rb:1) from (unknown).(unknown)(:1) It appears that, when extending FFI::Library, it is expected that there is a call to ffi_lib listing the libraries you'd want to load. In pty's case, it is 'libc', so on my MacBook Pro, the following makes the code go: diff --git a/lib/ruby/site_ruby/shared/pty.rb b/lib/ruby/site_ruby/shared/pty.rb index 04d7bdc..d3a0cb6 100644 --- a/lib/ruby/site_ruby/shared/pty.rb +++ b/lib/ruby/site_ruby/shared/pty.rb @@ -4,6 +4,7 @@ module PTY private module LibUtil extend FFI::Library + ffi_lib 'libc' # forkpty(3) is in libutil on linux, libc on MacOS/BSD if FFI::Platform.linux? ffi_lib 'libutil' @@ -12,6 +13,7 @@ module PTY end module LibC extend FFI::Library + ffi_lib 'libc' attach_function :close, [ :int ], :int attach_function :strerror, [ :int ], :string attach_function :execv, [ :string, :buffer_in ], :int Not sure if this is the best solution, however. In fact, on Ubuntu, it appears that libc.so FFI would load is a linker script, so this won't do. Wayne might have a better idea.
        Hide
        Wayne Meissner added a comment -

        ffi_lib FFI::Library::LIBC is the best way of doing it (that will resolve to the proper libc on the platform).

        Not directly related, but pty.rb should also be updated to use posix_spawn() instead of fork() or forkpty(), due to the flakiness of fork() when called from ruby code. Hiro, you might want to raise a ticket for that and convert it if you're feeling bored.

        Show
        Wayne Meissner added a comment - ffi_lib FFI::Library::LIBC is the best way of doing it (that will resolve to the proper libc on the platform). Not directly related, but pty.rb should also be updated to use posix_spawn() instead of fork() or forkpty(), due to the flakiness of fork() when called from ruby code. Hiro, you might want to raise a ticket for that and convert it if you're feeling bored.
        Hide
        Hiro Asari added a comment -

        Thanks, Wayne. Fixed in ad0afa7.

        Show
        Hiro Asari added a comment - Thanks, Wayne. Fixed in ad0afa7.
        Hide
        Michael Kohl added a comment - - edited

        This is the first time I'm looking at the JRuby source, so please take this with a grain of salt, but I think the MemoryPointer class in lib/ruby/site_ruby/shared/pty.rb needs to be properly namespace qualified, otherwise it tries to resolve it as PTY::MemoryPointer which it obviously can't find:

        @@ -24,10 +26,10 @@
          def self.build_args(args)
            cmd = args.shift
            cmd_args = args.map do |arg|

        •      MemoryPointer.from_string(arg)
          +      FFI::MemoryPointer.from_string(arg)
              end
        •    exec_args = MemoryPointer.new(:pointer, 1 + cmd_args.length + 1)
        •    exec_cmd = MemoryPointer.from_string(cmd)
          +    exec_args = FFI::MemoryPointer.new(:pointer, 1 + cmd_args.length + 1)
          +    exec_cmd = FFI::MemoryPointer.from_string(cmd)

        Sorry I can't look into this more myself right now, but I'll basically be offline for the next couple of days. Also excuse me for posting this here, but I'm in a rush and this bug is where I started my investigating and thus started playing with the current jruby-head...

        Show
        Michael Kohl added a comment - - edited This is the first time I'm looking at the JRuby source, so please take this with a grain of salt, but I think the MemoryPointer class in lib/ruby/site_ruby/shared/pty.rb needs to be properly namespace qualified, otherwise it tries to resolve it as PTY::MemoryPointer which it obviously can't find: @@ -24,10 +26,10 @@   def self.build_args(args)     cmd = args.shift     cmd_args = args.map do |arg|      MemoryPointer.from_string(arg) +      FFI::MemoryPointer.from_string(arg)     end    exec_args = MemoryPointer.new(:pointer, 1 + cmd_args.length + 1)    exec_cmd = MemoryPointer.from_string(cmd) +    exec_args = FFI::MemoryPointer.new(:pointer, 1 + cmd_args.length + 1) +    exec_cmd = FFI::MemoryPointer.from_string(cmd) Sorry I can't look into this more myself right now, but I'll basically be offline for the next couple of days. Also excuse me for posting this here, but I'm in a rush and this bug is where I started my investigating and thus started playing with the current jruby-head...
        Hide
        Hiro Asari added a comment -

        Hi, Michael,

        Thanks for the comment. Strictly speaking, your comment looks like a separate issue; that 'pty' library does not work (rather than that require 'pty' fails).

        Regardless…

        Your patch seems reasonable. Could you attach it as a git patch, so that we can give you credit?

        Thanks.

        Show
        Hiro Asari added a comment - Hi, Michael, Thanks for the comment. Strictly speaking, your comment looks like a separate issue; that 'pty' library does not work (rather than that require 'pty' fails). Regardless… Your patch seems reasonable. Could you attach it as a git patch, so that we can give you credit? Thanks.
        Hide
        Michael Kohl added a comment -

        Hiro, I know it was a separate issue, but I had problems with the current stable JRuby, investigated, found this issue, checked out head, found and fixed the other problem and then basically had to run to the airport, so I just wanted to let you guys know quickly so I wouldn't forget about it. Attaching a properly formatted patch now

        Show
        Michael Kohl added a comment - Hiro, I know it was a separate issue, but I had problems with the current stable JRuby, investigated, found this issue, checked out head, found and fixed the other problem and then basically had to run to the airport, so I just wanted to let you guys know quickly so I wouldn't forget about it. Attaching a properly formatted patch now
        Hide
        Michael Kohl added a comment -

        Finally a nicely formatted patch.

        Show
        Michael Kohl added a comment - Finally a nicely formatted patch.
        Hide
        Hiro Asari added a comment -

        Michael,

        I pushed your patch to master in 2d64da7. Thanks!

        Show
        Hiro Asari added a comment - Michael, I pushed your patch to master in 2d64da7 . Thanks!
        Hide
        zipizap added a comment - - edited

        This is my first bug, and I'm not very experienced with Java (I'm more on the ruby side) - this said, I'm using jruby to perform console-process automation and so 'pty' is really important for my work.

        The 'pty' library still does not work in jruby-complete-1.6.0.RC1.jar nor in jruby-complete-1.6.0.RC2.jar.
        This error was verified in Windows Vista and Sun Solaris (same in both OSs), using the jruby-complete-X.jar versions of Jruby.

        UPDATE: As indicated by Charles Oliver Nutter in the next comments, this error does not exist in the normal Jruby .tar.gz or .zip versions, it seems to only affect the .jar version

        If anyone can be so kind, please tell me what could I do to help debug and solve this issue

        Bellow the errors of require 'pty' in jruby-1.6.0.RC1 and jruby-1.6.0.RC2

        error in jruby-complete-1.6.0.RC1.jar

        C:\Ruby191\myProgs\r2d2>java -jar jruby-complete-1.6.0.RC1.jar -vrpty -e 'p 0'
        jruby 1.6.0.RC1 (ruby 1.8.7 patchlevel 330) (2011-01-10 769f847) (Java HotSpot(TM) Client VM 1.6.0_22) [Windows Vista-x86-java]
        org.jruby.exceptions.RaiseException: (NotFoundError) Function 'PTY::LibUtil' not found in [forkpty]
                at #<Class:0x1006798eb>.attach_function(file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/ffi/library.rb:100)
                at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1671)
                at FFI::Library(#<Class:0x1006798eb>).attach_function(file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/ffi/library.rb:96)
                at Module.(class LibUtil)(file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:12)
                at Module.(class PTY)(file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:5)
                at #<Class:0x10076db09>.(root)(file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:3)
        

        error in jruby-complete-1.6.0.RC2.jar

        C:\Ruby191\myProgs\r2d2>java -jar jruby-complete-1.6.0.RC2.jar -vrpty -e 'p 0'
        jruby 1.6.0.RC2 (ruby 1.8.7 patchlevel 330) (2011-02-09 5434c72) (Java HotSpot(TM) Client VM 1.6.0_22) [Windows Vista-x86-java]
        file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/ffi/library.rb:100:in `attach_function': Function 'PTY::LibUtil' not found in [forkpty] (FFI::NotFoundError)
                from org/jruby/RubyArray.java:1676:in `each'
                from file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/ffi/library.rb:96:in `attach_function'
                from file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:12:in `(class LibUtil)'
                from file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:5:in `(class PTY)'
                from file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:3:in `(root)'
        

        Should this same bug be re-opened or should it be better to open a new one about "Function 'PTY::LibUtil' not found in [forkpty] (FFI::NotFoundError)" ?

        Greetings

        Show
        zipizap added a comment - - edited This is my first bug, and I'm not very experienced with Java (I'm more on the ruby side) - this said, I'm using jruby to perform console-process automation and so 'pty' is really important for my work. The 'pty' library still does not work in jruby-complete-1.6.0.RC1.jar nor in jruby-complete-1.6.0.RC2.jar. This error was verified in Windows Vista and Sun Solaris (same in both OSs), using the jruby-complete-X.jar versions of Jruby. UPDATE: As indicated by Charles Oliver Nutter in the next comments, this error does not exist in the normal Jruby .tar.gz or .zip versions, it seems to only affect the .jar version If anyone can be so kind, please tell me what could I do to help debug and solve this issue Bellow the errors of require 'pty' in jruby-1.6.0.RC1 and jruby-1.6.0.RC2 error in jruby-complete-1.6.0.RC1.jar C:\Ruby191\myProgs\r2d2>java -jar jruby-complete-1.6.0.RC1.jar -vrpty -e 'p 0' jruby 1.6.0.RC1 (ruby 1.8.7 patchlevel 330) (2011-01-10 769f847) (Java HotSpot(TM) Client VM 1.6.0_22) [Windows Vista-x86-java] org.jruby.exceptions.RaiseException: (NotFoundError) Function 'PTY::LibUtil' not found in [forkpty] at #<Class:0x1006798eb>.attach_function(file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/ffi/library.rb:100) at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1671) at FFI::Library(#<Class:0x1006798eb>).attach_function(file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/ffi/library.rb:96) at Module.(class LibUtil)(file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:12) at Module.(class PTY)(file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:5) at #<Class:0x10076db09>.(root)(file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:3) error in jruby-complete-1.6.0.RC2.jar C:\Ruby191\myProgs\r2d2>java -jar jruby-complete-1.6.0.RC2.jar -vrpty -e 'p 0' jruby 1.6.0.RC2 (ruby 1.8.7 patchlevel 330) (2011-02-09 5434c72) (Java HotSpot(TM) Client VM 1.6.0_22) [Windows Vista-x86-java] file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/ffi/library.rb:100:in `attach_function': Function 'PTY::LibUtil' not found in [forkpty] (FFI::NotFoundError) from org/jruby/RubyArray.java:1676:in `each' from file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/ffi/library.rb:96:in `attach_function' from file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:12:in `(class LibUtil)' from file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:5:in `(class PTY)' from file:/C:/Ruby191/myProgs/r2d2/jruby-complete-1.6.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby/shared/pty.rb:3:in `(root)' Should this same bug be re-opened or should it be better to open a new one about "Function 'PTY::LibUtil' not found in [forkpty] (FFI::NotFoundError)" ? Greetings
        Hide
        Charles Oliver Nutter added a comment -

        zipzap: Can you open your issue as a new bug? The original issue here was fixed, but we'd happily look into your issues.

        I'd also recommend trying it without the "complete" jar. In otherwords, from a normal JRuby install. The "pty" library we have is loaded using native libraries, which may not be working properly from the complete jar as-is.

        Looking forward to your bug report.

        Show
        Charles Oliver Nutter added a comment - zipzap: Can you open your issue as a new bug? The original issue here was fixed, but we'd happily look into your issues. I'd also recommend trying it without the "complete" jar. In otherwords, from a normal JRuby install. The "pty" library we have is loaded using native libraries, which may not be working properly from the complete jar as-is. Looking forward to your bug report.
        Hide
        zipizap added a comment - - edited

        Charles, I've verified with the full Jruby install (.tar.gz or .zip binaries) and in those versions the 'pty' library works fine

        So it seems the problem is limited only to the jruby-complete-X.X.jar version

        I have opened a new bug report - see bug JRUBY-5584

        Hope anyone crossing the same problem sees this

        Thanks for your reply Charles

        Show
        zipizap added a comment - - edited Charles, I've verified with the full Jruby install (.tar.gz or .zip binaries) and in those versions the 'pty' library works fine So it seems the problem is limited only to the jruby-complete-X.X.jar version I have opened a new bug report - see bug JRUBY-5584 Hope anyone crossing the same problem sees this Thanks for your reply Charles

          People

          • Assignee:
            Hiro Asari
            Reporter:
            Jeff
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: