Alas, the saga continues: After a thinking a little bit more about
Simon's and Sigbjorn's replies to my question, I'm now convinced that
it is not as simple as it seems, because there are *two* kinds of pointers
in this game. Again my scenario, this time a little bit more verbose:
1. Create a callback via foreign export dynamic. This gets you an
Addr, which is basically a pointer to a block of machine code
malloc'ed and filled by createAdjustor. The code contains a
stable pointer to the Haskell closure to be called.
2. Register the Addr from step 1 to the C-API (GTK+, GLUT, etc.)
3. After a while, the adjustor code is called from C-land, which in
turn calls the Haskell callback via the stable pointer.
4. The Haskell callback wants to re-register a new callback for the
same event. It is *not* allowed to call freeHaskellFunctionPtr
with the Addr from step 1 at this point, because of step 6.
5. The running "old" callback can still do anything it pleases
6. The callback finishes and control passes through the code block
from step 1, finally reaching C-land again.
In step 4, freeHaskellFunctionPtr would (correctly) free the stable
pointer to the Haskell callback, but in addition it would free the
malloc'ed block, which is still needed in step 6.
Is it now me who missed something? I'm getting a little bit confused...
Cheers,
Sven
--
Sven Panne Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen Oettingenstr. 67
mailto:[EMAIL PROTECTED] D-80538 Muenchen
http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne