[MacRuby] #1160: Need ability to access errno from Ruby code
MacRuby
ruby-noreply at macosforge.org
Thu Feb 10 15:40:55 PST 2011
#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/>
More information about the macruby-tickets
mailing list