Re: ANNOUNCE: MonadCatchIO-foreign

Hi GHC,
Is there a reason that Foreign.Marshall.Array.allocaArray calls into
allocaBytes instead of allocaBytesAligned? Since alloca needs the
alignment, wouldn't allocaArray also need it?
I'm not too up on how memory access is supposed to work, it was just
something that jump out at me.
Thanks,
Antoine
On Sun, May 30, 2010 at 7:10 PM, Antoine Latter
Hello Haskell,
I'd like to announce a very small library in two flavors.
The problem I'm trying to solve is that we have some capabilities for writing functions which are polymorphic over monad but still use IO capabilities - liftIO :: (IO a -> m a) from the packages transformers and mtl. The packages[1,2] MonadCatchIO offer similar polymorphism for the exception capabilities of the IO monad.
The package MonadCatchIO-foreign offers similar polymorphism for the following functions:
alloca, allocaBytes, allocaArray, allocaArray0 and withForeignPtr.
It's a small thing, but I don't see why it should be written twice.
Links on hackage:
http://hackage.haskell.org/package/MonadCatchIO-mtl-foreign http://hackage.haskell.org/package/MonadCatchIO-transformers-foreign
GitHub link:
http://github.com/aslatter/MonadCatchIO-foreign
Feedback, praise and adulation welcome.
Antoine

On Sun, May 30, 2010 at 5:15 PM, Antoine Latter
Hi GHC,
Is there a reason that Foreign.Marshall.Array.allocaArray calls into allocaBytes instead of allocaBytesAligned? Since alloca needs the alignment, wouldn't allocaArray also need it?
I'm not too up on how memory access is supposed to work, it was just something that jump out at me.
I've been waiting for a response on this, because I'm curious too, in fact I always have been. At the upgrade to 6.10, ghc suddenly started using 'alignment' and all my programs which had defined it to 'undefined' since I didn't know what alignment was for and it didn't seem to be used, started crashing. So I dug around, dug up the '#let alignment' macro boilerplate, and copy and pasted it around. However, at the same time, my program started rarely but consistently crashing with an assertion failure from the gc runtime. I'm suspicious of the inconsistent use of alignment, but it's hard to use allocaBytesAligned since it's not exported, and the ffi lib is part of ghc and it's not obvious how to modify it.

On 03/06/2010 07:29, Evan Laforge wrote:
On Sun, May 30, 2010 at 5:15 PM, Antoine Latter
wrote: Hi GHC,
Is there a reason that Foreign.Marshall.Array.allocaArray calls into allocaBytes instead of allocaBytesAligned? Since alloca needs the alignment, wouldn't allocaArray also need it?
I'm not too up on how memory access is supposed to work, it was just something that jump out at me.
I've been waiting for a response on this, because I'm curious too, in fact I always have been. At the upgrade to 6.10, ghc suddenly started using 'alignment' and all my programs which had defined it to 'undefined' since I didn't know what alignment was for and it didn't seem to be used, started crashing. So I dug around, dug up the '#let alignment' macro boilerplate, and copy and pasted it around.
However, at the same time, my program started rarely but consistently crashing with an assertion failure from the gc runtime. I'm suspicious of the inconsistent use of alignment, but it's hard to use allocaBytesAligned since it's not exported, and the ffi lib is part of ghc and it's not obvious how to modify it.
Here's the ticket: http://hackage.haskell.org/trac/ghc/ticket/2917 Lennart's patch added allocaBytesAligned to Foreign.Marshal.Alloc, but we'll have to do a library proposal to add that. If you can reproduce the assertion failure, please submit a bug report. Cheers, Simon

Here's the ticket:
http://hackage.haskell.org/trac/ghc/ticket/2917
Lennart's patch added allocaBytesAligned to Foreign.Marshal.Alloc, but we'll have to do a library proposal to add that.
If you can reproduce the assertion failure, please submit a bug report.
Unfortunately this assertion failure, though it will always happen eventually, has proven to be a real pain to track down. I filed a bug report a long time ago, closed it when I mistakenly thought I had fixed the problem, and now I'm waiting until I've narrowed things down some more. I'm no longer so suspicious of allocaBytes since it still happened after I replaced it with alloca, which, contrary to the trac ticket, does appear to use allocaBytesAligned. And I don't really see how it could cause memory corruption anyway...
participants (3)
-
Antoine Latter
-
Evan Laforge
-
Simon Marlow