[libvirt] PATCH: 0/28: Thread safety for libvirtd daemon and drivers
Richard W.M. Jones
rjones at redhat.com
Thu Dec 18 15:52:33 UTC 2008
On Wed, Dec 03, 2008 at 11:57:54PM +0000, Daniel P. Berrange wrote:
> let isLockableThingNull exp funcheck =
> match exp with
> | UnOp (op,exp,typ) -> (
> match op with
> LNot -> (
> match exp with
> Lval (lhost, off) -> (
> match lhost with
> Var vi ->
> funcheck vi
> | _ -> false
> )
> | _ -> false
> )
> | _ -> false
> )
> | _ ->
> false
I guess this is better written using a nested pattern, something like:
let isLockableThingNull exp funcheck =
match exp with
| UnOp (LNot, Lval (Var vi, off), typ) when funcheck vi -> true
| _ -> false
> let isLockableObjectNull exp =
> isLockableThingNull exp isLockableObjectVar
>
> let isLockableDriverNull exp =
> isLockableThingNull exp isLockableDriverVar
It doesn't really matter, but you can also hide subfunctions (and
static variables) like this:
let isLockableObjectNull, isLockableDriverNull =
let isLockableThingNull exp funcheck = (* this function is hidden *)
(* the definition above *)
in
let isLockableObjectNull exp = (* visible *)
(* copy definition from above *)
in
let isLockableDriverNull exp = (* visible *)
(* copy definition from above *)
in
isLockableObjectNull, isLockableDriverNull
> module L = DF.ForwardsDataFlow(Locking)
CIL is kinda crazy isn't it :-(
> let prefixes = [ "qem"; "uml"; "lxc"; "ope"; "tes"; "net"; "sto"; "nod" ] in
> if String.length name > 4 then
> let prefix = String.sub fundec.svar.vname 0 3 in
There's also a function String.starts_with. It's in extlib, so you
need to compile with '-package extlib' and add 'open ExtString' at the
top of the source file.
Top marks for dealing with the sheer weirdness of CIL :-)
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
Read my OCaml programming blog: http://camltastic.blogspot.com/
Fedora now supports 68 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
More information about the libvir-list
mailing list