X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=docs%2Fusers_guide%2Fffi-chap.xml;h=97a237876ff69a4d0f865f7faea4b0dedfccc4ff;hb=a52ff7619e8b7d74a9d933d922eeea49f580bca8;hp=aea2f5eb137c9c7580bdab1b29bcd65f5acb177b;hpb=46809fa91667e952afe016e4cd704b21274241b4;p=ghc-hetmet.git
diff --git a/docs/users_guide/ffi-chap.xml b/docs/users_guide/ffi-chap.xml
index aea2f5e..97a2378 100644
--- a/docs/users_guide/ffi-chap.xml
+++ b/docs/users_guide/ffi-chap.xml
@@ -245,18 +245,11 @@ extern HsInt foo(HsInt a0);
#include "foo_stub.h"
#endif
-#ifdef __GLASGOW_HASKELL__
-extern void __stginit_Foo ( void );
-#endif
-
int main(int argc, char *argv[])
{
int i;
hs_init(&argc, &argv);
-#ifdef __GLASGOW_HASKELL__
- hs_add_root(__stginit_Foo);
-#endif
for (i = 0; i < 5; i++) {
printf("%d\n", foo(2500));
@@ -283,26 +276,6 @@ int main(int argc, char *argv[])
(i.e. those arguments between
+RTS...-RTS).
- Next, we call
- hs_add_rooths_add_root
- , a GHC-specific interface which is required to
- initialise the Haskell modules in the program. The argument
- to hs_add_root should be the name of the
- initialization function for the "root" module in your program
- - in other words, the module which directly or indirectly
- imports all the other Haskell modules in the program. In a
- standalone Haskell program the root module is normally
- Main, but when you are using Haskell code
- from a library it may not be. If your program has multiple
- root modules, then you can call
- hs_add_root multiple times, one for each
- root. The name of the initialization function for module
- M is
- __stginit_M, and
- it may be declared as an external function symbol as in the
- code above. Note that the symbol name should be transformed
- according to the Z-encoding:
-
@@ -380,9 +353,6 @@ int main(int argc, char *argv[])
// Initialize Haskell runtime
hs_init(&argc, &argv);
- // Tell Haskell about all root modules
- hs_add_root(__stginit_Foo);
-
// do any other initialization here and
// return false if there was a problem
return HS_BOOL_TRUE;
@@ -394,7 +364,7 @@ int main(int argc, char *argv[])
The initialisation routine, mylib_init, calls
- hs_init() and hs_add_root() as
+ hs_init() as
normal to initialise the Haskell runtime, and the corresponding
deinitialisation function mylib_end() calls
hs_exit() to shut down the runtime.
@@ -599,8 +569,7 @@ int main(int argc, char *argv[])
invoke foreign exported functions from
multiple OS threads concurrently. The runtime system must
be initialised as usual by
- calling hs_init()
- and hs_add_root, and these calls must
+ calling hs_init(), and this call must
complete before invoking any foreign
exported functions.
@@ -646,7 +615,65 @@ int main(int argc, char *argv[])
shutdownHaskellAndExit() instead).
-
+
+
+ Floating point and the FFI
+
+
+ The standard C99 fenv.h header
+ provides operations for inspecting and modifying the state of
+ the floating point unit. In particular, the rounding mode
+ used by floating point operations can be changed, and the
+ exception flags can be tested.
+
+
+
+ In Haskell, floating-point operations have pure types, and the
+ evaluation order is unspecified. So strictly speaking, since
+ the fenv.h functions let you change the
+ results of, or observe the effects of floating point
+ operations, use of fenv.h renders the
+ behaviour of floating-point operations anywhere in the program
+ undefined.
+
+
+
+ Having said that, we can document exactly
+ what GHC does with respect to the floating point state, so
+ that if you really need to use fenv.h then
+ you can do so with full knowledge of the pitfalls:
+
+
+
+ GHC completely ignores the floating-point
+ environment, the runtime neither modifies nor reads it.
+
+
+
+
+ The floating-point environment is not saved over a
+ normal thread context-switch. So if you modify the
+ floating-point state in one thread, those changes may be
+ visible in other threads. Furthermore, testing the
+ exception state is not reliable, because a context
+ switch may change it. If you need to modify or test the
+ floating point state and use threads, then you must use
+ bound threads
+ (Control.Concurrent.forkOS), because
+ a bound thread has its own OS thread, and OS threads do
+ save and restore the floating-point state.
+
+
+
+
+ It is safe to modify the floating-point unit state
+ temporarily during a foreign call, because foreign calls
+ are never pre-empted by GHC.
+
+
+
+
+