[MacRuby] #1160: Need ability to access errno from Ruby code
#1160: Need ability to access errno from Ruby code --------------------------------------+------------------------------------- Reporter: warpflyght@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: --------------------------------------+------------------------------------- There doesn't appear to be a way to obtain the current thread's errno value without dropping into native code. The FFI library defines FFI.errno, but MacRuby's implementation of FFI is best characterized as a stub and thus hasn't implemented this functionality yet. If FFI is removed before 1.0 (see comments in #585), I'm not sure what the right place to expose errno would be. If it is not removed, implementing FFI.errno seems like the right thing to do. -- Ticket URL: <http://www.macruby.org/trac/ticket/1160> MacRuby <http://macruby.org/>
#1160: Need ability to access errno from Ruby code --------------------------------------+------------------------------------- Reporter: warpflyght@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: --------------------------------------+------------------------------------- Comment(by warpflyght@…): My use case: calling openpty(3), then handling any errors that might result. I'll just wind up raising SystemCallError to emulate other Ruby APIs, but I need the errno value first. (The Ruby PTY library doesn't meet my needs in this case, and because I'm building a command-line tool, I'm trying to avoid native code.) -- Ticket URL: <http://www.macruby.org/trac/ticket/1160#comment:1> MacRuby <http://macruby.org/>
#1160: Need ability to access errno from Ruby code --------------------------------------+------------------------------------- Reporter: warpflyght@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: --------------------------------------+------------------------------------- Comment(by lsansonetti@…): How do you call openpty(3) from MacRuby? Using the FFI layer or BridgeSupport? (That's unrelated to this ticket but I'm curious.) I agree that exposing errno is a good idea, however I'm not sure if FFI.errno is the way to go. Scheduling for 1.0. -- Ticket URL: <http://www.macruby.org/trac/ticket/1160#comment:2> MacRuby <http://macruby.org/>
#1160: Need ability to access errno from Ruby code --------------------------------------+------------------------------------- Reporter: warpflyght@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: minor | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: --------------------------------------+------------------------------------- Changes (by lsansonetti@…): * milestone: => MacRuby 1.0 -- Ticket URL: <http://www.macruby.org/trac/ticket/1160#comment:3> MacRuby <http://macruby.org/>
#1160: Need ability to access errno from Ruby code --------------------------------------+------------------------------------- Reporter: warpflyght@… | Owner: lsansonetti@… Type: enhancement | Status: closed Priority: minor | Milestone: MacRuby 0.9 Component: MacRuby | Resolution: fixed Keywords: | --------------------------------------+------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: MacRuby 1.0 => MacRuby 0.9 Comment: I see that we define the Errno module, which is then used as the outer of all errno constants. I added the Errno.code method as of r5229. -- Ticket URL: <http://www.macruby.org/trac/ticket/1160#comment:4> MacRuby <http://macruby.org/>
#1160: Need ability to access errno from Ruby code --------------------------------------+------------------------------------- Reporter: warpflyght@… | Owner: lsansonetti@… Type: enhancement | Status: closed Priority: minor | Milestone: MacRuby 0.9 Component: MacRuby | Resolution: fixed Keywords: | --------------------------------------+------------------------------------- Comment(by warpflyght@…): Using BridgeSupport. I've added custom BridgeSupport definitions in a couple of tools now. In the case of openpty(3), I don't need to set the termios or winsize structs, so the XML looks like this: {{{ <?xml version='1.0'?> <!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd"> <signatures version='0.9'> <function name='openpty'> <arg type='^i' type_modifier='o'/> <arg type='^i' type_modifier='o'/> <arg type='*' type_modifier='o'/> <arg type='^v'/> <!-- ignored --> <arg type='^v'/> <!-- ignored --> <reval type='i'/> </function> </signatures> }}} And the code to call it should look like this (untested): {{{ load_bridge_support_file "/path/to/custom_file.bridgesupport" # Allocate space for file descriptors master_fd = Pointer.new(:int) slave_fd = pointer.new(:int) # Call openpty(3) to get descriptors back result = openpty(master, slave, nil, nil, nil) raise SystemCallError.new(Errno.code) unless result == 0 # Use IO.for_fd to wrap file descriptors # From here, treat like a pipe: fork, close appropriate ends, and hook up to stdin/stdout/stderr }}} I've used this technique to call various C functions with RubyCocoa (using a custom BridgeSupport file) and Ruby/DL (chanting the appropriate incantations), but not with MacRuby. -- Ticket URL: <http://www.macruby.org/trac/ticket/1160#comment:5> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby