From: Charles Oliver Nutter Date: 2009-08-02T17:32:27+09:00 Subject: Re: JRuby, ffi, bad file descriptor Hmm, did you post this to JRuby dev list or ruby-ffi list yet? Could be something simple... You might also try getting a raw Java backtrace by passing this flag to JRuby: -J-Djruby.backtrace.style=raw That will show us if it's happening in JRuby's IO code or in FFI somewhere. - Charlie On Fri, Jul 31, 2009 at 9:54 PM, Daniel Berger wrote: > Hi, > > JRuby 1.3.1 > OS X 10.4.9 > > The following code is a port of a tempfile library I wrote. Ruby 1.8.6 and > 1.9.x work alright, but with JRuby I'm getting a bad file descriptor error. > > Any ideas? Here's the code: > > require 'ffi' > > class FileTemp < File >   extend FFI::Library > >   attach_function 'fileno',  [:pointer], :int >   attach_function 'fclose',  [:pointer], :int >   attach_function 'mkstemp', [:string],  :int >   attach_function 'tmpfile', [],         :pointer >   attach_function 'tmpnam',  [:string],  :string >   attach_function 'umask',   [:int],     :int > >   TMPDIR = ENV['TEMP'] || ENV['TMP'] || '/tmp' > >   def initialize(delete = true, template = 'rb_file_temp_XXXXXX') >      @fptr = nil > >      if delete >         @fptr = tmpfile() >         fd = fileno(@fptr) >      else >         begin >            omask = umask(077) >            fd = mkstemp(template) >            raise SystemCallError, 'mkstemp()' if fd < 0 >         ensure >            umask(omask) >         end >      end > >      super(fd, 'wb+') >   end > >   def close >      super >      fclose(@fptr) if @fptr >   end > >   def self.temp_name >      TMPDIR + tmpnam(nil) << '.tmp' >   end > end > > if $0 == __FILE__ >   fh = FileTemp.new >   fh.print 'hello' >   fh.close > end > > Result: > > temp.rb:42:in `initialize': Bad file descriptor - Bad file descriptor > (Errno::EBADF) >        from temp.rb:56:in `new' >        from temp.rb:56 > > Regards, > > Dan > >