Changes between Version 21 and Version 22 of ForeignFunctionInterface


Ignore:
Timestamp:
Oct 21, 2009 11:47:09 AM (4 years ago)
Author:
chak@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ForeignFunctionInterface

    v21 v22  
    3131'''TODO:''' Decide whether we remove the requirement for re-initialisation. 
    3232 
    33 === Include files === 
    34  
    35 It can be tedious to add include files to a large number foreign imports, which is why GHC users often use `-#include` options instead.  I am wondering whether we should add a form  
    36 {{{ 
    37 foreign import "include FNAME" 
    38 }}} 
    39 We would still allow include files in other `foreign import` statements as before, but would gain a portable version of `-#include` options. 
    40  
    41 '''TODO:''' Decide whether we want this addition. 
    42  
    43 === `ccall` vs. `stdcall` === 
    44  
    45 Cross-platform libraries (e.g. HOpenGL) often want to import the same foreign functions using the `ccall` convention on Unix and the `stdcall` convention on Windows. The usual method is to use CPP hackery.  Would there be any harm to implement `stdcall` as `ccall` on Unix?  In other words, do we need `stdcall` on Unix at all? 
    46  
    47 '''TODO:''' Decide whether we allow implementations to implement `stdcall` as `ccall` if that is appropriate for the platform. 
    48  
    49 === Finalizers === 
    50  
    51 Finalizers can only be C functions (not Haskell functions), to avoid the problems discussed in Boehm's paper.  The original FFI addendum makes the following guarantees about finalizers: 
    52  
    53   There is no guarantee on how soon the finalizer is executed after the last reference to the associated foreign pointer was dropped; this depends on the details of the Haskell storage manager. The only guarantee is that the finalizer runs before the program terminates. Whether a finalizer may call back into the Haskell system is system dependent. Portable code may not rely on such callbacks. 
    54  
    55 There was some discussion, in the context of GHC's implementation, about these guarantees.  IIRC, the conclusion was that these guarantees are reasonable for C finalizers (but it would be hard for Haskell finalizers to guarantee that they run before the program terminates).  Is that right, or do we need to change the specification here? 
    56  
    57 '''TODO:''' Decide whether the current guarantees concerning finalizers are practical. 
    58  
    5933=== Alignment === 
    6034 
     
    8256 * `Foreign.Marshal.Error` does actually omit some routines of the FFI Addendum .  I think we need to keep them in the FFI specification. 
    8357 
     58Furthermore we add: 
     59 * Add `castCharToCUChar`, `castCUCharToChar`, `castCharToCSChar`, and `castCSCharToChar` (i.e., not only for CChar of which it is platform-dependent whether it is signed or not). 
     60 * Add types from ISO C99 (with conversion routines): 
     61{{{ 
     62WordPtr uintptr_t 
     63WordMax uintmax_t 
     64IntPtr  intptr_t 
     65IntMax  intmax_t 
     66 
     67ptrToWordPtr :: Ptr a -> WordPtr 
     68wordPtrToPtr :: WordPtr -> Ptr a 
     69 
     70ptrToIntPtr :: Ptr a -> IntPtr 
     71intPtrToPtr :: IntPtr -> Ptr a 
     72}}} 
     73 
    8474NB: 
    8575 * We do not include `Foreign.Marshal.Pool` in the standard as it doesn't appear to be widely used and doesn't have an efficient implementation at the moment. 
     
    9686 * We add one or two examples. 
    9787 
    98 === Additions to the FFI libraries === 
     88=== Concurrency === 
    9989 
    100 Additions to the library as discussed above under "Open Questions". 
    101  
    102 Furthermore we should add: 
    103  * We should also have `castCharToCUChar`, `castCUCharToChar`, `castCharToCSChar`, and `castCSCharToChar` (i.e., not only for CChar of which it is platform-dependent whether it is signed or not). 
    104  * Types from ISO C99 (with conversion routines): 
    105 {{{ 
    106 WordPtr uintptr_t 
    107 WordMax uintmax_t 
    108 IntPtr  intptr_t 
    109 IntMax  intmax_t 
    110  
    111 ptrToWordPtr :: Ptr a -> WordPtr 
    112 wordPtrToPtr :: WordPtr -> Ptr a 
    113  
    114 ptrToIntPtr :: Ptr a -> IntPtr 
    115 intPtrToPtr :: IntPtr -> Ptr a 
    116 }}} 
     90Multi-threading support is implementation-specific.