12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697(* This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. *)typemessage=|Unable_to_create_file|Unable_to_write_fileletstring_of_message=function|Unable_to_create_file->" *** Bisect runtime was unable to create file."|Unable_to_write_file->" *** Bisect runtime was unable to write file."letfull_pathfname=ifFilename.is_implicitfnamethenFilename.concatFilename.current_dir_namefnameelsefnameletenv_to_fnameenvdefault=trySys.getenvenvwithNot_found->defaultletverbose=lazybeginletfname=env_to_fname"BISECT_SILENT""bisect.log"inmatch(String.uppercase[@ocaml.warning"-3"])fnamewith|"YES"|"ON"->fun_->()|"ERR"->funmsg->prerr_endline(string_of_messagemsg)|_uc_fname->letoc_l=lazy((* A weird race condition is caused if we use this invocation instead
let oc = open_out_gen [Open_append] 0o244 (full_path fname) in
Note that verbose is called only during [at_exit]. *)letoc=open_out_bin(full_pathfname)inat_exit(fun()->close_out_noerroc);oc)infunmsg->Printf.fprintf(Lazy.forceoc_l)"%s\n"(string_of_messagemsg)endletverbosemessage=(Lazy.forceverbose)messagelettable:(string,intarray*string)Hashtbl.tLazy.t=lazy(Hashtbl.create17)letfile_channel()=letbase_name=full_path(env_to_fname"BISECT_FILE""bisect")inletsuffix=ref0inletnext_name()=incrsuffix;Printf.sprintf"%s%04d.%s"base_name!suffixExtension.valueinletrecic_opt_loopactual_name=trySome(open_out_gen[Open_wronly;Open_binary;Open_creat;Open_excl]0o644actual_name)withSys_error_->ic_opt_loop(next_name())|_->verboseUnable_to_create_file;Noneinletchannel_opt=ic_opt_loop(next_name())inchannel_optletdump_counters_exnchannel=letcontent=Hashtbl.fold(funkvacc->(k,v)::acc)(Lazy.forcetable)[]inCommon.write_runtime_datachannelcontentletreset_counters()=Hashtbl.iter(fun_(point_state,_)->matchArray.lengthpoint_statewith|0->()|n->Array.(fillpoint_state0(n-1)0))(Lazy.forcetable)letdump()=matchfile_channel()with|None->()|Somechannel->(trydump_counters_exnchannelwith_->verboseUnable_to_write_file);close_out_noerrchannelletregister_dump:unitLazy.t=lazy(at_exitdump)letregister_filefilepoint_statepoint_definitions=let()=Lazy.forceregister_dumpinlettable=Lazy.forcetableinifnot(Hashtbl.memtablefile)thenHashtbl.addtablefile(point_state,point_definitions)