ocamllabs/ocaml-ctypes — pull request #242 by yallop (2014-12-31 20:16:10+00:00)
Title: Extend Cstubs with foreign_value support

Add a `foreign_value` function to Cstubs for accessing global variables:

```ocaml
val foreign_value : string -> 'a Ctypes.typ -> 'a Ctypes.ptr fn
```

The behaviour is analogous to [Foreign.foreign_value][foreign-foreign-value]: given a type representation `t` and the name of a global value `n`, `foreign_value t n` returns the address of the global. For example, POSIX specifies a global variable holding the process environment:

```C
char **environ;
```

To bind to `environ` we might write

```ocaml
foreign_value "environ" (ptr string_opt)
```

which returns a value of type `string option ptr ptr` (corresponding to `char ***`) which can be used to read and write to `environ`.

Closes #136.

[foreign-foreign-value]: http://ocamllabs.github.io/ocaml-ctypes/Foreign.html#VALforeign_value