<commit_before>(*----
  Name: unsafe.ml
  Copyright <NAME> 2005-2016
  Author: <NAME> <<EMAIL>>

  This file is part of HSeq

  HSeq is free software; you can redistribute it and/or modify it under
  the terms of the Lesser GNU General Public License as published by
  the Free Software Foundation; either version 3, or (at your option)
  any later version.

  HSeq is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
  License for more details.

  You should have received a copy of the Lesser GNU General Public
  License along with HSeq.  If not see <http://www.gnu.org/licenses/>.
  ----*)

(** Utility functions which depend on unsafe/undocumented features. *)

let use_string st =
 try
   ignore (Toploop.execute_phrase true Format.std_formatter
             ((!Toploop.parse_toplevel_phrase) (Lexing.from_string st)))
 with _ -> failwith ("use_string "^st);;


let use_file silent f =
  if silent
  then ignore(Toploop.use_silently Format.std_formatter f)
  else ignore(Toploop.use_file Format.std_formatter f)

(* Dynlink.loadfile causes a segmentation fault in some circumstances. *)
(*let load_file f = Dynlink.loadfile f*)
let load_file f = ignore (Topdirs.load_file Format.std_formatter f)

let add_directory s = Topdirs.dir_directory s

(** [add_init f]: Setup function [f] to be called when OCaml
    starts.

    Use Toploop.parse_toplevel_phrase to call function [f] then
    restore Toploop.parse_toplevel_phrase to original (ocaml) value
    once init() has been called.
*)
let add_init f =
  let ocaml_init = !Toploop.parse_toplevel_phrase
  in
  Toploop.parse_toplevel_phrase :=
    (fun l ->
      ignore(f());
      Toploop.parse_toplevel_phrase:=ocaml_init;
      ocaml_init l)<commit_msg>[tools] Use Dynlink to load object files<commit_after>(*----
  Name: unsafe.ml
  Copyright <NAME> 2005-2016
  Author: <NAME> <<EMAIL>>

  This file is part of HSeq

  HSeq is free software; you can redistribute it and/or modify it under
  the terms of the Lesser GNU General Public License as published by
  the Free Software Foundation; either version 3, or (at your option)
  any later version.

  HSeq is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
  License for more details.

  You should have received a copy of the Lesser GNU General Public
  License along with HSeq.  If not see <http://www.gnu.org/licenses/>.
  ----*)

(** Utility functions which depend on unsafe/undocumented features. *)

let use_string st =
 try
   ignore (Toploop.execute_phrase true Format.std_formatter
             ((!Toploop.parse_toplevel_phrase) (Lexing.from_string st)))
 with _ -> failwith ("use_string "^st);;


let use_file silent f =
  if silent
  then ignore(Toploop.use_silently Format.std_formatter f)
  else ignore(Toploop.use_file Format.std_formatter f)

(* Dynlink.loadfile causes a segmentation fault in some circumstances. *)
let load_file f = Dynlink.loadfile f
(*
let load_file f = ignore (Topdirs.load_file Format.std_formatter f)
*)

let add_directory s = Topdirs.dir_directory s

(** [add_init f]: Setup function [f] to be called when OCaml
    starts.

    Use Toploop.parse_toplevel_phrase to call function [f] then
    restore Toploop.parse_toplevel_phrase to original (ocaml) value
    once init() has been called.
*)
let add_init f =
  let ocaml_init = !Toploop.parse_toplevel_phrase
  in
  Toploop.parse_toplevel_phrase :=
    (fun l ->
      ignore(f());
      Toploop.parse_toplevel_phrase:=ocaml_init;
      ocaml_init l)
{'fraction_non_alphanumeric': 0.07870247274660995, 'fraction_numerical': 0.004785961180537091, 'mean_word_length': 3.7560050568900127, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2324743', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1119, 'n_words': 435}