<span id="mailbox-conversation"><div>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);">Hi Joe,</p>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);">I was just commenting on your @_cdecl commit on GitHub but I’ll keep the discussion here.</p>
<p class="p2" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; min-height: 17px; color: rgb(73, 79, 80);"><br></p>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);">I was wondering what it is about your implementation that makes it rely on ObjC interop, as you noted. And whether this dependency can be removed for a quick and dirty proof of concept, or whether it’s something more fundamental than that?</p>
<p class="p2" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; min-height: 17px; color: rgb(73, 79, 80);"><br></p>
<p class="p2" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; min-height: 17px; color: rgb(73, 79, 80);"><br></p>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);">In this (admittedly very simple) example, the author just calls the mangled name from C and appears to get away with it:</p>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);"><a href="http://romain.goyet.com/articles/running_swift_code_on_android/">http://romain.goyet.com/articles/running_swift_code_on_android/</a></p>
<p class="p2" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; min-height: 17px; color: rgb(73, 79, 80);"><br></p>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);">Makes me wonder whether the @_silgen_name approach wouldn’t suffice after all for a proof of concept?</p>
<p class="p2" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; min-height: 17px; color: rgb(73, 79, 80);"><br></p>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);">Best regards,</p>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);" id="mb-reply">Geordie</p>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);" id="mb-reply"><br></p>
<p class="p1" style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: '.AppleSystemUIFont'; color: rgb(73, 79, 80);" id="mb-reply">(Joe: apologies for the double up, I’m evidently terrible at mailing lists and hit reply instead of reply all!)</p>
</div></span><br><br><div class="gmail_quote"><p>On Fri, Dec 11, 2015 at 5:53 PM, Joe Groff <span dir="ltr"><<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>></span> wrote:<br></p><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>> On Dec 11, 2015, at 7:13 AM, Douglas Gregor via swift-dev <swift-dev@swift.org> wrote:
<br>>
<br>>
<br>>> On Dec 11, 2015, at 4:33 AM, Geordie Jay via swift-dev <swift-dev@swift.org> wrote:
<br>>>
<br>>> Hi, maybe one of the Apple devs can help out with this quick Q:
<br>>>
<br>>> To interface with the JNI, we’d presumably need to call swift functions from our compiled swift binaries from C (or directly from Java, the result being the same). Is there a way to demangle certain symbols in the output binary to this effect, or is there another / a better way to access Swift functions from C?
<br>>
<br>> Others can probably give a more detailed response, but...
<br>>
<br>> There’s a Swift demangler in Swift’s “Basic” library (lib/Basic/Demangle.cpp), along with a standalone tool (swift-demangle) you can experiment with. The information in the mangled name should be complete enough to call, but you’ll need to match Swift’s calling convention.
<br>>
<br>> If it’s just a specific set of Swift functions you want to call from C, you can use the @_silgen_name attribute to override the mangled name, and/or make them @convention(c) to use the C calling convention.
<br><br>@_silgen_name isn't the right answer here, since the convention will be wrong, and it won't interact properly with Clang imports and exports. Like Slava said, you want something like the '@_cdecl' attribute he proposed and I half-implemented.
<br><br>-Joe</blockquote></div><br>