Subject:
[ruby-ffi] Re: calling internal ruby functions
From:
Wayne Meissner
Date:
4/29/11 4:39 PM
To:
ruby-ffi@googlegroups.com


Be careful when accessing internal ruby functions, it makes your gem non-portable (i.e. it won't work on other VMs like JRuby).

Unless you're hacking the internals of a specific VM, if you're calling internal functions, You Are Doing It Wrong[tm].

Why exactly do you need to call rb_thread_select()?

If you just need to wait on a bunch of file descriptors that you also obtained via FFI, just map in select(), or poll() like so:

module LibC
   ...
   @blocking = true
   attach_function :select, [ :int, :pointer, :pointer, :pointer, :pointer ], :int

   @blocking = true
   attach_function :poll, [ :pointer, int, int ], :int
end

The '@blocking = true' bit tags the following attached function as 'blocking', which means on VMs with a GIL, the GIL will be released during calls to that function.