GHC: Ticket #311: gmp's memory management
http://ghc.haskell.org/trac/ghc/ticket/311
<p>
I assume ghc allocates the lumps of gmp integers still
on ghc's heap, making it impossible (or very awkward)
to interface to C libraries that use gmp themselves. Is
there a chance that you could use the default memory
allocator for lumps starting from ghc 6.4? That would
make my life much easier.
</p>
<p>
Thanks,
Axel.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/311
Trac 1.0.1simonmarTue, 22 Feb 2005 10:49:03 GMT
http://ghc.haskell.org/trac/ghc/ticket/311#comment:1
http://ghc.haskell.org/trac/ghc/ticket/311#comment:1
<pre class="wiki">Logged In: YES
user_id=48280
It's a known problem that you can't use GMP via the FFI from
your Haskell code in GHC, or use a C library that internally
uses GMP. We should really use a private version of GMP
with function names that don't overlap, or better still
replace GMP altogether.
I don't think this is going to get fixed for 6.4, I'm afraid.
</pre>
TicketsigbjornTue, 23 Aug 2005 17:33:07 GMT
http://ghc.haskell.org/trac/ghc/ticket/311#comment:2
http://ghc.haskell.org/trac/ghc/ticket/311#comment:2
<pre class="wiki">Logged In: YES
user_id=232905
It wouldn't be too hard to provide an entry point that let you
enable/disable the use of GHC's custom allocator functions.
That entry point would be called by FFI wrapper code, either
as a service by the RTS or manually by user code. Would
only work in single (OS) threaded code, of course.
</pre>
TicketiglooFri, 13 Oct 2006 22:30:19 GMTdescription changed; difficulty, milestone, os, architecture set
http://ghc.haskell.org/trac/ghc/ticket/311#comment:3
http://ghc.haskell.org/trac/ghc/ticket/311#comment:3
<ul>
<li><strong>difficulty</strong>
set to <em>Unknown</em>
</li>
<li><strong>milestone</strong>
set to <em>6.8</em>
</li>
<li><strong>os</strong>
set to <em>Unknown</em>
</li>
<li><strong>architecture</strong>
set to <em>Unknown</em>
</li>
<li><strong>description</strong>
modified (<a href="/trac/ghc/ticket/311?action=diff&version=3">diff</a>)
</li>
</ul>
<p>
See also <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/601" title="task: Replace GMP (closed: fixed)">601</a>.
</p>
TicketsimonpjTue, 11 Sep 2007 07:03:23 GMTdescription changed
http://ghc.haskell.org/trac/ghc/ticket/311#comment:4
http://ghc.haskell.org/trac/ghc/ticket/311#comment:4
<ul>
<li><strong>description</strong>
modified (<a href="/trac/ghc/ticket/311?action=diff&version=4">diff</a>)
</li>
</ul>
<p>
Comment from Benedict Huber
</p>
<p>
I've been struggling using FFI bindings to libraries which rely on the
GNU Mp Bignum library (gmp) - this is apparently a well known problem
(<a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/311" title="bug: gmp's memory management (closed: fixed)">#311</a>, [<a class="wiki" href="http://ghc.haskell.org/trac/ghc/wiki/ReplacingGMPNotes">wiki:ReplacingGMPNotes</a>). I do rely on using such libraries, and so started to get it work on <tt>MacOsX</tt>; no solution was close to being satisfactory however, so I'd like to ask for some advice.
</p>
<p>
Those two options worked to some extend:
</p>
<ul><li>Create or modify the library in question, so gmp is statically linked and its symbols are hidden. When source code is available, this is relatively easy, altough it requires modification of the build process (which can be a hassle). If a static "ar" archive is available, it is cumbersome (at least on Mac Os X I ran into a lot of troubles using nmedit), but possible. Furthermore, the resulting libraries are bloated, as each of them contains a copy of the GMP; left alone portability issues.
</li></ul><ul><li>As suggested an earlier comment, I tried switching the allocator functions when switching to FFI. It worked, but not in GHCi; also, doing it manually is a lot of work, because, as far as I could figure out, it is neccessary to write a wrapper function for every C-function (indirectly) using the gmp.
</li></ul><p>
Furthermore, most of the libraries expose gmp datatypes (<tt>mpz_t</tt>,<tt>mpq_t</tt>) in
their API. I currently use a little haskell module working on
<tt>GHC.Exts</tt>, but that's propably not a good option from a maintainer's
point of view. There are certainly other possibilities, but I couldn't
find one which is both maintainable and portable.
</p>
<p>
I would be very grateful for any advice, or some information on plans
for resolving ticket <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/311" title="bug: gmp's memory management (closed: fixed)">#311</a>. There are some great libraries (like the
Parma Polyhedral Library, to pick an example) out there using gmp, and
it would be nice if writing bindings to those libs could be simplified.
</p>
<p>
Thanks,
Benedikt Huber
</p>
TicketsimonmarMon, 12 Nov 2007 13:34:26 GMTstatus, milestone changed; owner deleted
http://ghc.haskell.org/trac/ghc/ticket/311#comment:5
http://ghc.haskell.org/trac/ghc/ticket/311#comment:5
<ul>
<li><strong>owner</strong>
<em>nobody</em> deleted
</li>
<li><strong>status</strong>
changed from <em>assigned</em> to <em>new</em>
</li>
<li><strong>milestone</strong>
changed from <em>6.8 branch</em> to <em>6.10 branch</em>
</li>
</ul>
TicketguestThu, 31 Jul 2008 06:50:47 GMT
http://ghc.haskell.org/trac/ghc/ticket/311#comment:6
http://ghc.haskell.org/trac/ghc/ticket/311#comment:6TicketsimonmarTue, 30 Sep 2008 15:37:40 GMTarchitecture changed
http://ghc.haskell.org/trac/ghc/ticket/311#comment:7
http://ghc.haskell.org/trac/ghc/ticket/311#comment:7
<ul>
<li><strong>architecture</strong>
changed from <em>Unknown</em> to <em>Unknown/Multiple</em>
</li>
</ul>
TicketsimonmarTue, 30 Sep 2008 15:52:01 GMTos changed
http://ghc.haskell.org/trac/ghc/ticket/311#comment:8
http://ghc.haskell.org/trac/ghc/ticket/311#comment:8
<ul>
<li><strong>os</strong>
changed from <em>Unknown</em> to <em>Unknown/Multiple</em>
</li>
</ul>
TicketjudahjFri, 10 Oct 2008 19:29:37 GMT
http://ghc.haskell.org/trac/ghc/ticket/311#comment:9
http://ghc.haskell.org/trac/ghc/ticket/311#comment:9
<p>
In the following post, Aleš Bizjak suggests the following workaround: use the foreign library's custom memory interface, and allocate with malloc.
</p>
<p>
<a class="ext-link" href="http://www.haskell.org/pipermail/haskell-cafe/2008-October/048812.html"><span class="icon"></span>http://www.haskell.org/pipermail/haskell-cafe/2008-October/048812.html</a>
</p>
TicketiglooMon, 13 Apr 2009 17:32:22 GMTmilestone changed
http://ghc.haskell.org/trac/ghc/ticket/311#comment:10
http://ghc.haskell.org/trac/ghc/ticket/311#comment:10
<ul>
<li><strong>milestone</strong>
changed from <em>6.10 branch</em> to <em>6.12 branch</em>
</li>
</ul>
TicketiglooSat, 25 Jul 2009 18:50:20 GMTstatus, resolution changed
http://ghc.haskell.org/trac/ghc/ticket/311#comment:11
http://ghc.haskell.org/trac/ghc/ticket/311#comment:11
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
changed from <em>None</em> to <em>fixed</em>
</li>
</ul>
<p>
It is now possible to build GHC with a pure Haskell Integer library, so I'm closing this ticket.
</p>
TicketisaacdupreeSat, 25 Jul 2009 21:15:53 GMT
http://ghc.haskell.org/trac/ghc/ticket/311#comment:12
http://ghc.haskell.org/trac/ghc/ticket/311#comment:12
<p>
It's still a bug/issue for when GHC is built with GMP. Were we planning on switching to non-GMP as default or mandatory? (I think such a change would need more discussion, because some code might use the speed of GMP's algorithms on large numbers.) I guess just having non-gmp as a configure choice is a workaround for these users, although not a perfect or easy workaround
</p>
TicketiglooSat, 25 Jul 2009 21:38:04 GMT
http://ghc.haskell.org/trac/ghc/ticket/311#comment:13
http://ghc.haskell.org/trac/ghc/ticket/311#comment:13
<p>
It's also now easy to create alternative integer backends, e.g. using a renamed gmp, or another C integer library. I don't think we intend to do anything else on this front, though.
</p>
<p>
GMP will remain the default.
</p>
TickethvrWed, 23 Jul 2014 10:11:07 GMTfailure, related set
http://ghc.haskell.org/trac/ghc/ticket/311#comment:14
http://ghc.haskell.org/trac/ghc/ticket/311#comment:14
<ul>
<li><strong>failure</strong>
set to <em>None/Unknown</em>
</li>
<li><strong>related</strong>
set to <em>#9281</em>
</li>
</ul>
<p>
See <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/9281" title="task: Rewrite `integer-gmp` to use only non-allocating GMP functions (closed: fixed)">#9281</a> for a new attempt to improve the situation for the <tt>integer-gmp</tt>
</p>
Ticket