<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Apr 26, 2016, at 1:03 PM, Sangjin Han &lt;<a href="mailto:tinysun.net@gmail.com" class="">tinysun.net@gmail.com</a>&gt; wrote:</div><div class=""><div dir="ltr" class="">The problem can be solved by modifying that code. Thanks you. I thought that code will affect only to the CLong type not Int.</div></div></blockquote><div><br class=""></div>It changes what 'long' gets imported as. &nbsp;If there's a Windows API defined using 'long' (rather than some more meaningful typedef like 'size_t'), it's important for it to be imported as Int32 rather than Int, since 'long' is always 32 bits under MSVC.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">But I meet another problem to fix it. I couldn't find the conditional method to distinct x86_64-*-windows-msvc with x86_64-*-windows-cygnus in Swift source.</div><div class=""><br class=""></div><div class="">"#if os(Windows)" can not distinct MSVC from Cygwin.</div><div class=""><br class=""></div><div class="">Should I add new condition 'env()' for the environment?</div></div></div></blockquote><div><br class=""></div>That is an excellent question.</div><div><br class=""></div><div>My understanding / memory is that, as far as their programming interfaces goes, Cygwin and MSVC are very, very different environments. &nbsp;Maybe it's useful to have a condition that's true for both environments — although I'm not sure why it would — but I don't think it deserves to be as prominent as os(Windows). &nbsp;So my gut reaction is that, rather than adding a #env, we ought to just reserve os(Windows) for MSVC compatibility and make a new os(Cygwin) for Cygwin.</div><div><br class=""></div><div>This needs to be raised on swift-evolution, though. &nbsp;CC'ing that list.</div><div><br class=""></div><div>John.</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">- Han Sangjin</div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2016-04-26 14:39 GMT+09:00 John McCall <span dir="ltr" class="">&lt;<a href="mailto:rjmccall@apple.com" target="_blank" class="">rjmccall@apple.com</a>&gt;</span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">&gt; On Apr 25, 2016, at 7:54 PM, Sangjin Han via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class="">
&gt; Hi all,<br class="">
&gt;<br class="">
&gt; I found a bug in my port for MSVC and Cygwin.<br class="">
&gt;<br class="">
&gt; The C function swift_stdlib_readLine_stdin() is mapped to 'Int' type in Swift, but it generates i32 in LLVM if I specify the target as MSVC. If I give the target as Cygwin, it generates i64.<br class="">
&gt;<br class="">
&gt; With the target options, the Cygwin ported swiftc.exe has the same output.<br class="">
&gt;<br class="">
&gt; I know that the one of the differences between MSVC and Cygwin is the size of 'long' type. But I don't know even if it is related to this problem.<br class="">
&gt;<br class="">
&gt; I don't know where to I start with.<br class="">
<br class="">
</span>The problem is probably the unconditional line<br class="">
&nbsp; public typealias CLong = Int<br class="">
in CTypes.swift.&nbsp; That is generally true for Unix platforms (LP32 / LP64) but not MSVC (LLP64).<br class="">
<br class="">
You will need to conditionalize that line.<br class="">
<br class="">
John.<br class="">
<span class=""><br class="">
&gt;<br class="">
&gt; BEGIN OF tt.swift ---<br class="">
&gt; import SwiftShims<br class="">
&gt;<br class="">
&gt;&nbsp; var linePtr: UnsafeMutablePointer&lt;CChar&gt;? = nil<br class="">
&gt;&nbsp; var readBytes = swift_stdlib_readLine_stdin(&amp;linePtr)<br class="">
&gt;&nbsp; print(readBytes)<br class="">
&gt; END OF tt.swift -----<br class="">
&gt;<br class="">
&gt; C:\temp&gt;swiftc -emit-ir tt.swift -target x86_64-pc-windows-msvc&nbsp; | findstr stdlib<br class="">
&gt;&nbsp; &nbsp;%4 = call i32 @swift_stdlib_readLine_stdin(i8** bitcast (%Sq* @_Tv2tt7linePtrGSqGSpVs4Int8__ to i8**))<br class="">
&gt; declare i32 @swift_stdlib_readLine_stdin(i8**) #0<br class="">
&gt;<br class="">
&gt; C:\temp&gt;swiftc -emit-ir tt.swift -target x86_64-unknown-windows-cygnus | findstr stdlib<br class="">
&gt;&nbsp; &nbsp;%4 = call i64 @swift_stdlib_readLine_stdin(i8** bitcast (%Sq* @_Tv2tt7linePtrGSqGSpVs4Int8__ to i8**))<br class="">
&gt; declare i64 @swift_stdlib_readLine_stdin(i8**) #0<br class="">
&gt;<br class="">
&gt;<br class="">
&gt; - Han Sangjin<br class="">
&gt;<br class="">
</span>&gt; _______________________________________________<br class="">
&gt; swift-dev mailing list<br class="">
&gt; <a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class="">
<br class="">
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>