deRefStablePtr exception?

Alastair Reid reid at cs.utah.edu
Thu Jun 13 14:30:27 EDT 2002


Alastair:
>> btw What am I to make of the parenthetical remark
>> 
>> (in particular it may be Ptr.nullPtr)

Simon:
> 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.

Hmmm.  I vaguely remember (but can't locate at the moment), the spec
guaranteeing that valid HsStablePtrs are nonNull.  Maybe it is a
reference to that?

[Am I right that they must be non-Null?]

Simon:
> 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 behaviour.

Ok then, IOErrors are part of H98 and even get mentioned in the ffi
spec.  Can we at least specify that you get an IOError if you 

  deRefStablePtr (castPtrToStablePtr (Ptr.nullPtr))

(Of course, implementations might raise the same error for other
invalid stable pointers - but it's hard to make firm guarantees.)


-- 
Alastair Reid        reid at cs.utah.edu        http://www.cs.utah.edu/~reid/



More information about the FFI mailing list