[swift-dev] importer questions

Drew Crawford drew at sealedabstract.com
Tue Feb 16 03:04:01 CST 2016


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
2.  IPPROTO_TCP is Int on Glibc, while Int32 on Darwin
    a.  APIs (e.g. socket() ) expect Int32 for this argument in practice
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
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
5.  SHUT_RDWR is Int on Linux and Int32 on Darwin, 
    a. whereas function parameters (such as shutdown() ) expect Int32 in both cases
6.  The issues with POLLIN etc. I have documented in some detail on SR-178

Please let me know if I can provide more information.


> On Feb 16, 2016, at 2:42 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> 
> On Tue, Feb 16, 2016 at 12:36 AM, Drew Crawford <drew at sealedabstract.com> wrote:
>> 
>> On Feb 16, 2016, at 2:06 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
>> 
>> Could you give some examples?
>> 
>> 
>> Here are some that I #ifdefed on Linux just today:
> 
> Thank you for the list!
> 
> Unfortunately, it is not clear what is wrong about the import of these
> APIs.  Could you elaborate?
> 
> Dmitri
> 
>> 
>> SOCK_STREAM
>> IPPROTO_TCP
>> timeval.  This is a tricky case, as there are actually 2 types on Darwin
>> (timeval / timeval64), that map to 1 (as far as I know) on Linux.
>> timeval[64] members, which are in some platforms Int64, in some platforms
>> __darwin_xx and in other platforms Int
>> SHUT_RDWR
>> POLLIN etc. is wrong IMO even on Darwin.  I opened SR-178 for this (and
>> previously I filed a radar), but since that bug has sat for 2 months (and
>> the radar for longer) without any comment it motivated me to investigate the
>> DIY approach to these simple "importer bugs", as perhaps the core team is
>> too busy.
>> 
>> 
>> Obviously I don't expect 100% portability (these are different OSes
>> afterall), but there are several cases where the type differences feel more
>> by accident than by design.
>> 
>> I will probably have a new list in a few days if interested, as I am still
>> battling Linux-specific compile errors :-)
>> 
>> 
>> 
>> 
> 
> 
> 
> -- 
> 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