text
stringlengths
12
786k
let rec select r w e t = try Unix . select r w e t with
let create_process cmd env ~ stdin ~ stdout ~ stderr = let log_header pid = " EXEC " : ^ String . of_int pid in let line = Bos_cmd . to_list cmd in let prog = try List . hd line with Failure _ -> failwith err_empty_line in let line = Array . of_list line in match env with | None -> let pid = create_process prog line stdin stdout stderr in Bos_log . debug ( fun m -> m ~ header ( : log_header pid ) " [ @< 1 >% a ] " @ Bos_cmd . dump cmd ) ; pid | Some env -> let env = Bos_os_env . to_array env in let pid = create_process_env prog line env stdin stdout stderr in Bos_log . debug ( fun m -> m ~ header ( : log_header pid ) " [ @< v >% a , @% a ] " @ Fmt . Dump . ( array String . dump ) env Bos_cmd . dump cmd ) ; pid
let default_path_sep = if Sys . win32 then " ; " else " " :
let exe_is_path t = String . exists ( Char . equal dir_sep ) t
let tool_file ~ dir tool = match dir . [ String . length dir - 1 ] with
let search_in_path tool = let rec loop tool = function | " " -> None | p -> let dir , p = match String . cut ~ sep : default_path_sep p with | None -> p , " " | Some ( dir , p ) -> dir , p in if dir = " " then loop tool p else let tool_file = tool_file ~ dir tool in match Bos_os_file . _is_executable tool_file with | false -> loop tool p | true -> Some ( Fpath . v tool_file ) in try loop tool ( Unix . getenv " PATH " ) with | Not_found -> None
let search_in_dirs ~ dirs tool = let rec loop tool = function | [ ] -> None | d :: dirs -> let tool_file = tool_file ~ dir ( : Fpath . to_string d ) tool in match Bos_os_file . _is_executable tool_file with | false -> loop tool dirs | true -> Some ( Fpath . v tool_file ) in loop tool dirs
let ensure_exe_suffix_if_win32 = match Sys . win32 with fun t -> match String . is_suffix ~ affix " . : exe " t with | true -> t | false -> t ^ " . exe "
let _find_tool ? search tool = match tool with let tool = ensure_exe_suffix_if_win32 tool in match exe_is_path tool with | true -> begin match Fpath . of_string tool with | Ok t -> Ok ( Some t ) | Error ( ` Msg _ ) as e -> e end | false -> match search with | None -> Ok ( search_in_path tool ) | Some dirs -> Ok ( search_in_dirs ~ dirs tool )
let find_tool ? search cmd = match Bos_cmd . to_list cmd with
let err_not_found ? search cmd = match Bos_cmd . is_empty cmd with let pp_search ppf = function | None -> Fmt . string ppf " PATH " | Some dirs -> let pp_dir ppf d = Fmt . string ppf ( Filename . quote @@ Fpath . to_string d ) in Fmt . ( list ~ sep ( : Fmt . any " , @ " ) pp_dir ) ppf dirs in let tool = List . hd @@ Bos_cmd . to_list cmd in Fmt . error_msg " % s : no such command in % a " tool pp_search search
let get_tool ? search cmd = match find_tool ? search cmd with
let exists ? search cmd = match find_tool ? search cmd with
let must_exist ? search cmd = match find_tool ? search cmd with
let resolve ? search cmd = match find_tool ? search cmd with let t = Fpath . to_string t in Ok ( Bos_cmd . of_list ( t :: List . tl ( Bos_cmd . to_list cmd ) ) )
let search_path_dirs ( ? sep = default_path_sep ) path = let rec loop acc = function | " " -> Ok ( List . rev acc ) | p -> let dir , p = match String . cut ~ sep p with | None -> p , " " | Some ( dir , p ) -> dir , p in if dir = " " then loop acc p else match Fpath . of_string dir with | Error ( ` Msg m ) -> Fmt . error_msg " search path value % S : % s " path m | Ok d -> loop ( d :: acc ) p in loop [ ] path
module Fds = struct module Fd = struct type t = Unix . file_descr let compare : t -> t -> int = compare end module S = Set . Make ( Fd ) type t = S . t ref let empty ( ) = ref S . empty let rem fd s = s := S . remove fd ! s let add fd s = if fd = Unix . stdin || fd = Unix . stdout || fd = Unix . stderr then ( ) else ( s := S . add fd ! s ) let close_all s = S . iter close_no_err ! s ; s := S . empty let close fd s = if S . mem fd ! s then ( close_no_err fd ; s := S . remove fd ! s ) end
let write_fd_for_file ~ append f = try let flags = Unix . ( [ O_WRONLY ; O_CREAT ] ) in let flags = ( if append then Unix . O_APPEND else Unix . O_TRUNC ) :: flags in Ok ( openfile ( Fpath . to_string f ) flags 0o644 ) with Unix . Unix_error ( e , _ , _ ) -> err_file f e
let read_fd_for_file f = try Ok ( openfile ( Fpath . to_string f ) [ Unix . O_RDONLY ] 0o644 ) with Unix . Unix_error ( e , _ , _ ) -> err_file f e
let string_of_fd_async fd = let len = unix_buffer_size in let buf = Buffer . create len in let b = Bytes . create len in let rec step fd store b ( ) = try match Unix . read fd b 0 len with | 0 -> ` Ok ( Buffer . contents buf ) | n -> Buffer . add_substring buf ( Bytes . unsafe_to_string b ) 0 n ; step fd store b ( ) with | Unix . Unix_error ( Unix . EPIPE , _ , _ ) when Sys . win32 -> ` Ok ( Buffer . contents buf ) | Unix . Unix_error ( Unix . EINTR , _ , _ ) -> step fd buf b ( ) | Unix . Unix_error ( ( Unix . EWOULDBLOCK | Unix . EAGAIN ) , _ , _ ) -> ` Await ( step fd buf b ) in step fd buf b
let string_of_fd fd = let rec loop = function ` Ok s -> s | ` Await step -> loop ( step ( ) ) in loop ( string_of_fd_async fd ( ) )
let string_to_fd_async s fd = let rec step fd s first len ( ) = let b = Bytes . unsafe_of_string s in try match Unix . single_write fd b first len with | c when c = len -> ` Ok ( ) | c -> step fd s ( first + c ) ( len - c ) ( ) with | Unix . Unix_error ( Unix . EINTR , _ , _ ) -> step fd s first len ( ) | Unix . Unix_error ( ( Unix . EWOULDBLOCK | Unix . EAGAIN ) , _ , _ ) -> ` Await ( step fd s first len ) in step fd s 0 ( String . length s )
let string_to_fd s fd = let rec loop = function ` Ok ( ) -> ( ) | ` Await step -> loop ( step ( ) ) in loop ( string_to_fd_async s fd ( ) )
let string_to_of_fd s ~ to_fd ~ of_fd = let never ( ) = assert false in let wset , write = [ to_fd ] , string_to_fd_async s to_fd in let rset , read = [ of_fd ] , string_of_fd_async of_fd in let ret = ref " " in let rec loop rset read wset write = let rable , wable , _ = select rset wset [ ] ( - 1 . ) in let rset , read = match rable with | [ ] -> rset , read | _ -> match read ( ) with | ` Ok s -> ret := s ; [ ] , never | ` Await step -> rset , step in let wset , write = match wable with | [ ] -> wset , write | _ -> match write ( ) with | ` Ok ( ) -> close_no_err to_fd ; [ ] , never | ` Await step -> wset , step in if rset = [ ] && wset = [ ] then ! ret else loop rset read wset write in let sigpipe = if Sys . win32 then None else Some ( Sys . signal Sys . sigpipe Sys . Signal_ignore ) in let restore ( ) = match sigpipe with | None -> ( ) | Some sigpipe -> Sys . set_signal Sys . sigpipe sigpipe in try let ret = loop rset read wset write in restore ( ) ; ret with e -> restore ( ) ; raise e
type status = [ ` Exited of int | ` Signaled of int ]
let run_info_cmd ri = ri
let pp_status ppf = function
type run_status = run_info * status
let err_file ( ? append = false ) f = Err_file ( f , append )
let err_null = err_file Bos_os_file . null
let fd_for_run_err out_fd = function
type pipeline = { write : ( string * Unix . file_descr ) option ; read : Unix . file_descr ; pids : ( Bos_cmd . t * int ) list }
let in_string s = In_string s
let in_file f = In_file f
let in_null = in_file Bos_os_file . null
let in_stdin = In_fd Unix . stdin
type run_out = { env : Bos_os_env . t option ; cmd : Bos_cmd . t ; run_err : run_err ; run_in : run_in ; }
let rec wait_pids rev_pids = let rec loop ret = function | ( cmd , pid ) :: pids -> let s = snd ( waitpid [ ] pid ) in if ret <> None then loop ret pids else begin match s with | Unix . WEXITED 0 -> loop ret pids | Unix . WEXITED c -> loop ( Some ( cmd , ` Exited c ) ) pids | Unix . WSIGNALED s -> loop ( Some ( cmd , ` Signaled s ) ) pids | Unix . WSTOPPED _ -> assert false end | [ ] -> match ret with | None -> ( fst ( List . hd rev_pids ) , ` Exited 0 ) | Some s -> s in loop None ( List . rev rev_pids )
let do_in_fd_read_stdout stdin o pids do_read = let fds = Fds . empty ( ) in try Fds . add stdin fds ; let read_stdout , stdout = pipe ( ) in Fds . add read_stdout fds ; Fds . add stdout fds ; match fd_for_run_err stdout o . run_err with | Error _ as e -> Fds . close_all fds ; e | Ok stderr -> Fds . add stderr fds ; set_close_on_exec read_stdout ; let pid = create_process o . cmd o . env ~ stdin ~ stdout ~ stderr in clear_close_on_exec read_stdout ; Fds . close stdin fds ; Fds . close stdout fds ; do_read fds read_stdout ( ( o . cmd , pid ) :: pids ) with | Failure msg -> Error ( ` Msg msg ) | Unix . Unix_error ( e , _ , _ ) -> Fds . close_all fds ; err_run o . cmd pp_unix_error e
let do_in_fd_out_string stdin o pids = do_in_fd_read_stdout stdin o pids begin fun fds read_stdout pids -> let res = string_of_fd read_stdout in let ret = wait_pids pids in Fds . close_all fds ; Ok ( res , ret ) end
let do_in_fd_out_run_in stdin o pids = do_in_fd_read_stdout stdin o pids begin fun fds read_stdout pids -> Fds . rem read_stdout fds ; Fds . close_all fds ; Ok ( In_run_out { write = None ; read = read_stdout ; pids } ) end
let do_in_fd_out_fd stdin stdout o pids = let fds = Fds . empty ( ) in try Fds . add stdin fds ; Fds . add stdout fds ; match fd_for_run_err stdout o . run_err with | Error _ as e -> Fds . close_all fds ; e | Ok stderr -> Fds . add stderr fds ; let pid = create_process o . cmd o . env ~ stdin ~ stdout ~ stderr in let ret = wait_pids ( ( o . cmd , pid ) :: pids ) in Fds . close_all fds ; Ok ( ( ) , ret ) with | Failure msg -> Error ( ` Msg msg ) | Unix . Unix_error ( e , _ , _ ) -> Fds . close_all fds ; err_run o . cmd pp_unix_error e
let do_in_run_out_string p o = do_in_fd_out_string p . read o p . pids
let do_in_run_out_run_in p o = do_in_fd_out_run_in p . read o p . pids
let do_in_run_out_fd p out_fd o = do_in_fd_out_fd p . read out_fd o p . pids
let do_in_string_read_stdout s o do_read = let fds = Fds . empty ( ) in try let stdin , write_stdin = pipe ( ) in Fds . add stdin fds ; Fds . add write_stdin fds ; let read_stdout , stdout = pipe ( ) in Fds . add read_stdout fds ; Fds . add stdout fds ; match fd_for_run_err stdout o . run_err with | Error _ as e -> Fds . close_all fds ; e | Ok stderr -> Fds . add stderr fds ; set_close_on_exec read_stdout ; set_close_on_exec write_stdin ; let pid = create_process o . cmd o . env ~ stdin ~ stdout ~ stderr in Fds . close stdin fds ; Fds . close stdout fds ; do_read fds write_stdin read_stdout pid with | Failure msg -> Error ( ` Msg msg ) | Unix . Unix_error ( e , _ , _ ) -> Fds . close_all fds ; err_run o . cmd pp_unix_error e
let do_in_string_out_string s o = do_in_string_read_stdout s o begin fun fds write_stdin read_stdout pid -> let res = string_to_of_fd s ~ to_fd : write_stdin ~ of_fd : read_stdout in Fds . close write_stdin fds ; let ret = wait_pids [ ( o . cmd , pid ) ] in Fds . close_all fds ; Ok ( res , ret ) end
let do_in_string_out_run_in s o = do_in_string_read_stdout s o begin fun fds write_stdin read_stdout pid -> Fds . rem read_stdout fds ; Fds . close_all fds ; Ok ( In_run_out { write = Some ( s , write_stdin ) ; read = read_stdout ; pids = [ o . cmd , pid ] } ) end
let do_in_string_out_fd s stdout o = let fds = Fds . empty ( ) in try Fds . add stdout fds ; let stdin , write_stdin = pipe ( ) in Fds . add stdin fds ; Fds . add write_stdin fds ; match fd_for_run_err stdout o . run_err with | Error _ as e -> Fds . close_all fds ; e | Ok stderr -> Fds . add stderr fds ; set_close_on_exec write_stdin ; let pid = create_process o . cmd o . env ~ stdin ~ stdout ~ stderr in string_to_fd s write_stdin ; Fds . close write_stdin fds ; let ret = wait_pids [ ( o . cmd , pid ) ] in Fds . close_all fds ; Ok ( ( ) , ret ) with | Failure msg -> Error ( ` Msg msg ) | Unix . Unix_error ( e , _ , _ ) -> Fds . close_all fds ; err_run o . cmd pp_unix_error e
let do_in_fd : type a . Unix . file_descr -> run_out -> a _run_out -> ( a , [ > ` Msg of string ] ) result = fun in_fd o ret -> match ret with | To_string -> do_in_fd_out_string in_fd o [ ] | To_run_in -> do_in_fd_out_run_in in_fd o [ ] | To_fd out_fd -> do_in_fd_out_fd in_fd out_fd o [ ] | To_file ( f , append ) -> Result . bind ( write_fd_for_file ~ append f ) @@ fun fd -> do_in_fd_out_fd in_fd fd o [ ]
let run_cmd : type a . run_out -> a _run_out -> ( a , [ > ` Msg of string ] ) result = begin match ret with | To_string -> do_in_string_out_string s o | To_run_in -> do_in_string_out_run_in s o | To_fd out_fd -> do_in_string_out_fd s out_fd o | To_file ( f , append ) -> Result . bind ( write_fd_for_file ~ append f ) @@ fun fd -> do_in_string_out_fd s fd o end begin match ret with | To_string -> do_in_run_out_string p o | To_run_in -> do_in_run_out_run_in p o | To_fd out_fd -> do_in_run_out_fd p out_fd o | To_file ( f , append ) -> Result . bind ( write_fd_for_file ~ append f ) @@ fun fd -> do_in_run_out_fd p fd o end
let out_string ( ? trim = true ) o = match run_cmd o To_string with
let out_lines ? trim o = Result . bind ( out_string ? trim o ) @@ fun ( s , st ) -> Ok ( ( if s = " " then [ ] else String . cuts ~ sep " :\ n " s ) , st )
let out_file ( ? append = false ) f o = run_cmd o ( To_file ( f , append ) )
let out_run_in o = run_cmd o To_run_in
let out_null o = out_file Bos_os_file . null o
let out_stdout o = run_cmd o ( To_fd Unix . stdout )
let to_string ? trim o = out_string ? trim o |> success
let to_lines ? trim o = out_lines ? trim o |> success
let to_file ? append f o = out_file ? append f o |> success
let to_null o = out_null o |> success
let to_stdout o = out_stdout o |> success
let run_io ? env ? err ( : run_err = Err_stderr ) cmd run_in = { env ; cmd ; run_err ; run_in }
let run_out ? env ? err cmd = run_io ? env ? err cmd in_stdin
let run_in ? env ? err cmd i = run_io ? env ? err cmd i |> to_stdout
let run ? env ? err cmd = run_io ? env ? err cmd in_stdin |> to_stdout
let run_status ? env ? err ( ? quiet = false ) cmd = let err = match err with | None -> if quiet then err_null else err_stderr | Some err -> err in let ret = match quiet with | true -> in_null |> run_io ? env ~ err cmd |> out_null | false -> in_stdin |> run_io ? env ~ err cmd |> out_stdout in match ret with | Ok ( ( ) , ( _ , status ) ) -> Ok status | Error _ as e -> e
let create ( ? path = true ) ( ? mode = 0o755 ) dir = let rec mkdir d mode = try Ok ( Unix . mkdir ( Fpath . to_string d ) mode ) with | Unix . Unix_error ( Unix . EEXIST , _ , _ ) -> Ok ( ) | Unix . Unix_error ( e , _ , _ ) -> if d = dir then Fmt . error_msg " create directory % a : % s " Fpath . pp d ( uerror e ) else Fmt . error_msg " create directory % a : % a : % s " Fpath . pp dir Fpath . pp d ( uerror e ) in Result . bind ( Bos_os_path . exists dir ) @@ function | true -> Result . bind ( must_exist dir ) @@ fun _ -> Ok false | false -> match path with | false -> Result . bind ( mkdir dir mode ) @@ fun ( ) -> Ok true | true -> let rec dirs_to_create p acc = Result . bind ( exists p ) @@ function | true -> Ok acc | false -> dirs_to_create ( Fpath . parent p ) ( p :: acc ) in let rec create_them dirs ( ) = match dirs with | dir :: dirs -> Result . bind ( mkdir dir mode ) @@ create_them dirs | [ ] -> Ok ( ) in Result . bind ( dirs_to_create dir [ ] ) @@ fun dirs -> Result . bind ( create_them dirs ( ) ) @@ fun ( ) -> Ok true
let rec contents ( ? dotfiles = false ) ( ? rel = false ) dir = let rec readdir dh acc = match ( try Some ( Unix . readdir dh ) with End_of_file -> None ) with | None -> Ok acc | Some ( " . . " | " . " ) -> readdir dh acc | Some f when dotfiles || not ( String . is_prefix ~ affix " . " : f ) -> begin match Fpath . of_string f with | Ok f -> readdir dh ( ( if rel then f else Fpath . ( dir // f ) ) :: acc ) | Error ( ` Msg m ) -> Fmt . error_msg " directory contents % a : cannot parse element to a path ( % a ) " Fpath . pp dir String . dump f end | Some _ -> readdir dh acc in try let dh = Unix . opendir ( Fpath . to_string dir ) in Bos_base . apply ( readdir dh ) [ ] ~ finally : Unix . closedir dh with | Unix . Unix_error ( Unix . EINTR , _ , _ ) -> contents ~ rel dir | Unix . Unix_error ( e , _ , _ ) -> Fmt . error_msg " directory contents % a : % s " Fpath . pp dir ( uerror e )
let fold_contents ? err ? dotfiles ? elements ? traverse f acc d = Result . bind ( contents d ) @@ Bos_os_path . fold ? err ? dotfiles ? elements ? traverse f acc
let user ( ) = let debug err = Bos_log . debug ( fun m -> m " OS . Dir . user : % s " err ) in let env_var_fallback ( ) = Result . bind ( Bos_os_env . ( parse " HOME " ( some path ) ~ absent : None ) ) @@ function | Some p -> Ok p | None -> Fmt . error_msg " cannot determine user home directory : \ HOME environment variable is undefined " in if Sys . os_type = " Win32 " then env_var_fallback ( ) else try let uid = Unix . getuid ( ) in let home = ( Unix . getpwuid uid ) . Unix . pw_dir in match Fpath . of_string home with | Ok p -> Ok p | Error _ -> debug ( strf " could not parse path ( % a ) from passwd entry " String . dump home ) ; env_var_fallback ( ) with | Unix . Unix_error ( e , _ , _ ) -> debug ( uerror e ) ; env_var_fallback ( ) | Not_found -> env_var_fallback ( )
let rec current ( ) = try let p = Unix . getcwd ( ) in match Fpath . of_string p with | Ok dir -> if Fpath . is_abs dir then Ok dir else Fmt . error_msg " getcwd ( 3 ) returned a relative path : ( % a ) " Fpath . pp dir | Error _ -> Fmt . error_msg " get current working directory : cannot parse it to a path ( % a ) " String . dump p with | Unix . Unix_error ( Unix . EINTR , _ , _ ) -> current ( ) | Unix . Unix_error ( e , _ , _ ) -> Fmt . error_msg " get current working directory : % s " ( uerror e )
let rec set_current dir = try Ok ( Unix . chdir ( Fpath . to_string dir ) ) with Fmt . error_msg " set current working directory to % a : % s " Fpath . pp dir ( uerror e )
let with_current dir f v = Result . bind ( current ( ) ) @@ fun old -> try Result . bind ( set_current dir ) @@ fun ( ) -> let ret = f v in Result . bind ( set_current old ) @@ fun ( ) -> Ok ret with | exn -> ignore ( set_current old ) ; raise exn
type tmp_name_pat = ( string -> string , Format . formatter , unit , string ) format4
let delete_tmp dir = ignore ( delete ~ recurse : true dir )
let tmps = ref Fpath . Set . empty
let tmps_add file = tmps := Fpath . Set . add file ! tmps
let tmps_rem file = delete_tmp file ; tmps := Fpath . Set . remove file ! tmps
let delete_tmps ( ) = Fpath . Set . iter delete_tmp ! tmps
let ( ) = at_exit delete_tmps
let tmp ( ? mode = default_tmp_mode ) ? dir pat = let dir = match dir with None -> Bos_os_tmp . default_dir ( ) | Some d -> d in let err ( ) = Fmt . error_msg " create temporary directory % s in % a : \ too many failing attempts " ( strf pat " XXXXXX " ) Fpath . pp dir in let rec loop count = if count < 0 then err ( ) else let dir = Bos_os_tmp . rand_path dir pat in try Ok ( Unix . mkdir ( Fpath . to_string dir ) mode ; dir ) with | Unix . Unix_error ( Unix . EEXIST , _ , _ ) -> loop ( count - 1 ) | Unix . Unix_error ( Unix . EINTR , _ , _ ) -> loop count | Unix . Unix_error ( e , _ , _ ) -> Fmt . error_msg " create temporary directory % s in % a : % s " ( strf pat " XXXXXX " ) Fpath . pp dir ( uerror e ) in match loop 10000 with | Ok dir as r -> tmps_add dir ; r | Error _ as e -> e
let with_tmp ? mode ? dir pat f v = Result . bind ( tmp ? mode ? dir pat ) @@ fun dir -> try let ret = f dir v in tmps_rem dir ; Ok ret with e -> tmps_rem dir ; raise e
type t = string String . map
let current ( ) = try let env = Unix . environment ( ) in let add acc assign = match acc with | Error _ as e -> e | Ok m -> match String . cut ~ sep " " := assign with | Some ( var , value ) -> Ok ( String . Map . add var value m ) | None -> Fmt . error_msg " could not parse process environment variable ( % S ) " assign in Array . fold_left add ( Ok String . Map . empty ) env with | Unix . Unix_error ( e , _ , _ ) -> Fmt . error_msg " could not get process environment : % s " ( Unix . error_message e )
let to_array env = let add_var name value acc = String . concat [ name ; " " ; = value ] :: acc in Array . of_list ( String . Map . fold add_var env [ ] )
let var name = try Some ( Unix . getenv name ) with Not_found -> None
let set_var name v = let v = match v with None -> " " | Some v -> v in try Ok ( Unix . putenv name v ) with | Unix . Unix_error ( e , _ , _ ) -> Fmt . error_msg " set environment variable % s : % s " name ( Unix . error_message e )
let opt_var name ~ absent = try Unix . getenv name with Not_found -> absent
let req_var name = try Ok ( Unix . getenv name ) with
type ' a parser = string -> ( ' a , [ ` Msg of string ] ) result
let parser kind k_of_string = fun s -> match k_of_string s with | None -> Fmt . error_msg " could not parse % s value from % a " kind String . dump s | Some v -> Ok v
let bool = let of_string s = match String . Ascii . lowercase s with | " " | " false " | " no " | " n " | " 0 " -> Some false | " true " | " yes " | " y " | " 1 " -> Some true | _ -> None in parser " bool " of_string
let string = fun s -> Ok s
let cmd = fun s -> match Bos_cmd . of_string s with
let some p = fun s -> match p s with Ok v -> Ok ( Some v ) | Error _ as e -> e
let parse name p ~ absent = match var name with match p s with | Ok _ as r -> r | Error ( ` Msg e ) -> Fmt . error_msg " environment variable % s : % s " name e
let value ( ? log = Logs . Error ) name p ~ absent = Bos_log . on_error_msg ~ level : log ~ use ( : fun ( ) -> absent ) ( parse name p ~ absent )
let err_empty_buf = " buffer size can ' t be 0 "
let err_invalid_input = " input no longer valid , did it escape its scope " ?