[swift-dev] importer questions
Dmitri Gribenko
gribozavr at gmail.com
Tue Feb 16 03:20:52 CST 2016
On Tue, Feb 16, 2016 at 1:04 AM, Drew Crawford <drew at sealedabstract.com> wrote:
> Sorry, I wasn't sure how detailed to be.
>
> BTW, I have not determined how to print the interface for e.g. Glibc, if you know how to do that, it might help gather more items.
>
> 1. SOCK_STREAM is a __socket_type struct on Glibc, with an inner member rawValue : UInt32. On Darwin it is Int32 without any wrapper struct.
> a. However APIs where one would use this value (such as socket() ) take Int32 in both cases, this requires applications to do a member access + cast on Linux that is not necessary or allowed on Darwin
That's because __socket_type is an enum. This issue can be easily
fixed with an addition to the Glibc overlay that defines these
constants and shadows imported ones.
> 2. IPPROTO_TCP is Int on Glibc, while Int32 on Darwin
> a. APIs (e.g. socket() ) expect Int32 for this argument in practice
Again, I think overlay would fix this.
> 3. timeval is a royal pain.
> a. Darwin defines both timeval and timeval64, but at runtime, Darwin generally expects timeval64 on 64-bit platforms and timeval on 32-bit platforms
> b. Linux seems only to define timeval, although I have not tried 32-bit Linux so I cannot speak to that case
typealias timeval = timeval64 in the Darwin overlay?
> 4. timeval's members are (e.g. to construct one, you need to use)
> a. Int64 if using timeval64/Darwin64,
> b. __darwin_time_t and __darwin_suseconds_t if using 32-bit Darwin,
> c. and Int if on Linux
The overlay should add a sane initializer, timeval(tv_sec: tv_usec:),
on both platforms.
> 5. SHUT_RDWR is Int on Linux and Int32 on Darwin,
> a. whereas function parameters (such as shutdown() ) expect Int32 in both cases
Another overlay fix.
> 6. The issues with POLLIN etc. I have documented in some detail on SR-178
I think this would be another overlay fix.
By the way, I think everywhere where you mention Int32, you actually
meant 'CInt'.
Another approach that was considered, and sounds promising, is to
import more of C's constants as untyped integers, so that they would
infer the type from context. Unfortunately, this feature requires
design and compiler work.
Overlay fixes, I think, don't require special skills to prepare.
Here's an example: https://github.com/apple/swift/pull/1096/files
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the swift-dev
mailing list