X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fdocs%2Fusers_guide%2Fffi-chap.xml;h=e1374c461054f54a2d2b9f085d8ae92cda03101c;hb=ba41623270c1d541e74bd5182e1b4fcbe99809cc;hp=789a6a1a50b04f6eb8a50c30052a4aba5085644e;hpb=b9de29ac3fbf5192049a0bcaf1ab0c8bbbd57a83;p=ghc-hetmet.git diff --git a/ghc/docs/users_guide/ffi-chap.xml b/ghc/docs/users_guide/ffi-chap.xml index 789a6a1..e1374c4 100644 --- a/ghc/docs/users_guide/ffi-chap.xml +++ b/ghc/docs/users_guide/ffi-chap.xml @@ -2,13 +2,20 @@ -Foreign function interface (FFI) + +Foreign function interface (FFI) + GHC (mostly) conforms to the Haskell 98 Foreign Function Interface - Addendum 1.0, whose definition is available from http://haskell.org/. - The FFI support in GHC diverges from the Addendum in the following ways: - + Addendum 1.0, whose definition is available from http://haskell.org/. + + To enable FFI support in GHC, give the + flag, or +the + flag which implies +. + + The FFI support in GHC diverges from the Addendum in the following ways: @@ -18,8 +25,7 @@ GHC implements a number of GHC-specific extensions to the FFI - Addendum. These extensions are described in , but please note that programs using + Addendum. These extensions are described in , but please note that programs using these features are not portable. Hence, these features should be avoided where possible. @@ -101,6 +107,11 @@ extern HsInt foo(HsInt a0); invoke foo() from C, just #include "Foo_stub.h" and call foo(). + The foo_stub.c and + foo_stub.h files can be redirected using the + option; see . + Using your own <literal>main()</literal> @@ -108,7 +119,7 @@ extern HsInt foo(HsInt a0); main(), which arranges to invoke Main.main in the Haskell program. However, you might want to link some Haskell code into a program which - has a main function written in another languagem, say C. In + has a main function written in another language, say C. In order to do this, you have to initialize the Haskell runtime system explicitly. @@ -280,7 +291,7 @@ declaration itself: When compiling this module, GHC will generate a C file that includes the specified . However, GHC -disables cross-module inlinding for such foreign +disables cross-module inlining for such foreign calls, because it doesn't transport the information across module boundaries. (There is no fundamental reason for this; it was just tiresome to implement. The wrapper, which unboxes the arguments @@ -327,7 +338,7 @@ to be inlined across modules, use the command-line and package-configuration Useful for short-term allocation when the allocation is intended to scope over a given IO - compuatation. This kind of allocation is commonly used + computation. This kind of allocation is commonly used when marshalling data to and from FFI functions. In GHC, alloca is implemented @@ -366,7 +377,7 @@ to be inlined across modules, use the command-line and package-configuration If all else fails, then you need to resort to Foreign.malloc and Foreign.free. These are just wrappers - around the C funcitons of the same name, and their + around the C functions of the same name, and their efficiency will depend ultimately on the implementations of these functions in your platform's C library. We usually find malloc and @@ -376,14 +387,14 @@ to be inlined across modules, use the command-line and package-configuration - Foreign.Marhsal.Pool + Foreign.Marshal.Pool Pools are currently implemented using malloc/free, so while they might be a more convenient way to structure your memory allocation than using one of the other forms of allocation, they won't be any more efficient. We do plan to provide an - improved-performance implementaiton of Pools in the + improved-performance implementation of Pools in the future, however.