deRefStablePtr exception?

Simon Marlow simonmar at
Thu Jun 13 08:00:48 EDT 2002

> Aha!  I was reading the last sentence of the freeStablePtr description
> as though it applied to freeStablePtr when in fact it means that
> castStablePtrToPtr is guaranteed not to diverge.  Well that's a lot
> easier to implement.
> btw What am I to make of the parenthetical remark 
>   (in particular it may be Ptr.nullPtr)
> Should I read that as a recommendation to implementors that when
> casting a stableptr which has already been freed then they should
> return nullPtr?   If so, is this required or just hinted/recommended?

I'm not sure where this came from, perhaps Manuel can elucidate.  GHC
doesn't do this; it just casts the stable pointer value to a Ptr.

> > Either 'ErrorCall "Foreign.StablePtr.deRefStablePtr: invalid stable
> > pointer"', or a new exception.  I don't mind which.
> I'll pick one and add my choice to the spec then.

The spec doesn't say anything about exceptions, and it isn't dependent
on the implementation also supporting exceptions.  So all the spec
should say is that deRefStablePtr on a stable pointer which was not
generated by newStablePtr, or has already been freed, has undefined


More information about the FFI mailing list