Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004932OCamlOCaml generalpublic2009-12-01 14:222012-08-02 09:20
Reportererwan 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionsuspended 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0004932: Floating point exception is raised in caml_startup if FE_INEXACT or FE_INVALID are set
DescriptionI've copied the example from the doc that illustrate how to call ocaml code
from a main in C.

 http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html#toc135 [^]

and then I've add a call to

   "feenableexcept(FE_INVALID);"

before the call to caml_startup(), and I get a
« Floating point exception ». The same occurs with FE_INEXACT.

The fix, from the user point of view, is quite easy : save/restore the fe flag before/after the call to caml_startup().

    fe=fegetexcept();
    fedisableexcept(FE_ALL_EXCEPT);
    caml_startup(argv);
    feenableexcept(fe);

But I would say that it would be better to do it once for all inside
caml_startup (or to fix the line that triggers the excp, but most likely it is no something dangerous).
Additional InformationI've tried with 3.09.0 and 3.10.2 ; to reproduce it, just:

    tar xvfz fe_ocaml.tgz
    cd fe_ocaml
    make

TagsNo tags attached.
Attached Filestgz file icon fe_ocaml.tgz [^] (1,027 bytes) 2009-12-01 14:22

- Relationships

-  Notes
(0005709)
erwan (reporter)
2010-11-17 10:38
edited on: 2010-11-17 10:53

At the end of asmrun/floats.c, it is written

void caml_init_ieee_floats(void)
{
#if defined(__FreeBSD__) && (__FreeBSD_version < 400017)
  fpsetmask(0);
#endif
}

And here, http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=fpsetmask [^]
it is written that fpsetmask is depreacated.

Moreorer, the problem described in this issue occured under linux.
Therefore, I would suggest to patch this file with something like

#if (defined(_GNU_SOURCE)
  fedisableexcept(FE_ALL_EXCEPT);
#else
#if defined(__FreeBSD__) && (__FreeBSD_version < 400017)
  fpsetmask(0);
#endif
#endif


But my problem is to be able to do the same under MINGW32, for which _GNU_SOURCE
(end hence fedisableexcept) is not defined...

(0005710)
erwan (reporter)
2010-11-17 11:18
edited on: 2010-11-17 11:26

In asmrun/floats.c, it is written

/* The [caml_init_ieee_float] function should initialize floating-point
   hardware
   so that it behaves as much as possible like the IEEE standard.
   In particular, return special numbers like Infinity and NaN instead
   of signalling exceptions. Currently, everyone is in IEEE mode
   at program startup, except FreeBSD prior to 4.0R. */

For some reasons, I need to embed a camlruntime into a dll/so that is therefore not loaded at program startup. Hence fp signals I get when launching camlstartup (under linux and mingw).

So to sum-up, the only reasonnable solution is to fix the manual and to hint users to wrap camlstartup with fedisableexcept/
feenableexcept as I've suggested in the description section above (and to forget my note above, sorry for the noise).

(0007865)
xleroy (administrator)
2012-08-02 09:20

ISO C99 standardizes <fenv.h> functions such as feholdexcept() to select "non-stop" float handling (no signalling exceptions). However, Microsoft doesn't implement C99, so there is still no truly portable solution.

ISO C99 also specifies that all programs start in "non-stop" mode, so the issue affects only OCaml code embedded in DLLs.

My feeling is that there is no better solution than what the reporter proposes: on the C/C++ application side, wrap calls to caml_startup() with operations appropriate to select non-stop mode and restore the original mode. In C99. that would be feholdexcept() and fesetenv(). For Win32, I have no idea.

I'm "suspending" this PR until Win32 supports C99...



- Issue History
Date Modified Username Field Change
2009-12-01 14:22 erwan New Issue
2009-12-01 14:22 erwan File Added: fe_ocaml.tgz
2009-12-08 17:30 doligez Status new => acknowledged
2010-11-17 10:38 erwan Note Added: 0005709
2010-11-17 10:44 erwan Note Edited: 0005709
2010-11-17 10:53 erwan Note Edited: 0005709
2010-11-17 11:18 erwan Note Added: 0005710
2010-11-17 11:26 erwan Note Edited: 0005710
2012-07-11 13:32 doligez Target Version => 4.01.0+dev
2012-07-31 13:36 doligez Target Version 4.01.0+dev => 4.00.1+dev
2012-08-02 09:20 xleroy Note Added: 0007865
2012-08-02 09:20 xleroy Status acknowledged => resolved
2012-08-02 09:20 xleroy Resolution open => suspended
2012-08-02 09:20 xleroy Target Version 4.00.1+dev =>


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker