<html><body><p><tt>jgroff@apple.com wrote on 2016-03-22 12:05:06 PM:<br><br></tt><tt>></tt><tt> On Mar 22, 2016, at 5:57 AM, Bryan Chan via swift-dev <swift-dev@swift.org</tt><br><tt>></tt><tt> wrote:</tt><br><tt>></tt><br><tt>></tt><tt> > I tried to google for an answer but couldn't find anything. What is</tt><br><tt>></tt><tt> > the correct way to do the following on Linux?</tt><br><tt>></tt><tt> ></tt><br><tt>></tt><tt> > @_silgen_name("foo")</tt><br><tt>></tt><tt> > func foo(theInt: UInt)</tt><br><tt>></tt><tt> > -> (a: UInt, b: UInt, c: UInt)</tt><br><tt>></tt><tt> ></tt><br><tt>></tt><tt> > var (d, e, f) = foo(aNum)</tt><br><tt>></tt><tt> ></tt><br><tt>[snip]</tt><br><tt>></tt><tt> ></tt><br><tt>></tt><tt> > Currently, the call to foo crashes because foo wants to return the</tt><br><tt>></tt><tt> > tuple indirectly, but the Swift call expects the three scalar return</tt><br><tt>></tt><tt> > values in registers. This example is a generalization of runtime</tt><br><tt>></tt><tt> > functions such as swift_class_getInstanceExtents, which happens to</tt><br><tt>></tt><tt> > work because it only returns two scalars in RAX and RDX, which is</tt><br><tt>></tt><tt> > supported by Clang. But my tests show that three-scalar tuples/</tt><br><tt>></tt><tt> > structs will cause problems. On architectures where Clang only</tt><br><tt>></tt><tt> > supports one scalar return value, the problem is worse.</tt><br><tt>></tt><tt> ></tt><br><tt>></tt><tt> > Am I doing something wrong or is there already a way to deal with</tt><br><tt>></tt><tt> > this (e.g. annotation in Swift code to make it obey C ABI, or vice versa)?</tt><br><tt>></tt><br><tt>></tt><tt> Don't use @_silgen_name. If you want to use a C API from Swift,</tt><br><tt>></tt><tt> define a Clang module for its headers, and import the module. See</tt><br><tt>></tt><tt> </tt><a href="http://clang.llvm.org/docs/Modules.html"><tt>http://clang.llvm.org/docs/Modules.html</tt></a><tt> for documentation on Clang</tt><br><tt>></tt><tt> module maps.</tt><br><br><tt>Is this the solution for runtime functions like</tt><br><tt>swift_class_getInstanceExtents as well?</tt><BR>
</body></html>