[Haskell-cafe] carry "state" around ....

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Mon Jul 28 03:04:22 EDT 2008

On 2008 Jul 28, at 2:36, Galchin, Vasili wrote:

> Hi Brandon,
>       So even if I go to ForeignPtr is a problem? And/Or is this a  
> "by reference" vs "by value" issue?

As I read your code, you're allocating a C object, poking the Haskell  
fields into it, and passing it on, then peeking the values back out.   
This won't work; the C pointer value passed to aio_write() is the  
value that must be passed to subsequent operations on that aiocb (such  
as aio_return()).  More to the point:  the exact chunk of memory  
passed to aio_write(), unmodified, must be passed to any other aio  
functions checking for or blocking on completion of the write.  You  
may not move it around or arbitrarily change values within it.

You could do this if your Haskell aiocb also retained the ForeignPtr  
to the originally allocated C object... but after the initial pokes,  
the only thing you can safely do with that object is pass it to C and  
peek the current values out of it, unless the C API specifically says  
you can modify fields within it while I/O operations are pending (and  
I'd be rather surprised if it did).

brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080728/760ac09e/attachment.htm

More information about the Haskell-Cafe mailing list