Thank you!

2016-05-24 23:27 GMT+03:00 Phil Clayton <[email protected]>:

> Hi Kostirya,
>
> On 24/05/2016 09:07, Kostirya wrote:
>
>> Hello.
>>
>> I have some questions about Foreign.
>>
>> 1. How to convert OS.IO.iodesc (from socket) into cUint (uintptr_t)?
>>
>
> The Basis Library docs explain about converting iodesc values and
> portability issues:
> http://sml-family.org/Basis/os-io.html#SIG:OS_IO.iodesc:TY
>
> With Poly/ML, if you want to pass an iodesc value to/from a C function you
> probably want to create your own conversion by building on cUint. See
> (untested) code below that creates cIoDescConv.  Note that valOf may raise
> an exception.
>
>
> 2. C function is need 'const struct timespec *timeout' argument.
>> Where struct timespec is:
>>
>> struct timespec {
>>      time_t  tv_sec;
>>      long     tv_nsec;
>> };
>>
>> Do I understand correctly that this is
>> cOptionPtr (cStruct2 (cInt32, cLong))
>> ?
>>
>> But how can I call this from polyml?
>> I call as SAME (3, 0) and got error: Exception- Foreign "cOptionPtr must
>> be applied to a pointer type" raised
>>
>
> You need to use cStar or cConstStar for the dereferencing.  It looks like
> you want
>   cConstStar (cStruct2 (cInt32, cLong))
> Whether you use cOptionPtr around that depends on whether you want to be
> able to pass a null/non-null pointer for an optional value.
>
> Phil
>
>
> fun convMap (fromC, toC) conv =
>   let
>     open Foreign
>     val {ctype, load, store} = breakConversion conv
>   in
>      makeConversion {
>       ctype = ctype,
>       load  = fromC o load,
>       store = fn (p, x) => store (p, toC x)
>     }
>   end
>
> val cFileDescConv =
>   convMap
>     (
>       Posix.FileSys.wordToFD o SysWord.fromInt,
>       SysWord.toInt o Posix.FileSys.fdToWord
>     )
>     Foreign.cUint
>
> val cIoDescConv =
>   convMap
>     (Posix.FileSys.fdToIOD, valOf o Posix.FileSys.iodToFD)
>     cFileDescConv
>
> _______________________________________________
> polyml mailing list
> [email protected]
> http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
>
_______________________________________________
polyml mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml

Reply via email to