Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined method read_uint64 in JRuby. #77

Closed
Adithya-copart opened this issue Aug 6, 2019 · 15 comments
Closed

Undefined method read_uint64 in JRuby. #77

Adithya-copart opened this issue Aug 6, 2019 · 15 comments
Assignees

Comments

@Adithya-copart
Copy link

I noticed this error in my Macbook while trying to run ProcTable.ps(:pid => Process.pid).cmdline.split(' ').

jruby-head :001 > RUBY_VERSION
 => "2.5.3" 
jruby-head :002 > require 'sys/proctable'
 => true 
jruby-head :003 > include Sys
 => Object 
jruby-head :004 > ProcTable.ps(:pid => Process.pid).cmdline.split(' ')
Traceback (most recent call last):
       10: from /Users/adpentela/.rvm/rubies/jruby-head/bin/irb:13:in `<main>'
        9: from org/jruby/RubyKernel.java:1193:in `catch'
        8: from org/jruby/RubyKernel.java:1193:in `catch'
        7: from org/jruby/RubyKernel.java:1425:in `loop'
        6: from org/jruby/RubyKernel.java:1061:in `eval'
        5: from (irb):4:in `evaluate'
        4: from /Users/adpentela/.rvm/gems/jruby-head/gems/sys-proctable-1.2.1/lib/darwin/sys/proctable.rb:199:in `ps'
        3: from /Users/adpentela/.rvm/gems/jruby-head/gems/sys-proctable-1.2.1/lib/darwin/sys/proctable.rb:286:in `get_thread_info'
        2: from org/jruby/RubyInteger.java:209:in `upto'
        1: from /Users/adpentela/.rvm/gems/jruby-head/gems/sys-proctable-1.2.1/lib/darwin/sys/proctable.rb:288:in `block in get_thread_info'
NoMethodError (undefined method `read_uint64' for #<FFI::Pointer address=0x7f81cee78510 size=208>)
Did you mean?  read_uint
               read_int
               get_uint64
jruby-head :005 > 

I tried to see if I can get this working by using the alternatives suggested in the error message but it still results in an error.

Here are my environment specifics:

$ uname -a
Darwin MB-ADPENTELA.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64

$ ruby -v
jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server VM 25.191-b12 on 1.8.0_191-b12 +jit [darwin-x86_64]

$ java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
@djberg96
Copy link
Owner

djberg96 commented Aug 6, 2019

Hm, worked ok with 9.2.4.0 on my Linux laptop. I'll have to wait until this evening to test it against my Mac.

@djberg96 djberg96 self-assigned this Aug 6, 2019
@Adithya-copart
Copy link
Author

Adithya-copart commented Aug 6, 2019

@djberg96 It fails on my Macbook when I try irb using JRuby.
I tried replacing read_uint64 with get_uint64 and FFI::StructLayout::CharArray with FFI::StructLayout::CHAR_ARRAY.

I gave up after it failed with both those changes. It works fine with MRI Ruby and also within a JRuby docker container running on my mac.

@djberg96
Copy link
Owner

djberg96 commented Aug 6, 2019

@Adithya-copart Try read_ulong_long and see how that goes.

@Adithya-copart
Copy link
Author

With read_ulong_ulong

jruby-9.2.7.0 :003 > ProcTable.ps(:pid => Process.pid).cmdline.split(' ')
Traceback (most recent call last):
       13: from /Users/adpentela/.rvm/rubies/jruby-9.2.7.0/bin/irb:13:in `<main>'
       12: from org/jruby/RubyKernel.java:1193:in `catch'
       11: from org/jruby/RubyKernel.java:1193:in `catch'
       10: from org/jruby/RubyKernel.java:1425:in `loop'
        9: from org/jruby/RubyKernel.java:1061:in `eval'
        8: from (irb):3:in `evaluate'
        7: from /Users/adpentela/.rvm/gems/jruby-9.2.7.0/gems/sys-proctable-1.2.1/lib/darwin/sys/proctable.rb:200:in `ps'
        6: from /Users/adpentela/.rvm/gems/jruby-9.2.7.0/gems/sys-proctable-1.2.1/lib/darwin/sys/proctable.rb:258:in `apply_info_to_struct'
        5: from org/jruby/RubyArray.java:1792:in `each'
        4: from /Users/adpentela/.rvm/gems/jruby-9.2.7.0/gems/sys-proctable-1.2.1/lib/darwin/sys/proctable.rb:259:in `block in apply_info_to_struct'
        3: from org/jruby/RubyArray.java:1792:in `each'
        2: from /Users/adpentela/.rvm/gems/jruby-9.2.7.0/gems/sys-proctable-1.2.1/lib/darwin/sys/proctable.rb:260:in `block in apply_info_to_struct'
        1: from org/jruby/RubyModule.java:3742:in `const_missing'
NameError (uninitialized constant FFI::StructLayout::CharArray)
Did you mean?  FFI::StructLayout::CHAR_ARRAY

Used FFI::StructLayout::CHAR_ARRAY here:

jruby-9.2.7.0 :003 > ProcTable.ps(:pid => Process.pid).cmdline.split(' ')
Traceback (most recent call last):
       13: from /Users/adpentela/.rvm/rubies/jruby-9.2.7.0/bin/irb:13:in `<main>'
       12: from org/jruby/RubyKernel.java:1193:in `catch'
       11: from org/jruby/RubyKernel.java:1193:in `catch'
       10: from org/jruby/RubyKernel.java:1425:in `loop'
        9: from org/jruby/RubyKernel.java:1061:in `eval'
        8: from (irb):3:in `evaluate'
        7: from /Users/adpentela/.rvm/gems/jruby-9.2.7.0/gems/sys-proctable-1.2.1/lib/darwin/sys/proctable.rb:200:in `ps'
        6: from /Users/adpentela/.rvm/gems/jruby-9.2.7.0/gems/sys-proctable-1.2.1/lib/darwin/sys/proctable.rb:258:in `apply_info_to_struct'
        5: from org/jruby/RubyArray.java:1792:in `each'
        4: from /Users/adpentela/.rvm/gems/jruby-9.2.7.0/gems/sys-proctable-1.2.1/lib/darwin/sys/proctable.rb:259:in `block in apply_info_to_struct'
        3: from org/jruby/RubyArray.java:1792:in `each'
        2: from /Users/adpentela/.rvm/gems/jruby-9.2.7.0/gems/sys-proctable-1.2.1/lib/darwin/sys/proctable.rb:260:in `block in apply_info_to_struct'
        1: from org/jruby/RubyKernel.java:2096:in `kind_of?'
TypeError (class or module required)
jruby-9.2.7.0 :004 > 

@djberg96
Copy link
Owner

djberg96 commented Aug 6, 2019

@Adithya-copart What version of ffi are you using?

@Adithya-copart
Copy link
Author

Thanks for looking into this @djberg96 .

I got the same error using ffi '1.11.1' and '1.9.6' from github by adding this to my Gemfile:

  gem 'ffi', git: "git://github.com/ffi/ffi.git", tag: 'v1.9.6'
$ bundle show ffi
/Users/adpentela/.rvm/gems/jruby-9.2.7.0/gems/ffi-1.11.1-java

$ bundle update ffi
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/.
.....
Using ffi 1.11.1 (java)
....
Bundler attempted to update ffi but its version stayed the same
Bundle updated!

@djberg96
Copy link
Owner

djberg96 commented Aug 8, 2019

@Adithya-copart I think we can get around the lack of read_uint64 with read_array_of_uint64(1).first.

I'm not sure what's going on with the char array thing yet.

@djberg96
Copy link
Owner

djberg96 commented Aug 8, 2019

@Adithya-copart Looks like this will workaround will work for the CharArray issue:

unless defined? FFI::StructLayout::CharArray
    FFI::StructLayout::CharArray = FFI::StructLayout::CharArrayProxy
end

@Adithya-copart
Copy link
Author

@djberg96 Thanks, can confirm that this works on JRuby.

@djberg96
Copy link
Owner

Fixed by #78 and part of the 1.2.2 release. Thanks for the report!

@Adithya-copart
Copy link
Author

The conditional introduced due to the lack of read_uint64 in #78 can be removed if ffi/ffi#717 is resolved.

@djberg96
Copy link
Owner

@Adithya-copart Thanks, please remind me if/when that issue is addressed.

@headius
Copy link

headius commented Jan 9, 2020

This will be fixed for jruby/jruby#5947 by jruby/jruby#5948. Thanks for working around it! Hopefully with the FFIs synched up we won't see these sorts of incompatibilities.

@adi-pen
Copy link

adi-pen commented Sep 23, 2021

@Adithya-copart Thanks, please remind me if/when that issue is addressed.

@djberg96 https://www.jruby.org/2021/09/22/jruby-9-3-0-0.html is out and it includes the above fix @headius mentioned.

@djberg96
Copy link
Owner

@adi-pen Thanks. I'll probably wait a while to remove the previous changes since I imagine people will be running older versions of JRuby for a time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants