text
stringlengths
12
786k
let scheme uri = get_decoded_opt uri . scheme
let with_scheme uri = function | Some scheme -> { uri with scheme = Some ( Pct . cast_decoded scheme ) } | None -> { uri with scheme = None }
let host uri = get_decoded_opt uri . host
let with_host uri = function | Some host -> { uri with host = Some ( Pct . cast_decoded host ) } | None -> { uri with host = None }
let host_with_default ( ? default " = localhost " ) uri = match host uri with | None -> default | Some h -> h
let userinfo uri = match uri . userinfo with | None -> None | Some userinfo -> Some ( Pct . uncast_encoded ( match uri . scheme with | None -> encoded_of_userinfo userinfo | Some s -> encoded_of_userinfo ~ scheme ( : Pct . uncast_decoded s ) userinfo ) )
let with_userinfo uri userinfo = let userinfo = match userinfo with | Some u -> Some ( userinfo_of_encoded u ) | None -> None in match host uri with | None -> { uri with host = Some ( Pct . cast_decoded " " ) ; userinfo = userinfo } | Some _ -> { uri with userinfo = userinfo }
let user uri = match uri . userinfo with | None -> None | Some ( user , _ ) -> Some user
let password uri = match uri . userinfo with | None | Some ( _ , None ) -> None | Some ( _ , Some pass ) -> Some pass
let with_password uri password = let result userinfo = match host uri with | None -> { uri with host = Some ( Pct . cast_decoded " " ) ; userinfo = userinfo } | Some _ -> { uri with userinfo = userinfo } in match uri . userinfo , password with | None , None -> uri | None , Some ...
let port uri = uri . port
let with_port uri port = match host uri with | Some _ -> { uri with port = port } | None -> begin match port with | None -> { uri with host = None ; port = None } | Some _ -> { uri with host = Some ( Pct . cast_decoded " " ) ; port = port } end
let path uri = Pct . uncast_encoded ( match uri . scheme with | None -> encoded_of_path uri . path | Some s -> encoded_of_path ~ scheme ( : Pct . uncast_decoded s ) uri . path )
let with_path uri path = let path = path_of_encoded path in match host uri , path with | None , _ | Some _ , " " /:: _ | Some _ , [ ] -> { uri with path = path } | Some _ , _ -> { uri with path " " =/:: path }
let fragment uri = get_decoded_opt uri . fragment
let with_fragment uri = function | None -> { uri with fragment = None } | Some frag -> { uri with fragment = Some ( Pct . cast_decoded frag ) }
let query uri = Query . kv uri . query
let verbatim_query uri = Query . ( match uri . query with | Raw ( qs , _ ) -> qs | KV [ ] -> None | KV kv -> Some ( encoded_of_query ? scheme ( : scheme uri ) kv ) )
let get_query_param ' uri k = Query . ( find ( kv uri . query ) k )
let get_query_param uri k = match get_query_param ' uri k with | None -> None | Some v -> Some ( String . concat " , " v )
let with_query uri query = { uri with query = Query . KV query }
let q_s q = List . map ( fun ( k , v ) -> k , [ v ] ) q
let with_query ' uri query = with_query uri ( q_s query )
let add_query_param uri p = Query . ( { uri with query = KV ( p ( :: kv uri . query ) ) } )
let add_query_param ' uri ( k , v ) = Query . ( { uri with query = KV ( ( k , [ v ] ) ( :: kv uri . query ) ) } )
let add_query_params uri ps = Query . ( { uri with query = KV ( ps ( @ kv uri . query ) ) } )
let add_query_params ' uri ps = Query . ( { uri with query = KV ( ( q_s ps ) ( @ kv uri . query ) ) } )
let remove_query_param uri k = Query . ( { uri with query = KV ( List . filter ( fun ( k ' , _ ) -> k <> k ' ) ( kv uri . query ) ) } )
let with_uri ? scheme ? userinfo ? host ? port ? path ? query ? fragment uri = let with_path_opt u o = match o with | None -> with_path u " " | Some p -> with_path u p in let with_query_opt u o = match o with | None -> with_query u [ ] | Some q -> with_query u q in let with_ f o u = match o w...
let path_and_query uri = match ( path uri ) , ( query uri ) with " " , | [ ] -> " " / " " , | q -> let scheme = uncast_opt uri . scheme in Printf . sprintf " /?% s " ( encoded_of_query ? scheme q ) | p , [ ] -> p | p , q -> let scheme = uncast_opt uri . ...
let resolve schem base uri = let schem = Some ( Pct . cast_decoded ( match scheme base with | None -> schem | Some scheme -> scheme ) ) in normalize schem Path . ( match scheme uri , userinfo uri , host uri with | Some _ , _ , _ -> { uri with path = remove_dot_segments uri . path }...
let canonicalize uri = let uri = resolve " " empty uri in let module Scheme = ( val ( module_of_scheme ( uncast_opt uri . scheme ) ) : Scheme ) in { uri with port = Scheme . canonicalize_port uri . port ; path = Scheme . canonicalize_path uri . path ; }
let pp ppf uri = Format . pp_print_string ppf ( to_string uri )
let pp_hum ppf uri = Format . pp_print_string ppf ( to_string uri )
open Re module Raw = struct let ( ) + a b = seq [ a ; b ] let ( ) / a b = alt [ a ; b ] let sub_delims = Posix . re " [ ' ( ) , ; ] " !$&*+= let c_at = char ' ' @ let c_colon = char ' ' : let c_dot = char ' . ' let unreserved = Posix . re " [ A -...
let search_string keys k = let rec loop keys k low high = if low > high then ( - 1 ) else begin let mid = ( high + low ) / 2 in let diff = String . compare k keys . ( mid ) in if diff < 0 then loop keys k low ( mid - 1 ) else if diff > 0 then loop keys k ( mid + 1 ) high else m...
let search_int keys k = let rec loop keys k low high = if low > high then ( - 1 ) else begin let mid = ( high + low ) / 2 in let diff = k - keys . ( mid ) in if diff < 0 then loop keys k low ( mid - 1 ) else if diff > 0 then loop keys k ( mid + 1 ) high else mid end in loop keys...
let lookup search ( keys , values ) k = let i = search keys k in if i < 0 then [ ] else values . ( i )
let service_of_tcp_port p = lookup search_int service_of_tcp_port_tables p
let service_of_udp_port p = lookup search_int service_of_udp_port_tables p
let tcp_port_of_service s = lookup search_string tcp_port_of_service_tables s
let udp_port_of_service s = lookup search_string udp_port_of_service_tables s
let port_of_uri ? default lookupfn uri = match Uri . port uri with | Some _port as x -> x | None -> begin match Uri . scheme uri , default with | None , None -> None | None , Some scheme | Some scheme , _ -> begin match lookupfn scheme with [ ] | -> None | hd :: _ -> Some hd end end
let tcp_port_of_uri ? default uri = port_of_uri ? default tcp_port_of_service uri
let udp_port_of_uri ? default uri = port_of_uri ? default udp_port_of_service uri
module Derived = struct | ` Generic | ` Custom of ( component * string * string ) scheme : string option [ @ default None ] [ @ sexp_drop_default . sexp ] ; userinfo : string option [ @ default None ] [ @ sexp_drop_default . sexp ] ; host : string option [ @ default None ]...
let t_of_sexp sexp = Uri . make ? scheme : t . scheme ? userinfo : t . userinfo ? host : t . host ? port : t . port ~ path : t . path ~ query : t . query ? fragment : t . fragment ( )
let sexp_of_t t = }
let compare a b = Uri . compare a b
let equal a b = Uri . equal a b
let resolve url_to_string directories reference = let resolver = Resolver . create ~ important_digests : false ~ directories ~ open_modules [ ] : in let reference = let open Odoc_model in let warnings_options = { Error . warn_error = true ; print_warnings = true } in Semantics . parse_referen...
let reference_to_url_html root_url = let url_to_string url = let base = match root_url with | None | Some " " -> " " | Some base -> if base . [ String . length base - 1 ] = ' ' / then base else base ^ " " / in Odoc_html . Link . ( href ~ resolve ( : Base base ) url ) ...
let reference_to_url_latex = let url_to_string url = Odoc_latex . Generator . Link . label url in resolve url_to_string
let rec map_html_hrefs f html = List . ( rev ( rev_map ( map_html_element_hrefs f ) html ) ) | Nethtml . Data _ as d -> d | Nethtml . Element ( ( " a " | " link " ) as e , args , sub ) -> let href , args = List . partition ( fun ( a , _ ) -> a = " href " ...
let map_html_file f in_file out_file = let fh = open_in in_file in let html = Nethtml . parse_document ( Lexing . from_channel fh ) ~ dtd : Utils . relaxed_html40_dtd in close_in fh ; let html = map_html_hrefs f html in let fh = open_out out_file in let out = new Netchannels . output_channel fh in...
let map_css_file f in_file out_file = let fh = open_in in_file in let ch = new Netchannels . input_channel fh in let css = Netchannels . string_of_in_obj_channel ch in close_in fh ; let url_re = Str . regexp " url ( ( [ ( ) ] ) ) " \\^*\\ in let css = Str . global_substitute url_re ...
let map_file f in_file out_file = if Filename . check_suffix in_file " . html " || Filename . check_suffix in_file " . xhtml " then map_html_file f in_file out_file else if Filename . check_suffix in_file " . css " then map_css_file f in_file out_file else raise ( Unknown_file_type in_file )...
let rec remove_common_prefix p1 p2 = match p1 , p2 with | d1 :: p1 , d2 :: p2 when d1 = d2 -> remove_common_prefix p1 p2 | _ -> p1 , p2
let revert_path = let rec revert filename = match filename with | [ ] | [ _ ] -> [ ] | _ :: tl -> " . . " :: revert tl in fun to_base filename -> let filename = Neturl . norm_path ( Neturl . split_path filename ) in let to_base , filename = remove_common_prefix to_base filena...
match xs with | [ ] -> ys | x :: xs -> x :: append xs ys } ] | | [ ] -> [ ] | xs :: xss -> append xs ( flatten xss ) ^^^^^^^^^^^^^^^^^^^^^^^ } ] | | [ ] -> [ ] | xs :: xss -> let [ @ tail_mod_cons ] rec append_flatten xs xss = match xs with | [ ] -> flatten...
let rec flatten = function | [ ] -> [ ] | xs :: xss -> let [ @ tail_mod_cons ] rec append_flatten xs xss = match xs with | [ ] -> flatten xss | x :: xs -> x :: append_flatten xs xss in append_flatten xs xss ^^^^^^^^^^^ } ] |
module Tail_calls_to_non_specialized_functions = struct let list_id = function | [ ] -> [ ] | x :: xs -> x :: xs let [ @ tail_mod_cons ] rec filter_1 f li = match li with | [ ] -> [ ] | x :: xs -> if f x then x :: filter_1 f xs else list_id ( filter_1 f xs ) let [ @ tail_mod_c...
module Tail_calls_to_non_specialized_functions : sig val list_id : ' a list -> ' a list val filter_1 : ( ' a -> bool ) -> ' a list -> ' a list val filter_2 : ( ' a -> bool ) -> ' a list -> ' a list end } ] |
module All_annotations_correctly_used = struct type ' a t = | N of ' a | Graft of int | Tau of ' a t | C of ' a t * ' a t let [ @ inline never ] rec graft n = graft n let [ @ tail_mod_cons ] rec map f l = match l with | N v -> N ( f v ) | Graft n -> if n >= 0 then ( graft [ @...
module All_annotations_correctly_used : sig type ' a t = N of ' a | Graft of int | Tau of ' a t | C of ' a t * ' a t val graft : ' a -> ' b val map : ( ' a -> ' b ) -> ' a t -> ' b t end } ] |
module All_annotations_flipped = struct type ' a t = | N of ' a | Graft of int | Tau of ' a t | C of ' a t * ' a t let [ @ inline never ] rec graft n = graft n let [ @ tail_mod_cons ] rec map_wrong f l = match l with | N v -> N ( f v ) | Graft n -> if n >= 0 then ( graft [ @ ...
module All_annotations_flipped : sig type ' a t = N of ' a | Graft of int | Tau of ' a t | C of ' a t * ' a t val graft : ' a -> ' b val map_wrong : ( ' a -> ' b ) -> ' a t -> ' b t end } ] |
module Uint8 = struct type t = int let pp ppf t = Format . fprintf ppf " 0x % 02X " t let of_int i = if i < 0 then invalid_arg " out of range " else if i > 255 then invalid_arg " out of range " else i external add : t -> t -> t * bool = " caml__uint8_add_overflow " external mul : t -...
module Uint16 = struct type t = int let pp ppf t = Format . fprintf ppf " 0x % 04X " t let of_int i = if i < 0 then invalid_arg " out of range " else if i > 65535 then invalid_arg " out of range " else i external add : t -> t -> t * bool = " caml__uint16_add_overflow " external mul : ...
module Uint32 = struct type t = int32 let pp ppf t = Format . fprintf ppf " 0x % 08lX " t let of_int i = if i < 0 then invalid_arg " out of range " else if i > 2 * Int32 . ( to_int max_int ) + 1 then invalid_arg " out of range " else Int32 . of_int i let to_int t = if Sys . word_s...
module Uint64 = struct type t = int64 let pp ppf t = Format . fprintf ppf " 0x % 016LX " t let of_int i = if i < 0 then invalid_arg " out of range " else Int64 . of_int i let to_int t = if Sys . word_size <= 64 && t < 0L then None else if t < 0L then Some Int64 . ( to_int ( add t mi...
module Logging = struct type log_opts = { log_conns : bool ; log_async_exn : bool ; log_plugged_inout : bool ; log_everything_else : bool } bool let ( conn_section , async_exn , plugged_inout , everything_else ) everything_else = Lwt_log . Section . make " connections " , Lwt_log . Secti...
let byte_swap_16 value = ( ( value land 0xFF ) 0xFF lsl 8 ) 8 lor ( ( value lsr 8 ) 8 land 0xFF ) 0xFF
module Protocol = struct type msg_version_t = Binary | Plist type conn_code = Success | Device_requested_not_connected | Port_requested_not_available | Malformed_request type event = Attached of device_t | Detached of int and device_t = { serial_number : string ; connection_speed : int ; connection_ty...
module Relay = struct type action = Shutdown | Reload type tunnel = { udid : string ; name : string option ; forwarding : forward list ; } [ @@ deriving of_yojson ] of_yojson and forward = { local_port : int ; device_port : int ; } type exn += Client_closed | Mapping_file_error of str...
type t = { id : Common . id ; bio : string mc_option ; birthday : Common . calendar_us_date mc_option ; email : string mc_option ; first_name : string mc_option ; gender : string mc_option ; is_verified : bool mc_option ; last_name : string mc_option ; link : Common . uri mc_option ; ...
module Home = struct end end end type t = { id : Common . id ; name : string ; category : string mc_option ; } [ @@ conv . ignore_unknown_fields ] [ @@ deriving conv { json } ] end | Application [ @ conv . as " application " ] | Event [ @ conv . as " event " ] en...
module Feed = struct module ReadResponse : Common . PagedResponse with type data = Home . Post . t = struct type data = Home . Post . t [ @@ deriving conv { json } ] type cursors = { after : string ; before : string ; } [ @@ conv . ignore_unknown_fields ] [ @@ deriving conv ...
module Posts = struct let read_permissions = [ " read_stream " ; ] module ReadResponse : Common . PagedResponse with type data = Home . Post . t = struct type data = Home . Post . t [ @@ deriving conv { json } ] type cursors = { after : string ; before : string ; } [ @@ ...
module Friends = struct let read_permissions = [ " user_friends " ] module ReadResponse : Common . PagedResponse with type data = t = struct type data = t [ @@ deriving conv { json } ] type cursors = { after : string ; before : string ; } [ @@ conv . ignore_unknown_fields ] [ ...
let section = Lwt_log . Section . make " ocsigen : ext : userconf "
let err_500 = Ocsigen_extensions . Ext_stop_site ( Ocsigen_cookie_map . empty , ` Internal_server_error ) Internal_server_error
let handle_parsing_error { Ocsigen_extensions . request_info ; _ } _ = function | Ocsigen_extensions . Error_in_config_file s -> Lwt_log . ign_error_f ~ section " Syntax error in userconf configuration file for url % s : % s " ( Uri . to_string ( Ocsigen_request . uri request_info ) req...
let subresult new_req user_parse_site conf previous_err req req_state = Ocsigen_extensions . Ext_sub_result ( fun cookies_to_set _rs -> Lwt . catch ( fun ( ) -> user_parse_site conf cookies_to_set ( Ocsigen_extensions . Req_not_found ( previous_err , new_req ) new_req ) new_req >>= fun ( an...
let conf_to_xml conf = try [ Xml . parse_file conf ] conf with | Sys_error _ -> raise NoConfFile | Xml . Error ( s , loc ) loc -> let begin_char , end_char = Xml . range loc and line = Xml . line loc in raise ( Ocsigen_extensions . Error_in_config_file ( Printf . sprintf " % s , line...
let gen hostpattern sitepath ( regexp , conf , url , prefix , localpath ) localpath = function | Ocsigen_extensions . Req_found _ -> Lwt . return Ocsigen_extensions . Ext_do_nothing | Ocsigen_extensions . Req_not_found ( previous_err , ( { Ocsigen_extensions . request_info ; request_con...
let parse_config _ hostpattern _ path _ _ config_elem = let regexp = ref None in let conf = ref None in let url = ref None in let prefix = ref None in let localpath = ref None in Ocsigen_extensions ( . Configuration . process_element ~ in_tag " : host " ~ other_elements ( : fun t _ _ -> raise ...
let ( ) = Ocsigen_extensions . register ~ name " : userconf " ~ fun_site : parse_config ( )
let ( ) |> x f = f x ; ;
let allocate how_many str_len = let l = ref [ ] in for _i = 1 to how_many do let s = Bytes . create str_len in l := s ( ::! l ) ; done ; ! l
let allocate_a_lot ( ) = allocate 499 99991
let allocate_many_small ( ) = allocate 99991 499
module LuaBookDir = struct let readdir ls = let handle : Unix . dir_handle = let w = Lua . touserdata ls 1 in match w with | Some ` Userdata h -> h | _ -> failwith " Dir handle expected " ! in try Lua . pushstring ls ( Unix . readdir handle ) ; 1 with End_of_file -> 0 let dir_gc ls =...
let closure ( ) = let l1 = LuaL . newstate ( ) in LuaL . openlibs l1 ; LuaBookDir . luaopen_dir l1 ; LuaL . loadbuffer l1 " handle = opendir ( " " ) \/\ d = readdir ( handle ) end match Lua . pcall l1 0 0 0 with | Lua . LUA_OK -> ( ) | _err -> begin Printf . prin...
let print_timings start_space start_wtime start_ptime = let end_ptime = Unix . times ( ) in let self_u = end_ptime . Unix . tms_utime . - start_ptime . Unix . tms_utime in let self_s = end_ptime . Unix . tms_stime . - start_ptime . Unix . tms_stime in let self = self_u . + self_s in ...
let run func args = Gc . compact ( ) ; let start_space = Gc . quick_stat ( ) in let start_wtime = Unix . time ( ) in let start_ptime = Unix . times ( ) in let ret = try func args with e -> print_timings start_space start_wtime start_ptime ; raise e in print_timings start_space start_wt...
let test_duration = 60 . 0 . * 10 . 0 ; ;
let time_start = Unix . gettimeofday ( ) ; ;
let main ( ) = while Unix . gettimeofday ( ) < time_start . + test_duration do closure ( ) |> ignore ; Printf . printf " Calling Gc . compact from OCaml . . . " ; %! Gc . compact ( ) ; Printf . printf " done !\ n " ; %! done ; Gc . compact ( ) ; ; ;
type upgrades = ( Int32 . t * Protocol_hash . t ) list