RE: GHCI/FFI/GMP/Me madness

2004-08-13 Thread Simon Marlow
On 13 August 2004 14:04, Remi Turk wrote: How do you arrange to free a GMP integer when it is no longer referenced from the heap? You'd need finalizers, and that way lies madness. The memory allocation tricks we play with GMP are all to support GC of Integers. Errr, I guess I'll have to

RE: GHCI/FFI/GMP/Me madness

2004-08-12 Thread Simon Marlow
On 11 August 2004 20:45, Remi Turk wrote: But as long as GMP doesn't mind about being abused the way my most recent util.c does, I can get away with the mp_set_memory_functions-trick, can't I? Not really. You can't let GMP realloc() a memory block that was allocated using one method, with a

RE: GHCI/FFI/GMP/Me madness

2004-08-11 Thread Simon Marlow
On 10 August 2004 16:04, Remi Turk wrote: - 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

Re: GHCI/FFI/GMP/Me madness

2004-08-11 Thread Remi Turk
On Wed, Aug 11, 2004 at 02:27:19PM +0100, Simon Marlow wrote: On 10 August 2004 16:04, Remi Turk wrote: http://www.haskell.org/pipermail/glasgow-haskell-users/2004-June/006767.html Hmm yes, I now realise that it's not quite as easy as I implied in that message. The problem is the memory

RE: GHCI/FFI/GMP/Me madness

2004-08-10 Thread Simon Marlow
On 09 August 2004 16:57, Remi Turk wrote: On Sun, Aug 08, 2004 at 07:34:04AM -0700, Sigbjorn Finne wrote: Hi, please be aware that the RTS uses GMP as well, and upon initialisation it sets GMP's 'memory functions' to allocate memory from the RTS' heap. So, in the code below, the global

RE: GHCI/FFI/GMP/Me madness

2004-08-10 Thread Simon Marlow
On 10 August 2004 13:03, MR K P SCHUPKE wrote: Re GMP, Why not provide more GMP functions as primitives on the Integer type, and avoid the need to call out to GMP via the FFI? Show us the code! :-p Cheers, Simon ___ Glasgow-haskell-users

Re: GHCI/FFI/GMP/Me madness

2004-08-10 Thread Carsten Schultz
Hi! On Tue, Aug 10, 2004 at 12:59:46PM +0100, Simon Marlow wrote: On 09 August 2004 16:57, Remi Turk wrote: Hm, I _was_ aware of mp_set_memory_functions being used by the RTS. I've seen it often enough in ltrace's ;) It does indeed sound rather plausible (and making big allocations and

Re: GHCI/FFI/GMP/Me madness

2004-08-10 Thread Alastair Reid
- Rename all the symbols in our GMP to be unique. (sounds hard) Nah, easy. First get a list of symbols: nm libgmp.a | grep gmp [Supply a few flags to nm to get a better list.] Then turn it into a list of #defines: #define gmp_blah ghc_gmp_blah ... #include your list of #defines into

RE: GHCI/FFI/GMP/Me madness

2004-08-10 Thread Simon Marlow
On 10 August 2004 14:08, Alastair Reid wrote: - Rename all the symbols in our GMP to be unique. (sounds hard) Nah, easy. First get a list of symbols: nm libgmp.a | grep gmp [Supply a few flags to nm to get a better list.] Then turn it into a list of #defines: #define gmp_blah

Re: GHCI/FFI/GMP/Me madness

2004-08-10 Thread Remi Turk
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

Re: GHCI/FFI/GMP/Me madness

2004-08-10 Thread Remi Turk
On Tue, Aug 10, 2004 at 01:09:03PM +0100, Simon Marlow wrote: On 10 August 2004 13:03, MR K P SCHUPKE wrote: Re GMP, Why not provide more GMP functions as primitives on the Integer type, and avoid the need to call out to GMP via the FFI? Show us the code! :-p Or implement Integers via

Re: GHCI/FFI/GMP/Me madness

2004-08-09 Thread Remi Turk
On Sun, Aug 08, 2004 at 07:34:04AM -0700, Sigbjorn Finne wrote: Hi, please be aware that the RTS uses GMP as well, and upon initialisation it sets GMP's 'memory functions' to allocate memory from the RTS' heap. So, in the code below, the global variable 'p' will end up having components

Re: GHCI/FFI/GMP/Me madness

2004-08-09 Thread Tomasz Zielonka
On Sun, Aug 08, 2004 at 07:34:04AM -0700, Sigbjorn Finne wrote: Hi, please be aware that the RTS uses GMP as well, and upon initialisation it sets GMP's 'memory functions' to allocate memory from the RTS' heap. What about linking Haskell programs with C libraries that use GMP internally?

Re: GHCI/FFI/GMP/Me madness

2004-08-09 Thread Abraham Egnor
FWIW, I couldn't reproduce this problem on my system (i.e. str_test always printed 1). GHC 6.2.1, libgmp 4.1.3, debian unstable Abe On Mon, 9 Aug 2004 17:57:14 +0200, Remi Turk [EMAIL PROTECTED] wrote: On Sun, Aug 08, 2004 at 07:34:04AM -0700, Sigbjorn Finne wrote: Hi, please be aware

Re: GHCI/FFI/GMP/Me madness

2004-08-09 Thread Remi Turk
On Mon, Aug 09, 2004 at 01:09:40PM -0400, Abraham Egnor wrote: FWIW, I couldn't reproduce this problem on my system (i.e. str_test always printed 1). GHC 6.2.1, libgmp 4.1.3, debian unstable Abe Same versions here, on an old heavily-patched/FUBAR rock linux 1.4 system. Does the following

Re: GHCI/FFI/GMP/Me madness

2004-08-08 Thread Sigbjorn Finne
Hi, please be aware that the RTS uses GMP as well, and upon initialisation it sets GMP's 'memory functions' to allocate memory from the RTS' heap. So, in the code below, the global variable 'p' will end up having components pointing into the heap. Which is fine, until a GC occurs and the