text
stringlengths
12
786k
let decoder_byte_count d = d . byte_count
let decoder_count d = d . count
let decoder_removed_bom d = d . removed_bom
let decoder_src d = d . src
let decoder_nln d = d . nln
let decoder_encoding d = d . encoding
let set_decoder_encoding d e = d . encoding <- ( e :> decoder_encoding ) ; d . k <- decode_fun e
type dst = [ ` Channel of out_channel | ` Buffer of Buffer . t | ` Manual ]
type encode = [ ` Await | ` End | ` Uchar of Uchar . t ]
type encoder = { dst : dst ; encoding : encoding ; mutable o : Bytes . t ; mutable o_pos : int ; mutable o_max : int ; t : Bytes . t ; mutable t_pos : int ; mutable t_max : int ; mutable k : encoder -> encode -> [ ` Ok | ` Partial ] }
let o_rem e = e . o_max - e . o_pos + 1
let dst e s j l = if ( j < 0 || l < 0 || j + l > Bytes . length s ) then invalid_bounds j l ; e . o <- s ; e . o_pos <- j ; e . o_max <- j + l - 1
let partial k e = function ` Await -> k e | ` Uchar _ | ` End -> invalid_encode ( )
let flush k e = match e . dst with let o = Bytes . unsafe_to_string e . o in Buffer . add_substring b o 0 e . o_pos ; e . o_pos <- 0 ; k e
let t_range e max = e . t_pos <- 0 ; e . t_max <- max
let rec t_flush k e = let blit e l = unsafe_blit e . t e . t_pos e . o e . o_pos l ; e . o_pos <- e . o_pos + l ; e . t_pos <- e . t_pos + l in let rem = o_rem e in let len = e . t_max - e . t_pos + 1 in if rem < len then ( blit e rem ; flush ( t_flush k ) e ) else ( blit...
let rec encode_utf_8 e v = let k e = e . k <- encode_utf_8 ; ` Ok in match v with | ` Await -> k e | ` End -> flush k e | ` Uchar u as v -> let u = Uchar . to_int u in let rem = o_rem e in if u <= 0x007F then if rem < 1 then flush ( fun e -> encode_utf_8 e v ) e else ( unsafe_set_byt...
let rec encode_utf_16be e v = let k e = e . k <- encode_utf_16be ; ` Ok in match v with | ` Await -> k e | ` End -> flush k e | ` Uchar u -> let u = Uchar . to_int u in let rem = o_rem e in if u < 0x10000 then begin let s , j , k = if rem < 2 then ( t_range e 1 ; e . t , 0 , ...
let rec encode_utf_16le e v = let k e = e . k <- encode_utf_16le ; ` Ok in match v with | ` Await -> k e | ` End -> flush k e | ` Uchar u -> let u = Uchar . to_int u in let rem = o_rem e in if u < 0x10000 then begin let s , j , k = if rem < 2 then ( t_range e 1 ; e . t , 0 , ...
let encoder encoding dst = let o , o_pos , o_max = match dst with | ` Manual -> Bytes . empty , 1 , 0 | ` Buffer _ | ` Channel _ -> Bytes . create io_buffer_size , 0 , io_buffer_size - 1 in { dst = ( dst :> dst ) ; encoding = ( encoding :> encoding ) ; o ; o_pos ;...
let encode e v = e . k e ( v :> encode )
let encoder_encoding e = e . encoding
let encoder_dst e = e . dst
module Manual = struct let src = src let dst = dst let dst_rem = o_rem end
module String = struct let encoding_guess s = let s = Bytes . unsafe_of_string s in match r_encoding s 0 ( max ( Bytes . length s ) 3 ) with | ` UTF_8 d -> ` UTF_8 , ( d = ` BOM ) | ` UTF_16BE d -> ` UTF_16BE , ( d = ` BOM ) | ` UTF_16LE d -> ` UTF_16LE , ( d = ...
module Buffer = struct let add_utf_8 b u = let u = Uchar . to_int u in let w byte = Buffer . add_char b ( unsafe_chr byte ) in if u <= 0x007F then ( w u ) else if u <= 0x07FF then ( w ( 0xC0 lor ( u lsr 6 ) ) ; w ( 0x80 lor ( u land 0x3F ) ) ) else if u <= 0xFFFF then ( ...
type ' a result = Ok of ' a | Error of error
type status = unit result
let ok : status = Ok ( )
let ok_exn = function Ok a -> a | Error e -> failwith ( error_to_string e )
let int_to_status = function i when i = 0 -> ok | i when i < 0 -> Error ( Uv_consts . int_to_error i ) | _ -> failwith " This should never happen . Status code returned > 0 . "
type iobuf = ( char , Bigarray . int8_unsigned_elt , Bigarray . c_layout ) Bigarray . Array1 . t
let make_buft buf = let buf_data = make C . uv_buf in let buf_ptr = bigarray_start array1 buf in let buf_len = Bigarray . Array1 . dim buf in let ( ) = setf buf_data C . _uv_buf_base buf_ptr in let ( ) = setf buf_data C . _uv_buf_len ( Unsigned . Size_t . of_int buf_len ) in buf_data
type timespec = { tv_sec : int64 ; tv_nsec : int64 }
let from_uv_timespec uv_t = let tv_sec = Signed . Long . to_int64 ( getf uv_t C . _tv_sec ) in let tv_nsec = Signed . Long . to_int64 ( getf uv_t C . _tv_nsec ) in { tv_sec ; tv_nsec }
module Loop = struct type t = C . uv_loop type run_mode = RunDefault | RunOnce | RunNoWait let run_mode_to_int = function RunDefault -> 0 | RunOnce -> 1 | RunNoWait -> 2 let default_loop = C . uv_default_loop let run ( ? loop = default_loop ( ) ) run_mode = let ret = C . uv_run loop ( ...
let default_loop = Loop . default_loop ( )
type stat = { st_dev : int64 ; st_mode : int64 ; st_nlink : int64 ; st_uid : int64 ; st_gid : int64 ; st_rdev : int64 ; st_ino : int64 ; st_size : int64 ; st_blksize : int64 ; st_blocks : int64 ; st_flags : int64 ; st_gen : int64 ; st_atim : timespec ; st_mtim : timespec ; s...
module Request = struct type ' a t = unit ptr type write_req type write = write_req t let cancel req = failwith " Not Implemented " end
module Handle = struct type ' a t = unit ptr let loop handle = let ptr = from_voidp C . uv_handle handle in C . get_uv_handle_t_loop ptr let close ? cb handle = let cb ' = match cb with None -> None | Some f -> Some ( fun x -> f ( to_voidp x ) ) in let handle_ptr = from_voidp C . uv_handle...
module Stream = struct type ' a stream type ' a t = ' a stream Handle . t let refs = Refcount . create ( ) let ref_incr = Refcount . incr refs let ref_decr = Refcount . decr refs let read_cb_refs = Refcount . create ( ) let read_cb_ref_incr = Refcount . incr read_cb_refs let read_cb_ref...
module Shutdown = struct type shutdown type t = shutdown Request . t end
module FS = struct type fs type t = fs Request . t type iobuf = ( char , Bigarray . int8_unsigned_elt , Bigarray . c_layout ) Bigarray . Array1 . t let c_to_ocaml data = to_voidp data let ocaml_to_c data = from_voidp C . uv_fs data let coatCheck = Coat_check . create ( ) let alloc_uv_fs ...
type mysock = C . uv_sockaddr structure ptr
let ip4_addr str_addr port = let data = addr ( make C . uv_sockaddr_in ) in let _ = C . uv_ip4_addr str_addr port data in coerce ( ptr C . uv_sockaddr_in ) ( ptr C . uv_sockaddr ) data
module TCP = struct type tcp type t = tcp Stream . t type connect type c = connect Request . t let alloc_uv_tcp ( ) = let memory = allocate_n char ~ count ( : sizeof C . uv_tcp ) in coerce ( ptr char ) ( ptr C . uv_tcp ) memory let alloc_uv_connect ( ) = let memory = allocate_n char...
let ( ) = Random . self_init ( )
let src = Logs . Src . create " guit - v " ~ doc " : logs binary event "
module Log = ( val Logs . src_log src : Logs . LOG )
let pad n x = if String . length x > n then x else x ^ String . make ( n - String . length x ) ' '
let pp_header ppf ( level , header ) = let level_style = match level with | Logs . App -> Logs_fmt . app_style | Logs . Debug -> Logs_fmt . debug_style | Logs . Warning -> Logs_fmt . warn_style | Logs . Error -> Logs_fmt . err_style | Logs . Info -> Logs_fmt . info_style in let lev...
let reporter ppf = let report src level ~ over k msgf = let k _ = over ( ) ; k ( ) in let with_src_and_stamp h _ k fmt = let dt = Mtime . Span . to_us ( Mtime_clock . elapsed ( ) ) in Fmt . kpf k ppf ( " % s % a % a : [ " @ ^^ fmt ^^ " ] . " ) @@ ( pad 10 (...
let setup_logs style_renderer level = let quiet = Option . is_none level in Fmt_tty . setup_std_outputs ? style_renderer ( ) ; Logs . set_level level ; Logs . set_reporter ( reporter Fmt . stderr ) ; quiet
let main quiet path = let root = match path with Some path -> path | None -> Fpath . v ( Sys . getcwd ( ) ) in let open Lwt . Infix in Store . v root >>= function | Ok _t when not quiet -> Fmt . pr " % a ready to be used as a Git store . \ n " %! Fpath . pp root ; Lwt . return_...
let main logs path = match Lwt_main . run ( main logs path ) with | Ok ( ) -> Ok ( ) | Error ( ` Msg err ) -> Error ( Fmt . str " % s . " err )
let fpath = Arg . conv ( Fpath . of_string , Fpath . pp )
let directory = let doc = " Indicate path to repository root containing ' . git ' folder " in Arg . ( value & opt ( some fpath ) None & info [ " r " ; " root " ] ~ doc ~ docv " :< directory " ) >
let setup_logs = let docs = Manpage . s_common_options in Term . ( const setup_logs $ Fmt_cli . style_renderer ~ docs ( ) $ Logs_cli . level ~ docs ( ) )
let command = let doc = " Make a Git repository . " in let info = Cmd . info " v " ~ doc in Cmd . v info Term . ( const main $ setup_logs $ directory )
let ( ) = exit @@ Cmd . eval_result command
type t = { name : string ; dest_dir : string ; ocamlc : string ; log : string -> unit ; mutable counter : int ; ext_obj : string ; c_compiler : string ; stdlib_dir : string ; ccomp_type : string ; c_libraries : string list ; ocamlc_config : Ocaml_config . Vars . t ; ocamlc_confi...
let rec rm_rf dir = Array . iter ( Sys . readdir dir ) ~ f ( : fun fn -> let fn = dir ^/ fn in if Sys . is_directory fn then rm_rf fn else Unix . unlink fn ) ; Unix . rmdir dir
module Temp = struct let prng = lazy ( Random . State . make_self_init ( ) ) let gen_name ~ temp_dir ~ prefix ~ suffix = let rnd = Random . State . bits ( Lazy . force prng ) land 0xFFFFFF in temp_dir ^/ Printf . sprintf " % s % 06x % s " prefix rnd suffix let create ~ prefix ...
module Flags = struct let extract_words = String . extract_words let extract_comma_space_separated_words = String . extract_comma_space_separated_words let extract_blank_separated_words = String . extract_blank_separated_words let write_lines path s = Io . write_lines path s let write_sexp path s = let se...
module Find_in_path = struct let path_sep = if Sys . win32 then ' ; ' else ' ' : let get_path ( ) = match Sys . getenv " PATH " with | exception Not_found -> [ ] | s -> String . split s ~ on : path_sep let exe = if Sys . win32 then " . exe " else " " let prog_not_found...
let logf t fmt = Printf . ksprintf t . log fmt
let gen_id t = let n = t . counter in t . counter <- n + 1 ; n
let quote_if_needed = let need_quote = function | ' ' | ' " ' \ -> true | _ -> false in fun s -> if String . is_empty s || String . exists ~ f : need_quote s then Filename . quote s else s
module Process = struct type result = { exit_code : int ; stdout : string ; stderr : string } let command_line prog args = String . concat ~ sep " : " ( List . map ( prog :: args ) ~ f : quote_if_needed ) let run_process t ? dir ? env prog args = let prog_command_line = command_li...
let ocaml_config_var t var = Ocaml_config . Vars . find t . ocamlc_config var
let ocaml_config_var_exn t var = match Ocaml_config . Vars . find t . ocamlc_config var with | None -> die " variable % S not found in the output of ` % s ` " var t . ocamlc_config_cmd | Some s -> s
type config = { ocamlc : string ; vars : Ocaml_config . Vars . t }
let dune_is_too_old ~ min : v = die " You seem to be running dune < % s . This version of dune - configurator \ requires at least dune % s . " v v
let read_dot_dune_configurator_file ~ build_dir = let file = Filename . concat build_dir " . dune / configurator . v2 " in if not ( Sys . file_exists file ) then dune_is_too_old ~ min " : 2 . 6 " ; let open Sexp in let unable_to_parse err = die " Unable to parse % S . . @% s . ...
let fill_in_fields_that_depends_on_ocamlc_config t = let get = ocaml_config_var_exn t in let get_flags var = get var |> String . trim |> Flags . extract_blank_separated_words in let c_compiler , c_libraries = match Ocaml_config . Vars . find t . ocamlc_config " c_compiler " with | Some c_comp ->...
let create_from_inside_dune ~ dest_dir ~ log ~ build_dir ~ name = let dest_dir = match dest_dir with | Some dir -> dir | None -> Temp . create_temp_dir ~ prefix " : ocaml - configurator " ~ suffix " " : in let { ocamlc ; vars = ocamlc_config } = read_dot_dune_configurator_file ~ build_...
let create ? dest_dir ? ocamlc ( ? log = ignore ) name = match ( ocamlc , Option . try_with ( fun ( ) -> Sys . getenv " INSIDE_DUNE " ) ) with | None , Some build_dir when build_dir <> " 1 " -> create_from_inside_dune ~ dest_dir ~ log ~ build_dir ~ name | _ -> let dest_d...
let need_to_compile_and_link_separately t = match t . ccomp_type with | " msvc " -> true | _ -> false
let compile_and_link_c_prog t ( ? c_flags = [ ] ) ( ? link_flags = [ ] ) code = let dir = t . dest_dir ^/ sprintf " c - test -% d " ( gen_id t ) in Unix . mkdir dir 0o777 ; let base = dir ^/ " test " in let c_fname = base ^ " . c " in let obj_fname = base ^ t . ...
let compile_c_prog t ( ? c_flags = [ ] ) code = let dir = t . dest_dir ^/ sprintf " c - test -% d " ( gen_id t ) in Unix . mkdir dir 0o777 ; let base = dir ^/ " test " in let c_fname = base ^ " . c " in let obj_fname = base ^ t . ext_obj in Io . write_file c_fname code ...
let c_test t ? c_flags ? link_flags code = match compile_and_link_c_prog t ? c_flags ? link_flags code with | Ok _ -> true | Error _ -> false
module C_define = struct module Type = struct type t = | Switch | Int | String let name = function | Switch -> " bool " | Int -> " int " | String -> " string " end module Value = struct type t = | Switch of bool | Int of int | String of string end let extract_program ? prelude includes va...
let which t prog = logf t " which : % s " prog ; let x = Find_in_path . which prog in logf t " -> % s " ( match x with | None -> " not found " | Some fn -> " found : " ^ quote_if_needed fn ) ; x
module Pkg_config = struct type nonrec t = { pkg_config : string ; configurator : t } let get c = Option . map ( which c " pkg - config " ) ~ f ( : fun pkg_config -> { pkg_config ; configurator = c } ) type package_conf = { libs : string list ; cflags : string list } let gen...
let main ( ? args = [ ] ) ~ name f = let build_dir = match Sys . getenv " INSIDE_DUNE " with | exception Not_found -> die " Configurator scripts must be run with Dune . To manually run a script , \ use $ dune exec . " | " 1 " -> dune_is_too_old ~ min " : 2 . 3 " | s -...
type addr = [ ` OpenSSL of Ipaddr_sexp . t * int * Ssl . Config . t | ` TCP of Ipaddr_sexp . t * int | ` Unix_domain_socket of string ]
let connect ? interrupt dst = match dst with | ` TCP ( ip , port ) -> let endp = Host_and_port . create ~ host ( : Ipaddr . to_string ip ) ~ port in Tcp . connect ? interrupt ( Tcp . Where_to_connect . of_host_and_port endp ) >>= fun ( _ , rd , wr ) -> return ( rd , wr ...
let with_connection ? interrupt dst f = match dst with | ` TCP ( ip , port ) -> let endp = Host_and_port . create ~ host ( : Ipaddr . to_string ip ) ~ port in Tcp . with_connection ? interrupt ( Tcp . Where_to_connect . of_host_and_port endp ) ( fun _ rd wr -> f rd wr ) | ` O...
type trust_chain = [ ` Ca_file of string | ` Ca_path of string | ` Search_file_first_then_path of [ ` File of string ] * [ ` Path of string ] ]
type openssl = [ ` OpenSSL of [ ` Crt_file_path of string ] * [ ` Key_file_path of string ] ]
type requires_async_ssl = [ openssl | ` OpenSSL_with_trust_chain of openssl * trust_chain ]
type server = [ ` TCP | requires_async_ssl ] [ @@ deriving sexp ]
let serve ? max_connections ? backlog ? buffer_age_limit ~ on_handler_error mode where_to_listen handle_request = let handle_client handle_request sock rd wr = match mode with | ` TCP -> handle_request sock rd wr | # requires_async_ssl as async_ssl -> let crt_file , key_file , ca_file , ca_path = ma...
type ssl_version = Ssl . version [ @@ deriving sexp ]
type ssl_opt = Ssl . opt [ @@ deriving sexp ]
type ssl_conn = Ssl . connection [ @@ deriving sexp_of ]
type allowed_ciphers = [ ` Only of string list | ` Openssl_default | ` Secure ]
type verify_mode = Ssl . verify_mode [ @@ deriving sexp_of ]
type session = Ssl . session [ @@ deriving sexp_of ]
module Ssl = struct module Config = Ssl . Config end