6 Oct 02:25
MPFR / FFI - Nefarious (Simple?) bug
From: Jared Updike <jupdike <at> gmail.com>
Subject: MPFR / FFI - Nefarious (Simple?) bug
Newsgroups: gmane.comp.lang.haskell.cafe
Date: 2008-10-06 00:26:12 GMT
Subject: MPFR / FFI - Nefarious (Simple?) bug
Newsgroups: gmane.comp.lang.haskell.cafe
Date: 2008-10-06 00:26:12 GMT
In order to create an arbitrary precision floating point / drop in replacement for Double, I'm trying to wrap MPFR (http://www.mpfr.org/) using the FFI but despite all my efforts the simplest bit of code doesn't work. It compiles, it runs, but it crashes mockingly after pretending to work for a while. A simple C version of the code happily prints the number "1" to (640 decimal places) a total of 10,000 times. The Haskell version, when asked to do the same, silently corrupts (?) the data after only 289 print outs of "1.0000...0000" and after 385 print outs, it causes an assertion failure and bombs. I'm at a loss for how to proceed in debugging this since it "should work". The code can be perused at http://hpaste.org/10923 (and attached) and downloaded at http://www.updike.org/mpfr-broken.tar.gz I'm using GHC 6.83 on FreeBSD 6 and GHC 6.8.2 on Mac OS X. Note you will need MPFR (tested with 2.3.2) installed with the correct paths (change the Makefile) for libs and header files (along with those from GMP) to successfully compile this. Why does the C version work, but the Haskell version flake out? What else am I missing when approaching the FFI? I tried StablePtrs and had the exact same results. Can someone else verify if this is a Mac/BSD only problem by compiling and running my code? (Does the C executable"works" work? Does the Haskell executable "noworks" not work?) Can anyone on Linux and Windows attempt to compile/run and see if you can get the same results? Jared.(Continue reading)
RSS Feed