Import Upstream version 20180207
[hcoop/debian/mlton.git] / lib / mlnlffi-lib / internals / c-debug.sml
1 (* c-debug.sml
2 * 2005 Matthew Fluet (mfluet@acm.org)
3 * Adapted for MLton.
4 *)
5
6 (*
7 * Encoding C's type system in SML. This module provides the "public"
8 * view of the implementation.
9 *
10 * DEBUG VERSION with CHECKED POINTER DEREFERENCING.
11 *
12 * (C) 2002, Lucent Technologies, Bell Laboratories
13 *
14 * author: Matthias Blume (blume@research.bell-labs.com)
15 *)
16 structure C_Debug : C_DEBUG = struct
17 (* first of all, we look mostly like structure C... *)
18 open C
19
20 (* ... but then, we also check for NULL pointers... *)
21 exception NullPointer
22
23 (* ... which means that we have to re-implement some things: *)
24 structure Ptr = struct
25 open Ptr
26 val |*! = fn p => if isNull' p then raise NullPointer else |*! p
27 val |*| = fn p => if isNull p then raise NullPointer else |*| p
28 end
29 end