rturk at science.uva.nl
Tue Aug 10 11:03:54 EDT 2004
On Tue, Aug 10, 2004 at 12:59:46PM +0100, Simon Marlow wrote:
> GHC's use of GMP does cause problems if you want to use GMP for your own
> purposes, or if you link with external code that wants to use GMP. The
> real problem is that GMP has internal state, which means it can't be
> used in a modular way. But there's not much we can do about that.
> - Rename all the symbols in our GMP to be unique. (sounds hard)
> - Replace GMP with something else (someone is working on this,
> I believe).
Do you have a pointer? It sounds interesting. *see below*
> - try to get two copies of GMP into your program by pre-linking
> the RTS with one copy, then linking the rest of the program
> with the other copy. I'm being intentionally vague here - I
> feel that this ought to be possible, but it's an ugly hack
> at best.
I'm not sure I share your feelings about that ;) It sounds like
symbol-clash-hell. But quite possibly I'm just being ignorant.
> - reset GMP's memory allocators before calling it from your code,
> and set them back to the RTS allocators afterward. Slow, but it
> should work. It doesn't solve the problem properly though: external
> libraries which use GMP are still broken.
It does indeed seem to work, after a quick test. (new util.c attached)
And it does solve _my_ immediate "problem": I can surround every
gmp-operation with a gmp_begin()/gmp_end() and pretend to be
happy. (and anyway, I'm just messing around, failure merely means
I've got yet another unfinished project ;))
Part of the reason for all this messy FFIing is your post:
If Integers where implemented via the FFI that would make it
quite a bit easier to special-case e.g. (^) and Show for Integer.
(IIRC, GMP's mpz-to-string recently got a huge speedup, it would
be nice if GHC would automagically profit of that..)
Happy hacking & keep up the good work ;)
Nobody can be exactly like me. Even I have trouble doing it.
More information about the Glasgow-haskell-users