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

Re: GHCI/FFI/GMP/Me madness

2004-08-13 Thread Remi Turk
On Thu, Aug 12, 2004 at 09:30:58AM +0100, Simon Marlow wrote: > 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

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

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 memo

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 st

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 Integer

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 modul

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

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 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 allocation

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 ma

RE: GHCI/FFI/GMP/Me madness

2004-08-10 Thread MR K P SCHUPKE
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? Keean. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haske

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

Re: GHCI/FFI/GMP/Me madness

2004-08-09 Thread Abraham Egnor
Ah, that triggers the bug for me as well. Oddly, calling System.Mem.performGC once isn't enough, but twice is: Ok, modules loaded: Main. *Main> mpz_new *Main> System.Mem.performGC *Main> str_test 1 vs. Ok, modules loaded: Main. *Main> mpz_new *Main> System.Mem.performGC *Main> System.Mem.perfor

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 follow

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 b

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 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 component

GHCI/FFI/GMP/Me madness

2004-08-09 Thread Remi Turk
Hi all, I recently tried to create a ffi-binding to gmp in ghc, and failed miserably. After a few days of debugging, simplifying the code and tearing my hear out, I'm slightly completely stumped, and crying for help ;) In short: calling gmp-functions from GHCI *with a prompt between* them seems t

Re: GHCI/FFI/GMP/Me madness

2004-08-08 Thread Sigbjorn Finne
> To: <[EMAIL PROTECTED]> Sent: Sunday, August 08, 2004 05:52 Subject: GHCI/FFI/GMP/Me madness > [second attempt, this time from my bulk mailinglist address > instead of the normal one.] > > Hi all, > > I recently tried to create a ffi-binding to gmp in ghc, and > fai

GHCI/FFI/GMP/Me madness

2004-08-08 Thread Remi Turk
[second attempt, this time from my bulk mailinglist address instead of the normal one.] Hi all, I recently tried to create a ffi-binding to gmp in ghc, and failed miserably. After a few days of debugging, simplifying the code and tearing my hear out, I'm slightly completely stumped, and crying f