mallocForeignPtr vs. C

Edward Z. Yang ezyang at MIT.EDU
Mon Jul 12 16:35:40 EDT 2010


Excerpts from Evan Laforge's message of Mon Jul 12 16:23:39 -0400 2010:
> Well, what I'm worried about is that withForeignPtr says you should
> only use the pointer from inside it.  The situation here is that I've
> passed a pointer to C.  C wants to share ownership of the pointer, so
> even if all haskell references are gone, it needs to stay alive until
> C says so.  So there's nothing to pass to withForeignPtr.  C uses a
> ptr, not a foreign ptr.

Ah, I see your problem. Normally, pointers that end up getting freed in C
have no business being in a foreign pointer, but StorableVector only
generates foreign pointers.

The easiest thing to do is copy the contents to a regular area of memory not
managed by a Storable Vector.  This'll be much less painful because it's just a
normal free (not a recursive one, which can get hairy).

Cheers,
Edward


More information about the Glasgow-haskell-users mailing list