text stringlengths 12 786k |
|---|
let wrap_env fenv ftree arg = let env = ! printing_env in set_printing_env ( fenv env ) ; let tree = ftree arg in set_printing_env env ; tree |
let filter_rem_sig item rem = match item , rem with | Sig_class _ , ctydecl :: tydecl1 :: tydecl2 :: rem -> ( [ ctydecl ; tydecl1 ; tydecl2 ] , rem ) | Sig_class_type _ , tydecl1 :: tydecl2 :: rem -> ( [ tydecl1 ; tydecl2 ] , rem ) | _ -> ( [ ] , rem ) |
let dummy = { type_params = [ ] ; type_arity = 0 ; type_kind = Type_abstract ; type_private = Public ; type_manifest = None ; type_variance = [ ] ; type_newtype_level = None ; type_loc = Location . none ; type_attributes = [ ] ; type_immediate = false ; type_unboxed = un... |
let hide_rec_items = function | Sig_type ( id , _decl , rs ) :: rem when rs = Trec_first && not ! Clflags . real_paths -> let rec get_ids = function Sig_type ( id , _ , Trec_next ) :: rem -> id :: get_ids rem | _ -> [ ] in let ids = id :: get_ids rem in set_printing_env ( List ... |
let rec tree_of_modtype ( ? ellipsis = false ) = function | Mty_ident p -> Omty_ident ( tree_of_path p ) | Mty_signature sg -> Omty_signature ( if ellipsis then [ Osig_ellipsis ] else tree_of_signature sg ) | Mty_functor ( param , ty_arg , ty_res ) -> let res = match ty_arg with None ... |
module Exn = struct let protect f v ~ final = Spotlib . Exn . protect f v ~ finally : final end |
module Array = struct let shuffle ( ? random = Random . int ) a = let len = Array . length a - 1 in for i = 0 to len - 1 do let d = len - i in let j = random d + i in let x = Array . unsafe_get a i in let y = Array . unsafe_get a j in Array . unsafe_set a i y ; Array . unsafe_set a j ... |
module Base = struct let ( !++ ) r = let v = ! r in incr r ; v end |
module Gc = struct open Gc let used_words ( ) = let c = get ( ) in set { c with minor_heap_size = 1000 ; } ; compact ( ) ; let s = stat ( ) in let res = s . live_words in set c ; res let with_big_compacts f v = let used_before = used_words ( ) in Spotlib . Spot . Exn . p... |
let tnb data = try int_of_string ( List . hd ( String . split ' \ 000 ' data ) ) with _ -> 0 |
let do_test xb = let i = ref 0 in let disp op pkt = let tid , rid , ty , data = pkt in printf " % 3x % s % d ( % d ) % s " \% s " . \\ n " %! ! i op tid rid ( Xb . Op . to_string ty ) ( String . escaped data ) ; flush ( stdout ) ; in let y ( tid , ty , data... |
let ( ) = let xb = open_xb ( ) in finally ( fun ( ) -> do_test xb ) ( fun ( ) -> close_xb xb ) ; |
module type XStringSig = sig type xstring = UChar . t XArray . t val get : xstring -> int -> UChar . t val set : xstring -> int -> UChar . t -> unit val length : xstring -> int type index val look : xstring -> index -> UChar . t val nth : xstring -> int -> index val first : xstring -> index val ... |
module XStringAux : XStringSig = struct include XArray type xstring = UChar . t XArray . t let rec compare_aux i t1 t2 = if i >= length t1 then if i >= length t2 then 0 else ~- 1 else if i >= length t2 then 1 else match UChar . compare ( XArray . get t1 i ) i ( XArray . get t2 i ) i with 0 -... |
let init len f = XArray . init len ( UChar . chr_of_uint 0 ) 0 f |
module Buf = struct include XStringAux type buf = xstring let create bufsize = make ~ bufsize 0 ( UChar . chr_of_uint 0 ) 0 let contents x = x let add_string = add_xstring let add_buffer = add_xstring end |
module String = struct include String let of_char c = String . make 1 c let rev_map f string = let n = length string in String . init n ( fun i -> f string . [ n - i - 1 ] ) let rev_iter f string = for i = length string - 1 downto 0 do f string . [ i ] done let fold_left f accu string ... |
let test_boolean tested_f ( name , case , expected ) = let check ( ) = Alcotest . ( check bool ) name expected ( tested_f case ) in ( name , ` Quick , check ) |
let test_string tested_f ( name , case , expected ) = let check ( ) = Alcotest . ( check string ) name expected ( tested_f case ) in ( name , ` Quick , check ) |
let test_list tested_f ( name , case , expected ) = let check ( ) = Alcotest . ( check @@ list string ) name expected ( tested_f case ) in ( name , ` Quick , check ) |
let test_rev_map = let spec_rev = [ ( " " , " " ) ; ( " foo bar " , " rab oof " ) ] in let spec_func = [ ( " id " , Fun . id ) ; ( " uppercase_ascii " , Char . uppercase_ascii ) ] in let test ( f_name , f ) ( case , expected ) = let expecte... |
let test_split = let test ? limit ( splitter , splitted , expected ) = let split , name = match limit with | None -> let name = Printf . sprintf { ' |% c ' splits " % s " } | splitter splitted in let split = XString . split ~ limit ( :- 1 ) in ( split , name ) | Some l... |
let test_split_f = let specs = [ ( XString . isspace , " foo bar " , [ " foo " ; " bar " ] ) ; ( XString . isspace , " foo bar " , [ " foo " ; " bar " ] ) ; ( XString . isspace , " foo \ n \ t \ r bar " , [ " foo " ; " bar " ] ... |
let test_has_substr = let spec = [ ( " " , " " , true ) ; ( " " , " foo bar " , true ) ; ( " f " , " foof " , true ) ; ( " foofo " , " foof " , false ) ; ( " foof " , " foof " , true ) ; ( " f " , " foof " , true... |
let test_startswith = let spec = [ ( " " , " " , true ) ; ( " " , " foo bar " , true ) ; ( " foofo " , " foof " , false ) ; ( " foof " , " foof " , true ) ; ( " f " , " foof " , true ) ; ( " fo " , " foof " , tru... |
let test_endswith = let spec = [ ( " " , " " , true ) ; ( " " , " foo bar " , true ) ; ( " ofoof " , " foof " , false ) ; ( " foof " , " foof " , true ) ; ( " f " , " foof " , true ) ; ( " fo " , " foof " , false... |
let test_rtrim = let spec = [ ( " " , " " ) ; ( " \ n " , " " ) ; ( " \ n \ n " , " \ n " ) ; ( " \ n " , " \ n " ) ; ( " foo \ n " , " foo " ) ; ( " fo \ no " , " fo \ no " ) ] in let test ( case , expected... |
let ( ) = Alcotest . run " Xstringext " [ test_rev_map ; test_split ; test_split_f ; test_has_substr ; test_startswith ; test_endswith ; test_rtrim ] |
let ( |> ) a b = b a |
let getdomainpath domid client = immediate client ( fun xs -> getdomainpath xs domid ) >>= fun dom_path -> return ( prefix ^ dom_path ) |
let readdir d client = Lwt . catch ( fun ( ) -> immediate client ( fun xs -> directory xs d ) ) ( function | Xs_protocol . Enoent _ -> return [ ] | e -> Lwt . fail e ) |
let read_opt path xs = Lwt . catch ( fun ( ) -> read xs path >>= fun x -> Lwt . return ( Some x ) ) ( function | Xs_protocol . Enoent _ -> return None | e -> Lwt . fail e ) |
let exists path xs = read_opt path xs >|= ( fun x -> x <> None ) |
module Device = struct type kind = Vif | Vbd | Tap | Pci | Vfs | Vfb | Vkbd let kind_of_string = function | " vif " -> Some Vif | " vbd " -> Some Vbd | " tap " -> Some Tap | " pci " -> Some Pci | " vfs " -> Some Vfs | " vfb " -> Some Vfb | " vkbd " -> Some Vkbd | x -... |
module Domain = struct let make domid client = getdomainpath domid client >>= fun dom_path -> let uuid = Printf . sprintf " uuid -% d " domid in let name = " name " in let vm_path = prefix ^ " / vm " / ^ uuid in let vss_path = prefix ^ " / vss " / ^ uuid in let xsdata = [ " xsdat... |
let vm_shutdown domid client = Domain . shutdown domid ( ) client >>= fun _ -> Domain . destroy domid client |
let vm_start domid client = let vbd devid = { Device . frontend = { Device . domid = domid ; kind = Device . Vbd ; devid = 0 } ; backend = { Device . domid = 0 ; kind = Device . Vbd ; devid = 0 } } in Domain . make domid client >>= fun ( ) -> Lwt_list . iter_s ( ... |
let vm_cycle domid client = vm_start domid client >>= fun ( ) -> vm_shutdown domid client |
let rec between start finish = if start > finish then [ ] else start :: ( between ( start + 1 ) finish ) |
let sequential n client : unit Lwt . t = Lwt_list . iter_s ( fun domid -> vm_cycle domid client ) ( between 0 n ) |
let parallel n client = Lwt_list . iter_p ( fun domid -> vm_cycle domid client ) ( between 0 n ) |
let query m n client = Lwt_list . iter_s ( fun domid -> vm_start domid client ) ( between 0 n ) >>= fun ( ) -> let rec loop i = if i = m then Lwt . return_unit else begin Lwt_list . iter_p ( fun domid -> immediate client ( fun xs -> read xs ( Printf . sprintf " % s / local / doma... |
let time f = let start = Unix . gettimeofday ( ) in f ( ) >>= fun ( ) -> return ( Unix . gettimeofday ( ) . - start ) |
let usage ( ) = let bin x = Sys . argv . ( 0 ) ^ x in let lines = [ bin " : a xenstore benchmark tool " ; " " ; " Usage " ; : bin " [ - path / var / run / xenstored / socket ] [ - n number of vms ] " ; ] in List . iter ( fun x -> Printf . fprintf stder... |
let main ( ) = let verbose = ref false in let args = Sys . argv |> Array . to_list |> List . tl in if List . mem " - h " args then begin usage ( ) ; return ( ) ; end else begin verbose := List . mem " - v " args ; let args = List . filter ( fun x -> x <> " - v " )... |
let _ = Lwt_main . run ( main ( ) ) |
let ( |> ) a b = b a |
type expr = | Val of string | Not of expr | And of expr * expr | Or of expr * expr | Eq of expr * expr |
let rec pretty_print ( ) = let open Format in function | Val x -> sprintf " " \% s " " \ x | Not x -> sprintf " Not ( [ @% a ] ) " @ pretty_print x | And ( x , y ) -> sprintf " And ( [ @% a , @ % a ] ) " @ pretty_print x pretty_print y | Or ( x , y ) ->... |
let rec to_conjunction = function | And ( x , y ) -> ( to_conjunction x ) @ ( to_conjunction y ) | Eq ( Val k , Val v ) -> [ k , v ] | _ -> raise Invalid_expression |
let parse_expr s = let open Genlex in let keywords = [ " ( " ; " ) " ; " not " ; " " ; = " and " ; " or " ] in let flatten s = let to_list s = let result = ref [ ] in Stream . iter ( fun x -> result := x :: ! result ) s ; List . rev ! result in let iden... |
let rec eval_expression expr xs = match expr with | Val path -> Lwt . catch ( fun ( ) -> read xs path >>= fun _k -> return true ) ( function Enoent _ -> return false | e -> Lwt . fail e ) | Not a -> eval_expression a xs >>= fun a ' -> return ( not ( a ' ) ) | And ( a , b ... |
let usage ( ) = let bin x = Sys . argv . ( 0 ) ^ x in let lines = [ bin " : a xenstore protocol client " ; " " ; " Usage " ; : bin " [ - path / var / run / xenstored / socket ] [ - restrict domid ] < subcommand > [ args ] " ; " " ; " Where < subc... |
let main ( ) = let verbose = ref false in let args = Sys . argv |> Array . to_list |> List . tl in if List . mem " - h " args then begin usage ( ) ; return ( ) ; end else begin verbose := List . mem " - v " args ; let args = List . filter ( fun x -> x <> " - v " )... |
let _ = Lwt_main . run ( main ( ) ) |
module type IO = sig type ' a t = ' a Lwt . t val return : ' a -> ' a t val ( >>= ) : ' a t -> ( ' a -> ' b t ) -> ' b t type backend = [ ` xen | ` unix ] val backend : backend type channel val create : unit -> channel t val destroy : channel -> unit t val read : chann... |
module type S = sig type client val make : unit -> client Lwt . t val suspend : client -> unit Lwt . t val resume : client -> unit Lwt . t type handle val immediate : client -> ( handle -> ' a Lwt . t ) -> ' a Lwt . t val transaction : client -> ( handle -> ' a Lwt . t ) -> ' ... |
let ( |> ) a b = b a |
let ( ++ ) f g x = f ( g x ) |
module Watcher = struct type t = { mutable paths : StringSet . t ; mutable cancelling : bool ; c : unit Lwt_condition . t ; m : Lwt_mutex . t ; } let make ( ) = { paths = StringSet . empty ; cancelling = false ; c = Lwt_condition . create ( ) ; m = Lwt_mutex . create (... |
module Client = functor ( IO : IO with type ' a t = ' a Lwt . t ) -> struct module PS = PacketStream ( IO ) type client = { mutable transport : IO . channel ; ps : PS . stream ; rid_to_wakeup : ( int32 , Xs_protocol . t Lwt . u ) Hashtbl . t ; mutable dispatcher_thread : ... |
let finally f g = try let result = f ( ) in g ( ) ; result with e -> g ( ) ; raise e |
let with_mutex m f = Mutex . lock m ; finally f ( fun ( ) -> Mutex . unlock m ) |
let find_opt h x = if Hashtbl . mem h x then Some ( Hashtbl . find h x ) else None |
module type IO = sig type ' a t = ' a val return : ' a -> ' a t val ( >>= ) : ' a t -> ( ' a -> ' b t ) -> ' b t type channel val create : unit -> channel t val destroy : channel -> unit t val read : channel -> string -> int -> int -> int t val write : channel -> string -> i... |
let ( |> ) a b = b a |
let ( ++ ) f g x = f ( g x ) |
module Watcher = struct type t = { mutable paths : StringSet . t ; mutable cancelling : bool ; c : Condition . t ; m : Mutex . t ; } let make ( ) = { paths = StringSet . empty ; cancelling = false ; c = Condition . create ( ) ; m = Mutex . create ( ) ; } let pu... |
module Task = struct type ' a u = { mutable thing : ' a option ; mutable cancelling : bool ; mutable on_cancel : unit -> unit ; m : Mutex . t ; c : Condition . t } let make ( ) = { thing = None ; cancelling = false ; on_cancel = ( fun ( ) -> ( ) ) ; m = Mutex . ... |
type watch_callback = string * string -> unit |
let startswith prefix x = let prefix ' = String . length prefix and x ' = String . length x in x ' >= prefix ' && ( String . sub x 0 prefix ' ) = prefix |
module Client = functor ( IO : IO with type ' a t = ' a ) -> struct module PS = PacketStream ( IO ) let logger = ref ( fun s -> let _ : string = s in ( ) ) let error fmt = Printf . kprintf ! logger fmt let set_logger f = logger := f type client = { transport : IO . channel ; ... |
module StringSet = Set . Make ( struct type t = string let compare = compare end ) |
type ' a t = { client : ' a ; tid : int32 ; mutable accessed_paths : StringSet . t option ; mutable watched_paths : StringSet . t ; } |
let make client = { client = client ; tid = 0l ; accessed_paths = None ; watched_paths = StringSet . empty } |
let get_tid h = h . tid |
let get_client h = h . client |
let no_transaction client = make client |
let transaction client tid = { ( make client ) with tid = tid } |
let watching client = { ( make client ) with accessed_paths = Some StringSet . empty } |
let accessed_path h path = match h . accessed_paths with | None -> h | Some ps -> h . accessed_paths <- Some ( StringSet . add path ps ) ; h |
let get_accessed_paths h = match h . accessed_paths with | None -> StringSet . empty | Some xs -> xs |
let watch h path = h . watched_paths <- StringSet . add path h . watched_paths ; h |
let unwatch h path = h . watched_paths <- StringSet . remove path h . watched_paths ; h |
let get_watched_paths h = h . watched_paths |
let ( |> ) f g = g f |
let ( ++ ) f g x = f ( g x ) |
module Op = struct type t = | Debug | Directory | Read | Getperms | Watch | Unwatch | Transaction_start | Transaction_end | Introduce | Release | Getdomainpath | Write | Mkdir | Rm | Setperms | Watchevent | Error | Isintroduced | Resume | Set_target | Restrict |
let on_the_wire = [ | Debug ; Directory ; Read ; Getperms ; Watch ; Unwatch ; Transaction_start ; Transaction_end ; Introduce ; Release ; Getdomainpath ; Write ; Mkdir ; Rm ; Setperms ; Watchevent ; Error ; Isintroduced ; Resume ; Set_target ; Restrict ] | |
let of_int32 i = let i = Int32 . to_int i in if i >= 0 && i < Array . length on_the_wire then Some ( on_the_wire . ( i ) ) else None |
let to_int32 x = match snd ( Array . fold_left ( fun ( idx , result ) v -> if x = v then ( idx + 1 , Some idx ) else ( idx + 1 , result ) ) ( 0 , None ) on_the_wire ) with | None -> assert false | Some i -> Int32 . of_int i |
let to_string = function | Debug -> " debug " | Directory -> " directory " | Read -> " read " | Getperms -> " getperms " | Watch -> " watch " | Unwatch -> " unwatch " | Transaction_start -> " transaction_start " | Transaction_end -> " transaction_end " | Introduce -> "... |
let rec split_string ? limit ( : limit ( =- 1 ) ) c s = let i = try String . index s c with Not_found -> - 1 in let nlimit = if limit = - 1 || limit = 0 then limit else limit - 1 in if i = - 1 || nlimit = 0 then [ s ] else let a = String . sub s 0 i and b = String . sub s ( ... |
module ACL = struct type perm = | NONE | READ | WRITE | RDWR let char_of_perm = function | READ -> ' r ' | WRITE -> ' w ' | RDWR -> ' b ' | NONE -> ' n ' let perm_of_char = function | ' r ' -> Some READ | ' w ' -> Some WRITE | ' b ' -> Some RDWR | ' n ' -> Some NO... |
type t = { tid : int32 ; rid : int32 ; ty : Op . t ; len : int ; data : Buffer . t ; } uint32_t ty ; uint32_t rid ; uint32_t tid ; uint32_t len |
let to_string pkt = let header = Cstruct . create sizeof_header in let len = Int32 . of_int ( Buffer . length pkt . data ) in let ty = Op . to_int32 pkt . ty in set_header_ty header ty ; set_header_rid header pkt . rid ; set_header_tid header pkt . tid ; set_header_len header len ; Cstru... |
let get_tid pkt = pkt . tid |
let get_ty pkt = pkt . ty |
let get_data pkt = if pkt . len > 0 && Buffer . nth pkt . data ( pkt . len - 1 ) = ' \ 000 ' then Buffer . sub pkt . data 0 ( pkt . len - 1 ) else Buffer . contents pkt . data |
let get_rid pkt = pkt . rid |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.