Alastair: >> What exception does deRefStablePtr raise when handed an invalid >> pointer such as 0?
SimonM: > That's a good point, I don't think it has any error checking at all. > Of course the only way to get an invalid stable pointer is by > calling freeStablePointer on a valid one, or by using the FFI. >From an imported C function: return (HsStablePtr)0 >From Haskell code: castPtrToStablePtr Ptr.nullPtr My reading of the description of freeStablePtr is that it is perfectly legal to pass around a (void*)0 as an HsStablePtr and to hand that to freeStablePtr and castStablePtrToPtr and expect something meaningful to happen. (My personal leanings with anything resembling a C pointer have always been to use some variant of Maybe Addr Maybe (Ptr a) Maybe (FunPtr a) Maybe (StablePtr a) if the pointer can possibly be null. It turns out that many functions assume their argument cannot be null or guarantee that their result is not null and this both catches errors and reminds the programmer to think about the null case.) > Nevertheless, deRefStablePtr should raise an exception when it finds > an invalid stable pointer. Which brings me back to my question: _which_ exception should it raise? -- Alastair Reid [EMAIL PROTECTED] http://www.cs.utah.edu/~reid/ _______________________________________________ FFI mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/ffi