filename
stringlengths
3
67
data
stringlengths
0
58.3M
license
stringlengths
0
19.5k
mutable_set_v5.ml
module type S = sig type elt type t val empty : unit -> t val mem : elt -> t -> bool val add : elt -> t -> unit val cardinal : t -> int val remove : elt -> t -> elt option end module Lib : sig module Make : functor (Ord : Set.OrderedType) -> S with type elt = Ord.t end = struct module Make (Ord : Set.OrderedType) = struct module S = Set.Make (Ord) type elt = Ord.t type t = { mutable content : S.t; mutable cardinal : int; mutex : Mutex.t} let empty () = { content = S.empty; cardinal = 0; mutex = Mutex.create () } let mem_non_lock a t = S.mem a t.content let mem a t = Mutex.lock t.mutex; let b = mem_non_lock a t in Mutex.unlock t.mutex; b let add a t = Mutex.lock t.mutex; if not (mem_non_lock a t) then begin t.content <- S.add a t.content; t.cardinal <- t.cardinal + 1; end; Mutex.unlock t.mutex let cardinal t = Mutex.lock t.mutex; let c = t.cardinal in Mutex.unlock t.mutex; c let remove a t = Mutex.lock t.mutex; let r = if mem_non_lock a t then begin t.content <- S.remove a t.content; (* t.cardinal <- t.cardinal - 1; *) Some a end else None in Mutex.unlock t.mutex; r end end open QCheck open STM module Lib_spec : Spec = struct module S = Lib.Make (Int) type sut = S.t let init_sut () = S.empty () let cleanup _ = () type cmd = | Mem of int | Add of int | Cardinal | Remove of int [@@deriving show { with_path = false }] let run cmd sut = match cmd with | Mem i -> Res (bool, S.mem i sut) | Add i -> Res (unit, S.add i sut) | Cardinal -> Res (int, S.cardinal sut) | Remove i -> Res (option int, S.remove i sut) type state = int list let init_state = [] let next_state cmd state = match cmd with | Mem _ -> state | Add i -> if List.mem i state then state else i :: state | Cardinal -> state | Remove i -> if List.mem i state then List.filter (fun x -> x <> i) state else state let precond _cmd _state = true let postcond cmd state res = match cmd, res with | Mem i, Res ((Bool,_), b) -> b = List.mem i state | Cardinal, Res ((Int,_), l) -> l = List.length state | Add _, Res ((Unit,_),_) -> true | Remove i, Res ((Option Int, _), Some x) -> List.mem i state && i = x | Remove i, Res ((Option Int, _), None) -> not (List.mem i state) | _ -> false let arb_cmd state = let gen = match state with | [] -> Gen.int | xs -> Gen.(oneof [oneofl xs; int]) in QCheck.make ~print:show_cmd (QCheck.Gen.oneof [Gen.return Cardinal; Gen.map (fun i -> Mem i) gen; Gen.map (fun i -> Add i) gen; Gen.map (fun i -> Remove i) gen; ]) end module Lib_sequential = STM_sequential.Make(Lib_spec) let _ = QCheck_base_runner.run_tests_main [Lib_sequential.agree_test ~count:100 ~name:"STM sequential tests"]
fit_length.c
#include "fq_zech_mpoly.h" void _fq_zech_mpoly_fit_length(fq_zech_struct ** coeff, ulong ** exps, slong * alloc, slong len, slong N, const fq_zech_ctx_t fqctx) { if (len > *alloc) { slong i; len = FLINT_MAX(len, 2*(*alloc)); (* coeff) = (fq_zech_struct *) flint_realloc(* coeff, len*sizeof(fq_zech_struct)); (* exps) = (ulong *) flint_realloc(*exps, len*N*sizeof(ulong)); for (i = *alloc; i < len; i++) fq_zech_init((* coeff) + i, fqctx); (* alloc) = len; } } void fq_zech_mpoly_fit_length(fq_zech_mpoly_t A, slong length, const fq_zech_mpoly_ctx_t ctx) { slong i; slong old_alloc = A->alloc; slong new_alloc = FLINT_MAX(length, 2*A->alloc); if (length > old_alloc) { slong N = mpoly_words_per_exp(A->bits, ctx->minfo); if (old_alloc == 0) { A->exps = (ulong *) flint_malloc(new_alloc*N*sizeof(ulong)); A->coeffs = (fq_zech_struct *) flint_malloc(new_alloc *sizeof(fq_zech_struct)); } else { A->exps = (ulong *) flint_realloc(A->exps, new_alloc*N*sizeof(ulong)); A->coeffs = (fq_zech_struct *) flint_realloc(A->coeffs, new_alloc*sizeof(fq_zech_struct)); } for (i = old_alloc; i < new_alloc; i++) { fq_zech_init(A->coeffs + i, ctx->fqctx); } A->alloc = new_alloc; } }
/* Copyright (C) 2020 Daniel Schultz This file is part of FLINT. FLINT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>. */
dune
(test (name test) (libraries alcotest reparse reparse-unix))
rpc_server.ml
open Core open Async (* The list of implementations supported by the server. The server state is simply a counter used for allocating unique ids. *) let implementations = [ Rpc.Rpc.implement Rpc_intf.get_unique_id (fun ctr () -> printf ".%!"; incr ctr; return !ctr) ; Rpc.Rpc.implement Rpc_intf.set_id_counter (fun ctr i -> printf "!%!"; if i = 0 then failwith "Can't set counter back to zero"; return (ctr := i)) ; Rpc.Pipe_rpc.implement Rpc_intf.counter_values (fun ctr () -> let r, w = Pipe.create () in let last_value = ref !ctr in let send () = last_value := !ctr; Pipe.write w !ctr in don't_wait_for (send ()); Clock.every' ~stop:(Pipe.closed w) (sec 0.1) (fun () -> if !last_value <> !ctr then send () else return ()); return (Ok r)) ] ;; let main ~port = let counter = ref 0 in let implementations = Rpc.Implementations.create ~implementations ~on_unknown_rpc:`Close_connection in match implementations with | Error (`Duplicate_implementations (_ : Rpc.Description.t list)) -> assert false | Ok implementations -> let server = Tcp.Server.create (Tcp.Where_to_listen.of_port port) ~on_handler_error:`Ignore (fun (_ : Socket.Address.Inet.t) reader writer -> Rpc.Connection.server_with_close reader writer ~implementations ~connection_state:(fun (_ : Rpc.Connection.t) -> counter) ~on_handshake_error:`Ignore) in ignore (server : (Socket.Address.Inet.t, int) Tcp.Server.t Deferred.t); never () ;; let () = Command.async ~summary:"A trivial Async-RPC server" (let%map_open.Command port = flag "-port" ~doc:" Port to listen on" (optional_with_default 8080 int) in fun () -> main ~port) |> Command_unix.run ;;
script_ir_annot.ml
open Alpha_context open Micheline open Script_tc_errors type var_annot = Var_annot of Non_empty_string.t [@@ocaml.unboxed] type type_annot = Type_annot of Non_empty_string.t [@@ocaml.unboxed] type field_annot = Field_annot of Non_empty_string.t [@@ocaml.unboxed] module FOR_TESTS = struct let unsafe_var_annot_of_string s = Var_annot (Non_empty_string.of_string_exn s) let unsafe_type_annot_of_string s = Type_annot (Non_empty_string.of_string_exn s) let unsafe_field_annot_of_string s = Field_annot (Non_empty_string.of_string_exn s) end let some_var_annot_of_string_exn s = Some (Var_annot (Non_empty_string.of_string_exn s)) let some_field_annot_of_string_exn s = Some (Field_annot (Non_empty_string.of_string_exn s)) let default_now_annot = some_var_annot_of_string_exn "now" let default_amount_annot = some_var_annot_of_string_exn "amount" let default_balance_annot = some_var_annot_of_string_exn "balance" let default_level_annot = some_var_annot_of_string_exn "level" let default_source_annot = some_var_annot_of_string_exn "source" let default_sender_annot = some_var_annot_of_string_exn "sender" let default_self_annot = some_var_annot_of_string_exn "self" let default_arg_annot = some_var_annot_of_string_exn "arg" let lambda_arg_annot = some_var_annot_of_string_exn "@arg" let default_param_annot = some_var_annot_of_string_exn "parameter" let default_storage_annot = some_var_annot_of_string_exn "storage" let default_car_annot = some_field_annot_of_string_exn "car" let default_cdr_annot = some_field_annot_of_string_exn "cdr" let default_contract_annot = some_field_annot_of_string_exn "contract" let default_addr_annot = some_field_annot_of_string_exn "address" let default_pack_annot = some_field_annot_of_string_exn "packed" let default_unpack_annot = some_field_annot_of_string_exn "unpacked" let default_slice_annot = some_field_annot_of_string_exn "slice" let default_elt_annot = some_field_annot_of_string_exn "elt" let default_key_annot = some_field_annot_of_string_exn "key" let default_hd_annot = some_field_annot_of_string_exn "hd" let default_tl_annot = some_field_annot_of_string_exn "tl" let default_some_annot = some_field_annot_of_string_exn "some" let default_left_annot = some_field_annot_of_string_exn "left" let default_right_annot = some_field_annot_of_string_exn "right" let default_sapling_state_annot = some_var_annot_of_string_exn "sapling" let default_sapling_balance_annot = some_var_annot_of_string_exn "sapling_balance" let unparse_type_annot : type_annot option -> string list = function | None -> [] | Some (Type_annot a) -> [":" ^ (a :> string)] let unparse_var_annot : var_annot option -> string list = function | None -> [] | Some (Var_annot a) -> ["@" ^ (a :> string)] let unparse_field_annot : field_annot option -> string list = function | None -> [] | Some (Field_annot a) -> ["%" ^ (a :> string)] let field_to_var_annot : field_annot option -> var_annot option = function | None -> None | Some (Field_annot s) -> Some (Var_annot s) let type_to_var_annot : type_annot option -> var_annot option = function | None -> None | Some (Type_annot s) -> Some (Var_annot s) let var_to_field_annot : var_annot option -> field_annot option = function | None -> None | Some (Var_annot s) -> Some (Field_annot s) let default_annot ~default = function None -> default | annot -> annot let gen_access_annot : var_annot option -> ?default:field_annot option -> field_annot option -> var_annot option = fun value_annot ?(default = None) field_annot -> match (value_annot, field_annot, default) with | (None, None, _) | (Some _, None, None) -> None | (None, Some (Field_annot f), _) -> Some (Var_annot f) | (Some (Var_annot v), None, Some (Field_annot f)) -> Some (Var_annot (Non_empty_string.cat2 v ~sep:"." f)) | (Some (Var_annot v), Some (Field_annot f), _) -> Some (Var_annot (Non_empty_string.cat2 v ~sep:"." f)) let merge_type_annot : legacy:bool -> type_annot option -> type_annot option -> type_annot option tzresult = fun ~legacy annot1 annot2 -> match (annot1, annot2) with | (None, None) | (Some _, None) | (None, Some _) -> Result.return_none | (Some (Type_annot a1), Some (Type_annot a2)) -> if legacy || Non_empty_string.(a1 = a2) then ok annot1 else error (Inconsistent_annotations (":" ^ (a1 :> string), ":" ^ (a2 :> string))) let merge_field_annot : legacy:bool -> field_annot option -> field_annot option -> field_annot option tzresult = fun ~legacy annot1 annot2 -> match (annot1, annot2) with | (None, None) | (Some _, None) | (None, Some _) -> Result.return_none | (Some (Field_annot a1), Some (Field_annot a2)) -> if legacy || Non_empty_string.(a1 = a2) then ok annot1 else error (Inconsistent_annotations ("%" ^ (a1 :> string), "%" ^ (a2 :> string))) let merge_var_annot : var_annot option -> var_annot option -> var_annot option = fun annot1 annot2 -> match (annot1, annot2) with | (None, None) | (Some _, None) | (None, Some _) -> None | (Some (Var_annot a1), Some (Var_annot a2)) -> if Non_empty_string.(a1 = a2) then annot1 else None let error_unexpected_annot loc annot = match annot with | [] -> Result.return_unit | _ :: _ -> error (Unexpected_annotation loc) (* Check that the predicate p holds on all s.[k] for k >= i *) let string_iter p s i = let len = String.length s in let rec aux i = if Compare.Int.(i >= len) then Result.return_unit else p s.[i] >>? fun () -> aux (i + 1) in aux i let is_allowed_char = function | 'a' .. 'z' | 'A' .. 'Z' | '_' | '.' | '%' | '@' | '0' .. '9' -> true | _ -> false (* Valid annotation characters as defined by the allowed_annot_char function from lib_micheline/micheline_parser *) let check_char loc c = if is_allowed_char c then Result.return_unit else error (Unexpected_annotation loc) (* This constant is defined in lib_micheline/micheline_parser which is not available in the environment. *) let max_annot_length = 255 type annot_opt = | Field_annot_opt of Non_empty_string.t option | Type_annot_opt of Non_empty_string.t option | Var_annot_opt of Non_empty_string.t option let percent = Non_empty_string.of_string_exn "%" let percent_percent = Non_empty_string.of_string_exn "%%" let at = Non_empty_string.of_string_exn "@" let parse_annots loc ?(allow_special_var = false) ?(allow_special_field = false) l = (* allow empty annotations as wildcards but otherwise only accept annotations that start with [a-zA-Z_] *) let sub_or_wildcard wrap s = match Non_empty_string.of_string s with | None -> ok @@ wrap None | Some s -> ( match (s :> string).[0] with | 'a' .. 'z' | 'A' .. 'Z' | '_' | '0' .. '9' -> (* check that all characters are valid*) string_iter (check_char loc) (s :> string) 1 >>? fun () -> ok @@ wrap (Some s) | _ -> error (Unexpected_annotation loc)) in List.map_e (function | "@%" when allow_special_var -> ok @@ Var_annot_opt (Some percent) | "@%%" when allow_special_var -> ok @@ Var_annot_opt (Some percent_percent) | "%@" when allow_special_field -> ok @@ Field_annot_opt (Some at) | s -> ( let len = String.length s in if Compare.Int.(len = 0 || len > max_annot_length) then error (Unexpected_annotation loc) else let rest = String.sub s 1 (len - 1) in match s.[0] with | ':' -> sub_or_wildcard (fun a -> Type_annot_opt a) rest | '@' -> sub_or_wildcard (fun a -> Var_annot_opt a) rest | '%' -> sub_or_wildcard (fun a -> Field_annot_opt a) rest | _ -> error (Unexpected_annotation loc))) l let opt_var_of_var_opt = function None -> None | Some a -> Some (Var_annot a) let opt_field_of_field_opt = function | None -> None | Some a -> Some (Field_annot a) let opt_type_of_type_opt = function | None -> None | Some a -> Some (Type_annot a) let classify_annot loc l : (var_annot option list * type_annot option list * field_annot option list) tzresult = try let (_, rv, _, rt, _, rf) = List.fold_left (fun (in_v, rv, in_t, rt, in_f, rf) a -> match (a, in_v, rv, in_t, rt, in_f, rf) with | (Var_annot_opt a, true, _, _, _, _, _) | (Var_annot_opt a, false, [], _, _, _, _) -> (true, opt_var_of_var_opt a :: rv, false, rt, false, rf) | (Type_annot_opt a, _, _, true, _, _, _) | (Type_annot_opt a, _, _, false, [], _, _) -> (false, rv, true, opt_type_of_type_opt a :: rt, false, rf) | (Field_annot_opt a, _, _, _, _, true, _) | (Field_annot_opt a, _, _, _, _, false, []) -> (false, rv, false, rt, true, opt_field_of_field_opt a :: rf) | _ -> raise Exit) (false, [], false, [], false, []) l in ok (List.rev rv, List.rev rt, List.rev rf) with Exit -> error (Ungrouped_annotations loc) let get_one_annot loc = function | [] -> Result.return_none | [a] -> ok a | _ -> error (Unexpected_annotation loc) let get_two_annot loc = function | [] -> ok (None, None) | [a] -> ok (a, None) | [a; b] -> ok (a, b) | _ -> error (Unexpected_annotation loc) let parse_type_annot : Script.location -> string list -> type_annot option tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc vars >>? fun () -> error_unexpected_annot loc fields >>? fun () -> get_one_annot loc types let parse_composed_type_annot : Script.location -> string list -> (type_annot option * field_annot option * field_annot option) tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc vars >>? fun () -> get_one_annot loc types >>? fun t -> get_two_annot loc fields >|? fun (f1, f2) -> (t, f1, f2) let parse_field_annot : Script.location -> string list -> field_annot option tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc vars >>? fun () -> error_unexpected_annot loc types >>? fun () -> get_one_annot loc fields let extract_field_annot : Script.node -> (Script.node * field_annot option) tzresult = function | Prim (loc, prim, args, annot) -> let rec extract_first acc = function | [] -> (None, annot) | s :: rest -> if Compare.Int.(String.length s > 0) && Compare.Char.(s.[0] = '%') then (Some s, List.rev_append acc rest) else extract_first (s :: acc) rest in let (field_annot, annot) = extract_first [] annot in (match field_annot with | None -> Result.return_none | Some field_annot -> parse_field_annot loc [field_annot]) >|? fun field_annot -> (Prim (loc, prim, args, annot), field_annot) | expr -> ok (expr, None) let check_correct_field : field_annot option -> field_annot option -> unit tzresult = fun f1 f2 -> match (f1, f2) with | (None, _) | (_, None) -> Result.return_unit | (Some (Field_annot s1), Some (Field_annot s2)) -> if Non_empty_string.(s1 = s2) then Result.return_unit else error (Inconsistent_field_annotations ("%" ^ (s1 :> string), "%" ^ (s2 :> string))) let parse_var_annot : Script.location -> ?default:var_annot option -> string list -> var_annot option tzresult = fun loc ?default annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc types >>? fun () -> error_unexpected_annot loc fields >>? fun () -> get_one_annot loc vars >|? function | Some _ as a -> a | None -> ( match default with Some a -> a | None -> None) let split_last_dot = function | None -> (None, None) | Some (Field_annot s) -> ( match Non_empty_string.split_on_last '.' s with | Some (s1, s2) -> let f = match (s2 :> string) with | "car" | "cdr" -> None | _ -> Some (Field_annot s2) in (Some (Var_annot s1), f) | None -> (None, Some (Field_annot s))) let split_if_special ~loc ~if_special v f = match f with | Some (Field_annot fa) when Non_empty_string.(fa = at) -> ( match if_special with | Some special_var -> ok @@ split_last_dot special_var | None -> error (Unexpected_annotation loc)) | _ -> ok (v, f) let common_prefix v1 v2 = match (v1, v2) with | (Some (Var_annot s1), Some (Var_annot s2)) when Non_empty_string.(s1 = s2) -> v1 | (Some _, None) -> v1 | (None, Some _) -> v2 | (_, _) -> None let parse_constr_annot : Script.location -> ?if_special_first:field_annot option -> ?if_special_second:field_annot option -> string list -> (var_annot option * type_annot option * field_annot option * field_annot option) tzresult = fun loc ?if_special_first ?if_special_second annot -> parse_annots ~allow_special_field:true loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> get_one_annot loc vars >>? fun v -> get_one_annot loc types >>? fun t -> get_two_annot loc fields >>? fun (f1, f2) -> split_if_special ~loc ~if_special:if_special_first v f1 >>? fun (v1, f1) -> split_if_special ~loc ~if_special:if_special_second v f2 >|? fun (v2, f2) -> let v = match v with None -> common_prefix v1 v2 | Some _ -> v in (v, t, f1, f2) let parse_two_var_annot : Script.location -> string list -> (var_annot option * var_annot option) tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc types >>? fun () -> error_unexpected_annot loc fields >>? fun () -> get_two_annot loc vars let var_annot_from_special : field_name:field_annot option -> default:var_annot option -> value_annot:var_annot option -> var_annot option -> var_annot option = fun ~field_name ~default ~value_annot v -> match v with | Some (Var_annot va) -> ( match (va :> string) with | "%" -> field_to_var_annot field_name | "%%" -> default | _ -> v) | None -> value_annot let parse_destr_annot : Script.location -> string list -> default_accessor:field_annot option -> field_name:field_annot option -> pair_annot:var_annot option -> value_annot:var_annot option -> (var_annot option * field_annot option) tzresult = fun loc annot ~default_accessor ~field_name ~pair_annot ~value_annot -> parse_annots loc ~allow_special_var:true annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc types >>? fun () -> get_one_annot loc vars >>? fun v -> get_one_annot loc fields >|? fun f -> let default = gen_access_annot pair_annot field_name ~default:default_accessor in let v = var_annot_from_special ~field_name ~default ~value_annot v in (v, f) let parse_unpair_annot : Script.location -> string list -> field_name_car:field_annot option -> field_name_cdr:field_annot option -> pair_annot:var_annot option -> value_annot_car:var_annot option -> value_annot_cdr:var_annot option -> (var_annot option * var_annot option * field_annot option * field_annot option) tzresult = fun loc annot ~field_name_car ~field_name_cdr ~pair_annot ~value_annot_car ~value_annot_cdr -> parse_annots loc ~allow_special_var:true annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc types >>? fun () -> get_two_annot loc vars >>? fun (vcar, vcdr) -> get_two_annot loc fields >|? fun (fcar, fcdr) -> let default_car = gen_access_annot pair_annot field_name_car ~default:default_car_annot in let default_cdr = gen_access_annot pair_annot field_name_cdr ~default:default_cdr_annot in let vcar = var_annot_from_special ~field_name:field_name_car ~default:default_car ~value_annot:value_annot_car vcar in let vcdr = var_annot_from_special ~field_name:field_name_cdr ~default:default_cdr ~value_annot:value_annot_cdr vcdr in (vcar, vcdr, fcar, fcdr) let parse_entrypoint_annot : Script.location -> ?default:var_annot option -> string list -> (var_annot option * field_annot option) tzresult = fun loc ?default annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc types >>? fun () -> get_one_annot loc fields >>? fun f -> get_one_annot loc vars >|? function | Some _ as a -> (a, f) | None -> ( match default with Some a -> (a, f) | None -> (None, f)) let parse_var_type_annot : Script.location -> string list -> (var_annot option * type_annot option) tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc fields >>? fun () -> get_one_annot loc vars >>? fun v -> get_one_annot loc types >|? fun t -> (v, t)
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
dirTree.mli
type t val id : t -> int type label val children : t -> t list ;; val label : t -> label ;; val string_of_label : label -> string ;; val from_dir : string -> string -> t ;;
(**************************************************************************) (* *) (* Ocamlgraph: a generic graph library for OCaml *) (* Copyright (C) 2004-2010 *) (* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *) (* *) (* This software is free software; you can redistribute it and/or *) (* modify it under the terms of the GNU Library General Public *) (* License version 2.1, with the special exception on linking *) (* described in file LICENSE. *) (* *) (* This software 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. *) (* *) (**************************************************************************)
pr7618.ml
(* TEST * expect *) type _ t = I : int t;; let f (type a) (x : a t) (y : int) = match x, y with | I, (_:a) -> () ;; [%%expect{| type _ t = I : int t val f : 'a t -> int -> unit = <fun> |}] type ('a, 'b) eq = Refl : ('a, 'a) eq;; let ok (type a b) (x : (a, b) eq) = match x, [] with | Refl, [(_ : a) | (_ : b)] -> [] ;; [%%expect{| type ('a, 'b) eq = Refl : ('a, 'a) eq Line 4, characters 4-29: 4 | | Refl, [(_ : a) | (_ : b)] -> [] ^^^^^^^^^^^^^^^^^^^^^^^^^ Error: This pattern matches values of type (a, b) eq * b list This instance of b is ambiguous: it would escape the scope of its equation |}] let fails (type a b) (x : (a, b) eq) = match x, [] with | Refl, [(_ : a) | (_ : b)] -> [] | Refl, [(_ : b) | (_ : a)] -> [] ;; [%%expect{| Line 3, characters 4-29: 3 | | Refl, [(_ : a) | (_ : b)] -> [] ^^^^^^^^^^^^^^^^^^^^^^^^^ Error: This pattern matches values of type (a, b) eq * b list This instance of b is ambiguous: it would escape the scope of its equation |}] (* branches must be unified! *) let x = match [] with ["1"] -> 1 | [1.0] -> 2 | [1] -> 3 | _ -> 4;; [%%expect{| Line 1, characters 35-40: 1 | let x = match [] with ["1"] -> 1 | [1.0] -> 2 | [1] -> 3 | _ -> 4;; ^^^^^ Error: This pattern matches values of type float list but a pattern was expected which matches values of type string list Type float is not compatible with type string |}]
(* TEST * expect *)
client_proto_context_commands.ml
open Protocol open Alpha_context open Tezos_micheline open Client_proto_context open Client_proto_contracts open Client_keys let report_michelson_errors ?(no_print_source = false) ~msg (cctxt : #Client_context.printer) = function | Error errs -> cctxt#warning "%a" (Michelson_v1_error_reporter.report_errors ~details:(not no_print_source) ~show_source:(not no_print_source) ?parsed:None) errs >>= fun () -> cctxt#error "%s" msg >>= fun () -> Lwt.return_none | Ok data -> Lwt.return_some data let data_parameter = Clic.parameter (fun _ data -> Lwt.return (Micheline_parser.no_parsing_error @@ Michelson_v1_parser.parse_expression data)) let non_negative_param = Clic.parameter (fun _ s -> match int_of_string_opt s with | Some i when i >= 0 -> return i | _ -> failwith "Parameter should be a non-negative integer literal") let group = { Clic.name = "context"; title = "Block contextual commands (see option -block)"; } let binary_description = {Clic.name = "description"; title = "Binary Description"} let commands () = let open Clic in [ command ~group ~desc:"Access the timestamp of the block." (args1 (switch ~doc:"output time in seconds" ~short:'s' ~long:"seconds" ())) (fixed ["get"; "timestamp"]) (fun seconds (cctxt : Alpha_client_context.full) -> Shell_services.Blocks.Header.shell_header cctxt ~chain:cctxt#chain ~block:cctxt#block () >>=? fun {timestamp = v; _} -> (if seconds then cctxt#message "%Ld" (Time.Protocol.to_seconds v) else cctxt#message "%s" (Time.Protocol.to_notation v)) >>= fun () -> return_unit); command ~group ~desc:"Lists all non empty contracts of the block." no_options (fixed ["list"; "contracts"]) (fun () (cctxt : Alpha_client_context.full) -> list_contract_labels cctxt ~chain:cctxt#chain ~block:cctxt#block >>=? fun contracts -> List.iter_s (fun (alias, hash, kind) -> cctxt#message "%s%s%s" hash kind alias) contracts >>= fun () -> return_unit); command ~group ~desc:"Get the balance of a contract." no_options (prefixes ["get"; "balance"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun () (_, contract) (cctxt : Alpha_client_context.full) -> get_balance cctxt ~chain:cctxt#chain ~block:cctxt#block contract >>=? fun amount -> cctxt#answer "%a %s" Tez.pp amount Client_proto_args.tez_sym >>= fun () -> return_unit); command ~group ~desc:"Get the storage of a contract." no_options (prefixes ["get"; "script"; "storage"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun () (_, contract) (cctxt : Alpha_client_context.full) -> get_storage cctxt ~chain:cctxt#chain ~block:cctxt#block contract >>=? function | None -> cctxt#error "This is not a smart contract." | Some storage -> cctxt#answer "%a" Michelson_v1_printer.print_expr_unwrapped storage >>= fun () -> return_unit); command ~group ~desc: "Get the value associated to a key in the big map storage of a \ contract." no_options (prefixes ["get"; "big"; "map"; "value"; "for"] @@ Clic.param ~name:"key" ~desc:"the key to look for" data_parameter @@ prefixes ["of"; "type"] @@ Clic.param ~name:"type" ~desc:"type of the key" data_parameter @@ prefix "in" @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun () key key_type (_, contract) (cctxt : Alpha_client_context.full) -> get_big_map_value cctxt ~chain:cctxt#chain ~block:cctxt#block contract (key.expanded, key_type.expanded) >>=? function | None -> cctxt#error "No value associated to this key." | Some value -> cctxt#answer "%a" Michelson_v1_printer.print_expr_unwrapped value >>= fun () -> return_unit); command ~group ~desc:"Get the storage of a contract." no_options (prefixes ["get"; "script"; "code"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun () (_, contract) (cctxt : Alpha_client_context.full) -> get_script cctxt ~chain:cctxt#chain ~block:cctxt#block contract >>=? function | None -> cctxt#error "This is not a smart contract." | Some {code; storage = _} -> ( match Script_repr.force_decode code with | Error errs -> cctxt#error "%a" (Format.pp_print_list ~pp_sep:Format.pp_print_newline Environment.Error_monad.pp) errs | Ok (code, _) -> let {Michelson_v1_parser.source; _} = Michelson_v1_printer.unparse_toplevel code in cctxt#answer "%s" source >>= return)); command ~group ~desc:"Get the manager of a contract." no_options (prefixes ["get"; "manager"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun () (_, contract) (cctxt : Alpha_client_context.full) -> Client_proto_contracts.get_manager cctxt ~chain:cctxt#chain ~block:cctxt#block contract >>=? fun manager -> Public_key_hash.rev_find cctxt manager >>=? fun mn -> Public_key_hash.to_source manager >>=? fun m -> cctxt#message "%s (%s)" m (match mn with None -> "unknown" | Some n -> "known as " ^ n) >>= fun () -> return_unit); command ~group ~desc:"Get the delegate of a contract." no_options (prefixes ["get"; "delegate"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) (fun () (_, contract) (cctxt : Alpha_client_context.full) -> Client_proto_contracts.get_delegate cctxt ~chain:cctxt#chain ~block:cctxt#block contract >>=? function | None -> cctxt#message "none" >>= fun () -> return_unit | Some delegate -> Public_key_hash.rev_find cctxt delegate >>=? fun mn -> Public_key_hash.to_source delegate >>=? fun m -> cctxt#message "%s (%s)" m (match mn with None -> "unknown" | Some n -> "known as " ^ n) >>= fun () -> return_unit); command ~desc:"Get receipt for past operation" (args1 (default_arg ~long:"check-previous" ~placeholder:"num_blocks" ~doc:"number of previous blocks to check" ~default:"10" non_negative_param)) (prefixes ["get"; "receipt"; "for"] @@ param ~name:"operation" ~desc:"Operation to be looked up" (parameter (fun _ x -> match Operation_hash.of_b58check_opt x with | None -> Error_monad.failwith "Invalid operation hash: '%s'" x | Some hash -> return hash)) @@ stop) (fun predecessors operation_hash (ctxt : Alpha_client_context.full) -> display_receipt_for_operation ctxt ~chain:ctxt#chain ~predecessors operation_hash >>=? fun _ -> return_unit); command ~group:binary_description ~desc:"Describe unsigned block header" no_options (fixed ["describe"; "unsigned"; "block"; "header"]) (fun () (cctxt : Alpha_client_context.full) -> cctxt#message "%a" Data_encoding.Binary_schema.pp (Data_encoding.Binary.describe Alpha_context.Block_header.unsigned_encoding) >>= fun () -> return_unit); command ~group:binary_description ~desc:"Describe unsigned operation" no_options (fixed ["describe"; "unsigned"; "operation"]) (fun () (cctxt : Alpha_client_context.full) -> cctxt#message "%a" Data_encoding.Binary_schema.pp (Data_encoding.Binary.describe Alpha_context.Operation.unsigned_encoding) >>= fun () -> return_unit); command ~group ~desc:"Summarize the current voting period" no_options (fixed ["show"; "voting"; "period"]) (fun () (cctxt : Alpha_client_context.full) -> get_period_info ~chain:cctxt#chain ~block:cctxt#block cctxt >>=? fun info -> cctxt#message "Current period: %a\nBlocks remaining until end of period: %ld" Data_encoding.Json.pp (Data_encoding.Json.construct Alpha_context.Voting_period.kind_encoding info.current_period_kind) info.remaining >>= fun () -> Shell_services.Protocol.list cctxt >>=? fun known_protos -> get_proposals ~chain:cctxt#chain ~block:cctxt#block cctxt >>=? fun props -> let ranks = Environment.Protocol_hash.Map.bindings props |> List.sort (fun (_, v1) (_, v2) -> Int32.(compare v2 v1)) in let print_proposal = function | None -> assert false (* not called during proposal phase *) | Some proposal -> cctxt#message "Current proposal: %a" Protocol_hash.pp proposal in match info.current_period_kind with | Proposal -> cctxt#answer "Current proposals:%t" Format.( fun ppf -> pp_print_cut ppf () ; pp_open_vbox ppf 0 ; List.iter (fun (p, w) -> fprintf ppf "* %a %ld (%sknown by the node)@." Protocol_hash.pp p w (if List.mem ~equal:Protocol_hash.equal p known_protos then "" else "not ")) ranks ; pp_close_box ppf ()) >>= fun () -> return_unit | Testing_vote | Promotion_vote -> print_proposal info.current_proposal >>= fun () -> get_ballots_info ~chain:cctxt#chain ~block:cctxt#block cctxt >>=? fun ballots_info -> cctxt#answer "Ballots: %a@,\ Current participation %.2f%%, necessary quorum %.2f%%@,\ Current in favor %ld, needed supermajority %ld" Data_encoding.Json.pp (Data_encoding.Json.construct Vote.ballots_encoding ballots_info.ballots) (Int32.to_float ballots_info.participation /. 100.) (Int32.to_float ballots_info.current_quorum /. 100.) ballots_info.ballots.yay ballots_info.supermajority >>= fun () -> return_unit | Testing -> print_proposal info.current_proposal >>= fun () -> return_unit); ]
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
slot_repr.ml
type error += Invalid_slot of int let () = register_error_kind `Permanent ~id:"slot.invalid_slot" ~title:"invalid slot" ~description:"Invalid slot" ~pp:(fun ppf x -> Format.fprintf ppf "invalid slot: %d" x) Data_encoding.(obj1 (req "bad_slot" int31)) (function Invalid_slot x -> Some x | _ -> None) (fun x -> Invalid_slot x) include Compare.Int (* TODO? should there be some assertions to verify that slots are never too big ? Or do that in a storage module that depends on constants ? *) let encoding = Data_encoding.uint16 let pp = Format.pp_print_int let zero = 0 let succ = succ let to_int x = x let max_value = (1 lsl 16) - 1 let of_int_do_not_use_except_for_parameters i = i let of_int_exn i = if Compare.Int.(i < 0 || i > max_value) then invalid_arg (Format.sprintf "valid slot values are in the interval [0, %d] (%d given)" max_value i) else i module Map = Map.Make (Compare.Int) module Set = Set.Make (Compare.Int) module List = struct (* Expected invariant: list of increasing values *) (* TODO find a way to properly enforce this invariant *) type nonrec t = t list module Compressed = struct type elt = {skip : int; take : int} type encoded = elt list let elt_encoding = Data_encoding.( conv (fun {skip; take} -> (skip, take)) (fun (skip, take) -> {skip; take}) (obj2 (req "skip" uint16) (req "take" uint16))) let encoding = Data_encoding.list elt_encoding let encode l : encoded = let rec loop_taking ~pos ~skipped ~taken l = match l with | [] -> if taken > 0 then [{skip = skipped; take = taken}] else [] | h :: t -> if h = pos then loop_taking ~pos:(pos + 1) ~skipped ~taken:(taken + 1) t else let elt = {skip = skipped; take = taken} in let skipped = h - pos in let taken = 1 in let elts = loop_taking ~pos:(h + 1) ~skipped ~taken t in elt :: elts in loop_taking ~pos:0 ~skipped:0 ~taken:0 l let decode (elts : encoded) = let rec loop ~pos elts = match elts with | [] -> Ok [] | elt :: elts -> ( let pos = pos + elt.skip in match List.init ~when_negative_length:() elt.take (fun i -> i + pos) with | Ok l -> ( let pos = pos + elt.take in match loop ~pos elts with Ok t -> Ok (l @ t) | e -> e) | Error () -> Error "A compressed element contains a negative list size") in loop ~pos:0 elts end let encoding = Data_encoding.conv_with_guard Compressed.encode Compressed.decode Compressed.encoding let slot_range ~min ~count = error_when (min < 0) (Invalid_slot min) >>? fun () -> error_when (min > max_value) (Invalid_slot min) >>? fun () -> error_when (count < 1) (Invalid_slot count) >>? fun () -> error_when (count > max_value) (Invalid_slot count) >>? fun () -> let max = min + count - 1 in error_when (max > max_value) (Invalid_slot max) >>? fun () -> ok Misc.(min --> max) end
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2021 Nomadic Labs <contact@nomadic-labs.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
ccl_tcnf.c
#include "ccl_tcnf.h" #include "ccl_formulafunc.h" /*---------------------------------------------------------------------*/ /* Global Variables */ /*---------------------------------------------------------------------*/ /* long SimplificationCounter = 0; */ /*---------------------------------------------------------------------*/ /* Forward Declarations */ /*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/ /* Internal Functions */ /*---------------------------------------------------------------------*/ /*----------------------------------------------------------------------- // // Function: tprop_arg_return_other() // // If one of the args is a propositional formula of the desired // type, return the other one, else return NULL. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ TFormula_p tprop_arg_return_other(Sig_p sig, TFormula_p arg1, TFormula_p arg2, bool positive) { if(TFormulaIsPropConst(sig, arg1, positive)) { return arg2; } else if (TFormulaIsPropConst(sig, arg2, positive)) { return arg1; } return NULL; } /*----------------------------------------------------------------------- // // Function: tprop_arg_return() // // If one of the args is a propositional formula of the desired // type, return it, else return NULL. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ TFormula_p tprop_arg_return(Sig_p sig, TFormula_p arg1, TFormula_p arg2, bool positive) { if(TFormulaIsPropConst(sig, arg1, positive)) { return arg1; } else if (TFormulaIsPropConst(sig, arg2, positive)) { return arg2; } return NULL; } /*----------------------------------------------------------------------- // // Function: troot_nnf() // // Apply all NNF-transformation rules that can be applied at the // root level form and return it. // // Global Variables: // // Side Effects : // /----------------------------------------------------------------------*/ TFormula_p troot_nnf(TB_p terms, TFormula_p form, int polarity) { TFormula_p handle = form, arg1, arg2, arg21, arg22; FunCode f_code; assert((polarity<=1) && (polarity >=-1)); while(handle) { handle = NULL; if(form->f_code == terms->sig->not_code) { if(TFormulaIsLiteral(terms->sig, form->args[0])) { f_code = SigGetOtherEqnCode(terms->sig, form->args[0]->f_code); handle = TFormulaFCodeAlloc(terms, f_code, form->args[0]->args[0], form->args[0]->args[1]); } else if(form->args[0]->f_code == terms->sig->not_code) { handle = form->args[0]->args[0]; } else if(form->args[0]->f_code == terms->sig->or_code) { arg1 = TFormulaFCodeAlloc(terms, terms->sig->not_code, form->args[0]->args[0], NULL); arg2 = TFormulaFCodeAlloc(terms, terms->sig->not_code, form->args[0]->args[1], NULL); handle = TFormulaFCodeAlloc(terms, terms->sig->and_code, arg1, arg2); } else if(form->args[0]->f_code == terms->sig->and_code) { arg1 = TFormulaFCodeAlloc(terms, terms->sig->not_code, form->args[0]->args[0], NULL); arg2 = TFormulaFCodeAlloc(terms, terms->sig->not_code, form->args[0]->args[1], NULL); handle = TFormulaFCodeAlloc(terms, terms->sig->or_code, arg1, arg2); } else if(form->args[0]->f_code == terms->sig->qall_code) { arg1 = TFormulaFCodeAlloc(terms, terms->sig->not_code, form->args[0]->args[1], NULL); handle = TFormulaQuantorAlloc(terms, terms->sig->qex_code, form->args[0]->args[0], arg1); } else if(form->args[0]->f_code == terms->sig->qex_code) { arg1 = TFormulaFCodeAlloc(terms, terms->sig->not_code, form->args[0]->args[1], NULL); handle = TFormulaQuantorAlloc(terms, terms->sig->qall_code, form->args[0]->args[0], arg1); } } else if (form->f_code == terms->sig->impl_code) { arg1 = TFormulaFCodeAlloc(terms, terms->sig->not_code, form->args[0], NULL); handle = TFormulaFCodeAlloc(terms, terms->sig->or_code, arg1, form->args[1]); } else if (form->f_code == terms->sig->equiv_code) { assert((polarity == 1) || (polarity == -1)); if(polarity == 1) { arg1 = TFormulaFCodeAlloc(terms, terms->sig->impl_code, form->args[0], form->args[1]); arg2 = TFormulaFCodeAlloc(terms, terms->sig->impl_code, form->args[1], form->args[0]); handle = TFormulaFCodeAlloc(terms, terms->sig->and_code, arg1, arg2); } else { arg21 = TFormulaFCodeAlloc(terms, terms->sig->not_code, form->args[0], NULL); arg22 = TFormulaFCodeAlloc(terms, terms->sig->not_code, form->args[1], NULL); arg2 = TFormulaFCodeAlloc(terms, terms->sig->and_code, arg21, arg22); arg1 = TFormulaFCodeAlloc(terms, terms->sig->and_code, form->args[0], form->args[1]); handle = TFormulaFCodeAlloc(terms, terms->sig->or_code, arg1, arg2); } } if(handle) { form = handle; } } assert(form); return form; } /*----------------------------------------------------------------------- // // Function: tformula_rec_skolemize() // // Recursively Skolemize form. Note that it is not quite trivial // that it this works, as it works on a shared structure, and the // same subformula may occur in different contexts. It _does_ work // (I hope) because we require that every quantor binds a distinct // variable, and hence terms that were originally equal are either // invariant with respect to context (i.e. they are ground) or // contain different variables, and hence are not shared. // // Global Variables: - // // Side Effects : Changes form (and term bank), adds Skolem terms // to term bank, modifies signature. // /----------------------------------------------------------------------*/ TFormula_p tformula_rek_skolemize(TB_p terms, TFormula_p form, PStack_p free_vars) { Term_p sk_term, var; TFormula_p handle, handle2=NULL; bool modified = false; if(TermIsGround(form)) { /* All is well */ } else if(TFormulaIsLiteral(terms->sig, form)) { form = TFormulaCopy(terms, form); } else if(form->f_code == terms->sig->qex_code) { var = form->args[0]; assert(TermIsVar(var)); assert(!var->binding); sk_term = TBAllocNewSkolem(terms, free_vars, var->type); var->binding = sk_term; form = tformula_rek_skolemize(terms, form->args[1], free_vars); var->binding = NULL; } else if(form->f_code == terms->sig->qall_code) { var = form->args[0]; assert(TermIsVar(var)); assert(!var->binding); PStackPushP(free_vars, var); handle = tformula_rek_skolemize(terms, form->args[1], free_vars); form = TFormulaFCodeAlloc(terms, terms->sig->qall_code, var, handle); (void)PStackPopP(free_vars); } else { assert(TFormulaHasSubForm1(terms->sig, form)); handle = tformula_rek_skolemize(terms, form->args[0], free_vars); modified = handle!=form->args[0]; if(TFormulaHasSubForm2(terms->sig, form)) { handle2 = tformula_rek_skolemize(terms, form->args[1], free_vars); modified |= handle2!=form->args[1]; } if(modified) { form = TFormulaFCodeAlloc(terms, form->f_code, handle, handle2); } } return form; } /*----------------------------------------------------------------------- // // Function: tformula_rename_test() // // Return true if the formula at argument position i should be // renamed, false otherwise. Polarity is the polarity of root, not // root|i. def_limit determines how often a subformula can be // replicated before it is renamed. // // Global Variables: // // Side Effects : - // /----------------------------------------------------------------------*/ bool tformula_rename_test(TB_p bank, TFormula_p root, int pos, int polarity, long def_limit) { int subform_sign; assert((polarity<=1) && (polarity >=-1)); if((root->f_code == bank->sig->qex_code) || (root->f_code == bank->sig->qall_code)) { return false; } if(root->f_code == bank->sig->equiv_code) { if(TFormulaEstimateClauses(bank, root->args[pos],true) > def_limit) { return true; } if(TFormulaEstimateClauses(bank, root->args[pos],false) > def_limit) { return true; } } else { switch(polarity) { case 1: if(root->f_code == bank->sig->or_code && TFormulaEstimateClauses(bank, root->args[pos],true) > def_limit) { return true; } subform_sign = (pos==2?true:false); if(root->f_code == bank->sig->impl_code && TFormulaEstimateClauses(bank, root->args[pos],subform_sign) > def_limit) { return true; } break; case -1: if(root->f_code == bank->sig->and_code && TFormulaEstimateClauses(bank, root->args[pos],false) > def_limit) { return true; } break; case 0: if((root->f_code == bank->sig->and_code || root->f_code == bank->sig->or_code || root->f_code == bank->sig->impl_code) && (TFormulaEstimateClauses(bank, root->args[pos],true) > def_limit || TFormulaEstimateClauses(bank, root->args[pos],false) > def_limit)) { return true; } break; default: assert(false && "Impossible polarity."); break; } } return false; } /*----------------------------------------------------------------------- // // Function: extract_formula_core() // // Remove all (universal) quantifiers from Skolemized form in NNF // and push the corresponding variables onto varstack. // // Global Variables: - // // Side Effects : // /----------------------------------------------------------------------*/ TFormula_p extract_formula_core(TB_p terms, TFormula_p form, PStack_p varstack) { TFormula_p narg0, narg1; PStackPointer sp; while(TFormulaIsQuantified(terms->sig, form)) { /* Skip over variables */ assert(form->f_code == terms->sig->qall_code); PStackPushP(varstack, form->args[0]); form = form->args[1]; } if((form->f_code == terms->sig->and_code)|| (form->f_code == terms->sig->or_code)) { sp = PStackGetSP(varstack); narg0 = extract_formula_core(terms, form->args[0], varstack); narg1 = extract_formula_core(terms, form->args[1], varstack); if(PStackGetSP(varstack)!=sp) { form = TFormulaFCodeAlloc(terms, form->f_code, narg0, narg1); } else { /* Should be no change... */ assert(narg0 == form->args[0]); assert(narg1 == form->args[1]); } } /* else form already is elementary and quantor-free */ return form; } /*----------------------------------------------------------------------- // // Function: extract_formula_core2() // // Remove all quantifiers from form in NNF and push the // corresponding quantifier/variable pairs onto varstack. // // Global Variables: - // // Side Effects : // /----------------------------------------------------------------------*/ TFormula_p extract_formula_core2(TB_p terms, TFormula_p form, PStack_p varstack) { TFormula_p narg0, narg1; PStackPointer sp; while(TFormulaIsQuantified(terms->sig, form)) { /* Skip over variables */ PStackPushInt(varstack, form->f_code); PStackPushP(varstack, form->args[0]); form = form->args[1]; } if((form->f_code == terms->sig->and_code)|| (form->f_code == terms->sig->or_code)) { sp = PStackGetSP(varstack); narg0 = extract_formula_core2(terms, form->args[0], varstack); narg1 = extract_formula_core2(terms, form->args[1], varstack); if(PStackGetSP(varstack)!=sp) { form = TFormulaFCodeAlloc(terms, form->f_code, narg0, narg1); } else { /* Should be no change... */ assert(narg0 == form->args[0]); assert(narg1 == form->args[1]); } } /* else form already is elementary and quantor-free */ return form; } /*----------------------------------------------------------------------- // // Function: tform_mark_varocc() // // Mark all subforms/subterms in form in which var occurs. // // Global Variables: - // // Side Effects : Sets TPOpFlag, TPCheckFlag // /----------------------------------------------------------------------*/ /* __attribute__((noinline)) */ static bool tform_mark_varocc(TFormula_p form, Term_p var, TermProperties proc) { bool res = false; if(TermCellGiveProps(form, TPOpFlag)!=proc) { TermProperties found = TPIgnoreProps; if(form == var) { found = TPCheckFlag; } else { int i; for(i=0; i<form->arity; i++) { if(tform_mark_varocc(form->args[i], var, proc)) { found = TPCheckFlag; } } } TermCellAssignProp(form, TPOpFlag|TPCheckFlag, proc|found); } res = TermCellQueryProp(form, TPCheckFlag); //printf("# FCode: %ld VCode: %ld, Mark: %d Real: %d\n", // form->f_code, var->f_code, // res, TBTermIsSubterm(form, var)); assert(res == TBTermIsSubterm(form,var)); return res; } /*----------------------------------------------------------------------- // // Function: miniscope_qex() // // Assume var is existentially quantified in var and move the // quantifier inward as far as possible. Assumes that form is in NNF // and that TPCheckFlag is set in all subformulas of form in which // var occurs. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ static TFormula_p miniscope_qex(TB_p terms, TFormula_p form, Term_p var, TermProperties proc) { TFormula_p arg1, arg2; if(TermCellQueryProp(form, TPCheckFlag)) { if(form->f_code == terms->sig->and_code) { if(!TermCellQueryProp(form->args[0], TPCheckFlag)) { arg1 = form->args[0]; arg2 = miniscope_qex(terms, form->args[1], var, proc); form = TFormulaFCodeAlloc(terms, form->f_code, arg1, arg2); } else if(!TermCellQueryProp(form->args[1], TPCheckFlag)) { arg1 = miniscope_qex(terms, form->args[0], var, proc); arg2 = form->args[1]; form = TFormulaFCodeAlloc(terms, form->f_code, arg1, arg2); } else { form = TFormulaQuantorAlloc(terms, terms->sig->qex_code, var, form); } } else if(form->f_code == terms->sig->or_code) { arg1 = miniscope_qex(terms, form->args[0], var, proc); arg2 = miniscope_qex(terms, form->args[1], var, proc); form = TFormulaFCodeAlloc(terms, form->f_code, arg1, arg2); } else { form = TFormulaQuantorAlloc(terms, terms->sig->qex_code, var, form); } TermCellAssignProp(form, TPOpFlag, proc); } /* Else we don't need a quantifier */ return form; } /*----------------------------------------------------------------------- // // Function: miniscope_qall() // // Assume var is universally quantified in var and move the // quantifier inward as far as possible. Assumes that form is in NNF // and that TPCheckFlag is set in all subformulas of form in which // var occurs. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ static TFormula_p miniscope_qall(TB_p terms, TFormula_p form, Term_p var, TermProperties proc) { TFormula_p arg1, arg2; if(TermCellQueryProp(form, TPCheckFlag)) { if(form->f_code == terms->sig->or_code) { if(!TermCellQueryProp(form->args[0], TPCheckFlag)) { arg1 = form->args[0]; arg2 = miniscope_qall(terms, form->args[1], var, proc); form = TFormulaFCodeAlloc(terms, form->f_code, arg1, arg2); } else if(!TermCellQueryProp(form->args[1], TPCheckFlag)) { arg1 = miniscope_qall(terms, form->args[0], var, proc); arg2 = form->args[1]; form = TFormulaFCodeAlloc(terms, form->f_code, arg1, arg2); } else { form = TFormulaQuantorAlloc(terms, terms->sig->qall_code, var, form); } } else if(form->f_code == terms->sig->and_code) { arg1 = miniscope_qall(terms, form->args[0], var, proc); arg2 = miniscope_qall(terms, form->args[1], var, proc); form = TFormulaFCodeAlloc(terms, form->f_code, arg1, arg2); } else { form = TFormulaQuantorAlloc(terms, terms->sig->qall_code, var, form); } TermCellAssignProp(form, TPOpFlag, proc); } /* Else we don't need a quantifier */ return form; } /*----------------------------------------------------------------------- // // Function: tform_find_miniscopeable() // // Find all maximal miniscopable subformulas. A formula is // miniscopable, if it has at most limit subformulae, starts with a // universal quantifier, and contains an existential quantifier (we // only miniscope with the goal of moving existential quantifier out // of the scope of universal quantifiers - and that not at all // costs ;-). Return value is the size, candidates are stored in the // ptree at candidates, and the existance of an existential // quantifier is returned via *exq. Sometime I'm longing for // tuples... // // Global Variables: // // Side Effects : // /----------------------------------------------------------------------*/ long tform_find_miniscopeable(Sig_p sig, TFormula_p form, long limit, PTree_p *candidates, bool *exq) { bool lexq = false; long size; PTree_p lcands = NULL; assert(!TermIsVar(form)); if(!form->v_count) { return LONG_MAX; } if(TFormulaIsLiteral(sig, form)) { return 1; } if(TFormulaIsQuantified(sig, form)) { size = 1+tform_find_miniscopeable(sig, form->args[1], limit, &lcands, &lexq); if(form->f_code == sig->qex_code) { *exq = true; PTreeMerge(candidates, lcands); } else /* Universal quantifier */ { if(size<=limit && lexq) { PTreeFree(lcands); PTreeStore(candidates, form); } else { PTreeMerge(candidates, lcands); } *exq = lexq; } } else { size = 1; if(TFormulaHasSubForm1(sig, form)) { size += size+tform_find_miniscopeable(sig, form->args[0], limit, &lcands, &lexq); PTreeMerge(candidates, lcands); lcands = NULL; *exq |= lexq; } if(TFormulaHasSubForm2(sig, form)) { size += size+tform_find_miniscopeable(sig, form->args[1], limit, &lcands, &lexq); PTreeMerge(candidates, lcands); *exq |= lexq; } } return size; } /*----------------------------------------------------------------------- // // Function: tform_copy_mod() // // Copy a formula, following "binding" when it is set. Ground // formumas, variables, and literals are returned as-is. // // Global Variables: - // // Side Effects : Memory operations // /----------------------------------------------------------------------*/ TFormula_p tform_copy_mod(TB_p terms, TFormula_p form) { TFormula_p arg1=NULL, arg2=NULL; bool changed = false; if(TFormulaIsLiteral(terms->sig, form) ||!form->v_count ||TermIsVar(form)) { return form; } if(form->binding) { return form->binding; } if(TFormulaHasSubForm1(terms->sig, form)) { arg1 = tform_copy_mod(terms, form->args[0]); changed |= arg1!=form->args[0]; } if(TFormulaHasSubForm2(terms->sig, form)) { arg2 = tform_copy_mod(terms, form->args[1]); changed |= arg2!=form->args[1]; } if(changed) { form = TFormulaFCodeAlloc(terms, form->f_code, arg1, arg2); } return form; } /*---------------------------------------------------------------------*/ /* Exported Functions */ /*---------------------------------------------------------------------*/ /*----------------------------------------------------------------------- // // Function: TFormulaEstimateClauses() // // Given a formula, estimate how many clauses would be generated by // it. Assumes that formulas with TPCheckFlag are renamed into // atoms. If too many formulas result, just return // TFORM_MANY_CLAUSES. // // Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ #define RETURN_IF_LARGE(param) \ if((param) == TFORM_MANY_CLAUSES){return TFORM_MANY_CLAUSES;} long TFormulaEstimateClauses(TB_p bank, TFormula_p form, bool pos) { long posres1, posres2, negres1, negres2, res=0; assert(bank && form); assert((pos == true) || (pos == false)); /* printf("Estimating: ");TBPrintTermFull(stdout, bank, form);*/ if(TermCellQueryProp(form, TPCheckFlag) || TFormulaIsLiteral(bank->sig, form)) { return 1; } if(pos) { if(form->f_code == bank->sig->and_code) { posres1 = TFormulaEstimateClauses(bank, form->args[0], true); RETURN_IF_LARGE(posres1); posres2 = TFormulaEstimateClauses(bank, form->args[1], true); RETURN_IF_LARGE(posres2); res = posres1 + posres2; } else if(form->f_code == bank->sig->or_code) { posres1 = TFormulaEstimateClauses(bank, form->args[0], true); RETURN_IF_LARGE(posres1); posres2 = TFormulaEstimateClauses(bank, form->args[1], true); RETURN_IF_LARGE(posres2); res = posres1 * posres2; } else if(form->f_code == bank->sig->impl_code) { negres1 = TFormulaEstimateClauses(bank, form->args[0], false); RETURN_IF_LARGE(negres1); posres2 = TFormulaEstimateClauses(bank, form->args[1], true); RETURN_IF_LARGE(posres2); res = negres1 * posres2; } else if(form->f_code == bank->sig->equiv_code) { posres1 = TFormulaEstimateClauses(bank, form->args[0], true); RETURN_IF_LARGE(posres1); posres2 = TFormulaEstimateClauses(bank, form->args[1], true); RETURN_IF_LARGE(posres2); negres1 = TFormulaEstimateClauses(bank, form->args[0], false); RETURN_IF_LARGE(negres1); negres2 = TFormulaEstimateClauses(bank, form->args[1], false); RETURN_IF_LARGE(negres2); res = posres1*negres2+negres1*posres2; } else if(form->f_code == bank->sig->not_code) { negres1 = TFormulaEstimateClauses(bank, form->args[0], false); RETURN_IF_LARGE(negres1); res = negres1; } else if(TFormulaIsQuantified(bank->sig,form)) { posres1 = TFormulaEstimateClauses(bank, form->args[1], true); RETURN_IF_LARGE(posres1); res = posres1; } else { assert(false && "Formula not in correct simplified form"); } } else { if(form->f_code == bank->sig->and_code) { negres1 = TFormulaEstimateClauses(bank, form->args[0], false); RETURN_IF_LARGE(negres1); negres2 = TFormulaEstimateClauses(bank, form->args[1], false); RETURN_IF_LARGE(negres2); res = negres1 * negres2; } else if(form->f_code == bank->sig->or_code) { negres1 = TFormulaEstimateClauses(bank, form->args[0], false); RETURN_IF_LARGE(negres1); negres2 = TFormulaEstimateClauses(bank, form->args[1], false); RETURN_IF_LARGE(negres2); res = negres1 + negres2; } else if(form->f_code == bank->sig->impl_code) { posres1 = TFormulaEstimateClauses(bank, form->args[0], true); RETURN_IF_LARGE(posres1); negres2 = TFormulaEstimateClauses(bank, form->args[1], false); RETURN_IF_LARGE(negres2); res = posres1 + negres2; } else if(form->f_code == bank->sig->equiv_code) { posres1 = TFormulaEstimateClauses(bank, form->args[0], true); RETURN_IF_LARGE(posres1); posres2 = TFormulaEstimateClauses(bank, form->args[1], true); RETURN_IF_LARGE(posres2); negres1 = TFormulaEstimateClauses(bank, form->args[0], false); RETURN_IF_LARGE(negres1); negres2 = TFormulaEstimateClauses(bank, form->args[1], false); RETURN_IF_LARGE(negres2); res = posres1*posres2+negres1*negres2; } else if(form->f_code == bank->sig->not_code) { posres1 = TFormulaEstimateClauses(bank, form->args[0], true); RETURN_IF_LARGE(posres1); res = posres1; } else if(TFormulaIsQuantified(bank->sig,form)) { negres1 = TFormulaEstimateClauses(bank, form->args[1], false); RETURN_IF_LARGE(negres1); res = negres1; } else { fprintf(stderr, "error in "); TermPrintDbg(stderr, form, bank->sig, DEREF_NEVER); fprintf(stderr, ".\n"); assert(false && "Formula not in correct simplified form"); } } if(res > TFORM_MANY_LIMIT) { res = TFORM_MANY_CLAUSES; } return res; } /*----------------------------------------------------------------------- // // Function: TFormulaDefRename() // // Given a tformula, return a renaming atom for it and register // the (potential) need for a renaming formula of the proper // polarity in defs. In defs, the key is the entry_no, val1 is the // most general polarity, and val2 is the renaming atom. // // Global Variables: - // // Side Effects : Changes bank and defs. // /----------------------------------------------------------------------*/ TFormula_p TFormulaDefRename(TB_p bank, TFormula_p form, int polarity, NumXTree_p *defs, PStack_p renamed_forms) { NumXTree_p def = NumXTreeFind(defs, form->entry_no); assert((polarity<=1) && (polarity >=-1)); if(def) { if(polarity!=def->vals[0].i_val) { def->vals[0].i_val = 0; } return def->vals[1].p_val; } else { PTree_p free_vars = NULL; PStack_p var_stack = PStackAlloc(); TFormula_p rename_atom; VarBankVarsSetProp(bank->vars, TPIsFreeVar); TFormulaCollectFreeVars(bank, form, &free_vars); PTreeToPStack(var_stack, free_vars); /* printf("# Found %d free variables\n", PStackGetSP(var_stack)); */ rename_atom = TBAllocNewSkolem(bank, var_stack, bank->sig->type_bank->bool_type); rename_atom = EqnTermsTBTermEncode(bank, rename_atom, bank->true_term, true, PENormal); PStackFree(var_stack); PTreeFree(free_vars); def = NumXTreeCellAlloc(); def->key = form->entry_no; def->vals[0].i_val = polarity; def->vals[1].p_val = rename_atom; NumXTreeInsert(defs, def); TermCellSetProp(form, TPCheckFlag); PStackPushP(renamed_forms, form); return def->vals[1].p_val; } } /*----------------------------------------------------------------------- // // Function: TFormulaFindDefs() // // Find all useful definitions in form and enter them in defs and // renamed_forms. def_limit determines when a formula is // replicated sufficiently often to warrant renaming. // // Remember: TPCheckFlag means we already have a definition for // this formula (though possibly not of the right polarity). // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ void TFormulaFindDefs(TB_p bank, TFormula_p form, int polarity, long def_limit, NumXTree_p *defs, PStack_p renamed_forms) { assert((polarity<=1) && (polarity >=-1)); //printf("TFormulaFindDefs(%ld)...\n",TermDepth(form)); if(TFormulaIsLiteral(bank->sig, form)) { return; } if(TermCellQueryProp(form, TPCheckFlag)) { /* We already have a definition, but it may be of the wrong * polarity to be applied here (and it will be, for * consistency). Easiest way to handle this is to just to re-add * it with the current polarity - if necessary, this will extend * the definition to deal with a more general polarity.*/ TFormulaDefRename(bank, form, polarity, defs, renamed_forms); /* And this potentially different polarity applies to // subformulae, hence "return" is WRONG!!! // return;*/ } /* Check if we want to rename args[0] (we are doing depth * first). Also remember that we check if a _subformula_ should be * renamed! */ if((form->f_code == bank->sig->and_code)|| (form->f_code == bank->sig->or_code)) { TFormulaFindDefs(bank, form->args[0], polarity, def_limit, defs, renamed_forms); if(tformula_rename_test(bank, form, 0, polarity, def_limit)) { TFormulaDefRename(bank, form->args[0], polarity, defs, renamed_forms); } } else if((form->f_code == bank->sig->not_code)|| (form->f_code == bank->sig->impl_code)) { TFormulaFindDefs(bank, form->args[0], -polarity, def_limit,defs, renamed_forms); if(tformula_rename_test(bank, form, 0, -polarity, def_limit)) { TFormulaDefRename(bank, form->args[0], -polarity, defs, renamed_forms); } } else if(form->f_code == bank->sig->equiv_code) { TFormulaFindDefs(bank, form->args[0], 0, def_limit, defs, renamed_forms); if(tformula_rename_test(bank, form, 0, polarity, def_limit)) { TFormulaDefRename(bank, form->args[0], 0, defs, renamed_forms); } } /* Handle args[1] */ if((form->f_code == bank->sig->and_code)|| (form->f_code == bank->sig->or_code) || (form->f_code == bank->sig->impl_code)|| (form->f_code == bank->sig->qex_code)|| (form->f_code == bank->sig->qall_code)) { TFormulaFindDefs(bank, form->args[1], polarity, def_limit, defs, renamed_forms); if(tformula_rename_test(bank, form, 1, polarity, def_limit)) { TFormulaDefRename(bank, form->args[1], polarity, defs, renamed_forms); } } else if(form->f_code == bank->sig->equiv_code) { TFormulaFindDefs(bank, form->args[1], 0, def_limit, defs, renamed_forms); if(tformula_rename_test(bank, form, 1, polarity, def_limit)) { TFormulaDefRename(bank, form->args[1], 0, defs, renamed_forms); } } } /*----------------------------------------------------------------------- // // Function: TFormulaCopyDef() // // Copy a formula, replacing all defined subformulas (except for the // blocked one, if any) with the proper definition). Record _all_ // definitions (but not sub-definitions) on the stack (by pushing the // definition numbers onto the stack). // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ TFormula_p TFormulaCopyDef(TB_p bank, TFormula_p form, long blocked, NumXTree_p *defs, PStack_p defs_used) { TFormula_p res = NULL, arg1, arg2 = NULL; NumXTree_p def_entry; long realdef; if(TFormulaIsLiteral(bank->sig, form)) { res = form; } else if(TermCellQueryProp(form, TPCheckFlag)) { def_entry = NumXTreeFind(defs, form->entry_no); assert(def_entry); realdef = def_entry->vals[2].i_val; if(realdef!=blocked) { res = def_entry->vals[1].p_val; PStackPushP(defs_used, def_entry->vals[3].p_val); } } if(!res) { if((form->f_code == bank->sig->and_code)|| (form->f_code == bank->sig->or_code)|| (form->f_code == bank->sig->impl_code)|| (form->f_code == bank->sig->equiv_code)|| (form->f_code == bank->sig->nand_code)|| (form->f_code == bank->sig->nor_code)|| (form->f_code == bank->sig->bimpl_code)|| (form->f_code == bank->sig->xor_code)|| (form->f_code == bank->sig->not_code)) { arg1 = TFormulaCopyDef(bank, form->args[0], blocked, defs, defs_used); } else { assert((form->f_code == bank->sig->qex_code) || (form->f_code == bank->sig->qall_code)); arg1 = form->args[0]; } if(form->f_code != bank->sig->not_code) { arg2 = TFormulaCopyDef(bank, form->args[1], blocked, defs, defs_used); } res = TFormulaFCodeAlloc(bank, form->f_code, arg1, arg2); } return res; } /*----------------------------------------------------------------------- // // Function: TFormulaNegAlloc() // // Return a formula equivalent to ~form. If form is of the form ~f, // return f, otherwise ~form. // // Global Variables: - // // Side Effects : Memory operations // /----------------------------------------------------------------------*/ TFormula_p TFormulaNegAlloc(TB_p terms, TFormula_p form) { if(form->f_code == terms->sig->not_code) { return form->args[0]; } return TFormulaFCodeAlloc(terms, terms->sig->not_code, form, NULL); } /*----------------------------------------------------------------------- // // Function: TFormulaSimplify() // // Maximally simplify a formula using (primarily) // the simplification rules (from [NW:SmallCNF-2001]). // // P | P => P P | T => T P | F => P // P & P => F P & T => P P & F -> F // ~T = F ~F = T // P <-> P => T P <-> F => ~P P <-> T => P // P <~> P => ~(P<->P) // P -> P => T P -> T => T P -> F => ~P // ... // // We only check for redundant quantifiers in "small" formulas // (weight less than quopt_limit) // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ TFormula_p TFormulaSimplify(TB_p terms, TFormula_p form, long quopt_limit) { TFormula_p handle, arg1=NULL, arg2=NULL, newform; FunCode f_code; bool modified=false; assert(terms); // printf("Simplify %p %ld: ", form, form->weight);/* TFormulaTPTPPrint(stdout, terms, form, true, false)*/;printf("\n"); if(TFormulaIsLiteral(terms->sig, form)) { return form; } if(TFormulaHasSubForm1(terms->sig,form)) { arg1 = TFormulaSimplify(terms, form->args[0], quopt_limit); modified = arg1!=form->args[0]; } else if(TFormulaIsQuantified(terms->sig, form)) { arg1 = form->args[0]; } if(TFormulaHasSubForm2(terms->sig, form)|| TFormulaIsQuantified(terms->sig, form)) { arg2 = TFormulaSimplify(terms, form->args[1], quopt_limit); modified |= arg2!=form->args[1]; } if(modified) { assert(terms); form = TFormulaFCodeAlloc(terms, form->f_code, arg1, arg2); } modified = true; while(modified) { // printf("Loop %p %ld: ", form, form->weight);/*TFormulaTPTPPrint(stdout, terms, form, true, false);*/printf("\n"); modified = false; newform = form; /* Inelegant, fix when awake! */ if(form->f_code == terms->sig->not_code) { if(TFormulaIsLiteral(terms->sig, form->args[0])) { f_code = SigGetOtherEqnCode(terms->sig, form->args[0]->f_code); newform = TFormulaFCodeAlloc(terms, f_code, form->args[0]->args[0], form->args[0]->args[1]); } } else if(form->f_code == terms->sig->or_code) { if((handle = tprop_arg_return_other(terms->sig, form->args[0], form->args[1], false))) { newform = handle; } else if((handle = tprop_arg_return(terms->sig, form->args[0], form->args[1], true))) { newform = handle; } else if(TFormulaEqual(form->args[0], form->args[1])) { newform = form->args[0]; } } else if(form->f_code == terms->sig->and_code) { if((handle = tprop_arg_return_other(terms->sig, form->args[0], form->args[1], true))) { newform = handle; } else if((handle = tprop_arg_return(terms->sig, form->args[0], form->args[1], false))) { newform = handle; } else if(TFormulaEqual(form->args[0], form->args[1])) { newform = form->args[0]; } } else if(form->f_code == terms->sig->equiv_code) { if((handle = tprop_arg_return_other(terms->sig, form->args[0], form->args[1], true))) { /* p <=> T -> p */ newform = handle; } else if((handle = tprop_arg_return_other(terms->sig, form->args[0], form->args[1], false))) { /* p <=> F -> ~p */ newform = TFormulaNegAlloc(terms, handle); } else if(TFormulaEqual(form->args[0], form->args[1])) { newform = TFormulaPropConstantAlloc(terms, true); } } else if(form->f_code == terms->sig->impl_code) { if(TFormulaIsPropTrue(terms->sig, form->args[0])) { /* T => p -> p */ newform = form->args[1]; } else if(TFormulaIsPropFalse(terms->sig, form->args[0])) { /* F => p -> T */ newform = TFormulaPropConstantAlloc(terms, true); } else if(TFormulaIsPropFalse(terms->sig, form->args[1])) { /* p => F -> ~p */ newform = TFormulaNegAlloc(terms, form->args[0]); } else if(TFormulaIsPropTrue(terms->sig, form->args[1])) { /* p => T -> T */ newform = TFormulaPropConstantAlloc(terms, true); } else if(TFormulaEqual(form->args[0], form->args[1])) { /* p => p -> T */ newform = TFormulaPropConstantAlloc(terms, true); } } else if(form->f_code == terms->sig->xor_code) { handle = TFormulaFCodeAlloc(terms, terms->sig->equiv_code, form->args[0], form->args[1]); newform = TFormulaFCodeAlloc(terms, terms->sig->not_code, handle, NULL); newform = TFormulaSimplify(terms, newform, quopt_limit); } else if(form->f_code == terms->sig->bimpl_code) { newform = TFormulaFCodeAlloc(terms, terms->sig->impl_code, form->args[1], form->args[0]); newform = TFormulaSimplify(terms, newform, quopt_limit); } else if(form->f_code == terms->sig->nor_code) { handle = TFormulaFCodeAlloc(terms, terms->sig->or_code, form->args[0], form->args[1]); newform = TFormulaFCodeAlloc(terms, terms->sig->not_code, handle, NULL); newform = TFormulaSimplify(terms, newform, quopt_limit); } else if(form->f_code == terms->sig->nand_code) { handle = TFormulaFCodeAlloc(terms, terms->sig->and_code, form->args[0], form->args[1]); newform = TFormulaFCodeAlloc(terms, terms->sig->not_code, handle, NULL); newform = TFormulaSimplify(terms, newform, quopt_limit); } else if((form->f_code == terms->sig->qex_code)|| (form->f_code == terms->sig->qall_code)) { if(!form->v_count || ((form->weight<=quopt_limit) && !TFormulaVarIsFree(terms, form->args[1], form->args[0]))) { newform = form->args[1]; } } if(newform!=form) { modified = true; form = newform; } } return newform; } /*----------------------------------------------------------------------- // // Function: TFormulaNNF() // // Destructively transform a (simplified) formula into NNF. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ TFormula_p TFormulaNNF(TB_p terms, TFormula_p form, int polarity) { bool normalform = false; TFormula_p handle, handle2; assert(form && terms); assert((polarity<=1) && (polarity >=-1)); while(!normalform) { normalform = true; handle = troot_nnf(terms, form, polarity); assert(handle); form = handle; if(form->f_code == terms->sig->not_code) { handle = TFormulaNNF(terms, form->args[0], -polarity); if(handle!=form->args[0]) { normalform = false; form = TFormulaFCodeAlloc(terms, terms->sig->not_code, handle, NULL); } } else if((form->f_code == terms->sig->qex_code)|| (form->f_code == terms->sig->qall_code)) { handle = TFormulaNNF(terms, form->args[1], polarity); if(handle!=form->args[1]) { normalform = false; form = TFormulaFCodeAlloc(terms, form->f_code, form->args[0], handle); } } else if((form->f_code == terms->sig->and_code)|| (form->f_code == terms->sig->or_code)) { handle = TFormulaNNF(terms, form->args[0], polarity); assert(handle); handle2 = TFormulaNNF(terms, form->args[1], polarity); assert(handle2); if((handle!=form->args[0]) || (handle2!=form->args[1])) { normalform = false; form = TFormulaFCodeAlloc(terms, form->f_code, handle, handle2); } } else { assert(TFormulaIsLiteral(terms->sig, form) && "Top level term not in normal form"); } } assert(form); return form; } /*----------------------------------------------------------------------- // // Function: TFormulaMiniScope() // // Perform mini-scoping, i.e. move quantors inward as far as // possible. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ TFormula_p TFormulaMiniScope(TB_p terms, TFormula_p form) { bool modified; TFormula_p arg1,arg2; FunCode op, quant; if(TFormulaIsQuantified(terms->sig, form)) { op = form->args[1]->f_code; quant = form->f_code; if((op == terms->sig->and_code) || (op == terms->sig->or_code)) { if(!TFormulaVarIsFree(terms, form->args[1]->args[0], form->args[0])) { arg2 = TFormulaQuantorAlloc(terms, quant, form->args[0], form->args[1]->args[1]); arg1 = form->args[1]->args[0]; form = TFormulaFCodeAlloc(terms, op, arg1, arg2); } else if(!TFormulaVarIsFree(terms, form->args[1]->args[1], form->args[0])) { arg1 = TFormulaQuantorAlloc(terms, quant, form->args[0], form->args[1]->args[0]); arg2 = form->args[1]->args[1]; form = TFormulaFCodeAlloc(terms, op, arg1, arg2); } else { if((op == terms->sig->and_code) && (quant == terms->sig->qall_code)) { arg1 = TFormulaQuantorAlloc(terms, terms->sig->qall_code, form->args[0], form->args[1]->args[0]); arg2 = TFormulaQuantorAlloc(terms, terms->sig->qall_code, form->args[0], form->args[1]->args[1]); form = TFormulaFCodeAlloc(terms, terms->sig->and_code, arg1, arg2); } else if((op == terms->sig->or_code) && (quant == terms->sig->qex_code)) { arg1 = TFormulaQuantorAlloc(terms, terms->sig->qex_code, form->args[0], form->args[1]->args[0]); arg2 = TFormulaQuantorAlloc(terms, terms->sig->qex_code, form->args[0], form->args[1]->args[1]); form = TFormulaFCodeAlloc(terms, terms->sig->or_code, arg1, arg2); } } } } arg1 = form->args[0]; arg2 = form->args[1]; modified = false; if(TFormulaHasSubForm1(terms->sig, form)) { arg1 = TFormulaMiniScope(terms,form->args[0]); modified = arg1!=form->args[0]; } if(TFormulaHasSubForm2(terms->sig, form) || TFormulaIsQuantified(terms->sig, form)) { arg2 = TFormulaMiniScope(terms,form->args[1]); modified |= arg2!=form->args[1]; } if(modified) { form = TFormulaFCodeAlloc(terms, form->f_code, arg1, arg2); form = TFormulaMiniScope(terms, form); } return form; } /*----------------------------------------------------------------------- // // Function: TFormulaMiniScope2() // // Perform mini-scoping, i.e. move quantors inward as far as // possible. Assumes that variables for each quantor are unique, and // that the formula is in NNF. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ TFormula_p TFormulaMiniScope2(TB_p terms, TFormula_p form, long miniscope_limit) { Term_p var; FunCode quantor, qex, qall; PStack_p prenex = PStackAlloc(); TermProperties proc = TPOpFlag; form = extract_formula_core2(terms, form, prenex); qall = terms->sig->qall_code; qex = terms->sig->qex_code; TermDelPropOpt(form, TPOpFlag|TPCheckFlag); while(!PStackEmpty(prenex)) { var = PStackPopP(prenex); //printf("# MiniScope ");TermPrint(stdout, var, terms->sig, DEREF_NEVER);printf("\n"); quantor = PStackPopInt(prenex); if(miniscope_limit) { miniscope_limit--; assert(TermVerifyProp(form, DEREF_NEVER, TPOpFlag, proc?TPIgnoreProps:TPOpFlag)); tform_mark_varocc(form, var, proc); assert(TermVerifyProp(form, DEREF_NEVER, TPOpFlag, proc)); if(quantor == qex) { form = miniscope_qex(terms, form, var, proc); } else if(quantor == qall) { form = miniscope_qall(terms, form, var, proc); } else { assert(false && "Only universal or existential quantifier allowed"); } proc = proc?TPIgnoreProps:TPOpFlag; } else { form = TFormulaFCodeAlloc(terms, quantor, var, form); } } PStackFree(prenex); return form; } /*----------------------------------------------------------------------- // // Function: TFormulaMiniScope3() // // Perform (conditional) mini-scoping, i.e. move quantors inward as // far as possible if there are "small" subformulas that might // profit from miniskoping. Assumes that variables for each quantor // are unique, and that the formula is in NNF. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ TFormula_p TFormulaMiniScope3(TB_p terms, TFormula_p form, long miniscope_limit) { PTree_p ms_forms = NULL, entry; bool exq = false; TFormula_p cand; tform_find_miniscopeable(terms->sig, form, miniscope_limit, &ms_forms, &exq); if(ms_forms) { assert(exq); PStack_p iter; // printf("# Found %ld positions\n", PTreeNodes(ms_forms)); iter = PTreeTraverseInit(ms_forms); while((entry = PTreeTraverseNext(iter))) { cand = entry->key; assert(!cand->binding); cand->binding = TFormulaMiniScope(terms, cand); } PTreeTraverseExit(iter); form = tform_copy_mod(terms, form); iter = PTreeTraverseInit(ms_forms); while((entry = PTreeTraverseNext(iter))) { cand = entry->key; cand->binding = NULL; } PTreeTraverseExit(iter); } PTreeFree(ms_forms); return form; } /*----------------------------------------------------------------------- // // Function: TFormulaVarRename() // // Convert the formula into one where all the bound variables have // been replaced by fresh one. // // IMPORTANT PRECONDITION: terms->vars->f_count _must_ point to a // variable bigger than all in form. // // Global Variables: - // // Side Effects : Consumes fresh variables from the term bank. // /----------------------------------------------------------------------*/ TFormula_p TFormulaVarRename(TB_p terms, TFormula_p form) { assert(!TermIsAppliedVar(form)); Term_p old_var = NULL, new_var = NULL; TFormula_p handle = NULL, arg1=NULL, arg2=NULL; if(TFormulaIsQuantified(terms->sig, form)) { old_var = form->args[0]->binding; new_var = VarBankGetFreshVar(terms->vars, form->args[0]->type); assert(new_var != form->args[0]); form->args[0]->binding = new_var; } if(form->f_code == SIG_LET_CODE || form->f_code == SIG_ITE_CODE) { TFormula_p newform = TermTopCopyWithoutArgs(form); for(long i=0; i < newform->arity; i++) { newform->args[i] = TFormulaVarRename(terms, form->args[i]); } handle = TBTermTopInsert(terms, newform); } else if(TFormulaIsLiteral(terms->sig, form)) { handle = TFormulaCopy(terms, form); } else { if(TFormulaIsQuantified(terms->sig, form)) { arg1 = new_var; arg2 = TFormulaVarRename(terms, form->args[1]); } else if(TFormulaHasSubForm1(terms->sig, form)) { arg1 = TFormulaVarRename(terms, form->args[0]); } if(TFormulaHasSubForm2(terms->sig, form)) { arg2 = TFormulaVarRename(terms, form->args[1]); } handle = TFormulaFCodeAlloc(terms, form->f_code, arg1, arg2); } if(TFormulaIsQuantified(terms->sig, form)) { form->args[0]->binding = old_var; } return handle; } /*----------------------------------------------------------------------- // // Function: FormulaSkolemizeOutermost() // // Skolemize a formula in an outermost // manner. Interpretes the formula as its universal closure, // i.e. globally free variables in form are used as Skolem function // arguments. Also assumes that every quantor binds a new // variable. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ TFormula_p TFormulaSkolemizeOutermost(TB_p terms, TFormula_p form) { TFormula_p res = NULL; PTree_p free_vars = NULL; PStack_p var_stack = PStackAlloc(); Term_p var; /* The next line should now be unnecessary, since formulas need to be closed. But let's be conservative for now... */ TFormulaCollectFreeVars(terms, form, &free_vars); while(free_vars) { var = PTreeExtractRootKey(&free_vars); PStackPushP(var_stack, var); } res = tformula_rek_skolemize(terms, form, var_stack); PStackFree(var_stack); return res; } /*----------------------------------------------------------------------- // // Function: TFormulaShiftQuantors() // // Shift all remaining all-quantors outward. This has several // premises: // - All quantified variables are disjoint from each other and from // the free variables. // - The formula is in negation normal form. // - All quantifiers are universal. // // Global Variables: - // // Side Effects : Destroys original formula. // /----------------------------------------------------------------------*/ TFormula_p TFormulaShiftQuantors(TB_p terms, TFormula_p form) { Term_p var; PStack_p varstack; varstack = PStackAlloc(); form = extract_formula_core(terms, form, varstack); while(!PStackEmpty(varstack)) { var = PStackPopP(varstack); form = TFormulaQuantorAlloc(terms, terms->sig->qall_code, var, form); } PStackFree(varstack); return form; } /*----------------------------------------------------------------------- // // Function: TFormulaShiftQuantors2() // // Shift all all-quantors outward. This has several // premises: // - All quantified variables are disjoint from each other and from // the free variables. // - The formula is in negation normal form. // // Global Variables: - // // Side Effects : Destroys original formula. // /----------------------------------------------------------------------*/ TFormula_p TFormulaShiftQuantors2(TB_p terms, TFormula_p form) { Term_p var; FunCode quantor; PStack_p varstack; varstack = PStackAlloc(); form = extract_formula_core2(terms, form, varstack); while(!PStackEmpty(varstack)) { var = PStackPopP(varstack); quantor = PStackPopInt(varstack); form = TFormulaQuantorAlloc(terms, quantor, var, form); } PStackFree(varstack); return form; } /*----------------------------------------------------------------------- // // Function: TFormulaDistributeDisjunctions() // // Apply distributivity law to transform a suitably preprocessed // formula into conjunctive normal form. // // Global Variables: - // // Side Effects : Rebuilds formula // /----------------------------------------------------------------------*/ TFormula_p TFormulaDistributeDisjunctions(TB_p terms, TFormula_p form) { TFormula_p handle, narg1=NULL, narg2=NULL; bool change = false; // formula is in NNF assert((TFormulaIsQuantified(terms->sig, form) || form->f_code == terms->sig->or_code || form->f_code == terms->sig->and_code || TFormulaIsLiteral(terms->sig, form))); if(TFormulaHasSubForm1(terms->sig, form)) { narg1 = TFormulaDistributeDisjunctions(terms, form->args[0]); change = narg1!=form->args[0]; } else if(TFormulaIsQuantified(terms->sig, form)) { narg1=form->args[0]; } if(TFormulaHasSubForm2(terms->sig, form)|| TFormulaIsQuantified(terms->sig, form)) { narg2 = TFormulaDistributeDisjunctions(terms, form->args[1]); change |= narg2!=form->args[1]; } if(change) { form = TFormulaFCodeAlloc(terms, form->f_code, narg1, narg2); } if(form->f_code == terms->sig->or_code) { if(form->args[0]->f_code == terms->sig->and_code) { /* or(and(f1,f2), f3) -> and(or(f1,f3), or(f2, f3) */ narg1 = TFormulaFCodeAlloc(terms, terms->sig->or_code, form->args[0]->args[0], form->args[1]); narg2 = TFormulaFCodeAlloc(terms, terms->sig->or_code, form->args[0]->args[1], form->args[1]); handle = TFormulaFCodeAlloc(terms, terms->sig->and_code, narg1, narg2); form = TFormulaDistributeDisjunctions(terms, handle); } else if(form->args[1]->f_code == terms->sig->and_code) { narg2 = TFormulaFCodeAlloc(terms, terms->sig->or_code, form->args[1]->args[1], form->args[0]); narg1 = TFormulaFCodeAlloc(terms, terms->sig->or_code, form->args[1]->args[0], form->args[0]); handle = TFormulaFCodeAlloc(terms, terms->sig->and_code, narg1, narg2); form = TFormulaDistributeDisjunctions(terms, handle); } } return form; } /*----------------------------------------------------------------------- // // Function: WTFormulaConjunctiveNF() // // Transform a formula into Conjunctive Normal Form. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ void WTFormulaConjunctiveNF(WFormula_p form, TB_p terms) { TFormula_p handle; /*printf("Start: "); WFormulaPrint(GlobalOut, form, true); printf("\n");*/ handle = TFormulaSimplify(terms, form->tformula, 1000); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_fof_simpl); WFormulaPushDerivation(form, DCFofSimplify, NULL, NULL); } handle = TFormulaNNF(terms, form->tformula, 1); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_fof_nnf); WFormulaPushDerivation(form, DCFNNF, NULL, NULL); } handle = TFormulaMiniScope(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_shift_quantors); WFormulaPushDerivation(form, DCShiftQuantors, NULL, NULL); } TFormulaFindMaxVarCode(form->tformula); VarBankSetVCountsToUsed(terms->vars); handle = TFormulaVarRename(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_var_rename); WFormulaPushDerivation(form, DCVarRename, NULL, NULL); } handle = TFormulaSkolemizeOutermost(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_skolemize_out); WFormulaPushDerivation(form, DCSkolemize, NULL, NULL); } handle = TFormulaShiftQuantors(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_shift_quantors); WFormulaPushDerivation(form, DCShiftQuantors, NULL, NULL); } handle = TFormulaDistributeDisjunctions(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_fof_distrib); WFormulaPushDerivation(form, DCDistDisjunctions, NULL, NULL); } } /*----------------------------------------------------------------------- // // Function: WTFormulaConjunctiveNF2() // // Transform a formula into Conjunctive Normal Form. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ void WTFormulaConjunctiveNF2(WFormula_p form, TB_p terms, long miniscope_limit) { TFormula_p handle; // printf("# Start: "); WFormulaPrint(GlobalOut, form, true); printf("\n"); handle = TFormulaSimplify(terms, form->tformula, 0); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_fof_simpl); WFormulaPushDerivation(form, DCFofSimplify, NULL, NULL); } // printf("# Simplified\n"); handle = TFormulaNNF(terms, form->tformula, 1); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_fof_nnf); WFormulaPushDerivation(form, DCFNNF, NULL, NULL); } //printf("# NNFed\n"); TFormulaFindMaxVarCode(form->tformula); VarBankSetVCountsToUsed(terms->vars); handle = TFormulaVarRename(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_var_rename); WFormulaPushDerivation(form, DCVarRename, NULL, NULL); } //printf("# Renamed\n"); handle = TFormulaShiftQuantors2(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_shift_quantors); WFormulaPushDerivation(form, DCShiftQuantors, NULL, NULL); } //printf("# Prenexed\n"); handle = TFormulaSimplify(terms, form->tformula, 100); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_fof_simpl); WFormulaPushDerivation(form, DCFofSimplify, NULL, NULL); } //printf("# Resimplified\n"); // Here efficient miniscoping handle = TFormulaMiniScope2(terms, form->tformula, miniscope_limit); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_shift_quantors); WFormulaPushDerivation(form, DCShiftQuantors, NULL, NULL); } handle = TFormulaSkolemizeOutermost(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_skolemize_out); WFormulaPushDerivation(form, DCSkolemize, NULL, NULL); } handle = TFormulaShiftQuantors(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_shift_quantors); WFormulaPushDerivation(form, DCShiftQuantors, NULL, NULL); } // Skolemization might have introduced Skolem predicates, which // we have to unroll again -- unrolling keeps things in NNF TFormulaUnrollFOOL(form,terms); // handles proof object internally handle = TFormulaDistributeDisjunctions(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_fof_distrib); WFormulaPushDerivation(form, DCDistDisjunctions, NULL, NULL); } } /*----------------------------------------------------------------------- // // Function: WTFormulaConjunctiveNF3() // // Transform a formula into Conjunctive Normal Form. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ void WTFormulaConjunctiveNF3(WFormula_p form, TB_p terms, long miniscope_limit) { TFormula_p handle; /*printf("Start: "); WFormulaPrint(GlobalOut, form, true); printf("\n");*/ handle = TFormulaSimplify(terms, form->tformula, 1000); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_fof_simpl); WFormulaPushDerivation(form, DCFofSimplify, NULL, NULL); } handle = TFormulaNNF(terms, form->tformula, 1); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_fof_nnf); WFormulaPushDerivation(form, DCFNNF, NULL, NULL); } handle = TFormulaMiniScope3(terms, form->tformula, miniscope_limit); //handle = TFormulaMiniScope(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_shift_quantors); WFormulaPushDerivation(form, DCShiftQuantors, NULL, NULL); } TFormulaFindMaxVarCode(form->tformula); VarBankSetVCountsToUsed(terms->vars); handle = TFormulaVarRename(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_var_rename); WFormulaPushDerivation(form, DCVarRename, NULL, NULL); } handle = TFormulaSkolemizeOutermost(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_skolemize_out); WFormulaPushDerivation(form, DCSkolemize, NULL, NULL); } handle = TFormulaShiftQuantors(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_shift_quantors); WFormulaPushDerivation(form, DCShiftQuantors, NULL, NULL); } TFormulaUnrollFOOL(form,terms); // handles proof object internally handle = TFormulaDistributeDisjunctions(terms, form->tformula); if(handle!=form->tformula) { form->tformula = handle; DocFormulaModificationDefault(form, inf_fof_distrib); WFormulaPushDerivation(form, DCDistDisjunctions, NULL, NULL); } } /*---------------------------------------------------------------------*/ /* End of File */ /*---------------------------------------------------------------------*/
/*----------------------------------------------------------------------- File : ccl_tcnf.c Author: Stephan Schulz Contents Functions for CNF conversion of a term-encoded FOF formula. Copyright 2003-2019 by the author. This code is released under the GNU General Public Licence and the GNU Lesser General Public License. See the file COPYING in the main E directory for details.. Run "eprover -h" for contact information. Changes Created: Thu Feb 26 00:21:17 CET 2004 -----------------------------------------------------------------------*/
main_pattern.mli
open! Core val pat_query_command : Command.t val pat_change_command : Command.t
oprinter.ml
(* print object code *) open Zmisc open Zlocation open Zident open Obc open Format open Pp_tools open Printer (** Priorities *) let rec priority_exp = function | Oconst _ | Oconstr0 _| Oglobal _ | Olocal _ | Ovar _ | Ostate _ | Oaccess _ | Orecord _ | Orecord_access _ | Orecord_with _ | Otypeconstraint _ | Otuple _ -> 3 | Oconstr1 _ | Oapp _ | Omethodcall _ | Ovec _ | Oupdate _ | Oslice _ | Oconcat _ -> 2 | Oifthenelse _ -> 0 | Oinst i -> priority_inst i and priority_inst = function | Olet _ | Oletvar _ -> 0 | Ofor _ | Owhile _ -> 3 | Omatch _ -> 0 | Oif _ -> 0 | Oassign _ -> 2 | Oassign_state _ -> 2 | Osequence _ -> 0 | Oexp(e) -> priority_exp e let kind = function | Deftypes.Tstatic _ | Deftypes.Tany | Deftypes.Tdiscrete _ -> "discrete" | Deftypes.Tcont -> "continuous" | Deftypes.Tproba -> "proba" let rec psize prio ff si = let operator = function Splus -> "+" | Sminus -> "-" in let priority = function Splus -> 0 | Sminus -> 1 in match si with | Sconst(i) -> fprintf ff "%d" i | Sglobal(ln) -> longname ff ln | Sname(n) -> name ff n | Sop(op, e1, e2) -> let prio_op = priority op in if prio > prio_op then fprintf ff "("; fprintf ff "@[%a %s %a@]" (psize prio_op) e1 (operator op) (psize prio_op) e2; if prio > prio_op then fprintf ff ")" let print_concrete_type ff ty = let priority = function | Otypevar _ | Otypeconstr _ | Otypevec _ -> 2 | Otypetuple _ -> 2 | Otypefun _ -> 1 in let rec ptype prio ff ty = let prio_ty = priority ty in if prio_ty < prio then fprintf ff "("; begin match ty with | Otypevar(s) -> fprintf ff "'%s" s | Otypefun(k, opt_name, ty_arg, ty) -> let arg prio ff (opt_name, ty) = match opt_name with | None -> ptype prio ff ty | Some(n) -> fprintf ff "@[(%a : %a)@]" name n (ptype 0) ty in let k = match k with Ofun -> "->" | Onode -> "=>" in fprintf ff "@[<hov2>%a %s@ %a@]" (arg prio_ty) (opt_name, ty_arg) k (ptype prio_ty) ty | Otypetuple(ty_list) -> fprintf ff "@[<hov2>%a@]" (print_list_r (ptype prio_ty) "("" *"")") ty_list | Otypeconstr(ln, ty_list) -> fprintf ff "@[<hov2>%a@]%a" (print_list_r_empty (ptype 2) "("","")") ty_list longname ln | Otypevec(ty_arg, si) -> fprintf ff "@[%a[%a]@]" (ptype prio_ty) ty_arg (psize 0) si end; if prio_ty < prio then fprintf ff ")" in ptype 0 ff ty let ptype ff ty = Ptypes.output ff ty let immediate ff = function | Oint i -> if i < 0 then fprintf ff "(%a)" pp_print_int i else pp_print_int ff i | Oint32 i -> if i < 0 then fprintf ff "(%al)" pp_print_int i else fprintf ff "%al" pp_print_int i | Ofloat f -> if f < 0.0 then fprintf ff "(%a)" pp_print_float f else pp_print_float ff f | Obool b -> if b then fprintf ff "true" else fprintf ff "false" | Ostring s -> fprintf ff "%S" s | Ochar c -> fprintf ff "'%c'" c | Ovoid -> pp_print_string ff "()" | Oany -> fprintf ff "any" let rec pattern ff pat = match pat with | Owildpat -> fprintf ff "_" | Oconstpat(i) -> immediate ff i | Oconstr0pat(lname) -> longname ff lname | Oconstr1pat(lname, pat_list) -> fprintf ff "@[%a%a@]" longname lname (print_list_r pattern "("","")") pat_list | Ovarpat(n, ty_exp) -> fprintf ff "@[(%a:%a)@]" name n print_concrete_type ty_exp | Otuplepat(pat_list) -> pattern_comma_list ff pat_list | Oaliaspat(p, n) -> fprintf ff "@[%a as %a@]" pattern p name n | Oorpat(pat1, pat2) -> fprintf ff "@[%a | %a@]" pattern pat1 pattern pat2 | Otypeconstraintpat(p, ty_exp) -> fprintf ff "@[(%a: %a)@]" pattern p print_concrete_type ty_exp | Orecordpat(n_pat_list) -> print_record (print_couple longname pattern """ =""") ff n_pat_list and pattern_list ff pat_list = print_list_r pattern """""" ff pat_list and pattern_comma_list ff pat_list = print_list_r pattern "("","")" ff pat_list and method_name m_name = m_name (** Print the call to a method *) and method_call ff { met_name = m; met_instance = i_opt; met_args = e_list } = let m = method_name m in let instance ff i_opt = match i_opt with | None -> (* a call to the self machine *) fprintf ff "self" | Some(o, e_list) -> match e_list with | [] -> fprintf ff "self.%a" name o | e_list -> fprintf ff "self.%a.%a" name o (print_list_no_space (print_with_braces (exp 3) "(" ")") "" "." "") e_list in fprintf ff "@[<hov 2>%a.%s @ %a@]" instance i_opt m (print_list_r (exp 3) "" "" "") e_list and left_value ff left = match left with | Oleft_name(n) -> name ff n | Oleft_record_access(left, n) -> fprintf ff "@[%a.%a@]" left_value left longname n | Oleft_index(left, idx) -> fprintf ff "@[%a.(%a)@]" left_value left (exp 0) idx and left_state_value ff left = match left with | Oself -> fprintf ff "self." | Oleft_instance_name(n) -> name ff n | Oleft_state_global(ln) -> longname ff ln | Oleft_state_name(n) -> name ff n | Oleft_state_record_access(left, n) -> fprintf ff "@[%a.%a@]" left_state_value left longname n | Oleft_state_index(left, idx) -> fprintf ff "@[%a.(%a)@]" left_state_value left (exp 0) idx | Oleft_state_primitive_access(left, a) -> fprintf ff "@[%a.%a@]" left_state_value left access a and assign ff left e = match left with | Oleft_name(n) -> fprintf ff "@[<v 2>%a := %a@]" name n (exp 2) e | _ -> fprintf ff "@[<v 2>%a <- %a@]" left_value left (exp 2) e and assign_state ff left e = match left with | Oleft_state_global(gname) -> fprintf ff "@[<v 2>%a := %a@]" longname gname (exp 2) e | _ -> fprintf ff "@[<v 2>%a <- %a@]" left_state_value left (exp 2) e and access ff a = let s = match a with | Oder -> "der" | Ocont -> "pos" | Ozero_out -> "zout" | Ozero_in -> "zin" in fprintf ff "%s" s and local ff n = name ff n and var ff n = name ff n and letvar ff n ty e_opt i = match e_opt with | None -> fprintf ff "@[<v 0>var %a: %a in@ %a@]" name n ptype ty (inst 0) i | Some(e0) -> fprintf ff "@[<v 0>var %a: %a = %a in@ %a@]" name n ptype ty (exp 0) e0 (inst 0) i and exp prio ff e = let prio_e = priority_exp e in if prio_e < prio then fprintf ff "("; begin match e with | Oconst(i) -> immediate ff i | Oconstr0(lname) -> longname ff lname | Oconstr1(lname, e_list) -> fprintf ff "@[%a%a@]" longname lname (print_list_r (exp prio_e) "("","")") e_list | Oglobal(ln) -> longname ff ln | Olocal(n) -> local ff n | Ovar(_, n) -> local ff n | Ostate(l) -> left_state_value ff l | Oaccess(e, eidx) -> fprintf ff "%a.(@[%a@])" (exp prio_e) e (exp prio_e) eidx | Ovec(e, se) -> fprintf ff "%a[%a]" (exp prio_e) e (psize 0) se | Oupdate(se, e1, i, e2) -> fprintf ff "@[<hov2>{%a:%a with@ %a = %a}@]" (exp prio_e) e1 (psize prio_e) se (exp 0) i (exp 0) e2 | Oslice(e, s1, s2) -> fprintf ff "%a{%a..%a}" (exp prio_e) e (psize 0) s1 (psize 0) s2 | Oconcat(e1, s1, e2, s2) -> fprintf ff "{%a:%a | %a:%a}" (exp 0) e1 (psize 0) s1 (exp 0) e2 (psize 0) s2 | Otuple(e_list) -> fprintf ff "@[<hov2>%a@]" (print_list_r (exp prio_e) "("","")") e_list | Oapp(e, e_list) -> fprintf ff "@[<hov2>%a %a@]" (exp (prio_e + 1)) e (print_list_r (exp (prio_e + 1)) """""") e_list | Omethodcall m -> method_call ff m | Orecord(r) -> print_record (print_couple longname (exp prio_e) """ =""") ff r | Orecord_access(e_record, lname) -> fprintf ff "%a.%a" (exp prio_e) e_record longname lname | Orecord_with(e_record, r) -> fprintf ff "@[{ %a with %a }@]" (exp prio_e) e_record (print_list_r (print_couple longname (exp prio_e) """ =""") "" ";" "") r | Otypeconstraint(e, ty_e) -> fprintf ff "@[(%a : %a)@]" (exp prio_e) e print_concrete_type ty_e | Oifthenelse(e, e1, e2) -> fprintf ff "@[<hv>if %a@ @[<hv 2>then@ %a@]@ @[<hv 2>else@ %a@]@]" (exp 0) e (exp 1) e1 (exp 1) e2 | Oinst(i) -> inst prio ff i end; if prio_e < prio then fprintf ff ")" and inst prio ff i = let prio_i = priority_inst i in if prio_i < prio then fprintf ff "("; begin match i with | Olet(p, e, i) -> fprintf ff "@[<v 0>let %a in@ %a@]" pat_exp (p, e) (inst (prio_i-1)) i | Oletvar(x, _, ty, e_opt, i) -> letvar ff x ty e_opt i | Omatch(e, match_handler_l) -> fprintf ff "@[<v2>match %a with@ @[%a@]@]" (exp 0) e (print_list_l match_handler """""") match_handler_l | Ofor(is_to, n, e1, e2, i3) -> fprintf ff "@[<hv>for %a = %a %s %a@ @[<hv 2>do@ %a@ done@]@]" name n (exp 0) e1 (if is_to then "to" else "downto") (exp 0) e2 (inst 0) i3 | Owhile(e1, i2) -> fprintf ff "@[<hv>while %a do %a done@]@]" (exp 0) e1 (inst 0) i2 | Oassign(left, e) -> assign ff left e | Oassign_state(left, e) -> assign_state ff left e | Osequence(i_list) -> if i_list = [] then fprintf ff "()" else fprintf ff "@[<hv>%a@]" (print_list_r (inst 1) "" ";" "") i_list | Oexp(e) -> exp prio ff e | Oif(e, i1, None) -> fprintf ff "@[<hov>if %a@ then@ %a@]" (exp 0) e sinst i1 | Oif(e, i1, Some(i2)) -> fprintf ff "@[<hov>if %a@ then@ %a@ else %a@]" (exp 0) e sinst i1 sinst i2 end; if prio_i < prio then fprintf ff ")" (* special treatment to add an extra parenthesis if [i] is a sequence *) and sinst ff i = match i with | Osequence(i_list) -> if i_list = [] then fprintf ff "()" else fprintf ff "@[<hv>%a@]" (print_list_r (inst 1) "(" ";" ")") i_list | _ -> inst 0 ff i and pat_exp ff (p, e) = fprintf ff "@[@[%a@] =@ @[%a@]@]" pattern p (exp 0) e and exp_with_typ ff (e, ty) = fprintf ff "(%a:%a)" (exp 2) e ptype ty and expression ff e = exp 0 ff e and match_handler ff { w_pat = pat; w_body = b } = fprintf ff "@[<hov 4>| %a ->@ %a@]" pattern pat (inst 0) b (** The main entry functions for expressions and instructions *) let rec type_decl ff = function | Oabstract_type -> () | Oabbrev(ty) -> print_concrete_type ff ty | Ovariant_type(constr_decl_list) -> print_list_l constr_decl """| """ ff constr_decl_list | Orecord_type(s_ty_list) -> print_record (print_couple pp_print_string print_concrete_type """ :""") ff s_ty_list and constr_decl ff = function | Oconstr0decl(s) -> fprintf ff "%s" s | Oconstr1decl(s, ty_list) -> fprintf ff "%s of %a" s (print_list_l print_concrete_type """ *""") ty_list let memory ff { m_name = n; m_value = e_opt; m_typ = ty; m_kind = k_opt; m_size = m_size } = let mem = function | None -> "" | Some(k) -> (Printer.kind k) ^ " " in match e_opt with | None -> fprintf ff "%s%a%a : %a" (mem k_opt) name n (print_list_no_space (print_with_braces (exp 0) "[" "]") "" "" "") m_size ptype ty | Some(e) -> fprintf ff "%s%a%a : %a = %a" (mem k_opt) name n (print_list_no_space (print_with_braces (exp 0) "[" "]") "" "" "") m_size ptype ty (exp 0) e let instance ff { i_name = n; i_machine = ei; i_kind = k; i_params = e_list; i_size = i_size } = fprintf ff "@[%a : %s(%a)%a%a@]" name n (kind k) (exp 0) ei (print_list_no_space (print_with_braces (exp 0) "(" ")") "" "" "") e_list (print_list_no_space (print_with_braces (exp 0) "[" "]") "" "" "") i_size let pmethod ff { me_name = m_name; me_params = p_list; me_body = i; me_typ = ty } = fprintf ff "@[<hov 2>method %s %a@ =@ (%a:%a)@]" (method_name m_name) pattern_list p_list (inst 2) i ptype ty let pinitialize ff i_opt = match i_opt with | None -> () | Some(e) -> fprintf ff "@[<hov2>initialize@;%a@]" (inst 0) e (** Print a machine *) let machine f ff { ma_kind = k; ma_params = pat_list; ma_initialize = i_opt; ma_memories = memories; ma_instances = instances; ma_methods = m_list } = fprintf ff "@[<hov 2>let %s = machine(%s)%a@ \ {@, %a@,@[<v2>memories@ @[%a@]@]@;@[<v 2>instances@ @[%a@]@]@;@[%a@]@]]}@.@]" f (kind k) pattern_list pat_list pinitialize i_opt (print_list_r_empty memory """;""") memories (print_list_r_empty instance """;""") instances (print_list_r pmethod """""") m_list let implementation ff impl = match impl with | Oletvalue(n, i) -> fprintf ff "@[<v 2>let %a = %a@.@.@]" shortname n (inst 0) i | Oletfun(n, pat_list, i) -> fprintf ff "@[<v 2>let %a %a =@ %a@.@.@]" shortname n pattern_list pat_list (inst 0) i | Oletmachine(n, m) -> machine n ff m | Oopen(s) -> fprintf ff "@[open %s@.@]" s | Otypedecl(l) -> fprintf ff "@[%a@.@]" (print_list_l (fun ff (s, s_list, ty_decl) -> fprintf ff "%a%s =@ %a" Ptypes.print_type_params s_list s type_decl ty_decl) "type ""and """) l let implementation_list ff impl_list = fprintf ff "@[(* %s *)@.@]" header_in_file; fprintf ff "@[open Ztypes@.@]"; List.iter (implementation ff) impl_list
(***********************************************************************) (* *) (* *) (* Zelus, a synchronous language for hybrid systems *) (* *) (* (c) 2020 Inria Paris (see the AUTHORS file) *) (* *) (* Copyright Institut National de Recherche en Informatique et en *) (* Automatique. All rights reserved. This file is distributed under *) (* the terms of the INRIA Non-Commercial License Agreement (see the *) (* LICENSE file). *) (* *) (* *********************************************************************)
transf_simplify.mli
(* Copyright ENS, CNRS, INRIA contributors: Bruno Blanchet, Bruno.Blanchet@inria.fr David Cadé This software is a computer program whose purpose is to verify cryptographic protocols in the computational model. This software is governed by the CeCILL-B license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-B license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL-B license and that you accept its terms. *) open Types (* The "simplify" game transformation The terms and processes in the input game must be physically distinct, since [Terms.build_def_process] is called. The terms and processes in the returned game (and in the intermediate games inside the transformation) are guaranteed to be physically distinct, by calling [Transf_auto_sa_rename.auto_sa_rename]. *) val simplify_main : known_when_adv_wins option -> coll_elim_t list -> game_transformer
(************************************************************* * * * Cryptographic protocol verifier * * * * Bruno Blanchet and David Cadé * * * * Copyright (C) ENS, CNRS, INRIA, 2005-2022 * * * *************************************************************)
example1.ml
(* generated from "example1.bare" using bare-codegen *) [@@@ocaml.warning "-26-27"] module Bare = Bare_encoding module PublicKey = struct type t = bytes (** @raise Invalid_argument in case of error. *) let decode (dec: Bare.Decode.t) : t = Bare.Decode.data_of ~size:128 dec let encode (enc: Bare.Encode.t) (self: t) : unit = (assert (Bytes.length self=128); Bare.Encode.data_of ~size:128 enc self) end module Time = struct type t = string (** @raise Invalid_argument in case of error. *) let decode (dec: Bare.Decode.t) : t = Bare.Decode.string dec let encode (enc: Bare.Encode.t) (self: t) : unit = Bare.Encode.string enc self end module Department = struct type t = ACCOUNTING | ADMINISTRATION | CUSTOMER_SERVICE | DEVELOPMENT | JSMITH let to_int = function | ACCOUNTING -> 0L | ADMINISTRATION -> 1L | CUSTOMER_SERVICE -> 2L | DEVELOPMENT -> 3L | JSMITH -> 99L let of_int = function | 0L -> ACCOUNTING | 1L -> ADMINISTRATION | 2L -> CUSTOMER_SERVICE | 3L -> DEVELOPMENT | 99L -> JSMITH | x -> invalid_arg (Printf.sprintf "unknown enum member for Department.t: %Ld" x) (** @raise Invalid_argument in case of error. *) let decode (dec: Bare.Decode.t) : t = of_int (Bare.Decode.uint dec) let encode (enc: Bare.Encode.t) (self: t) : unit = Bare.Encode.uint enc (to_int self) end module Customer_orders_0 = struct type t = { orderId: int64; quantity: int32; } (** @raise Invalid_argument in case of error. *) let decode (dec: Bare.Decode.t) : t = let orderId = Bare.Decode.i64 dec in let quantity = Bare.Decode.i32 dec in {orderId; quantity; } let encode (enc: Bare.Encode.t) (self: t) : unit = begin Bare.Encode.i64 enc self.orderId; Bare.Encode.i32 enc self.quantity; end end module Address = struct type t = { address: string array; city: string; state: string; country: string; } (** @raise Invalid_argument in case of error. *) let decode (dec: Bare.Decode.t) : t = let address = Array.init 4 (fun _ -> Bare.Decode.string dec) in let city = Bare.Decode.string dec in let state = Bare.Decode.string dec in let country = Bare.Decode.string dec in {address; city; state; country; } let encode (enc: Bare.Encode.t) (self: t) : unit = begin (assert (Array.length self.address = 4); Array.iter (fun xi -> Bare.Encode.string enc xi) self.address); Bare.Encode.string enc self.city; Bare.Encode.string enc self.state; Bare.Encode.string enc self.country; end end module Customer = struct type t = { name: string; email: string; address: Address.t; orders: Customer_orders_0.t array; metadata: bytes Bare.String_map.t; } (** @raise Invalid_argument in case of error. *) let decode (dec: Bare.Decode.t) : t = let name = Bare.Decode.string dec in let email = Bare.Decode.string dec in let address = Address.decode dec in let orders = (let len = Bare.Decode.uint dec in if len>Int64.of_int Sys.max_array_length then invalid_arg "array too big"; Array.init (Int64.to_int len) (fun _ -> Customer_orders_0.decode dec)) in let metadata = (let len = Bare.Decode.uint dec in if len>Int64.of_int max_int then invalid_arg "array too big"; List.init (Int64.to_int len) (fun _ -> let k = Bare.Decode.string dec in let v = Bare.Decode.data dec in k,v) |> List.to_seq |> Bare.String_map.of_seq) in {name; email; address; orders; metadata; } let encode (enc: Bare.Encode.t) (self: t) : unit = begin Bare.Encode.string enc self.name; Bare.Encode.string enc self.email; Address.encode enc self.address; (let arr = self.orders in Bare.Encode.uint enc (Int64.of_int (Array.length arr)); Array.iter (fun xi -> Customer_orders_0.encode enc xi) arr); (Bare.Encode.uint enc (Int64.of_int (Bare.String_map.cardinal self.metadata)); Bare.String_map.iter (fun x y -> Bare.Encode.string enc x; Bare.Encode.data enc y) self.metadata); end end module Employee = struct type t = { name: string; email: string; address: Address.t; department: Department.t; hireDate: Time.t; publicKey: PublicKey.t option; metadata: bytes Bare.String_map.t; } (** @raise Invalid_argument in case of error. *) let decode (dec: Bare.Decode.t) : t = let name = Bare.Decode.string dec in let email = Bare.Decode.string dec in let address = Address.decode dec in let department = Department.decode dec in let hireDate = Time.decode dec in let publicKey = Bare.Decode.optional (fun dec -> PublicKey.decode dec) dec in let metadata = (let len = Bare.Decode.uint dec in if len>Int64.of_int max_int then invalid_arg "array too big"; List.init (Int64.to_int len) (fun _ -> let k = Bare.Decode.string dec in let v = Bare.Decode.data dec in k,v) |> List.to_seq |> Bare.String_map.of_seq) in {name; email; address; department; hireDate; publicKey; metadata; } let encode (enc: Bare.Encode.t) (self: t) : unit = begin Bare.Encode.string enc self.name; Bare.Encode.string enc self.email; Address.encode enc self.address; Department.encode enc self.department; Time.encode enc self.hireDate; Bare.Encode.optional (fun enc xopt -> PublicKey.encode enc xopt) enc self.publicKey; (Bare.Encode.uint enc (Int64.of_int (Bare.String_map.cardinal self.metadata)); Bare.String_map.iter (fun x y -> Bare.Encode.string enc x; Bare.Encode.data enc y) self.metadata); end end module Person = struct type t = | Customer of Customer.t | Employee of Employee.t (** @raise Invalid_argument in case of error. *) let decode (dec: Bare.Decode.t) : t = let tag = Bare.Decode.uint dec in match tag with | 0L -> Customer (Customer.decode dec) | 1L -> Employee (Employee.decode dec) | _ -> invalid_arg (Printf.sprintf "unknown union tag Person.t: %Ld" tag) let encode (enc: Bare.Encode.t) (self: t) : unit = match self with | Customer x -> Bare.Encode.uint enc 0L; Customer.encode enc x | Employee x -> Bare.Encode.uint enc 1L; Employee.encode enc x end
(* generated from "example1.bare" using bare-codegen *) [@@@ocaml.warning "-26-27"]
moebius_mu.c
#include "flint.h" #include "ulong_extras.h" #define FLINT_MU_LOOKUP_CUTOFF 1024 #if FLINT64 const mp_limb_t FLINT_MOEBIUS_ODD[] = { UWORD(0x4289108a05208102), UWORD(0x19988004a8a12422), UWORD(0x1a8245028906a062), UWORD(0x229428012aa26a00), UWORD(0x8422a98980440a18), 0x224925084068929aUL, UWORD(0xa1200942a8980a84), UWORD(0x8622622216a00428), UWORD(0x6060829286a590a9), UWORD(0x5a2190081420a1a8), UWORD(0x8a92a284a8018200), UWORD(0x980a2602491a2248), UWORD(0x8106a08982a26848), UWORD(0xa60085a6004a5919), UWORD(0x88a188245a221228), UWORD(0x0108884a22186025) }; #else const mp_limb_t FLINT_MOEBIUS_ODD[] = { UWORD(0x05208102), 0x4289108aUL, UWORD(0xa8a12422), UWORD(0x19988004), UWORD(0x8906a062), UWORD(0x1a824502), UWORD(0x2aa26a00), UWORD(0x22942801), UWORD(0x80440a18), UWORD(0x8422a989), 0x4068929aUL, UWORD(0x22492508), UWORD(0xa8980a84), UWORD(0xa1200942), UWORD(0x16a00428), UWORD(0x86226222), UWORD(0x86a590a9), UWORD(0x60608292), UWORD(0x1420a1a8), UWORD(0x5a219008), UWORD(0xa8018200), UWORD(0x8a92a284), UWORD(0x491a2248), UWORD(0x980a2602), UWORD(0x82a26848), UWORD(0x8106a089), UWORD(0x004a5919), UWORD(0xa60085a6), UWORD(0x5a221228), UWORD(0x88a18824), UWORD(0x22186025), 0x0108884aUL }; #endif void n_moebius_mu_vec(int * mu, ulong len) { slong k; ulong pi; const mp_limb_t * primes; mp_limb_t p, q; pi = n_prime_pi(len); primes = n_primes_arr_readonly(pi); if (len) mu[0] = 0; for (k = 1; k < len; k++) mu[k] = 1; for (k = 0; k < pi; k++) { p = primes[k]; for (q = p; q < len; q += p) mu[q] = -mu[q]; p = p * p; for (q = p; q < len; q += p) mu[q] = 0; } } int n_moebius_mu(mp_limb_t n) { int i; n_factor_t fac; if (n % 2 == 0) { if (n % 4 == 0) return 0; return -n_moebius_mu(n / 2); } if (n < FLINT_MU_LOOKUP_CUTOFF) { mp_limb_t m; n -= 1; m = FLINT_MOEBIUS_ODD[n / FLINT_BITS]; m &= (UWORD(3) << (n % FLINT_BITS)); m >>= (n % FLINT_BITS); return ((int) m) - 1; } /* Weed out just a few more common squares first */ if (n % 9 == 0 || n % 25 == 0) return 0; n_factor_init(&fac); n_factor(&fac, n, 1); for (i = 0; i < fac.num; i++) { if (fac.exp[i] != 1) return 0; } if (fac.num % 2) return -1; else return 1; }
/* Copyright (C) 2010 Fredrik Johansson This file is part of FLINT. FLINT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>. */
CLI_common.mli
val help_page_bottom : Cmdliner.Manpage.block list (* small wrapper around Cmdliner.Cmd.eval_value *) val eval_value : argv:string array -> 'a Cmdliner.Cmd.t -> 'a
test13.ml
#!/usr/bin/env lablglut (* Ported to lablglut by Issac Trotts on Tue Aug 6 21:18:31 MDT 2002. *) #load "unix.cma" open Printf (* Copyright (c) Mark J. Kilgard 1994. *) (* This program is freely distributable without licensing fees and is provided without guarantee or warrantee expressed or implied. This program is -not- in the public domain. *) let window1 = ref (-1);; let window2 = ref (-1);; let win1reshaped = ref false;; let win2reshaped = ref false;; let win1displayed = ref false;; let win2displayed = ref false;; let checkifdone () = if (!win1reshaped && !win2reshaped && !win1displayed && !win2displayed) then begin Unix.sleep(1); printf("PASS -> test13\n"); exit(0); end ;; let window1reshape ~w ~h = if (Glut.getWindow() <> !window1) then failwith(" window1reshape\n"); GlDraw.viewport ~x:0 ~y:0 ~w ~h ; win1reshaped := true ;; let window1display () = if (Glut.getWindow() <> !window1) then failwith(" window1display\n"); GlClear.color (0.0, 1.0, 0.0); GlClear.clear [`color]; Gl.flush(); win1displayed := true; checkifdone(); ;; let window2reshape ~w ~h = if (Glut.getWindow() <> !window2) then failwith(" window2reshape\n"); GlDraw.viewport ~x:0 ~y:0 ~w ~h ; win2reshaped := true; ;; let window2display () = if (Glut.getWindow() <> !window2) then failwith(" window2display\n"); GlClear.color (0.0, 0.0, 1.0); GlClear.clear [`color]; Gl.flush(); win2displayed := true; checkifdone(); ;; let timefunc ~value = failwith(" test13\n") ;; let main () = ignore (Glut.init Sys.argv); Glut.initWindowSize 100 100 ; Glut.initWindowPosition 50 100 ; Glut.initDisplayMode ~double_buffer:false ~alpha:false (); window1 := Glut.createWindow("1"); if (Glut.get(Glut.WINDOW_X) <> 50) then failwith(" test13\n"); if (Glut.get(Glut.WINDOW_Y) <> 100) then failwith(" test13\n"); Glut.reshapeFunc(window1reshape); Glut.displayFunc(window1display); Glut.initWindowSize 100 100 ; Glut.initWindowPosition 250 100 ; Glut.initDisplayMode ~double_buffer:false ~alpha:false (); window2 := Glut.createWindow("2"); if (Glut.get(Glut.WINDOW_X) <> 250) then failwith(" test13\n"); if (Glut.get(Glut.WINDOW_Y) <> 100) then failwith(" test13\n"); Glut.reshapeFunc(window2reshape); Glut.displayFunc(window2display); Glut.timerFunc 7000 timefunc 1 ; Glut.mainLoop(); ;; let _ = main();;
ast_mapper_class.mli
(** Class-based customizable mapper *) open Parsetree class mapper: object method attribute: attribute -> attribute method attributes: attribute list -> attribute list method binding_op: binding_op -> binding_op method case: case -> case method cases: case list -> case list method class_declaration: class_declaration -> class_declaration method class_description: class_description -> class_description method class_expr: class_expr -> class_expr method class_field: class_field -> class_field method class_signature: class_signature -> class_signature method class_structure: class_structure -> class_structure method class_type: class_type -> class_type method class_type_declaration: class_type_declaration -> class_type_declaration method class_type_field: class_type_field -> class_type_field #if OCAML_VERSION >= (4, 11, 0) method constant : constant -> constant #endif method constructor_arguments: constructor_arguments -> constructor_arguments method constructor_declaration: constructor_declaration -> constructor_declaration method expr: expression -> expression method extension: extension -> extension method extension_constructor: extension_constructor -> extension_constructor method include_declaration: include_declaration -> include_declaration method include_description: include_description -> include_description method label_declaration: label_declaration -> label_declaration method location: Location.t -> Location.t method module_binding: module_binding -> module_binding method module_declaration: module_declaration -> module_declaration method module_substitution: module_substitution -> module_substitution method module_expr: module_expr -> module_expr method module_type: module_type -> module_type method module_type_declaration: module_type_declaration -> module_type_declaration method open_declaration: open_declaration -> open_declaration method open_description: open_description -> open_description method pat: pattern -> pattern method payload: payload -> payload method signature: signature -> signature method signature_item: signature_item -> signature_item method structure: structure -> structure method structure_item: structure_item -> structure_item method typ: core_type -> core_type method type_declaration: type_declaration -> type_declaration method type_exception: type_exception -> type_exception method type_extension: type_extension -> type_extension method type_kind: type_kind -> type_kind method value_binding: value_binding -> value_binding method value_description: value_description -> value_description method with_constraint: with_constraint -> with_constraint end val to_mapper: #mapper -> Ast_mapper.mapper (** The resulting mapper is "closed", i.e. methods ignore their first argument. *)
(* This file is part of the ppx_tools package. It is released *) (* under the terms of the MIT license (see LICENSE file). *) (* Copyright 2013 Alain Frisch and LexiFi *)
at_intervals.mli
(** A module internal to Incremental. Users should see {!Incremental_intf}. An [At_intervals.t] is a kind of DAG node that changes at a regular time interval. *) open! Core open! Import include module type of struct include Types.At_intervals end include Invariant.S with type t := t include Sexp_of.S with type t := t
(** A module internal to Incremental. Users should see {!Incremental_intf}. An [At_intervals.t] is a kind of DAG node that changes at a regular time interval. *)
addRoleToDBInstance.ml
open Types open Aws type input = AddRoleToDBInstanceMessage.t type output = unit type error = Errors_internal.t let service = "rds" let signature_version = Request.V4 let to_http service region req = let uri = Uri.add_query_params (Uri.of_string (Aws.Util.of_option_exn (Endpoints.url_of service region))) (List.append [("Version", ["2014-10-31"]); ("Action", ["AddRoleToDBInstance"])] (Util.drop_empty (Uri.query_of_encoded (Query.render (AddRoleToDBInstanceMessage.to_query req))))) in (`POST, uri, []) let of_http body = `Ok () let parse_error code err = let errors = [] @ Errors_internal.common in match Errors_internal.of_string err with | Some var -> if (List.mem var errors) && ((match Errors_internal.to_http_code var with | Some var -> var = code | None -> true)) then Some var else None | None -> None
rmark.ml
open Gg open Vg (* Images with random marks. *) let mark_count = 1500 let note = Printf.sprintf "%d marks." mark_count let size = Size2.v 120. 60. let view = Box2.v P2.o (Size2.v 120. 60.) let tags = ["image"] let random_marks m = let r = Random.State.make [|1557|] in let rx = Float.srandom r ~min:6. ~len:108. in let ry = Float.srandom r ~min:6. ~len:48. in let rpt () = V2.v (rx ()) (ry ()) in let rec rpts n acc = if n = 0 then acc else rpts (n-1) (rpt ():: acc) in let mark pt = let area = `O { P.o with P.width = 0.25 } in (I.const (Color.gray 0.9) |> I.cut m) |> I.blend (I.const (Color.gray 0.3) |> I.cut ~area m) |> I.move pt in let nodes = List.map mark (rpts mark_count []) in List.fold_left I.blend I.void nodes ;; Db.image "rmark-dots" __POS__ ~author:Db.dbuenzli ~title:"Random dot mark" ~tags ~note ~size ~view begin fun _ -> random_marks (P.empty |> P.circle P2.o 2.1) end; Db.image "rmark-ticks" __POS__ ~author:Db.dbuenzli ~title:"Random line mark" ~tags ~note ~size ~view begin fun _ -> random_marks (P.empty |> P.line (P2.v 0.5 1.1)) end; Db.image "rmark-qcurve" __POS__ ~author:Db.dbuenzli ~title:"Random quadratic mark" ~tags ~note ~size ~view begin fun _ -> random_marks (P.empty |> P.qcurve (P2.v 1.0 1.5) (P2.v 1.0 0.0)) end; Db.image "rmark-ccurve" __POS__ ~author:Db.dbuenzli ~title:"Random cubic mark" ~tags ~note ~size ~view begin fun _ -> random_marks (P.empty |> P.ccurve (P2.v 0.5 1.0) (P2.v 1.0 1.5) (P2.v 1.0 0.0)) end; (*--------------------------------------------------------------------------- Copyright (c) 2013 The vg programmers Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ---------------------------------------------------------------------------*)
(*--------------------------------------------------------------------------- Copyright (c) 2013 The vg programmers. All rights reserved. Distributed under the ISC license, see terms at the end of the file. vg v0.9.4 ---------------------------------------------------------------------------*)
stock_chart.mli
open! Core open! Bonsai_web val app : Vdom.Node.t Computation.t
m3d.h
#ifndef _M3D_H_ #define _M3D_H_ #ifdef __cplusplus extern "C" { #endif #include <stdint.h> /*** configuration ***/ #ifndef M3D_MALLOC # define M3D_MALLOC(sz) malloc(sz) #endif #ifndef M3D_REALLOC # define M3D_REALLOC(p,nsz) realloc(p,nsz) #endif #ifndef M3D_FREE # define M3D_FREE(p) free(p) #endif #ifndef M3D_LOG # define M3D_LOG(x) #endif #ifndef M3D_APIVERSION #define M3D_APIVERSION 0x0100 #ifndef M3D_DOUBLE typedef float M3D_FLOAT; #ifndef M3D_EPSILON /* carefully choosen for IEEE 754 don't change */ #define M3D_EPSILON ((M3D_FLOAT)1e-7) #endif #else typedef double M3D_FLOAT; #ifndef M3D_EPSILON #define M3D_EPSILON ((M3D_FLOAT)1e-14) #endif #endif #if !defined(M3D_SMALLINDEX) typedef uint32_t M3D_INDEX; typedef uint16_t M3D_VOXEL; #define M3D_UNDEF 0xffffffff #define M3D_INDEXMAX 0xfffffffe #define M3D_VOXUNDEF 0xffff #define M3D_VOXCLEAR 0xfffe #else typedef uint16_t M3D_INDEX; typedef uint8_t M3D_VOXEL; #define M3D_UNDEF 0xffff #define M3D_INDEXMAX 0xfffe #define M3D_VOXUNDEF 0xff #define M3D_VOXCLEAR 0xfe #endif #define M3D_NOTDEFINED 0xffffffff #ifndef M3D_NUMBONE #define M3D_NUMBONE 4 #endif #ifndef M3D_BONEMAXLEVEL #define M3D_BONEMAXLEVEL 8 #endif #ifndef _MSC_VER #ifndef _inline #define _inline __inline__ #endif #define _pack __attribute__((packed)) #define _unused __attribute__((unused)) #else #define _inline #define _pack #define _unused __pragma(warning(suppress:4100)) #endif #ifndef __cplusplus #define _register register #else #define _register #endif /*** File format structures ***/ /** * M3D file format structure * 3DMO m3dchunk_t file header chunk, may followed by compressed data * PRVW preview chunk (optional) * HEAD m3dhdr_t model header chunk * n x m3dchunk_t more chunks follow * CMAP color map chunk (optional) * TMAP texture map chunk (optional) * VRTS vertex data chunk (optional if it's a material library) * BONE bind-pose skeleton, bone hierarchy chunk (optional) * n x m3db_t contains propably more, but at least one bone * n x m3ds_t skin group records * MTRL* material chunk(s), can be more (optional) * n x m3dp_t each material contains propapbly more, but at least one property * the properties are configurable with a static array, see m3d_propertytypes * n x m3dchunk_t at least one, but maybe more face chunks * PROC* procedural face, or * MESH* triangle mesh (vertex index list) or * VOXT, VOXD* voxel image (converted to mesh) or * SHPE* mathematical shapes like parameterized surfaces * LBLS* annotation label chunks, can be more (optional) * ACTN* action chunk(s), animation-pose skeletons, can be more (optional) * n x m3dfr_t each action contains probably more, but at least one frame * n x m3dtr_t each frame contains probably more, but at least one transformation * ASET* inlined asset chunk(s), can be more (optional) * OMD3 end chunk * * Typical chunks for a game engine: 3DMO, HEAD, CMAP, TMAP, VRTS, BONE, MTRL, MESH, ACTN, OMD3 * Typical chunks for distibution: 3DMO, PRVW, HEAD, CMAP, TMAP, VRTS, BONE, MTRL, MESH, ACTN, ASET, OMD3 * Typical chunks for voxel image: 3DMO, HEAD, CMAP, MTRL, VOXT, VOXD, VOXD, VOXD, OMD3 * Typical chunks for CAD software: 3DMO, PRVW, HEAD, CMAP, TMAP, VRTS, MTRL, SHPE, LBLS, OMD3 */ #ifdef _MSC_VER #pragma pack(push) #pragma pack(1) #endif typedef struct { char magic[4]; uint32_t length; float scale; /* deliberately not M3D_FLOAT */ uint32_t types; } _pack m3dhdr_t; typedef struct { char magic[4]; uint32_t length; } _pack m3dchunk_t; #ifdef _MSC_VER #pragma pack(pop) #endif /*** in-memory model structure ***/ /* textmap entry */ typedef struct { M3D_FLOAT u; M3D_FLOAT v; } m3dti_t; #define m3d_textureindex_t m3dti_t /* texture */ typedef struct { char *name; /* texture name */ uint8_t *d; /* pixels data */ uint16_t w; /* width */ uint16_t h; /* height */ uint8_t f; /* format, 1 = grayscale, 2 = grayscale+alpha, 3 = rgb, 4 = rgba */ } m3dtx_t; #define m3d_texturedata_t m3dtx_t typedef struct { M3D_INDEX vertexid; M3D_FLOAT weight; } m3dw_t; #define m3d_weight_t m3dw_t /* bone entry */ typedef struct { M3D_INDEX parent; /* parent bone index */ char *name; /* name for this bone */ M3D_INDEX pos; /* vertex index position */ M3D_INDEX ori; /* vertex index orientation (quaternion) */ M3D_INDEX numweight; /* number of controlled vertices */ m3dw_t *weight; /* weights for those vertices */ M3D_FLOAT mat4[16]; /* transformation matrix */ } m3db_t; #define m3d_bone_t m3db_t /* skin: bone per vertex entry */ typedef struct { M3D_INDEX boneid[M3D_NUMBONE]; M3D_FLOAT weight[M3D_NUMBONE]; } m3ds_t; #define m3d_skin_t m3ds_t /* vertex entry */ typedef struct { M3D_FLOAT x; /* 3D coordinates and weight */ M3D_FLOAT y; M3D_FLOAT z; M3D_FLOAT w; uint32_t color; /* default vertex color */ M3D_INDEX skinid; /* skin index */ #ifdef M3D_VERTEXTYPE uint8_t type; #endif } m3dv_t; #define m3d_vertex_t m3dv_t /* material property formats */ enum { m3dpf_color, m3dpf_uint8, m3dpf_uint16, m3dpf_uint32, m3dpf_float, m3dpf_map }; typedef struct { uint8_t format; uint8_t id; #ifdef M3D_ASCII #define M3D_PROPERTYDEF(f,i,n) { (f), (i), (char*)(n) } char *key; #else #define M3D_PROPERTYDEF(f,i,n) { (f), (i) } #endif } m3dpd_t; /* material property types */ /* You shouldn't change the first 8 display and first 4 physical property. Assign the rest as you like. */ enum { m3dp_Kd = 0, /* scalar display properties */ m3dp_Ka, m3dp_Ks, m3dp_Ns, m3dp_Ke, m3dp_Tf, m3dp_Km, m3dp_d, m3dp_il, m3dp_Pr = 64, /* scalar physical properties */ m3dp_Pm, m3dp_Ps, m3dp_Ni, m3dp_Nt, m3dp_map_Kd = 128, /* textured display map properties */ m3dp_map_Ka, m3dp_map_Ks, m3dp_map_Ns, m3dp_map_Ke, m3dp_map_Tf, m3dp_map_Km, /* bump map */ m3dp_map_D, m3dp_map_N, /* normal map */ m3dp_map_Pr = 192, /* textured physical map properties */ m3dp_map_Pm, m3dp_map_Ps, m3dp_map_Ni, m3dp_map_Nt }; enum { /* aliases */ m3dp_bump = m3dp_map_Km, m3dp_map_il = m3dp_map_N, m3dp_refl = m3dp_map_Pm }; /* material property */ typedef struct { uint8_t type; /* property type, see "m3dp_*" enumeration */ union { uint32_t color; /* if value is a color, m3dpf_color */ uint32_t num; /* if value is a number, m3dpf_uint8, m3pf_uint16, m3dpf_uint32 */ float fnum; /* if value is a floating point number, m3dpf_float */ M3D_INDEX textureid; /* if value is a texture, m3dpf_map */ } value; } m3dp_t; #define m3d_property_t m3dp_t /* material entry */ typedef struct { char *name; /* name of the material */ uint8_t numprop; /* number of properties */ m3dp_t *prop; /* properties array */ } m3dm_t; #define m3d_material_t m3dm_t /* face entry */ typedef struct { M3D_INDEX materialid; /* material index */ M3D_INDEX vertex[3]; /* 3D points of the triangle in CCW order */ M3D_INDEX normal[3]; /* normal vectors */ M3D_INDEX texcoord[3]; /* UV coordinates */ #ifdef M3D_VERTEXMAX M3D_INDEX paramid; /* parameter index */ M3D_INDEX vertmax[3]; /* maximum 3D points of the triangle in CCW order */ #endif } m3df_t; #define m3d_face_t m3df_t typedef struct { uint16_t count; char *name; } m3dvi_t; #define m3d_voxelitem_t m3dvi_t #define m3d_parameter_t m3dvi_t /* voxel types (voxel palette) */ typedef struct { char *name; /* technical name of the voxel */ uint8_t rotation; /* rotation info */ uint16_t voxshape; /* voxel shape */ M3D_INDEX materialid; /* material index */ uint32_t color; /* default voxel color */ M3D_INDEX skinid; /* skin index */ uint8_t numitem; /* number of sub-voxels */ m3dvi_t *item; /* list of sub-voxels */ } m3dvt_t; #define m3d_voxeltype_t m3dvt_t /* voxel data blocks */ typedef struct { char *name; /* name of the block */ int32_t x, y, z; /* position */ uint32_t w, h, d; /* dimension */ uint8_t uncertain; /* probability */ uint8_t groupid; /* block group id */ M3D_VOXEL *data; /* voxel data, indices to voxel type */ } m3dvx_t; #define m3d_voxel_t m3dvx_t /* shape command types. must match the row in m3d_commandtypes */ enum { /* special commands */ m3dc_use = 0, /* use material */ m3dc_inc, /* include another shape */ m3dc_mesh, /* include part of polygon mesh */ /* approximations */ m3dc_div, /* subdivision by constant resolution for both u, v */ m3dc_sub, /* subdivision by constant, different for u and v */ m3dc_len, /* spacial subdivision by maxlength */ m3dc_dist, /* subdivision by maxdistance and maxangle */ /* modifiers */ m3dc_degu, /* degree for both u, v */ m3dc_deg, /* separate degree for u and v */ m3dc_rangeu, /* range for u */ m3dc_range, /* range for u and v */ m3dc_paru, /* u parameters (knots) */ m3dc_parv, /* v parameters */ m3dc_trim, /* outer trimming curve */ m3dc_hole, /* inner trimming curve */ m3dc_scrv, /* spacial curve */ m3dc_sp, /* special points */ /* helper curves */ m3dc_bez1, /* Bezier 1D */ m3dc_bsp1, /* B-spline 1D */ m3dc_bez2, /* bezier 2D */ m3dc_bsp2, /* B-spline 2D */ /* surfaces */ m3dc_bezun, /* Bezier 3D with control, UV, normal */ m3dc_bezu, /* with control and UV */ m3dc_bezn, /* with control and normal */ m3dc_bez, /* control points only */ m3dc_nurbsun, /* B-spline 3D */ m3dc_nurbsu, m3dc_nurbsn, m3dc_nurbs, m3dc_conn, /* connect surfaces */ /* geometrical */ m3dc_line, m3dc_polygon, m3dc_circle, m3dc_cylinder, m3dc_shpere, m3dc_torus, m3dc_cone, m3dc_cube }; /* shape command argument types */ enum { m3dcp_mi_t = 1, /* material index */ m3dcp_hi_t, /* shape index */ m3dcp_fi_t, /* face index */ m3dcp_ti_t, /* texture map index */ m3dcp_vi_t, /* vertex index */ m3dcp_qi_t, /* vertex index for quaternions */ m3dcp_vc_t, /* coordinate or radius, float scalar */ m3dcp_i1_t, /* int8 scalar */ m3dcp_i2_t, /* int16 scalar */ m3dcp_i4_t, /* int32 scalar */ m3dcp_va_t /* variadic arguments */ }; #define M3D_CMDMAXARG 8 /* if you increase this, add more arguments to the macro below */ typedef struct { #ifdef M3D_ASCII #define M3D_CMDDEF(t,n,p,a,b,c,d,e,f,g,h) { (char*)(n), (p), { (a), (b), (c), (d), (e), (f), (g), (h) } } char *key; #else #define M3D_CMDDEF(t,n,p,a,b,c,d,e,f,g,h) { (p), { (a), (b), (c), (d), (e), (f), (g), (h) } } #endif uint8_t p; uint8_t a[M3D_CMDMAXARG]; } m3dcd_t; /* shape command */ typedef struct { uint16_t type; /* shape type */ uint32_t *arg; /* arguments array */ } m3dc_t; #define m3d_shapecommand_t m3dc_t /* shape entry */ typedef struct { char *name; /* name of the mathematical shape */ M3D_INDEX group; /* group this shape belongs to or -1 */ uint32_t numcmd; /* number of commands */ m3dc_t *cmd; /* commands array */ } m3dh_t; #define m3d_shape_t m3dh_t /* label entry */ typedef struct { char *name; /* name of the annotation layer or NULL */ char *lang; /* language code or NULL */ char *text; /* the label text */ uint32_t color; /* color */ M3D_INDEX vertexid; /* the vertex the label refers to */ } m3dl_t; #define m3d_label_t m3dl_t /* frame transformations / working copy skeleton entry */ typedef struct { M3D_INDEX boneid; /* selects a node in bone hierarchy */ M3D_INDEX pos; /* vertex index new position */ M3D_INDEX ori; /* vertex index new orientation (quaternion) */ } m3dtr_t; #define m3d_transform_t m3dtr_t /* animation frame entry */ typedef struct { uint32_t msec; /* frame's position on the timeline, timestamp */ M3D_INDEX numtransform; /* number of transformations in this frame */ m3dtr_t *transform; /* transformations */ } m3dfr_t; #define m3d_frame_t m3dfr_t /* model action entry */ typedef struct { char *name; /* name of the action */ uint32_t durationmsec; /* duration in millisec (1/1000 sec) */ M3D_INDEX numframe; /* number of frames in this animation */ m3dfr_t *frame; /* frames array */ } m3da_t; #define m3d_action_t m3da_t /* inlined asset */ typedef struct { char *name; /* asset name (same pointer as in texture[].name) */ uint8_t *data; /* compressed asset data */ uint32_t length; /* compressed data length */ } m3di_t; #define m3d_inlinedasset_t m3di_t /*** in-memory model structure ***/ #define M3D_FLG_FREERAW (1<<0) #define M3D_FLG_FREESTR (1<<1) #define M3D_FLG_MTLLIB (1<<2) #define M3D_FLG_GENNORM (1<<3) typedef struct { m3dhdr_t *raw; /* pointer to raw data */ char flags; /* internal flags */ signed char errcode; /* returned error code */ char vc_s, vi_s, si_s, ci_s, ti_s, bi_s, nb_s, sk_s, fc_s, hi_s, fi_s, vd_s, vp_s; /* decoded sizes for types */ char *name; /* name of the model, like "Utah teapot" */ char *license; /* usage condition or license, like "MIT", "LGPL" or "BSD-3clause" */ char *author; /* nickname, email, homepage or github URL etc. */ char *desc; /* comments, descriptions. May contain '\n' newline character */ M3D_FLOAT scale; /* the model's bounding cube's size in SI meters */ M3D_INDEX numcmap; uint32_t *cmap; /* color map */ M3D_INDEX numtmap; m3dti_t *tmap; /* texture map indices */ M3D_INDEX numtexture; m3dtx_t *texture; /* uncompressed textures */ M3D_INDEX numbone; m3db_t *bone; /* bone hierarchy */ M3D_INDEX numvertex; m3dv_t *vertex; /* vertex data */ M3D_INDEX numskin; m3ds_t *skin; /* skin data */ M3D_INDEX nummaterial; m3dm_t *material; /* material list */ #ifdef M3D_VERTEXMAX M3D_INDEX numparam; m3dvi_t *param; /* parameters and their values list */ #endif M3D_INDEX numface; m3df_t *face; /* model face, polygon (triangle) mesh */ M3D_INDEX numvoxtype; m3dvt_t *voxtype; /* model face, voxel types */ M3D_INDEX numvoxel; m3dvx_t *voxel; /* model face, cubes compressed into voxels */ M3D_INDEX numshape; m3dh_t *shape; /* model face, shape commands */ M3D_INDEX numlabel; m3dl_t *label; /* annotation labels */ M3D_INDEX numaction; m3da_t *action; /* action animations */ M3D_INDEX numinlined; m3di_t *inlined; /* inlined assets */ M3D_INDEX numextra; m3dchunk_t **extra; /* unknown chunks, application / engine specific data probably */ m3di_t preview; /* preview chunk */ } m3d_t; /*** export parameters ***/ #define M3D_EXP_INT8 0 #define M3D_EXP_INT16 1 #define M3D_EXP_FLOAT 2 #define M3D_EXP_DOUBLE 3 #define M3D_EXP_NOCMAP (1<<0) #define M3D_EXP_NOMATERIAL (1<<1) #define M3D_EXP_NOFACE (1<<2) #define M3D_EXP_NONORMAL (1<<3) #define M3D_EXP_NOTXTCRD (1<<4) #define M3D_EXP_FLIPTXTCRD (1<<5) #define M3D_EXP_NORECALC (1<<6) #define M3D_EXP_IDOSUCK (1<<7) #define M3D_EXP_NOBONE (1<<8) #define M3D_EXP_NOACTION (1<<9) #define M3D_EXP_INLINE (1<<10) #define M3D_EXP_EXTRA (1<<11) #define M3D_EXP_NOZLIB (1<<14) #define M3D_EXP_ASCII (1<<15) #define M3D_EXP_NOVRTMAX (1<<16) /*** error codes ***/ #define M3D_SUCCESS 0 #define M3D_ERR_ALLOC -1 #define M3D_ERR_BADFILE -2 #define M3D_ERR_UNIMPL -65 #define M3D_ERR_UNKPROP -66 #define M3D_ERR_UNKMESH -67 #define M3D_ERR_UNKIMG -68 #define M3D_ERR_UNKFRAME -69 #define M3D_ERR_UNKCMD -70 #define M3D_ERR_UNKVOX -71 #define M3D_ERR_TRUNC -72 #define M3D_ERR_CMAP -73 #define M3D_ERR_TMAP -74 #define M3D_ERR_VRTS -75 #define M3D_ERR_BONE -76 #define M3D_ERR_MTRL -77 #define M3D_ERR_SHPE -78 #define M3D_ERR_VOXT -79 #define M3D_ERR_ISFATAL(x) ((x) < 0 && (x) > -65) /* callbacks */ typedef unsigned char *(*m3dread_t)(char *filename, unsigned int *size); /* read file contents into buffer */ typedef void (*m3dfree_t)(void *buffer); /* free file contents buffer */ typedef int (*m3dtxsc_t)(const char *name, const void *script, uint32_t len, m3dtx_t *output); /* interpret texture script */ typedef int (*m3dprsc_t)(const char *name, const void *script, uint32_t len, m3d_t *model); /* interpret surface script */ #endif /* ifndef M3D_APIVERSION */ /*** C prototypes ***/ /* import / export */ m3d_t *m3d_load(unsigned char *data, m3dread_t readfilecb, m3dfree_t freecb, m3d_t *mtllib); unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size); void m3d_free(m3d_t *model); /* generate animation pose skeleton */ m3dtr_t *m3d_frame(m3d_t *model, M3D_INDEX actionid, M3D_INDEX frameid, m3dtr_t *skeleton); m3db_t *m3d_pose(m3d_t *model, M3D_INDEX actionid, uint32_t msec); /* private prototypes used by both importer and exporter */ char *_m3d_safestr(char *in, int morelines); /*** C implementation ***/ #ifdef M3D_IMPLEMENTATION #if !defined(M3D_NOIMPORTER) || defined(M3D_EXPORTER) /* material property definitions */ static m3dpd_t m3d_propertytypes[] = { M3D_PROPERTYDEF(m3dpf_color, m3dp_Kd, "Kd"), /* diffuse color */ M3D_PROPERTYDEF(m3dpf_color, m3dp_Ka, "Ka"), /* ambient color */ M3D_PROPERTYDEF(m3dpf_color, m3dp_Ks, "Ks"), /* specular color */ M3D_PROPERTYDEF(m3dpf_float, m3dp_Ns, "Ns"), /* specular exponent */ M3D_PROPERTYDEF(m3dpf_color, m3dp_Ke, "Ke"), /* emissive (emitting light of this color) */ M3D_PROPERTYDEF(m3dpf_color, m3dp_Tf, "Tf"), /* transmission color */ M3D_PROPERTYDEF(m3dpf_float, m3dp_Km, "Km"), /* bump strength */ M3D_PROPERTYDEF(m3dpf_float, m3dp_d, "d"), /* dissolve (transparency) */ M3D_PROPERTYDEF(m3dpf_uint8, m3dp_il, "il"), /* illumination model (informational, ignored by PBR-shaders) */ M3D_PROPERTYDEF(m3dpf_float, m3dp_Pr, "Pr"), /* roughness */ M3D_PROPERTYDEF(m3dpf_float, m3dp_Pm, "Pm"), /* metallic, also reflection */ M3D_PROPERTYDEF(m3dpf_float, m3dp_Ps, "Ps"), /* sheen */ M3D_PROPERTYDEF(m3dpf_float, m3dp_Ni, "Ni"), /* index of refraction (optical density) */ M3D_PROPERTYDEF(m3dpf_float, m3dp_Nt, "Nt"), /* thickness of face in millimeter, for printing */ /* aliases, note that "map_*" aliases are handled automatically */ M3D_PROPERTYDEF(m3dpf_map, m3dp_map_Km, "bump"), M3D_PROPERTYDEF(m3dpf_map, m3dp_map_N, "map_N"),/* as normal map has no scalar version, it's counterpart is 'il' */ M3D_PROPERTYDEF(m3dpf_map, m3dp_map_Pm, "refl") }; /* shape command definitions. if more commands start with the same string, the longer must come first */ static m3dcd_t m3d_commandtypes[] = { /* technical */ M3D_CMDDEF(m3dc_use, "use", 1, m3dcp_mi_t, 0, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_inc, "inc", 3, m3dcp_hi_t, m3dcp_vi_t, m3dcp_qi_t, m3dcp_vi_t, 0, 0, 0, 0), M3D_CMDDEF(m3dc_mesh, "mesh", 1, m3dcp_fi_t, m3dcp_fi_t, m3dcp_vi_t, m3dcp_qi_t, m3dcp_vi_t, 0, 0, 0), /* approximations */ M3D_CMDDEF(m3dc_div, "div", 1, m3dcp_vc_t, 0, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_sub, "sub", 2, m3dcp_vc_t, m3dcp_vc_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_len, "len", 1, m3dcp_vc_t, 0, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_dist, "dist", 2, m3dcp_vc_t, m3dcp_vc_t, 0, 0, 0, 0, 0, 0), /* modifiers */ M3D_CMDDEF(m3dc_degu, "degu", 1, m3dcp_i1_t, 0, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_deg, "deg", 2, m3dcp_i1_t, m3dcp_i1_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_rangeu, "rangeu", 1, m3dcp_ti_t, 0, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_range, "range", 2, m3dcp_ti_t, m3dcp_ti_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_paru, "paru", 2, m3dcp_va_t, m3dcp_vc_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_parv, "parv", 2, m3dcp_va_t, m3dcp_vc_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_trim, "trim", 3, m3dcp_va_t, m3dcp_ti_t, m3dcp_i2_t, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_hole, "hole", 3, m3dcp_va_t, m3dcp_ti_t, m3dcp_i2_t, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_scrv, "scrv", 3, m3dcp_va_t, m3dcp_ti_t, m3dcp_i2_t, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_sp, "sp", 2, m3dcp_va_t, m3dcp_vi_t, 0, 0, 0, 0, 0, 0), /* helper curves */ M3D_CMDDEF(m3dc_bez1, "bez1", 2, m3dcp_va_t, m3dcp_vi_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_bsp1, "bsp1", 2, m3dcp_va_t, m3dcp_vi_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_bez2, "bez2", 2, m3dcp_va_t, m3dcp_vi_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_bsp2, "bsp2", 2, m3dcp_va_t, m3dcp_vi_t, 0, 0, 0, 0, 0, 0), /* surfaces */ M3D_CMDDEF(m3dc_bezun, "bezun", 4, m3dcp_va_t, m3dcp_vi_t, m3dcp_ti_t, m3dcp_vi_t, 0, 0, 0, 0), M3D_CMDDEF(m3dc_bezu, "bezu", 3, m3dcp_va_t, m3dcp_vi_t, m3dcp_ti_t, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_bezn, "bezn", 3, m3dcp_va_t, m3dcp_vi_t, m3dcp_vi_t, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_bez, "bez", 2, m3dcp_va_t, m3dcp_vi_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_nurbsun, "nurbsun", 4, m3dcp_va_t, m3dcp_vi_t, m3dcp_ti_t, m3dcp_vi_t, 0, 0, 0, 0), M3D_CMDDEF(m3dc_nurbsu, "nurbsu", 3, m3dcp_va_t, m3dcp_vi_t, m3dcp_ti_t, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_nurbsn, "nurbsn", 3, m3dcp_va_t, m3dcp_vi_t, m3dcp_vi_t, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_nurbs, "nurbs", 2, m3dcp_va_t, m3dcp_vi_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_conn, "conn", 6, m3dcp_i2_t, m3dcp_ti_t, m3dcp_i2_t, m3dcp_i2_t, m3dcp_ti_t, m3dcp_i2_t, 0, 0), /* geometrical */ M3D_CMDDEF(m3dc_line, "line", 2, m3dcp_va_t, m3dcp_vi_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_polygon, "polygon", 2, m3dcp_va_t, m3dcp_vi_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_circle, "circle", 3, m3dcp_vi_t, m3dcp_qi_t, m3dcp_vc_t, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_cylinder,"cylinder",6, m3dcp_vi_t, m3dcp_qi_t, m3dcp_vc_t, m3dcp_vi_t, m3dcp_qi_t, m3dcp_vc_t, 0, 0), M3D_CMDDEF(m3dc_shpere, "shpere", 2, m3dcp_vi_t, m3dcp_vc_t, 0, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_torus, "torus", 4, m3dcp_vi_t, m3dcp_qi_t, m3dcp_vc_t, m3dcp_vc_t, 0, 0, 0, 0), M3D_CMDDEF(m3dc_cone, "cone", 3, m3dcp_vi_t, m3dcp_vi_t, m3dcp_vi_t, 0, 0, 0, 0, 0), M3D_CMDDEF(m3dc_cube, "cube", 3, m3dcp_vi_t, m3dcp_vi_t, m3dcp_vi_t, 0, 0, 0, 0, 0) }; #endif #include <stdlib.h> #include <string.h> #if !defined(M3D_NOIMPORTER) && !defined(STBI_INCLUDE_STB_IMAGE_H) /* PNG decompressor from stb_image - v2.23 - public domain image loader - http://nothings.org/stb_image.h */ static const char *_m3dstbi__g_failure_reason; enum { STBI_default = 0, STBI_grey = 1, STBI_grey_alpha = 2, STBI_rgb = 3, STBI_rgb_alpha = 4 }; enum { STBI__SCAN_load=0, STBI__SCAN_type, STBI__SCAN_header }; typedef unsigned short _m3dstbi_us; typedef uint16_t _m3dstbi__uint16; typedef int16_t _m3dstbi__int16; typedef uint32_t _m3dstbi__uint32; typedef int32_t _m3dstbi__int32; typedef struct { _m3dstbi__uint32 img_x, img_y; int img_n, img_out_n; void *io_user_data; int read_from_callbacks; int buflen; unsigned char buffer_start[128]; unsigned char *img_buffer, *img_buffer_end; unsigned char *img_buffer_original, *img_buffer_original_end; } _m3dstbi__context; typedef struct { int bits_per_channel; int num_channels; int channel_order; } _m3dstbi__result_info; #define STBI_ASSERT(v) #define STBI_NOTUSED(v) (void)sizeof(v) #define STBI__BYTECAST(x) ((unsigned char) ((x) & 255)) #define STBI_MALLOC(sz) M3D_MALLOC(sz) #define STBI_REALLOC(p,newsz) M3D_REALLOC(p,newsz) #define STBI_FREE(p) M3D_FREE(p) #define STBI_REALLOC_SIZED(p,oldsz,newsz) STBI_REALLOC(p,newsz) _inline static unsigned char _m3dstbi__get8(_m3dstbi__context *s) { if (s->img_buffer < s->img_buffer_end) return *s->img_buffer++; return 0; } _inline static int _m3dstbi__at_eof(_m3dstbi__context *s) { return s->img_buffer >= s->img_buffer_end; } static void _m3dstbi__skip(_m3dstbi__context *s, int n) { if (n < 0) { s->img_buffer = s->img_buffer_end; return; } s->img_buffer += n; } static int _m3dstbi__getn(_m3dstbi__context *s, unsigned char *buffer, int n) { if (s->img_buffer+n <= s->img_buffer_end) { memcpy(buffer, s->img_buffer, n); s->img_buffer += n; return 1; } else return 0; } static int _m3dstbi__get16be(_m3dstbi__context *s) { int z = _m3dstbi__get8(s); return (z << 8) + _m3dstbi__get8(s); } static _m3dstbi__uint32 _m3dstbi__get32be(_m3dstbi__context *s) { _m3dstbi__uint32 z = _m3dstbi__get16be(s); return (z << 16) + _m3dstbi__get16be(s); } #define _m3dstbi__err(x,y) _m3dstbi__errstr(y) static int _m3dstbi__errstr(const char *str) { _m3dstbi__g_failure_reason = str; return 0; } _inline static void *_m3dstbi__malloc(size_t size) { return STBI_MALLOC(size); } static int _m3dstbi__addsizes_valid(int a, int b) { if (b < 0) return 0; return a <= 2147483647 - b; } static int _m3dstbi__mul2sizes_valid(int a, int b) { if (a < 0 || b < 0) return 0; if (b == 0) return 1; return a <= 2147483647/b; } static int _m3dstbi__mad2sizes_valid(int a, int b, int add) { return _m3dstbi__mul2sizes_valid(a, b) && _m3dstbi__addsizes_valid(a*b, add); } static int _m3dstbi__mad3sizes_valid(int a, int b, int c, int add) { return _m3dstbi__mul2sizes_valid(a, b) && _m3dstbi__mul2sizes_valid(a*b, c) && _m3dstbi__addsizes_valid(a*b*c, add); } static void *_m3dstbi__malloc_mad2(int a, int b, int add) { if (!_m3dstbi__mad2sizes_valid(a, b, add)) return NULL; return _m3dstbi__malloc(a*b + add); } static void *_m3dstbi__malloc_mad3(int a, int b, int c, int add) { if (!_m3dstbi__mad3sizes_valid(a, b, c, add)) return NULL; return _m3dstbi__malloc(a*b*c + add); } static unsigned char _m3dstbi__compute_y(int r, int g, int b) { return (unsigned char) (((r*77) + (g*150) + (29*b)) >> 8); } static unsigned char *_m3dstbi__convert_format(unsigned char *data, int img_n, int req_comp, unsigned int x, unsigned int y) { int i,j; unsigned char *good; if (req_comp == img_n) return data; STBI_ASSERT(req_comp >= 1 && req_comp <= 4); good = (unsigned char *) _m3dstbi__malloc_mad3(req_comp, x, y, 0); if (good == NULL) { STBI_FREE(data); _m3dstbi__err("outofmem", "Out of memory"); return NULL; } for (j=0; j < (int) y; ++j) { unsigned char *src = data + j * x * img_n ; unsigned char *dest = good + j * x * req_comp; #define STBI__COMBO(a,b) ((a)*8+(b)) #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b) switch (STBI__COMBO(img_n, req_comp)) { STBI__CASE(1,2) { dest[0]=src[0], dest[1]=255; } break; STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=255; } break; STBI__CASE(2,1) { dest[0]=src[0]; } break; STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; } break; STBI__CASE(3,4) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=255; } break; STBI__CASE(3,1) { dest[0]=_m3dstbi__compute_y(src[0],src[1],src[2]); } break; STBI__CASE(3,2) { dest[0]=_m3dstbi__compute_y(src[0],src[1],src[2]), dest[1] = 255; } break; STBI__CASE(4,1) { dest[0]=_m3dstbi__compute_y(src[0],src[1],src[2]); } break; STBI__CASE(4,2) { dest[0]=_m3dstbi__compute_y(src[0],src[1],src[2]), dest[1] = src[3]; } break; STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break; default: STBI_ASSERT(0); } #undef STBI__CASE } STBI_FREE(data); return good; } static _m3dstbi__uint16 _m3dstbi__compute_y_16(int r, int g, int b) { return (_m3dstbi__uint16) (((r*77) + (g*150) + (29*b)) >> 8); } static _m3dstbi__uint16 *_m3dstbi__convert_format16(_m3dstbi__uint16 *data, int img_n, int req_comp, unsigned int x, unsigned int y) { int i,j; _m3dstbi__uint16 *good; if (req_comp == img_n) return data; STBI_ASSERT(req_comp >= 1 && req_comp <= 4); good = (_m3dstbi__uint16 *) _m3dstbi__malloc(req_comp * x * y * 2); if (good == NULL) { STBI_FREE(data); _m3dstbi__err("outofmem", "Out of memory"); return NULL; } for (j=0; j < (int) y; ++j) { _m3dstbi__uint16 *src = data + j * x * img_n ; _m3dstbi__uint16 *dest = good + j * x * req_comp; #define STBI__COMBO(a,b) ((a)*8+(b)) #define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b) switch (STBI__COMBO(img_n, req_comp)) { STBI__CASE(1,2) { dest[0]=src[0], dest[1]=0xffff; } break; STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=0xffff; } break; STBI__CASE(2,1) { dest[0]=src[0]; } break; STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break; STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; } break; STBI__CASE(3,4) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=0xffff; } break; STBI__CASE(3,1) { dest[0]=_m3dstbi__compute_y_16(src[0],src[1],src[2]); } break; STBI__CASE(3,2) { dest[0]=_m3dstbi__compute_y_16(src[0],src[1],src[2]), dest[1] = 0xffff; } break; STBI__CASE(4,1) { dest[0]=_m3dstbi__compute_y_16(src[0],src[1],src[2]); } break; STBI__CASE(4,2) { dest[0]=_m3dstbi__compute_y_16(src[0],src[1],src[2]), dest[1] = src[3]; } break; STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break; default: STBI_ASSERT(0); } #undef STBI__CASE } STBI_FREE(data); return good; } #define STBI__ZFAST_BITS 9 #define STBI__ZFAST_MASK ((1 << STBI__ZFAST_BITS) - 1) typedef struct { _m3dstbi__uint16 fast[1 << STBI__ZFAST_BITS]; _m3dstbi__uint16 firstcode[16]; int maxcode[17]; _m3dstbi__uint16 firstsymbol[16]; unsigned char size[288]; _m3dstbi__uint16 value[288]; } _m3dstbi__zhuffman; _inline static int _m3dstbi__bitreverse16(int n) { n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1); n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2); n = ((n & 0xF0F0) >> 4) | ((n & 0x0F0F) << 4); n = ((n & 0xFF00) >> 8) | ((n & 0x00FF) << 8); return n; } _inline static int _m3dstbi__bit_reverse(int v, int bits) { STBI_ASSERT(bits <= 16); return _m3dstbi__bitreverse16(v) >> (16-bits); } static int _m3dstbi__zbuild_huffman(_m3dstbi__zhuffman *z, unsigned char *sizelist, int num) { int i,k=0; int code, next_code[16], sizes[17]; memset(sizes, 0, sizeof(sizes)); memset(z->fast, 0, sizeof(z->fast)); for (i=0; i < num; ++i) ++sizes[sizelist[i]]; sizes[0] = 0; for (i=1; i < 16; ++i) if (sizes[i] > (1 << i)) return _m3dstbi__err("bad sizes", "Corrupt PNG"); code = 0; for (i=1; i < 16; ++i) { next_code[i] = code; z->firstcode[i] = (_m3dstbi__uint16) code; z->firstsymbol[i] = (_m3dstbi__uint16) k; code = (code + sizes[i]); if (sizes[i]) if (code-1 >= (1 << i)) return _m3dstbi__err("bad codelengths","Corrupt PNG"); z->maxcode[i] = code << (16-i); code <<= 1; k += sizes[i]; } z->maxcode[16] = 0x10000; for (i=0; i < num; ++i) { int s = sizelist[i]; if (s) { int c = next_code[s] - z->firstcode[s] + z->firstsymbol[s]; _m3dstbi__uint16 fastv = (_m3dstbi__uint16) ((s << 9) | i); z->size [c] = (unsigned char ) s; z->value[c] = (_m3dstbi__uint16) i; if (s <= STBI__ZFAST_BITS) { int j = _m3dstbi__bit_reverse(next_code[s],s); while (j < (1 << STBI__ZFAST_BITS)) { z->fast[j] = fastv; j += (1 << s); } } ++next_code[s]; } } return 1; } typedef struct { unsigned char *zbuffer, *zbuffer_end; int num_bits; _m3dstbi__uint32 code_buffer; char *zout; char *zout_start; char *zout_end; int z_expandable; _m3dstbi__zhuffman z_length, z_distance; } _m3dstbi__zbuf; _inline static unsigned char _m3dstbi__zget8(_m3dstbi__zbuf *z) { if (z->zbuffer >= z->zbuffer_end) return 0; return *z->zbuffer++; } static void _m3dstbi__fill_bits(_m3dstbi__zbuf *z) { do { STBI_ASSERT(z->code_buffer < (1U << z->num_bits)); z->code_buffer |= (unsigned int) _m3dstbi__zget8(z) << z->num_bits; z->num_bits += 8; } while (z->num_bits <= 24); } _inline static unsigned int _m3dstbi__zreceive(_m3dstbi__zbuf *z, int n) { unsigned int k; if (z->num_bits < n) _m3dstbi__fill_bits(z); k = z->code_buffer & ((1 << n) - 1); z->code_buffer >>= n; z->num_bits -= n; return k; } static int _m3dstbi__zhuffman_decode_slowpath(_m3dstbi__zbuf *a, _m3dstbi__zhuffman *z) { int b,s,k; k = _m3dstbi__bit_reverse(a->code_buffer, 16); for (s=STBI__ZFAST_BITS+1; ; ++s) if (k < z->maxcode[s]) break; if (s == 16) return -1; b = (k >> (16-s)) - z->firstcode[s] + z->firstsymbol[s]; STBI_ASSERT(z->size[b] == s); a->code_buffer >>= s; a->num_bits -= s; return z->value[b]; } _inline static int _m3dstbi__zhuffman_decode(_m3dstbi__zbuf *a, _m3dstbi__zhuffman *z) { int b,s; if (a->num_bits < 16) _m3dstbi__fill_bits(a); b = z->fast[a->code_buffer & STBI__ZFAST_MASK]; if (b) { s = b >> 9; a->code_buffer >>= s; a->num_bits -= s; return b & 511; } return _m3dstbi__zhuffman_decode_slowpath(a, z); } static int _m3dstbi__zexpand(_m3dstbi__zbuf *z, char *zout, int n) { char *q; int cur, limit, old_limit; z->zout = zout; if (!z->z_expandable) return _m3dstbi__err("output buffer limit","Corrupt PNG"); cur = (int) (z->zout - z->zout_start); limit = old_limit = (int) (z->zout_end - z->zout_start); while (cur + n > limit) limit *= 2; q = (char *) STBI_REALLOC_SIZED(z->zout_start, old_limit, limit); STBI_NOTUSED(old_limit); if (q == NULL) return _m3dstbi__err("outofmem", "Out of memory"); z->zout_start = q; z->zout = q + cur; z->zout_end = q + limit; return 1; } static int _m3dstbi__zlength_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 }; static int _m3dstbi__zlength_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 }; static int _m3dstbi__zdist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0}; static int _m3dstbi__zdist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; static int _m3dstbi__parse_huffman_block(_m3dstbi__zbuf *a) { char *zout = a->zout; for(;;) { int z = _m3dstbi__zhuffman_decode(a, &a->z_length); if (z < 256) { if (z < 0) return _m3dstbi__err("bad huffman code","Corrupt PNG"); if (zout >= a->zout_end) { if (!_m3dstbi__zexpand(a, zout, 1)) return 0; zout = a->zout; } *zout++ = (char) z; } else { unsigned char *p; int len,dist; if (z == 256) { a->zout = zout; return 1; } z -= 257; len = _m3dstbi__zlength_base[z]; if (_m3dstbi__zlength_extra[z]) len += _m3dstbi__zreceive(a, _m3dstbi__zlength_extra[z]); z = _m3dstbi__zhuffman_decode(a, &a->z_distance); if (z < 0) return _m3dstbi__err("bad huffman code","Corrupt PNG"); dist = _m3dstbi__zdist_base[z]; if (_m3dstbi__zdist_extra[z]) dist += _m3dstbi__zreceive(a, _m3dstbi__zdist_extra[z]); if (zout - a->zout_start < dist) return _m3dstbi__err("bad dist","Corrupt PNG"); if (zout + len > a->zout_end) { if (!_m3dstbi__zexpand(a, zout, len)) return 0; zout = a->zout; } p = (unsigned char *) (zout - dist); if (dist == 1) { unsigned char v = *p; if (len) { do *zout++ = v; while (--len); } } else { if (len) { do *zout++ = *p++; while (--len); } } } } } static int _m3dstbi__compute_huffman_codes(_m3dstbi__zbuf *a) { static unsigned char length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 }; _m3dstbi__zhuffman z_codelength; unsigned char lencodes[286+32+137]; unsigned char codelength_sizes[19]; int i,n; int hlit = _m3dstbi__zreceive(a,5) + 257; int hdist = _m3dstbi__zreceive(a,5) + 1; int hclen = _m3dstbi__zreceive(a,4) + 4; int ntot = hlit + hdist; memset(codelength_sizes, 0, sizeof(codelength_sizes)); for (i=0; i < hclen; ++i) { int s = _m3dstbi__zreceive(a,3); codelength_sizes[length_dezigzag[i]] = (unsigned char) s; } if (!_m3dstbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) return 0; n = 0; while (n < ntot) { int c = _m3dstbi__zhuffman_decode(a, &z_codelength); if (c < 0 || c >= 19) return _m3dstbi__err("bad codelengths", "Corrupt PNG"); if (c < 16) lencodes[n++] = (unsigned char) c; else { unsigned char fill = 0; if (c == 16) { c = _m3dstbi__zreceive(a,2)+3; if (n == 0) return _m3dstbi__err("bad codelengths", "Corrupt PNG"); fill = lencodes[n-1]; } else if (c == 17) c = _m3dstbi__zreceive(a,3)+3; else { STBI_ASSERT(c == 18); c = _m3dstbi__zreceive(a,7)+11; } if (ntot - n < c) return _m3dstbi__err("bad codelengths", "Corrupt PNG"); memset(lencodes+n, fill, c); n += c; } } if (n != ntot) return _m3dstbi__err("bad codelengths","Corrupt PNG"); if (!_m3dstbi__zbuild_huffman(&a->z_length, lencodes, hlit)) return 0; if (!_m3dstbi__zbuild_huffman(&a->z_distance, lencodes+hlit, hdist)) return 0; return 1; } _inline static int _m3dstbi__parse_uncompressed_block(_m3dstbi__zbuf *a) { unsigned char header[4]; int len,nlen,k; if (a->num_bits & 7) _m3dstbi__zreceive(a, a->num_bits & 7); k = 0; while (a->num_bits > 0) { header[k++] = (unsigned char) (a->code_buffer & 255); a->code_buffer >>= 8; a->num_bits -= 8; } STBI_ASSERT(a->num_bits == 0); while (k < 4) header[k++] = _m3dstbi__zget8(a); len = header[1] * 256 + header[0]; nlen = header[3] * 256 + header[2]; if (nlen != (len ^ 0xffff)) return _m3dstbi__err("zlib corrupt","Corrupt PNG"); if (a->zbuffer + len > a->zbuffer_end) return _m3dstbi__err("read past buffer","Corrupt PNG"); if (a->zout + len > a->zout_end) if (!_m3dstbi__zexpand(a, a->zout, len)) return 0; memcpy(a->zout, a->zbuffer, len); a->zbuffer += len; a->zout += len; return 1; } static int _m3dstbi__parse_zlib_header(_m3dstbi__zbuf *a) { int cmf = _m3dstbi__zget8(a); int cm = cmf & 15; /* int cinfo = cmf >> 4; */ int flg = _m3dstbi__zget8(a); if ((cmf*256+flg) % 31 != 0) return _m3dstbi__err("bad zlib header","Corrupt PNG"); if (flg & 32) return _m3dstbi__err("no preset dict","Corrupt PNG"); if (cm != 8) return _m3dstbi__err("bad compression","Corrupt PNG"); return 1; } static unsigned char _m3dstbi__zdefault_length[288], _m3dstbi__zdefault_distance[32]; static void _m3dstbi__init_zdefaults(void) { int i; for (i=0; i <= 143; ++i) _m3dstbi__zdefault_length[i] = 8; for ( ; i <= 255; ++i) _m3dstbi__zdefault_length[i] = 9; for ( ; i <= 279; ++i) _m3dstbi__zdefault_length[i] = 7; for ( ; i <= 287; ++i) _m3dstbi__zdefault_length[i] = 8; for (i=0; i <= 31; ++i) _m3dstbi__zdefault_distance[i] = 5; } static int _m3dstbi__parse_zlib(_m3dstbi__zbuf *a, int parse_header) { int final, type; if (parse_header) if (!_m3dstbi__parse_zlib_header(a)) return 0; a->num_bits = 0; a->code_buffer = 0; do { final = _m3dstbi__zreceive(a,1); type = _m3dstbi__zreceive(a,2); if (type == 0) { if (!_m3dstbi__parse_uncompressed_block(a)) return 0; } else if (type == 3) { return 0; } else { if (type == 1) { if (!_m3dstbi__zbuild_huffman(&a->z_length , _m3dstbi__zdefault_length , 288)) return 0; if (!_m3dstbi__zbuild_huffman(&a->z_distance, _m3dstbi__zdefault_distance, 32)) return 0; } else { if (!_m3dstbi__compute_huffman_codes(a)) return 0; } if (!_m3dstbi__parse_huffman_block(a)) return 0; } } while (!final); return 1; } static int _m3dstbi__do_zlib(_m3dstbi__zbuf *a, char *obuf, int olen, int exp, int parse_header) { a->zout_start = obuf; a->zout = obuf; a->zout_end = obuf + olen; a->z_expandable = exp; _m3dstbi__init_zdefaults(); return _m3dstbi__parse_zlib(a, parse_header); } char *_m3dstbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header) { _m3dstbi__zbuf a; char *p = (char *) _m3dstbi__malloc(initial_size); if (p == NULL) return NULL; a.zbuffer = (unsigned char *) buffer; a.zbuffer_end = (unsigned char *) buffer + len; if (_m3dstbi__do_zlib(&a, p, initial_size, 1, parse_header)) { if (outlen) *outlen = (int) (a.zout - a.zout_start); return a.zout_start; } else { STBI_FREE(a.zout_start); return NULL; } } typedef struct { _m3dstbi__uint32 length; _m3dstbi__uint32 type; } _m3dstbi__pngchunk; static _m3dstbi__pngchunk _m3dstbi__get_chunk_header(_m3dstbi__context *s) { _m3dstbi__pngchunk c; c.length = _m3dstbi__get32be(s); c.type = _m3dstbi__get32be(s); return c; } _inline static int _m3dstbi__check_png_header(_m3dstbi__context *s) { static unsigned char png_sig[8] = { 137,80,78,71,13,10,26,10 }; int i; for (i=0; i < 8; ++i) if (_m3dstbi__get8(s) != png_sig[i]) return _m3dstbi__err("bad png sig","Not a PNG"); return 1; } typedef struct { _m3dstbi__context *s; unsigned char *idata, *expanded, *out; int depth; } _m3dstbi__png; enum { STBI__F_none=0, STBI__F_sub=1, STBI__F_up=2, STBI__F_avg=3, STBI__F_paeth=4, STBI__F_avg_first, STBI__F_paeth_first }; static unsigned char first_row_filter[5] = { STBI__F_none, STBI__F_sub, STBI__F_none, STBI__F_avg_first, STBI__F_paeth_first }; static int _m3dstbi__paeth(int a, int b, int c) { int p = a + b - c; int pa = abs(p-a); int pb = abs(p-b); int pc = abs(p-c); if (pa <= pb && pa <= pc) return a; if (pb <= pc) return b; return c; } static unsigned char _m3dstbi__depth_scale_table[9] = { 0, 0xff, 0x55, 0, 0x11, 0,0,0, 0x01 }; static int _m3dstbi__create_png_image_raw(_m3dstbi__png *a, unsigned char *raw, _m3dstbi__uint32 raw_len, int out_n, _m3dstbi__uint32 x, _m3dstbi__uint32 y, int depth, int color) { int bytes = (depth == 16? 2 : 1); _m3dstbi__context *s = a->s; _m3dstbi__uint32 i,j,stride = x*out_n*bytes; _m3dstbi__uint32 img_len, img_width_bytes; int k; int img_n = s->img_n; int output_bytes = out_n*bytes; int filter_bytes = img_n*bytes; int width = x; STBI_ASSERT(out_n == s->img_n || out_n == s->img_n+1); a->out = (unsigned char *) _m3dstbi__malloc_mad3(x, y, output_bytes, 0); if (!a->out) return _m3dstbi__err("outofmem", "Out of memory"); if (!_m3dstbi__mad3sizes_valid(img_n, x, depth, 7)) return _m3dstbi__err("too large", "Corrupt PNG"); img_width_bytes = (((img_n * x * depth) + 7) >> 3); img_len = (img_width_bytes + 1) * y; if (s->img_x == x && s->img_y == y) { if (raw_len != img_len) return _m3dstbi__err("not enough pixels","Corrupt PNG"); } else { if (raw_len < img_len) return _m3dstbi__err("not enough pixels","Corrupt PNG"); } for (j=0; j < y; ++j) { unsigned char *cur = a->out + stride*j; unsigned char *prior = cur - stride; int filter = *raw++; if (filter > 4) return _m3dstbi__err("invalid filter","Corrupt PNG"); if (depth < 8) { STBI_ASSERT(img_width_bytes <= x); cur += x*out_n - img_width_bytes; filter_bytes = 1; width = img_width_bytes; } prior = cur - stride; if (j == 0) filter = first_row_filter[filter]; for (k=0; k < filter_bytes; ++k) { switch (filter) { case STBI__F_none : cur[k] = raw[k]; break; case STBI__F_sub : cur[k] = raw[k]; break; case STBI__F_up : cur[k] = STBI__BYTECAST(raw[k] + prior[k]); break; case STBI__F_avg : cur[k] = STBI__BYTECAST(raw[k] + (prior[k]>>1)); break; case STBI__F_paeth : cur[k] = STBI__BYTECAST(raw[k] + _m3dstbi__paeth(0,prior[k],0)); break; case STBI__F_avg_first : cur[k] = raw[k]; break; case STBI__F_paeth_first: cur[k] = raw[k]; break; } } if (depth == 8) { if (img_n != out_n) cur[img_n] = 255; raw += img_n; cur += out_n; prior += out_n; } else if (depth == 16) { if (img_n != out_n) { cur[filter_bytes] = 255; cur[filter_bytes+1] = 255; } raw += filter_bytes; cur += output_bytes; prior += output_bytes; } else { raw += 1; cur += 1; prior += 1; } if (depth < 8 || img_n == out_n) { int nk = (width - 1)*filter_bytes; #define STBI__CASE(f) \ case f: \ for (k=0; k < nk; ++k) switch (filter) { case STBI__F_none: memcpy(cur, raw, nk); break; STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k-filter_bytes]); } break; STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } break; STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k-filter_bytes])>>1)); } break; STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + _m3dstbi__paeth(cur[k-filter_bytes],prior[k],prior[k-filter_bytes])); } break; STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k-filter_bytes] >> 1)); } break; STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + _m3dstbi__paeth(cur[k-filter_bytes],0,0)); } break; } #undef STBI__CASE raw += nk; } else { STBI_ASSERT(img_n+1 == out_n); #define STBI__CASE(f) \ case f: \ for (i=x-1; i >= 1; --i, cur[filter_bytes]=255,raw+=filter_bytes,cur+=output_bytes,prior+=output_bytes) \ for (k=0; k < filter_bytes; ++k) switch (filter) { STBI__CASE(STBI__F_none) { cur[k] = raw[k]; } break; STBI__CASE(STBI__F_sub) { cur[k] = STBI__BYTECAST(raw[k] + cur[k- output_bytes]); } break; STBI__CASE(STBI__F_up) { cur[k] = STBI__BYTECAST(raw[k] + prior[k]); } break; STBI__CASE(STBI__F_avg) { cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k- output_bytes])>>1)); } break; STBI__CASE(STBI__F_paeth) { cur[k] = STBI__BYTECAST(raw[k] + _m3dstbi__paeth(cur[k- output_bytes],prior[k],prior[k- output_bytes])); } break; STBI__CASE(STBI__F_avg_first) { cur[k] = STBI__BYTECAST(raw[k] + (cur[k- output_bytes] >> 1)); } break; STBI__CASE(STBI__F_paeth_first) { cur[k] = STBI__BYTECAST(raw[k] + _m3dstbi__paeth(cur[k- output_bytes],0,0)); } break; } #undef STBI__CASE if (depth == 16) { cur = a->out + stride*j; for (i=0; i < x; ++i,cur+=output_bytes) { cur[filter_bytes+1] = 255; } } } } if (depth < 8) { for (j=0; j < y; ++j) { unsigned char *cur = a->out + stride*j; unsigned char *in = a->out + stride*j + x*out_n - img_width_bytes; unsigned char scale = (color == 0) ? _m3dstbi__depth_scale_table[depth] : 1; if (depth == 4) { for (k=x*img_n; k >= 2; k-=2, ++in) { *cur++ = scale * ((*in >> 4) ); *cur++ = scale * ((*in ) & 0x0f); } if (k > 0) *cur++ = scale * ((*in >> 4) ); } else if (depth == 2) { for (k=x*img_n; k >= 4; k-=4, ++in) { *cur++ = scale * ((*in >> 6) ); *cur++ = scale * ((*in >> 4) & 0x03); *cur++ = scale * ((*in >> 2) & 0x03); *cur++ = scale * ((*in ) & 0x03); } if (k > 0) *cur++ = scale * ((*in >> 6) ); if (k > 1) *cur++ = scale * ((*in >> 4) & 0x03); if (k > 2) *cur++ = scale * ((*in >> 2) & 0x03); } else if (depth == 1) { for (k=x*img_n; k >= 8; k-=8, ++in) { *cur++ = scale * ((*in >> 7) ); *cur++ = scale * ((*in >> 6) & 0x01); *cur++ = scale * ((*in >> 5) & 0x01); *cur++ = scale * ((*in >> 4) & 0x01); *cur++ = scale * ((*in >> 3) & 0x01); *cur++ = scale * ((*in >> 2) & 0x01); *cur++ = scale * ((*in >> 1) & 0x01); *cur++ = scale * ((*in ) & 0x01); } if (k > 0) *cur++ = scale * ((*in >> 7) ); if (k > 1) *cur++ = scale * ((*in >> 6) & 0x01); if (k > 2) *cur++ = scale * ((*in >> 5) & 0x01); if (k > 3) *cur++ = scale * ((*in >> 4) & 0x01); if (k > 4) *cur++ = scale * ((*in >> 3) & 0x01); if (k > 5) *cur++ = scale * ((*in >> 2) & 0x01); if (k > 6) *cur++ = scale * ((*in >> 1) & 0x01); } if (img_n != out_n) { int q; cur = a->out + stride*j; if (img_n == 1) { for (q=x-1; q >= 0; --q) { cur[q*2+1] = 255; cur[q*2+0] = cur[q]; } } else { STBI_ASSERT(img_n == 3); for (q=x-1; q >= 0; --q) { cur[q*4+3] = 255; cur[q*4+2] = cur[q*3+2]; cur[q*4+1] = cur[q*3+1]; cur[q*4+0] = cur[q*3+0]; } } } } } else if (depth == 16) { unsigned char *cur = a->out; _m3dstbi__uint16 *cur16 = (_m3dstbi__uint16*)cur; for(i=0; i < x*y*out_n; ++i,cur16++,cur+=2) { *cur16 = (cur[0] << 8) | cur[1]; } } return 1; } static int _m3dstbi__create_png_image(_m3dstbi__png *a, unsigned char *image_data, _m3dstbi__uint32 image_data_len, int out_n, int depth, int color, int interlaced) { int bytes = (depth == 16 ? 2 : 1); int out_bytes = out_n * bytes; unsigned char *final; int p; if (!interlaced) return _m3dstbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color); final = (unsigned char *) _m3dstbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0); for (p=0; p < 7; ++p) { int xorig[] = { 0,4,0,2,0,1,0 }; int yorig[] = { 0,0,4,0,2,0,1 }; int xspc[] = { 8,8,4,4,2,2,1 }; int yspc[] = { 8,8,8,4,4,2,2 }; int i,j,x,y; x = (a->s->img_x - xorig[p] + xspc[p]-1) / xspc[p]; y = (a->s->img_y - yorig[p] + yspc[p]-1) / yspc[p]; if (x && y) { _m3dstbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y; if (!_m3dstbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth, color)) { STBI_FREE(final); return 0; } for (j=0; j < y; ++j) { for (i=0; i < x; ++i) { int out_y = j*yspc[p]+yorig[p]; int out_x = i*xspc[p]+xorig[p]; memcpy(final + out_y*a->s->img_x*out_bytes + out_x*out_bytes, a->out + (j*x+i)*out_bytes, out_bytes); } } STBI_FREE(a->out); image_data += img_len; image_data_len -= img_len; } } a->out = final; return 1; } static int _m3dstbi__compute_transparency(_m3dstbi__png *z, unsigned char tc[3], int out_n) { _m3dstbi__context *s = z->s; _m3dstbi__uint32 i, pixel_count = s->img_x * s->img_y; unsigned char *p = z->out; STBI_ASSERT(out_n == 2 || out_n == 4); if (out_n == 2) { for (i=0; i < pixel_count; ++i) { p[1] = (p[0] == tc[0] ? 0 : 255); p += 2; } } else { for (i=0; i < pixel_count; ++i) { if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2]) p[3] = 0; p += 4; } } return 1; } static int _m3dstbi__compute_transparency16(_m3dstbi__png *z, _m3dstbi__uint16 tc[3], int out_n) { _m3dstbi__context *s = z->s; _m3dstbi__uint32 i, pixel_count = s->img_x * s->img_y; _m3dstbi__uint16 *p = (_m3dstbi__uint16*) z->out; STBI_ASSERT(out_n == 2 || out_n == 4); if (out_n == 2) { for (i = 0; i < pixel_count; ++i) { p[1] = (p[0] == tc[0] ? 0 : 65535); p += 2; } } else { for (i = 0; i < pixel_count; ++i) { if (p[0] == tc[0] && p[1] == tc[1] && p[2] == tc[2]) p[3] = 0; p += 4; } } return 1; } static int _m3dstbi__expand_png_palette(_m3dstbi__png *a, unsigned char *palette, int len, int pal_img_n) { _m3dstbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y; unsigned char *p, *temp_out, *orig = a->out; p = (unsigned char *) _m3dstbi__malloc_mad2(pixel_count, pal_img_n, 0); if (p == NULL) return _m3dstbi__err("outofmem", "Out of memory"); temp_out = p; if (pal_img_n == 3) { for (i=0; i < pixel_count; ++i) { int n = orig[i]*4; p[0] = palette[n ]; p[1] = palette[n+1]; p[2] = palette[n+2]; p += 3; } } else { for (i=0; i < pixel_count; ++i) { int n = orig[i]*4; p[0] = palette[n ]; p[1] = palette[n+1]; p[2] = palette[n+2]; p[3] = palette[n+3]; p += 4; } } STBI_FREE(a->out); a->out = temp_out; STBI_NOTUSED(len); return 1; } #define STBI__PNG_TYPE(a,b,c,d) (((unsigned) (a) << 24) + ((unsigned) (b) << 16) + ((unsigned) (c) << 8) + (unsigned) (d)) static int _m3dstbi__parse_png_file(_m3dstbi__png *z, int scan, int req_comp) { unsigned char palette[1024], pal_img_n=0; unsigned char has_trans=0, tc[3]; _m3dstbi__uint16 tc16[3]; _m3dstbi__uint32 ioff=0, idata_limit=0, i, pal_len=0; int first=1,k,interlace=0, color=0; _m3dstbi__context *s = z->s; z->expanded = NULL; z->idata = NULL; z->out = NULL; if (!_m3dstbi__check_png_header(s)) return 0; if (scan == STBI__SCAN_type) return 1; for (;;) { _m3dstbi__pngchunk c = _m3dstbi__get_chunk_header(s); switch (c.type) { case STBI__PNG_TYPE('C','g','B','I'): _m3dstbi__skip(s, c.length); break; case STBI__PNG_TYPE('I','H','D','R'): { int comp,filter; if (!first) return _m3dstbi__err("multiple IHDR","Corrupt PNG"); first = 0; if (c.length != 13) return _m3dstbi__err("bad IHDR len","Corrupt PNG"); s->img_x = _m3dstbi__get32be(s); if (s->img_x > (1 << 24)) return _m3dstbi__err("too large","Very large image (corrupt?)"); s->img_y = _m3dstbi__get32be(s); if (s->img_y > (1 << 24)) return _m3dstbi__err("too large","Very large image (corrupt?)"); z->depth = _m3dstbi__get8(s); if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8 && z->depth != 16) return _m3dstbi__err("1/2/4/8/16-bit only","PNG not supported: 1/2/4/8/16-bit only"); color = _m3dstbi__get8(s); if (color > 6) return _m3dstbi__err("bad ctype","Corrupt PNG"); if (color == 3 && z->depth == 16) return _m3dstbi__err("bad ctype","Corrupt PNG"); if (color == 3) pal_img_n = 3; else if (color & 1) return _m3dstbi__err("bad ctype","Corrupt PNG"); comp = _m3dstbi__get8(s); if (comp) return _m3dstbi__err("bad comp method","Corrupt PNG"); filter= _m3dstbi__get8(s); if (filter) return _m3dstbi__err("bad filter method","Corrupt PNG"); interlace = _m3dstbi__get8(s); if (interlace>1) return _m3dstbi__err("bad interlace method","Corrupt PNG"); if (!s->img_x || !s->img_y) return _m3dstbi__err("0-pixel image","Corrupt PNG"); if (!pal_img_n) { s->img_n = (color & 2 ? 3 : 1) + (color & 4 ? 1 : 0); if ((1 << 30) / s->img_x / s->img_n < s->img_y) return _m3dstbi__err("too large", "Image too large to decode"); if (scan == STBI__SCAN_header) return 1; } else { s->img_n = 1; if ((1 << 30) / s->img_x / 4 < s->img_y) return _m3dstbi__err("too large","Corrupt PNG"); } break; } case STBI__PNG_TYPE('P','L','T','E'): { if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); if (c.length > 256*3) return _m3dstbi__err("invalid PLTE","Corrupt PNG"); pal_len = c.length / 3; if (pal_len * 3 != c.length) return _m3dstbi__err("invalid PLTE","Corrupt PNG"); for (i=0; i < pal_len; ++i) { palette[i*4+0] = _m3dstbi__get8(s); palette[i*4+1] = _m3dstbi__get8(s); palette[i*4+2] = _m3dstbi__get8(s); palette[i*4+3] = 255; } break; } case STBI__PNG_TYPE('t','R','N','S'): { if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); if (z->idata) return _m3dstbi__err("tRNS after IDAT","Corrupt PNG"); if (pal_img_n) { if (scan == STBI__SCAN_header) { s->img_n = 4; return 1; } if (pal_len == 0) return _m3dstbi__err("tRNS before PLTE","Corrupt PNG"); if (c.length > pal_len) return _m3dstbi__err("bad tRNS len","Corrupt PNG"); pal_img_n = 4; for (i=0; i < c.length; ++i) palette[i*4+3] = _m3dstbi__get8(s); } else { if (!(s->img_n & 1)) return _m3dstbi__err("tRNS with alpha","Corrupt PNG"); if (c.length != (_m3dstbi__uint32) s->img_n*2) return _m3dstbi__err("bad tRNS len","Corrupt PNG"); has_trans = 1; if (z->depth == 16) { for (k = 0; k < s->img_n; ++k) tc16[k] = (_m3dstbi__uint16)_m3dstbi__get16be(s); } else { for (k = 0; k < s->img_n; ++k) tc[k] = (unsigned char)(_m3dstbi__get16be(s) & 255) * _m3dstbi__depth_scale_table[z->depth]; } } break; } case STBI__PNG_TYPE('I','D','A','T'): { if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); if (pal_img_n && !pal_len) return _m3dstbi__err("no PLTE","Corrupt PNG"); if (scan == STBI__SCAN_header) { s->img_n = pal_img_n; return 1; } if ((int)(ioff + c.length) < (int)ioff) return 0; if (ioff + c.length > idata_limit) { _m3dstbi__uint32 idata_limit_old = idata_limit; unsigned char *p; if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; while (ioff + c.length > idata_limit) idata_limit *= 2; STBI_NOTUSED(idata_limit_old); p = (unsigned char *) STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); if (p == NULL) return _m3dstbi__err("outofmem", "Out of memory"); z->idata = p; } if (!_m3dstbi__getn(s, z->idata+ioff,c.length)) return _m3dstbi__err("outofdata","Corrupt PNG"); ioff += c.length; break; } case STBI__PNG_TYPE('I','E','N','D'): { _m3dstbi__uint32 raw_len, bpl; if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); if (scan != STBI__SCAN_load) return 1; if (z->idata == NULL) return _m3dstbi__err("no IDAT","Corrupt PNG"); bpl = (s->img_x * z->depth + 7) / 8; raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */; z->expanded = (unsigned char *) _m3dstbi_zlib_decode_malloc_guesssize_headerflag((char *) z->idata, ioff, raw_len, (int *) &raw_len, 1); if (z->expanded == NULL) return 0; STBI_FREE(z->idata); z->idata = NULL; if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans) s->img_out_n = s->img_n+1; else s->img_out_n = s->img_n; if (!_m3dstbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, z->depth, color, interlace)) return 0; if (has_trans) { if (z->depth == 16) { if (!_m3dstbi__compute_transparency16(z, tc16, s->img_out_n)) return 0; } else { if (!_m3dstbi__compute_transparency(z, tc, s->img_out_n)) return 0; } } if (pal_img_n) { s->img_n = pal_img_n; s->img_out_n = pal_img_n; if (req_comp >= 3) s->img_out_n = req_comp; if (!_m3dstbi__expand_png_palette(z, palette, pal_len, s->img_out_n)) return 0; } else if (has_trans) { ++s->img_n; } STBI_FREE(z->expanded); z->expanded = NULL; return 1; } default: if (first) return _m3dstbi__err("first not IHDR", "Corrupt PNG"); if ((c.type & (1 << 29)) == 0) { return _m3dstbi__err("invalid_chunk", "PNG not supported: unknown PNG chunk type"); } _m3dstbi__skip(s, c.length); break; } _m3dstbi__get32be(s); } } static void *_m3dstbi__do_png(_m3dstbi__png *p, int *x, int *y, int *n, int req_comp, _m3dstbi__result_info *ri) { void *result=NULL; if (req_comp < 0 || req_comp > 4) { _m3dstbi__err("bad req_comp", "Internal error"); return NULL; } if (_m3dstbi__parse_png_file(p, STBI__SCAN_load, req_comp)) { if (p->depth < 8) ri->bits_per_channel = 8; else ri->bits_per_channel = p->depth; result = p->out; p->out = NULL; if (req_comp && req_comp != p->s->img_out_n) { if (ri->bits_per_channel == 8) result = _m3dstbi__convert_format((unsigned char *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y); else result = _m3dstbi__convert_format16((_m3dstbi__uint16 *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y); p->s->img_out_n = req_comp; if (result == NULL) return result; } *x = p->s->img_x; *y = p->s->img_y; if (n) *n = p->s->img_n; } STBI_FREE(p->out); p->out = NULL; STBI_FREE(p->expanded); p->expanded = NULL; STBI_FREE(p->idata); p->idata = NULL; return result; } static void *_m3dstbi__png_load(_m3dstbi__context *s, int *x, int *y, int *comp, int req_comp, _m3dstbi__result_info *ri) { _m3dstbi__png p; p.s = s; return _m3dstbi__do_png(&p, x,y,comp,req_comp, ri); } #define stbi__context _m3dstbi__context #define stbi__result_info _m3dstbi__result_info #define stbi__png_load _m3dstbi__png_load #define stbi_zlib_decode_malloc_guesssize_headerflag _m3dstbi_zlib_decode_malloc_guesssize_headerflag #endif #if !defined(M3D_NOIMPORTER) && defined(STBI_INCLUDE_STB_IMAGE_H) && !defined(STB_IMAGE_IMPLEMENTATION) #error "stb_image.h included without STB_IMAGE_IMPLEMENTATION. Sorry, we need some stuff defined inside the ifguard for proper integration" #endif #if defined(M3D_EXPORTER) && !defined(INCLUDE_STB_IMAGE_WRITE_H) /* zlib_compressor from stb_image_write - v1.13 - public domain - http://nothings.org/stb/stb_image_write.h */ typedef unsigned char _m3dstbiw__uc; typedef unsigned short _m3dstbiw__us; typedef uint16_t _m3dstbiw__uint16; typedef int16_t _m3dstbiw__int16; typedef uint32_t _m3dstbiw__uint32; typedef int32_t _m3dstbiw__int32; #define STBIW_MALLOC(s) M3D_MALLOC(s) #define STBIW_REALLOC(p,ns) M3D_REALLOC(p,ns) #define STBIW_REALLOC_SIZED(p,oldsz,newsz) STBIW_REALLOC(p,newsz) #define STBIW_FREE M3D_FREE #define STBIW_MEMMOVE memmove #define STBIW_UCHAR (uint8_t) #define STBIW_ASSERT(x) #define _m3dstbiw___sbraw(a) ((int *) (a) - 2) #define _m3dstbiw___sbm(a) _m3dstbiw___sbraw(a)[0] #define _m3dstbiw___sbn(a) _m3dstbiw___sbraw(a)[1] #define _m3dstbiw___sbneedgrow(a,n) ((a)==0 || _m3dstbiw___sbn(a)+n >= _m3dstbiw___sbm(a)) #define _m3dstbiw___sbmaybegrow(a,n) (_m3dstbiw___sbneedgrow(a,(n)) ? _m3dstbiw___sbgrow(a,n) : 0) #define _m3dstbiw___sbgrow(a,n) _m3dstbiw___sbgrowf((void **) &(a), (n), sizeof(*(a))) #define _m3dstbiw___sbpush(a, v) (_m3dstbiw___sbmaybegrow(a,1), (a)[_m3dstbiw___sbn(a)++] = (v)) #define _m3dstbiw___sbcount(a) ((a) ? _m3dstbiw___sbn(a) : 0) #define _m3dstbiw___sbfree(a) ((a) ? STBIW_FREE(_m3dstbiw___sbraw(a)),0 : 0) static void *_m3dstbiw___sbgrowf(void **arr, int increment, int itemsize) { int m = *arr ? 2*_m3dstbiw___sbm(*arr)+increment : increment+1; void *p = STBIW_REALLOC_SIZED(*arr ? _m3dstbiw___sbraw(*arr) : 0, *arr ? (_m3dstbiw___sbm(*arr)*itemsize + sizeof(int)*2) : 0, itemsize * m + sizeof(int)*2); STBIW_ASSERT(p); if (p) { if (!*arr) ((int *) p)[1] = 0; *arr = (void *) ((int *) p + 2); _m3dstbiw___sbm(*arr) = m; } return *arr; } static unsigned char *_m3dstbiw___zlib_flushf(unsigned char *data, unsigned int *bitbuffer, int *bitcount) { while (*bitcount >= 8) { _m3dstbiw___sbpush(data, STBIW_UCHAR(*bitbuffer)); *bitbuffer >>= 8; *bitcount -= 8; } return data; } static int _m3dstbiw___zlib_bitrev(int code, int codebits) { int res=0; while (codebits--) { res = (res << 1) | (code & 1); code >>= 1; } return res; } static unsigned int _m3dstbiw___zlib_countm(unsigned char *a, unsigned char *b, int limit) { int i; for (i=0; i < limit && i < 258; ++i) if (a[i] != b[i]) break; return i; } static unsigned int _m3dstbiw___zhash(unsigned char *data) { _m3dstbiw__uint32 hash = data[0] + (data[1] << 8) + (data[2] << 16); hash ^= hash << 3; hash += hash >> 5; hash ^= hash << 4; hash += hash >> 17; hash ^= hash << 25; hash += hash >> 6; return hash; } #define _m3dstbiw___zlib_flush() (out = _m3dstbiw___zlib_flushf(out, &bitbuf, &bitcount)) #define _m3dstbiw___zlib_add(code,codebits) \ (bitbuf |= (code) << bitcount, bitcount += (codebits), _m3dstbiw___zlib_flush()) #define _m3dstbiw___zlib_huffa(b,c) _m3dstbiw___zlib_add(_m3dstbiw___zlib_bitrev(b,c),c) #define _m3dstbiw___zlib_huff1(n) _m3dstbiw___zlib_huffa(0x30 + (n), 8) #define _m3dstbiw___zlib_huff2(n) _m3dstbiw___zlib_huffa(0x190 + (n)-144, 9) #define _m3dstbiw___zlib_huff3(n) _m3dstbiw___zlib_huffa(0 + (n)-256,7) #define _m3dstbiw___zlib_huff4(n) _m3dstbiw___zlib_huffa(0xc0 + (n)-280,8) #define _m3dstbiw___zlib_huff(n) ((n) <= 143 ? _m3dstbiw___zlib_huff1(n) : (n) <= 255 ? _m3dstbiw___zlib_huff2(n) : (n) <= 279 ? _m3dstbiw___zlib_huff3(n) : _m3dstbiw___zlib_huff4(n)) #define _m3dstbiw___zlib_huffb(n) ((n) <= 143 ? _m3dstbiw___zlib_huff1(n) : _m3dstbiw___zlib_huff2(n)) #define _m3dstbiw___ZHASH 16384 unsigned char * _m3dstbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality) { static unsigned short lengthc[] = { 3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258, 259 }; static unsigned char lengtheb[]= { 0,0,0,0,0,0,0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 }; static unsigned short distc[] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577, 32768 }; static unsigned char disteb[] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13 }; unsigned int bitbuf=0; int i,j, bitcount=0; unsigned char *out = NULL; unsigned char ***hash_table = (unsigned char***) STBIW_MALLOC(_m3dstbiw___ZHASH * sizeof(char**)); if (hash_table == NULL) return NULL; if (quality < 5) quality = 5; _m3dstbiw___sbpush(out, 0x78); _m3dstbiw___sbpush(out, 0x5e); _m3dstbiw___zlib_add(1,1); _m3dstbiw___zlib_add(1,2); for (i=0; i < _m3dstbiw___ZHASH; ++i) hash_table[i] = NULL; i=0; while (i < data_len-3) { int h = _m3dstbiw___zhash(data+i)&(_m3dstbiw___ZHASH-1), best=3; unsigned char *bestloc = 0; unsigned char **hlist = hash_table[h]; int n = _m3dstbiw___sbcount(hlist); for (j=0; j < n; ++j) { if (hlist[j]-data > i-32768) { int d = _m3dstbiw___zlib_countm(hlist[j], data+i, data_len-i); if (d >= best) best=d,bestloc=hlist[j]; } } if (hash_table[h] && _m3dstbiw___sbn(hash_table[h]) == 2*quality) { STBIW_MEMMOVE(hash_table[h], hash_table[h]+quality, sizeof(hash_table[h][0])*quality); _m3dstbiw___sbn(hash_table[h]) = quality; } _m3dstbiw___sbpush(hash_table[h],data+i); if (bestloc) { h = _m3dstbiw___zhash(data+i+1)&(_m3dstbiw___ZHASH-1); hlist = hash_table[h]; n = _m3dstbiw___sbcount(hlist); for (j=0; j < n; ++j) { if (hlist[j]-data > i-32767) { int e = _m3dstbiw___zlib_countm(hlist[j], data+i+1, data_len-i-1); if (e > best) { bestloc = NULL; break; } } } } if (bestloc) { int d = (int) (data+i - bestloc); STBIW_ASSERT(d <= 32767 && best <= 258); for (j=0; best > lengthc[j+1]-1; ++j); _m3dstbiw___zlib_huff(j+257); if (lengtheb[j]) _m3dstbiw___zlib_add(best - lengthc[j], lengtheb[j]); for (j=0; d > distc[j+1]-1; ++j); _m3dstbiw___zlib_add(_m3dstbiw___zlib_bitrev(j,5),5); if (disteb[j]) _m3dstbiw___zlib_add(d - distc[j], disteb[j]); i += best; } else { _m3dstbiw___zlib_huffb(data[i]); ++i; } } for (;i < data_len; ++i) _m3dstbiw___zlib_huffb(data[i]); _m3dstbiw___zlib_huff(256); while (bitcount) _m3dstbiw___zlib_add(0,1); for (i=0; i < _m3dstbiw___ZHASH; ++i) (void) _m3dstbiw___sbfree(hash_table[i]); STBIW_FREE(hash_table); { unsigned int s1=1, s2=0; int blocklen = (int) (data_len % 5552); j=0; while (j < data_len) { for (i=0; i < blocklen; ++i) s1 += data[j+i], s2 += s1; s1 %= 65521, s2 %= 65521; j += blocklen; blocklen = 5552; } _m3dstbiw___sbpush(out, STBIW_UCHAR(s2 >> 8)); _m3dstbiw___sbpush(out, STBIW_UCHAR(s2)); _m3dstbiw___sbpush(out, STBIW_UCHAR(s1 >> 8)); _m3dstbiw___sbpush(out, STBIW_UCHAR(s1)); } *out_len = _m3dstbiw___sbn(out); STBIW_MEMMOVE(_m3dstbiw___sbraw(out), out, *out_len); return (unsigned char *) _m3dstbiw___sbraw(out); } #define stbi_zlib_compress _m3dstbi_zlib_compress #else unsigned char * _m3dstbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality); #endif #define M3D_CHUNKMAGIC(m, a,b,c,d) ((m)[0]==(a) && (m)[1]==(b) && (m)[2]==(c) && (m)[3]==(d)) #ifdef M3D_ASCII #include <stdio.h> /* get sprintf */ #include <locale.h> /* sprintf and strtod cares about number locale */ #endif #ifdef M3D_PROFILING #include <sys/time.h> #endif #if !defined(M3D_NOIMPORTER) && defined(M3D_ASCII) /* helper functions for the ASCII parser */ static char *_m3d_findarg(char *s) { while(s && *s && *s != ' ' && *s != '\t' && *s != '\r' && *s != '\n') s++; while(s && *s && (*s == ' ' || *s == '\t')) s++; return s; } static char *_m3d_findnl(char *s) { while(s && *s && *s != '\r' && *s != '\n') s++; if(*s == '\r') s++; if(*s == '\n') s++; return s; } static char *_m3d_gethex(char *s, uint32_t *ret) { if(*s == '#') s++; *ret = 0; for(; *s; s++) { if(*s >= '0' && *s <= '9') { *ret <<= 4; *ret += (uint32_t)(*s-'0'); } else if(*s >= 'a' && *s <= 'f') { *ret <<= 4; *ret += (uint32_t)(*s-'a'+10); } else if(*s >= 'A' && *s <= 'F') { *ret <<= 4; *ret += (uint32_t)(*s-'A'+10); } else break; } return _m3d_findarg(s); } static char *_m3d_getint(char *s, uint32_t *ret) { char *e = s; if(!s || !*s || *s == '\r' || *s == '\n') return s; for(; *e >= '0' && *e <= '9'; e++); *ret = atoi(s); return e; } static char *_m3d_getfloat(char *s, M3D_FLOAT *ret) { char *e = s; if(!s || !*s || *s == '\r' || *s == '\n') return s; for(; *e == '-' || *e == '+' || *e == '.' || (*e >= '0' && *e <= '9') || *e == 'e' || *e == 'E'; e++); *ret = (M3D_FLOAT)strtod(s, NULL); return _m3d_findarg(e); } #endif #if !defined(M3D_NODUP) && (!defined(M3D_NOIMPORTER) || defined(M3D_ASCII) || defined(M3D_EXPORTER)) /* helper function to create safe strings */ char *_m3d_safestr(char *in, int morelines) { char *out, *o, *i = in; int l; if(!in || !*in) { out = (char*)M3D_MALLOC(1); if(!out) return NULL; out[0] =0; } else { for(o = in, l = 0; *o && ((morelines & 1) || (*o != '\r' && *o != '\n')) && l < 256; o++, l++); out = o = (char*)M3D_MALLOC(l+1); if(!out) return NULL; while(*i == ' ' || *i == '\t' || *i == '\r' || (morelines && *i == '\n')) i++; for(; *i && (morelines || (*i != '\r' && *i != '\n')); i++) { if(*i == '\r') continue; if(*i == '\n') { if(morelines >= 3 && o > out && *(o-1) == '\n') break; if(i > in && *(i-1) == '\n') continue; if(morelines & 1) { if(morelines == 1) *o++ = '\r'; *o++ = '\n'; } else break; } else if(*i == ' ' || *i == '\t') { *o++ = morelines? ' ' : '_'; } else *o++ = !morelines && (*i == '/' || *i == '\\') ? '_' : *i; } for(; o > out && (*(o-1) == ' ' || *(o-1) == '\t' || *(o-1) == '\r' || *(o-1) == '\n'); o--); *o = 0; out = (char*)M3D_REALLOC(out, (uintptr_t)o - (uintptr_t)out + 1); } return out; } #endif #ifndef M3D_NOIMPORTER /* helper function to load and decode/generate a texture */ M3D_INDEX _m3d_gettx(m3d_t *model, m3dread_t readfilecb, m3dfree_t freecb, char *fn) { unsigned int i, len = 0; unsigned char *buff = NULL; char *fn2; unsigned int w, h; stbi__context s; stbi__result_info ri; /* do we have loaded this texture already? */ for(i = 0; i < model->numtexture; i++) if(!strcmp(fn, model->texture[i].name)) return i; /* see if it's inlined in the model */ if(model->inlined) { for(i = 0; i < model->numinlined; i++) if(!strcmp(fn, model->inlined[i].name)) { buff = model->inlined[i].data; len = model->inlined[i].length; freecb = NULL; break; } } /* try to load from external source */ if(!buff && readfilecb) { i = (unsigned int)strlen(fn); if(i < 5 || fn[i - 4] != '.') { fn2 = (char*)M3D_MALLOC(i + 5); if(!fn2) { model->errcode = M3D_ERR_ALLOC; return M3D_UNDEF; } memcpy(fn2, fn, i); memcpy(fn2+i, ".png", 5); buff = (*readfilecb)(fn2, &len); M3D_FREE(fn2); } if(!buff) { buff = (*readfilecb)(fn, &len); if(!buff) return M3D_UNDEF; } } /* add to textures array */ i = model->numtexture++; model->texture = (m3dtx_t*)M3D_REALLOC(model->texture, model->numtexture * sizeof(m3dtx_t)); if(!model->texture) { if(buff && freecb) (*freecb)(buff); model->errcode = M3D_ERR_ALLOC; return M3D_UNDEF; } model->texture[i].name = fn; model->texture[i].w = model->texture[i].h = 0; model->texture[i].d = NULL; if(buff) { if(buff[0] == 0x89 && buff[1] == 'P' && buff[2] == 'N' && buff[3] == 'G') { s.read_from_callbacks = 0; s.img_buffer = s.img_buffer_original = (unsigned char *) buff; s.img_buffer_end = s.img_buffer_original_end = (unsigned char *) buff+len; /* don't use model->texture[i].w directly, it's a uint16_t */ w = h = len = 0; ri.bits_per_channel = 8; model->texture[i].d = (uint8_t*)stbi__png_load(&s, (int*)&w, (int*)&h, (int*)&len, 0, &ri); model->texture[i].w = w; model->texture[i].h = h; model->texture[i].f = (uint8_t)len; } else { #ifdef M3D_TX_INTERP if((model->errcode = M3D_TX_INTERP(fn, buff, len, &model->texture[i])) != M3D_SUCCESS) { M3D_LOG("Unable to generate texture"); M3D_LOG(fn); } #else M3D_LOG("Unimplemented interpreter"); M3D_LOG(fn); #endif } if(freecb) (*freecb)(buff); } if(!model->texture[i].d) model->errcode = M3D_ERR_UNKIMG; return i; } /* helper function to load and generate a procedural surface */ void _m3d_getpr(m3d_t *model, _unused m3dread_t readfilecb, _unused m3dfree_t freecb, _unused char *fn) { #ifdef M3D_PR_INTERP unsigned int i, len = 0; unsigned char *buff = readfilecb ? (*readfilecb)(fn, &len) : NULL; if(!buff && model->inlined) { for(i = 0; i < model->numinlined; i++) if(!strcmp(fn, model->inlined[i].name)) { buff = model->inlined[i].data; len = model->inlined[i].length; freecb = NULL; break; } } if(!buff || !len || (model->errcode = M3D_PR_INTERP(fn, buff, len, model)) != M3D_SUCCESS) { M3D_LOG("Unable to generate procedural surface"); M3D_LOG(fn); model->errcode = M3D_ERR_UNKIMG; } if(freecb && buff) (*freecb)(buff); #else (void)readfilecb; (void)freecb; (void)fn; M3D_LOG("Unimplemented interpreter"); M3D_LOG(fn); model->errcode = M3D_ERR_UNIMPL; #endif } /* helpers to read indices from data stream */ #define M3D_GETSTR(x) do{offs=0;data=_m3d_getidx(data,model->si_s,&offs);x=offs?((char*)model->raw+16+offs):NULL;}while(0) _inline static unsigned char *_m3d_getidx(unsigned char *data, char type, M3D_INDEX *idx) { switch(type) { case 1: *idx = data[0] > 253 ? (int8_t)data[0] : data[0]; data++; break; case 2: *idx = *((uint16_t*)data) > 65533 ? *((int16_t*)data) : *((uint16_t*)data); data += 2; break; case 4: *idx = *((int32_t*)data); data += 4; break; } return data; } #ifndef M3D_NOANIMATION /* multiply 4 x 4 matrices. Do not use float *r[16] as argument, because some compilers misinterpret that as * 16 pointers each pointing to a float, but we need a single pointer to 16 floats. */ void _m3d_mul(M3D_FLOAT *r, M3D_FLOAT *a, M3D_FLOAT *b) { r[ 0] = b[ 0] * a[ 0] + b[ 4] * a[ 1] + b[ 8] * a[ 2] + b[12] * a[ 3]; r[ 1] = b[ 1] * a[ 0] + b[ 5] * a[ 1] + b[ 9] * a[ 2] + b[13] * a[ 3]; r[ 2] = b[ 2] * a[ 0] + b[ 6] * a[ 1] + b[10] * a[ 2] + b[14] * a[ 3]; r[ 3] = b[ 3] * a[ 0] + b[ 7] * a[ 1] + b[11] * a[ 2] + b[15] * a[ 3]; r[ 4] = b[ 0] * a[ 4] + b[ 4] * a[ 5] + b[ 8] * a[ 6] + b[12] * a[ 7]; r[ 5] = b[ 1] * a[ 4] + b[ 5] * a[ 5] + b[ 9] * a[ 6] + b[13] * a[ 7]; r[ 6] = b[ 2] * a[ 4] + b[ 6] * a[ 5] + b[10] * a[ 6] + b[14] * a[ 7]; r[ 7] = b[ 3] * a[ 4] + b[ 7] * a[ 5] + b[11] * a[ 6] + b[15] * a[ 7]; r[ 8] = b[ 0] * a[ 8] + b[ 4] * a[ 9] + b[ 8] * a[10] + b[12] * a[11]; r[ 9] = b[ 1] * a[ 8] + b[ 5] * a[ 9] + b[ 9] * a[10] + b[13] * a[11]; r[10] = b[ 2] * a[ 8] + b[ 6] * a[ 9] + b[10] * a[10] + b[14] * a[11]; r[11] = b[ 3] * a[ 8] + b[ 7] * a[ 9] + b[11] * a[10] + b[15] * a[11]; r[12] = b[ 0] * a[12] + b[ 4] * a[13] + b[ 8] * a[14] + b[12] * a[15]; r[13] = b[ 1] * a[12] + b[ 5] * a[13] + b[ 9] * a[14] + b[13] * a[15]; r[14] = b[ 2] * a[12] + b[ 6] * a[13] + b[10] * a[14] + b[14] * a[15]; r[15] = b[ 3] * a[12] + b[ 7] * a[13] + b[11] * a[14] + b[15] * a[15]; } /* calculate 4 x 4 matrix inverse */ void _m3d_inv(M3D_FLOAT *m) { M3D_FLOAT r[16]; M3D_FLOAT det = m[ 0]*m[ 5]*m[10]*m[15] - m[ 0]*m[ 5]*m[11]*m[14] + m[ 0]*m[ 6]*m[11]*m[13] - m[ 0]*m[ 6]*m[ 9]*m[15] + m[ 0]*m[ 7]*m[ 9]*m[14] - m[ 0]*m[ 7]*m[10]*m[13] - m[ 1]*m[ 6]*m[11]*m[12] + m[ 1]*m[ 6]*m[ 8]*m[15] - m[ 1]*m[ 7]*m[ 8]*m[14] + m[ 1]*m[ 7]*m[10]*m[12] - m[ 1]*m[ 4]*m[10]*m[15] + m[ 1]*m[ 4]*m[11]*m[14] + m[ 2]*m[ 7]*m[ 8]*m[13] - m[ 2]*m[ 7]*m[ 9]*m[12] + m[ 2]*m[ 4]*m[ 9]*m[15] - m[ 2]*m[ 4]*m[11]*m[13] + m[ 2]*m[ 5]*m[11]*m[12] - m[ 2]*m[ 5]*m[ 8]*m[15] - m[ 3]*m[ 4]*m[ 9]*m[14] + m[ 3]*m[ 4]*m[10]*m[13] - m[ 3]*m[ 5]*m[10]*m[12] + m[ 3]*m[ 5]*m[ 8]*m[14] - m[ 3]*m[ 6]*m[ 8]*m[13] + m[ 3]*m[ 6]*m[ 9]*m[12]; if(det == (M3D_FLOAT)0.0 || det == (M3D_FLOAT)-0.0) det = (M3D_FLOAT)1.0; else det = (M3D_FLOAT)1.0 / det; r[ 0] = det *(m[ 5]*(m[10]*m[15] - m[11]*m[14]) + m[ 6]*(m[11]*m[13] - m[ 9]*m[15]) + m[ 7]*(m[ 9]*m[14] - m[10]*m[13])); r[ 1] = -det*(m[ 1]*(m[10]*m[15] - m[11]*m[14]) + m[ 2]*(m[11]*m[13] - m[ 9]*m[15]) + m[ 3]*(m[ 9]*m[14] - m[10]*m[13])); r[ 2] = det *(m[ 1]*(m[ 6]*m[15] - m[ 7]*m[14]) + m[ 2]*(m[ 7]*m[13] - m[ 5]*m[15]) + m[ 3]*(m[ 5]*m[14] - m[ 6]*m[13])); r[ 3] = -det*(m[ 1]*(m[ 6]*m[11] - m[ 7]*m[10]) + m[ 2]*(m[ 7]*m[ 9] - m[ 5]*m[11]) + m[ 3]*(m[ 5]*m[10] - m[ 6]*m[ 9])); r[ 4] = -det*(m[ 4]*(m[10]*m[15] - m[11]*m[14]) + m[ 6]*(m[11]*m[12] - m[ 8]*m[15]) + m[ 7]*(m[ 8]*m[14] - m[10]*m[12])); r[ 5] = det *(m[ 0]*(m[10]*m[15] - m[11]*m[14]) + m[ 2]*(m[11]*m[12] - m[ 8]*m[15]) + m[ 3]*(m[ 8]*m[14] - m[10]*m[12])); r[ 6] = -det*(m[ 0]*(m[ 6]*m[15] - m[ 7]*m[14]) + m[ 2]*(m[ 7]*m[12] - m[ 4]*m[15]) + m[ 3]*(m[ 4]*m[14] - m[ 6]*m[12])); r[ 7] = det *(m[ 0]*(m[ 6]*m[11] - m[ 7]*m[10]) + m[ 2]*(m[ 7]*m[ 8] - m[ 4]*m[11]) + m[ 3]*(m[ 4]*m[10] - m[ 6]*m[ 8])); r[ 8] = det *(m[ 4]*(m[ 9]*m[15] - m[11]*m[13]) + m[ 5]*(m[11]*m[12] - m[ 8]*m[15]) + m[ 7]*(m[ 8]*m[13] - m[ 9]*m[12])); r[ 9] = -det*(m[ 0]*(m[ 9]*m[15] - m[11]*m[13]) + m[ 1]*(m[11]*m[12] - m[ 8]*m[15]) + m[ 3]*(m[ 8]*m[13] - m[ 9]*m[12])); r[10] = det *(m[ 0]*(m[ 5]*m[15] - m[ 7]*m[13]) + m[ 1]*(m[ 7]*m[12] - m[ 4]*m[15]) + m[ 3]*(m[ 4]*m[13] - m[ 5]*m[12])); r[11] = -det*(m[ 0]*(m[ 5]*m[11] - m[ 7]*m[ 9]) + m[ 1]*(m[ 7]*m[ 8] - m[ 4]*m[11]) + m[ 3]*(m[ 4]*m[ 9] - m[ 5]*m[ 8])); r[12] = -det*(m[ 4]*(m[ 9]*m[14] - m[10]*m[13]) + m[ 5]*(m[10]*m[12] - m[ 8]*m[14]) + m[ 6]*(m[ 8]*m[13] - m[ 9]*m[12])); r[13] = det *(m[ 0]*(m[ 9]*m[14] - m[10]*m[13]) + m[ 1]*(m[10]*m[12] - m[ 8]*m[14]) + m[ 2]*(m[ 8]*m[13] - m[ 9]*m[12])); r[14] = -det*(m[ 0]*(m[ 5]*m[14] - m[ 6]*m[13]) + m[ 1]*(m[ 6]*m[12] - m[ 4]*m[14]) + m[ 2]*(m[ 4]*m[13] - m[ 5]*m[12])); r[15] = det *(m[ 0]*(m[ 5]*m[10] - m[ 6]*m[ 9]) + m[ 1]*(m[ 6]*m[ 8] - m[ 4]*m[10]) + m[ 2]*(m[ 4]*m[ 9] - m[ 5]*m[ 8])); memcpy(m, &r, sizeof(r)); } /* compose a coloumn major 4 x 4 matrix from vec3 position and vec4 orientation/rotation quaternion */ void _m3d_mat(M3D_FLOAT *r, m3dv_t *p, m3dv_t *q) { if(q->x == (M3D_FLOAT)0.0 && q->y == (M3D_FLOAT)0.0 && q->z >=(M3D_FLOAT) 0.7071065 && q->z <= (M3D_FLOAT)0.7071075 && q->w == (M3D_FLOAT)0.0) { r[ 1] = r[ 2] = r[ 4] = r[ 6] = r[ 8] = r[ 9] = (M3D_FLOAT)0.0; r[ 0] = r[ 5] = r[10] = (M3D_FLOAT)-1.0; } else { r[ 0] = 1 - 2 * (q->y * q->y + q->z * q->z); if(r[ 0]>-M3D_EPSILON && r[ 0]<M3D_EPSILON) r[ 0]=(M3D_FLOAT)0.0; r[ 1] = 2 * (q->x * q->y - q->z * q->w); if(r[ 1]>-M3D_EPSILON && r[ 1]<M3D_EPSILON) r[ 1]=(M3D_FLOAT)0.0; r[ 2] = 2 * (q->x * q->z + q->y * q->w); if(r[ 2]>-M3D_EPSILON && r[ 2]<M3D_EPSILON) r[ 2]=(M3D_FLOAT)0.0; r[ 4] = 2 * (q->x * q->y + q->z * q->w); if(r[ 4]>-M3D_EPSILON && r[ 4]<M3D_EPSILON) r[ 4]=(M3D_FLOAT)0.0; r[ 5] = 1 - 2 * (q->x * q->x + q->z * q->z); if(r[ 5]>-M3D_EPSILON && r[ 5]<M3D_EPSILON) r[ 5]=(M3D_FLOAT)0.0; r[ 6] = 2 * (q->y * q->z - q->x * q->w); if(r[ 6]>-M3D_EPSILON && r[ 6]<M3D_EPSILON) r[ 6]=(M3D_FLOAT)0.0; r[ 8] = 2 * (q->x * q->z - q->y * q->w); if(r[ 8]>-M3D_EPSILON && r[ 8]<M3D_EPSILON) r[ 8]=(M3D_FLOAT)0.0; r[ 9] = 2 * (q->y * q->z + q->x * q->w); if(r[ 9]>-M3D_EPSILON && r[ 9]<M3D_EPSILON) r[ 9]=(M3D_FLOAT)0.0; r[10] = 1 - 2 * (q->x * q->x + q->y * q->y); if(r[10]>-M3D_EPSILON && r[10]<M3D_EPSILON) r[10]=(M3D_FLOAT)0.0; } r[ 3] = p->x; r[ 7] = p->y; r[11] = p->z; r[12] = 0; r[13] = 0; r[14] = 0; r[15] = 1; } #endif #if !defined(M3D_NOANIMATION) || !defined(M3D_NONORMALS) /* portable fast inverse square root calculation. returns 1/sqrt(x) */ static M3D_FLOAT _m3d_rsq(M3D_FLOAT x) { #ifdef M3D_DOUBLE return ((M3D_FLOAT)15.0/(M3D_FLOAT)8.0) + ((M3D_FLOAT)-5.0/(M3D_FLOAT)4.0)*x + ((M3D_FLOAT)3.0/(M3D_FLOAT)8.0)*x*x; #else /* John Carmack's */ float x2 = x * 0.5f; uint32_t *i = (uint32_t*)&x; *i = (0x5f3759df - (*i >> 1)); return x * (1.5f - (x2 * x * x)); #endif } #endif /** * Function to decode a Model 3D into in-memory format */ m3d_t *m3d_load(unsigned char *data, m3dread_t readfilecb, m3dfree_t freecb, m3d_t *mtllib) { unsigned char *end, *chunk, *buff, weights[8]; unsigned int i, j, k, l, n, am, len = 0, reclen, offs; #ifndef M3D_NOVOXELS int32_t min_x, min_y, min_z, max_x, max_y, max_z, sx, sy, sz, x, y, z; M3D_INDEX edge[8], enorm; #endif char *name, *lang; float f; m3d_t *model; M3D_INDEX mi; #ifdef M3D_VERTEXMAX M3D_INDEX pi; #endif M3D_FLOAT w; m3dcd_t *cd; m3dtx_t *tx; m3dh_t *h; m3dm_t *m; m3da_t *a; m3di_t *t; #ifndef M3D_NONORMALS char neednorm = 0; m3dv_t *norm = NULL, *v0, *v1, *v2, va, vb; #endif #ifndef M3D_NOANIMATION M3D_FLOAT r[16]; #endif #if !defined(M3D_NOWEIGHTS) || !defined(M3D_NOANIMATION) m3db_t *b; #endif #ifndef M3D_NOWEIGHTS m3ds_t *sk; #endif #ifdef M3D_ASCII m3ds_t s; M3D_INDEX bi[M3D_BONEMAXLEVEL+1], level; const char *ol; char *ptr, *pe, *fn; #endif #ifdef M3D_PROFILING struct timeval tv0, tv1, tvd; gettimeofday(&tv0, NULL); #endif if(!data || (!M3D_CHUNKMAGIC(data, '3','D','M','O') #ifdef M3D_ASCII && !M3D_CHUNKMAGIC(data, '3','d','m','o') #endif )) return NULL; model = (m3d_t*)M3D_MALLOC(sizeof(m3d_t)); if(!model) { M3D_LOG("Out of memory"); return NULL; } memset(model, 0, sizeof(m3d_t)); if(mtllib) { model->nummaterial = mtllib->nummaterial; model->material = mtllib->material; model->numtexture = mtllib->numtexture; model->texture = mtllib->texture; model->flags |= M3D_FLG_MTLLIB; } #ifdef M3D_ASCII /* ASCII variant? */ if(M3D_CHUNKMAGIC(data, '3','d','m','o')) { model->errcode = M3D_ERR_BADFILE; model->flags |= M3D_FLG_FREESTR; model->raw = (m3dhdr_t*)data; ptr = (char*)data; ol = setlocale(LC_NUMERIC, NULL); setlocale(LC_NUMERIC, "C"); /* parse header. Don't use sscanf, that's incredibly slow */ ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; pe = _m3d_findnl(ptr); model->scale = (float)strtod(ptr, NULL); ptr = pe; if(model->scale <= (M3D_FLOAT)0.0) model->scale = (M3D_FLOAT)1.0; model->name = _m3d_safestr(ptr, 2); ptr = _m3d_findnl(ptr); if(!*ptr) goto asciiend; model->license = _m3d_safestr(ptr, 2); ptr = _m3d_findnl(ptr); if(!*ptr) goto asciiend; model->author = _m3d_safestr(ptr, 2); ptr = _m3d_findnl(ptr); if(!*ptr) goto asciiend; if(*ptr != '\r' && *ptr != '\n') model->desc = _m3d_safestr(ptr, 3); while(*ptr) { while(*ptr && *ptr!='\n') ptr++; ptr++; if(*ptr=='\r') ptr++; if(*ptr == '\n') break; } /* the main chunk reader loop */ while(*ptr) { while(*ptr && (*ptr == '\r' || *ptr == '\n')) ptr++; if(!*ptr || (ptr[0]=='E' && ptr[1]=='n' && ptr[2]=='d')) break; /* make sure there's at least one data row */ pe = ptr; ptr = _m3d_findnl(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; /* Preview chunk */ if(!memcmp(pe, "Preview", 7)) { if(readfilecb) { pe = _m3d_safestr(ptr, 0); if(!pe || !*pe) goto asciiend; model->preview.data = (*readfilecb)(pe, &model->preview.length); M3D_FREE(pe); } while(*ptr && *ptr != '\r' && *ptr != '\n') ptr = _m3d_findnl(ptr); } else /* texture map chunk */ if(!memcmp(pe, "Textmap", 7)) { if(model->tmap) { M3D_LOG("More texture map chunks, should be unique"); goto asciiend; } while(*ptr && *ptr != '\r' && *ptr != '\n') { i = model->numtmap++; model->tmap = (m3dti_t*)M3D_REALLOC(model->tmap, model->numtmap * sizeof(m3dti_t)); if(!model->tmap) goto memerr; ptr = _m3d_getfloat(ptr, &model->tmap[i].u); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; _m3d_getfloat(ptr, &model->tmap[i].v); ptr = _m3d_findnl(ptr); } } else /* vertex chunk */ if(!memcmp(pe, "Vertex", 6)) { if(model->vertex) { M3D_LOG("More vertex chunks, should be unique"); goto asciiend; } while(*ptr && *ptr != '\r' && *ptr != '\n') { i = model->numvertex++; model->vertex = (m3dv_t*)M3D_REALLOC(model->vertex, model->numvertex * sizeof(m3dv_t)); if(!model->vertex) goto memerr; memset(&model->vertex[i], 0, sizeof(m3dv_t)); model->vertex[i].skinid = M3D_UNDEF; model->vertex[i].color = 0; model->vertex[i].w = (M3D_FLOAT)1.0; ptr = _m3d_getfloat(ptr, &model->vertex[i].x); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; ptr = _m3d_getfloat(ptr, &model->vertex[i].y); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; ptr = _m3d_getfloat(ptr, &model->vertex[i].z); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; ptr = _m3d_getfloat(ptr, &model->vertex[i].w); if(!*ptr) goto asciiend; if(*ptr == '#') { ptr = _m3d_gethex(ptr, &model->vertex[i].color); if(!*ptr) goto asciiend; } /* parse skin */ memset(&s, 0, sizeof(m3ds_t)); for(j = 0, w = (M3D_FLOAT)0.0; j < M3D_NUMBONE && *ptr && *ptr != '\r' && *ptr != '\n'; j++) { ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; ptr = _m3d_getint(ptr, &k); s.boneid[j] = (M3D_INDEX)k; if(*ptr == ':') { ptr++; ptr = _m3d_getfloat(ptr, &s.weight[j]); w += s.weight[j]; } else if(!j) s.weight[j] = (M3D_FLOAT)1.0; if(!*ptr) goto asciiend; } if(s.boneid[0] != M3D_UNDEF && s.weight[0] > (M3D_FLOAT)0.0) { if(w != (M3D_FLOAT)1.0 && w != (M3D_FLOAT)0.0) for(j = 0; j < M3D_NUMBONE && s.weight[j] > (M3D_FLOAT)0.0; j++) s.weight[j] /= w; k = M3D_NOTDEFINED; if(model->skin) { for(j = 0; j < model->numskin; j++) if(!memcmp(&model->skin[j], &s, sizeof(m3ds_t))) { k = j; break; } } if(k == M3D_NOTDEFINED) { k = model->numskin++; model->skin = (m3ds_t*)M3D_REALLOC(model->skin, model->numskin * sizeof(m3ds_t)); if(!model->skin) goto memerr; memcpy(&model->skin[k], &s, sizeof(m3ds_t)); } model->vertex[i].skinid = (M3D_INDEX)k; } ptr = _m3d_findnl(ptr); } } else /* Skeleton, bone hierarchy */ if(!memcmp(pe, "Bones", 5)) { if(model->bone) { M3D_LOG("More bones chunks, should be unique"); goto asciiend; } bi[0] = M3D_UNDEF; while(*ptr && *ptr != '\r' && *ptr != '\n') { i = model->numbone++; model->bone = (m3db_t*)M3D_REALLOC(model->bone, model->numbone * sizeof(m3db_t)); if(!model->bone) goto memerr; for(level = 0; *ptr == '/'; ptr++, level++); if(level > M3D_BONEMAXLEVEL || !*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; bi[level+1] = i; model->bone[i].numweight = 0; model->bone[i].weight = NULL; model->bone[i].parent = bi[level]; ptr = _m3d_getint(ptr, &k); ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; model->bone[i].pos = (M3D_INDEX)k; ptr = _m3d_getint(ptr, &k); ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; model->bone[i].ori = (M3D_INDEX)k; model->vertex[k].skinid = M3D_INDEXMAX; pe = _m3d_safestr(ptr, 0); if(!pe || !*pe) goto asciiend; model->bone[i].name = pe; ptr = _m3d_findnl(ptr); } } else /* material chunk */ if(!memcmp(pe, "Material", 8)) { pe = _m3d_findarg(pe); if(!*pe || *pe == '\r' || *pe == '\n') goto asciiend; pe = _m3d_safestr(pe, 0); if(!pe || !*pe) goto asciiend; for(i = 0; i < model->nummaterial; i++) if(!strcmp(pe, model->material[i].name)) { M3D_LOG("Multiple definitions for material"); M3D_LOG(pe); M3D_FREE(pe); pe = NULL; while(*ptr && *ptr != '\r' && *ptr != '\n') ptr = _m3d_findnl(ptr); break; } if(!pe) continue; i = model->nummaterial++; if(model->flags & M3D_FLG_MTLLIB) { m = model->material; model->material = (m3dm_t*)M3D_MALLOC(model->nummaterial * sizeof(m3dm_t)); if(!model->material) goto memerr; memcpy(model->material, m, (model->nummaterial - 1) * sizeof(m3dm_t)); if(model->texture) { tx = model->texture; model->texture = (m3dtx_t*)M3D_MALLOC(model->numtexture * sizeof(m3dtx_t)); if(!model->texture) goto memerr; memcpy(model->texture, tx, model->numtexture * sizeof(m3dm_t)); } model->flags &= ~M3D_FLG_MTLLIB; } else { model->material = (m3dm_t*)M3D_REALLOC(model->material, model->nummaterial * sizeof(m3dm_t)); if(!model->material) goto memerr; } m = &model->material[i]; m->name = pe; m->numprop = 0; m->prop = NULL; while(*ptr && *ptr != '\r' && *ptr != '\n') { k = n = 256; if(*ptr == 'm' && *(ptr+1) == 'a' && *(ptr+2) == 'p' && *(ptr+3) == '_') { k = m3dpf_map; ptr += 4; } for(j = 0; j < sizeof(m3d_propertytypes)/sizeof(m3d_propertytypes[0]); j++) if(!memcmp(ptr, m3d_propertytypes[j].key, strlen(m3d_propertytypes[j].key))) { n = m3d_propertytypes[j].id; if(k != m3dpf_map) k = m3d_propertytypes[j].format; break; } if(n != 256 && k != 256) { ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; j = m->numprop++; m->prop = (m3dp_t*)M3D_REALLOC(m->prop, m->numprop * sizeof(m3dp_t)); if(!m->prop) goto memerr; m->prop[j].type = n + (k == m3dpf_map && n < 128 ? 128 : 0); switch(k) { case m3dpf_color: ptr = _m3d_gethex(ptr, &m->prop[j].value.color); break; case m3dpf_uint8: case m3dpf_uint16: case m3dpf_uint32: ptr = _m3d_getint(ptr, &m->prop[j].value.num); break; case m3dpf_float: ptr = _m3d_getfloat(ptr, &m->prop[j].value.fnum); break; case m3dpf_map: pe = _m3d_safestr(ptr, 0); if(!pe || !*pe) goto asciiend; m->prop[j].value.textureid = _m3d_gettx(model, readfilecb, freecb, pe); if(model->errcode == M3D_ERR_ALLOC) { M3D_FREE(pe); goto memerr; } /* this error code only returned if readfilecb was specified */ if(m->prop[j].value.textureid == M3D_UNDEF) { M3D_LOG("Texture not found"); M3D_LOG(pe); m->numprop--; } M3D_FREE(pe); break; } } else { M3D_LOG("Unknown material property in"); M3D_LOG(m->name); model->errcode = M3D_ERR_UNKPROP; } ptr = _m3d_findnl(ptr); } if(!m->numprop) model->nummaterial--; } else /* procedural */ if(!memcmp(pe, "Procedural", 10)) { pe = _m3d_safestr(ptr, 0); _m3d_getpr(model, readfilecb, freecb, pe); M3D_FREE(pe); while(*ptr && *ptr != '\r' && *ptr != '\n') ptr = _m3d_findnl(ptr); } else /* mesh */ if(!memcmp(pe, "Mesh", 4)) { mi = M3D_UNDEF; #ifdef M3D_VERTEXMAX pi = M3D_UNDEF; #endif while(*ptr && *ptr != '\r' && *ptr != '\n') { if(*ptr == 'u') { ptr = _m3d_findarg(ptr); if(!*ptr) goto asciiend; mi = M3D_UNDEF; if(*ptr != '\r' && *ptr != '\n') { pe = _m3d_safestr(ptr, 0); if(!pe || !*pe) goto asciiend; for(j = 0; j < model->nummaterial; j++) if(!strcmp(pe, model->material[j].name)) { mi = (M3D_INDEX)j; break; } if(mi == M3D_UNDEF && !(model->flags & M3D_FLG_MTLLIB)) { mi = model->nummaterial++; model->material = (m3dm_t*)M3D_REALLOC(model->material, model->nummaterial * sizeof(m3dm_t)); if(!model->material) goto memerr; model->material[mi].name = pe; model->material[mi].numprop = 1; model->material[mi].prop = NULL; } else M3D_FREE(pe); } } else if(*ptr == 'p') { ptr = _m3d_findarg(ptr); if(!*ptr) goto asciiend; #ifdef M3D_VERTEXMAX pi = M3D_UNDEF; if(*ptr != '\r' && *ptr != '\n') { pe = _m3d_safestr(ptr, 0); if(!pe || !*pe) goto asciiend; for(j = 0; j < model->numparam; j++) if(!strcmp(pe, model->param[j].name)) { pi = (M3D_INDEX)j; break; } if(pi == M3D_UNDEF) { pi = model->numparam++; model->param = (m3dvi_t*)M3D_REALLOC(model->param, model->numparam * sizeof(m3dvi_t)); if(!model->param) goto memerr; model->param[pi].name = pe; model->param[pi].count = 0; } else M3D_FREE(pe); } #endif } else { i = model->numface++; model->face = (m3df_t*)M3D_REALLOC(model->face, model->numface * sizeof(m3df_t)); if(!model->face) goto memerr; memset(&model->face[i], 255, sizeof(m3df_t)); /* set all index to -1 by default */ model->face[i].materialid = mi; #ifdef M3D_VERTEXMAX model->face[i].paramid = pi; #endif /* hardcoded triangles. */ for(j = 0; j < 3; j++) { /* vertex */ ptr = _m3d_getint(ptr, &k); model->face[i].vertex[j] = (M3D_INDEX)k; if(!*ptr) goto asciiend; if(*ptr == '/') { ptr++; if(*ptr != '/') { /* texcoord */ ptr = _m3d_getint(ptr, &k); model->face[i].texcoord[j] = (M3D_INDEX)k; if(!*ptr) goto asciiend; } if(*ptr == '/') { ptr++; /* normal */ ptr = _m3d_getint(ptr, &k); model->face[i].normal[j] = (M3D_INDEX)k; if(!*ptr) goto asciiend; } if(*ptr == '/') { ptr++; /* maximum */ ptr = _m3d_getint(ptr, &k); #ifdef M3D_VERTEXMAX model->face[i].vertmax[j] = (M3D_INDEX)k; #endif if(!*ptr) goto asciiend; } } #ifndef M3D_NONORMALS if(model->face[i].normal[j] == M3D_UNDEF) neednorm = 1; #endif ptr = _m3d_findarg(ptr); } } ptr = _m3d_findnl(ptr); } } else /* voxel types chunk */ if(!memcmp(pe, "VoxTypes", 8) || !memcmp(pe, "Voxtypes", 8)) { if(model->voxtype) { M3D_LOG("More voxel types chunks, should be unique"); goto asciiend; } while(*ptr && *ptr != '\r' && *ptr != '\n') { i = model->numvoxtype++; model->voxtype = (m3dvt_t*)M3D_REALLOC(model->voxtype, model->numvoxtype * sizeof(m3dvt_t)); if(!model->voxtype) goto memerr; memset(&model->voxtype[i], 0, sizeof(m3dvt_t)); model->voxtype[i].materialid = M3D_UNDEF; model->voxtype[i].skinid = M3D_UNDEF; ptr = _m3d_gethex(ptr, &model->voxtype[i].color); if(!*ptr) goto asciiend; if(*ptr == '/') { ptr = _m3d_gethex(ptr, &k); model->voxtype[i].rotation = k; if(!*ptr) goto asciiend; if(*ptr == '/') { ptr = _m3d_gethex(ptr, &k); model->voxtype[i].voxshape = k; if(!*ptr) goto asciiend; } } while(*ptr == ' ' || *ptr == '\t') ptr++; if(*ptr == '\r' || *ptr == '\n') { ptr = _m3d_findnl(ptr); continue; } /* name */ if(*ptr != '-') { pe = _m3d_safestr(ptr, 0); if(!pe || !*pe) goto asciiend; model->voxtype[i].name = pe; for(j = 0; j < model->nummaterial; j++) if(!strcmp(pe, model->material[j].name)) { model->voxtype[i].materialid = (M3D_INDEX)j; break; } } ptr = _m3d_findarg(ptr); /* parse skin */ memset(&s, 0, sizeof(m3ds_t)); for(j = 0, w = (M3D_FLOAT)0.0; j < M3D_NUMBONE && *ptr && *ptr != '{' && *ptr != '\r' && *ptr != '\n'; j++) { ptr = _m3d_getint(ptr, &k); s.boneid[j] = (M3D_INDEX)k; if(*ptr == ':') { ptr++; ptr = _m3d_getfloat(ptr, &s.weight[j]); w += s.weight[j]; } else if(!j) s.weight[j] = (M3D_FLOAT)1.0; if(!*ptr) goto asciiend; ptr = _m3d_findarg(ptr); } if(s.boneid[0] != M3D_UNDEF && s.weight[0] > (M3D_FLOAT)0.0) { if(w != (M3D_FLOAT)1.0 && w != (M3D_FLOAT)0.0) for(j = 0; j < M3D_NUMBONE && s.weight[j] > (M3D_FLOAT)0.0; j++) s.weight[j] /= w; k = M3D_NOTDEFINED; if(model->skin) { for(j = 0; j < model->numskin; j++) if(!memcmp(&model->skin[j], &s, sizeof(m3ds_t))) { k = j; break; } } if(k == M3D_NOTDEFINED) { k = model->numskin++; model->skin = (m3ds_t*)M3D_REALLOC(model->skin, model->numskin * sizeof(m3ds_t)); if(!model->skin) goto memerr; memcpy(&model->skin[k], &s, sizeof(m3ds_t)); } model->voxtype[i].skinid = (M3D_INDEX)k; } /* parse item list */ if(*ptr == '{') { while(*ptr == '{' || *ptr == ' ' || *ptr == '\t') ptr++; while(*ptr && *ptr != '}' && *ptr != '\r' && *ptr != '\n') { ptr = _m3d_getint(ptr, &k); ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '}' || *ptr == '\r' || *ptr == '\n') goto asciiend; pe = _m3d_safestr(ptr, 0); if(!pe || !*pe) goto asciiend; ptr = _m3d_findarg(ptr); j = model->voxtype[i].numitem++; model->voxtype[i].item = (m3dvi_t*)M3D_REALLOC(model->voxtype[i].item, model->voxtype[i].numitem * sizeof(m3dvi_t)); if(!model->voxtype[i].item) goto memerr; model->voxtype[i].item[j].count = k; model->voxtype[i].item[j].name = pe; } if(*ptr != '}') goto asciiend; } ptr = _m3d_findnl(ptr); } } else /* voxel data */ if(!memcmp(pe, "Voxel", 5)) { if(!model->voxtype) { M3D_LOG("No voxel type chunk before voxel data"); goto asciiend; } pe = _m3d_findarg(pe); if(!*pe) goto asciiend; if(*pe == '\r' || *pe == '\n') pe = NULL; else pe = _m3d_safestr(pe, 0); i = model->numvoxel++; model->voxel = (m3dvx_t*)M3D_REALLOC(model->voxel, model->numvoxel * sizeof(m3dvx_t)); if(!model->voxel) goto memerr; memset(&model->voxel[i], 0, sizeof(m3dvx_t)); model->voxel[i].name = pe; k = l = 0; while(*ptr && *ptr != '\r' && *ptr != '\n') { switch(*ptr) { case 'u': ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; ptr = _m3d_getint(ptr, &n); model->voxel[i].uncertain = ((n > 0 && n < 256 ? n : 0) * 255) / 100; ptr = _m3d_findarg(ptr); if(*ptr && *ptr != '\r' && *ptr != '\n') { ptr = _m3d_getint(ptr, &n); model->voxel[i].groupid = n > 0 && n < 256 ? n : 0; } break; case 'p': ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; ptr = _m3d_getint(ptr, &n); model->voxel[i].x = n; ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; ptr = _m3d_getint(ptr, &n); model->voxel[i].y = n; ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; ptr = _m3d_getint(ptr, &n); model->voxel[i].z = n; break; case 'd': ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; ptr = _m3d_getint(ptr, &n); model->voxel[i].w = n; ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; ptr = _m3d_getint(ptr, &n); model->voxel[i].h = n; ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; ptr = _m3d_getint(ptr, &n); model->voxel[i].d = n; break; case 'l': if(model->voxel[i].data) { l++; k = 0; } else { if(!model->voxel[i].w || !model->voxel[i].h || !model->voxel[i].d) { M3D_LOG("No voxel dimension before layer data"); goto asciiend; } model->voxel[i].data = (M3D_VOXEL*)M3D_MALLOC( model->voxel[i].w * model->voxel[i].h * model->voxel[i].d * sizeof(M3D_VOXEL)); if(!model->voxel[i].data) goto memerr; } break; default: if(!model->voxel[i].data || l >= model->voxel[i].h || k >= model->voxel[i].d) { M3D_LOG("Missing voxel attributes or out of bound data"); goto asciiend; } for(n = l * model->voxel[i].w * model->voxel[i].d + k * model->voxel[i].w; j < model->voxel[i].w && *ptr && *ptr != '\r' && *ptr != '\n'; j++) { ptr = _m3d_getint(ptr, &am); if(am >= model->numvoxtype) goto asciiend; model->voxel[i].data[n + j] = am; } k++; break; } ptr = _m3d_findnl(ptr); } } else /* mathematical shape */ if(!memcmp(pe, "Shape", 5)) { pe = _m3d_findarg(pe); if(!*pe || *pe == '\r' || *pe == '\n') goto asciiend; pe = _m3d_safestr(pe, 0); if(!pe || !*pe) goto asciiend; i = model->numshape++; model->shape = (m3dh_t*)M3D_REALLOC(model->shape, model->numshape * sizeof(m3ds_t)); if(!model->shape) goto memerr; h = &model->shape[i]; h->name = pe; h->group = M3D_UNDEF; h->numcmd = 0; h->cmd = NULL; while(*ptr && *ptr != '\r' && *ptr != '\n') { if(!memcmp(ptr, "group", 5)) { ptr = _m3d_findarg(ptr); ptr = _m3d_getint(ptr, &h->group); ptr = _m3d_findnl(ptr); if(h->group != M3D_UNDEF && h->group >= model->numbone) { M3D_LOG("Unknown bone id as shape group in shape"); M3D_LOG(pe); h->group = M3D_UNDEF; model->errcode = M3D_ERR_SHPE; } continue; } for(cd = NULL, k = 0; k < (unsigned int)(sizeof(m3d_commandtypes)/sizeof(m3d_commandtypes[0])); k++) { j = (unsigned int)strlen(m3d_commandtypes[k].key); if(!memcmp(ptr, m3d_commandtypes[k].key, j) && (ptr[j] == ' ' || ptr[j] == '\r' || ptr[j] == '\n')) { cd = &m3d_commandtypes[k]; break; } } if(cd) { j = h->numcmd++; h->cmd = (m3dc_t*)M3D_REALLOC(h->cmd, h->numcmd * sizeof(m3dc_t)); if(!h->cmd) goto memerr; h->cmd[j].type = k; h->cmd[j].arg = (uint32_t*)M3D_MALLOC(cd->p * sizeof(uint32_t)); if(!h->cmd[j].arg) goto memerr; memset(h->cmd[j].arg, 0, cd->p * sizeof(uint32_t)); for(k = n = 0, l = cd->p; k < l; k++) { ptr = _m3d_findarg(ptr); if(!*ptr) goto asciiend; if(*ptr == '[') { ptr = _m3d_findarg(ptr + 1); if(!*ptr) goto asciiend; } if(*ptr == ']' || *ptr == '\r' || *ptr == '\n') break; switch(cd->a[((k - n) % (cd->p - n)) + n]) { case m3dcp_mi_t: mi = M3D_UNDEF; if(*ptr != '\r' && *ptr != '\n') { pe = _m3d_safestr(ptr, 0); if(!pe || !*pe) goto asciiend; for(n = 0; n < model->nummaterial; n++) if(!strcmp(pe, model->material[n].name)) { mi = (M3D_INDEX)n; break; } if(mi == M3D_UNDEF && !(model->flags & M3D_FLG_MTLLIB)) { mi = model->nummaterial++; model->material = (m3dm_t*)M3D_REALLOC(model->material, model->nummaterial * sizeof(m3dm_t)); if(!model->material) goto memerr; model->material[mi].name = pe; model->material[mi].numprop = 1; model->material[mi].prop = NULL; } else M3D_FREE(pe); } h->cmd[j].arg[k] = mi; break; case m3dcp_vc_t: #ifdef M3D_DOUBLE _m3d_getfloat(ptr, &w); f = w; memcpy(&h->cmd[j].arg[k], &f, 4); #else _m3d_getfloat(ptr, (float*)&h->cmd[j].arg[k]); #endif break; case m3dcp_va_t: ptr = _m3d_getint(ptr, &h->cmd[j].arg[k]); n = k + 1; l += (h->cmd[j].arg[k] - 1) * (cd->p - k - 1); h->cmd[j].arg = (uint32_t*)M3D_REALLOC(h->cmd[j].arg, l * sizeof(uint32_t)); if(!h->cmd[j].arg) goto memerr; memset(&h->cmd[j].arg[k + 1], 0, (l - k - 1) * sizeof(uint32_t)); break; case m3dcp_qi_t: ptr = _m3d_getint(ptr, &h->cmd[j].arg[k]); model->vertex[h->cmd[i].arg[k]].skinid = M3D_INDEXMAX; break; default: ptr = _m3d_getint(ptr, &h->cmd[j].arg[k]); break; } } } else { M3D_LOG("Unknown shape command in"); M3D_LOG(h->name); model->errcode = M3D_ERR_UNKCMD; } ptr = _m3d_findnl(ptr); } if(!h->numcmd) model->numshape--; } else /* annotation labels */ if(!memcmp(pe, "Labels", 6)) { pe = _m3d_findarg(pe); if(!*pe) goto asciiend; if(*pe == '\r' || *pe == '\n') pe = NULL; else pe = _m3d_safestr(pe, 0); k = 0; fn = NULL; while(*ptr && *ptr != '\r' && *ptr != '\n') { if(*ptr == 'c') { ptr = _m3d_findarg(ptr); if(!*pe || *pe == '\r' || *pe == '\n') goto asciiend; ptr = _m3d_gethex(ptr, &k); } else if(*ptr == 'l') { ptr = _m3d_findarg(ptr); if(!*pe || *pe == '\r' || *pe == '\n') goto asciiend; fn = _m3d_safestr(ptr, 2); } else { i = model->numlabel++; model->label = (m3dl_t*)M3D_REALLOC(model->label, model->numlabel * sizeof(m3dl_t)); if(!model->label) goto memerr; model->label[i].name = pe; model->label[i].lang = fn; model->label[i].color = k; ptr = _m3d_getint(ptr, &j); model->label[i].vertexid = (M3D_INDEX)j; ptr = _m3d_findarg(ptr); if(!*pe || *pe == '\r' || *pe == '\n') goto asciiend; model->label[i].text = _m3d_safestr(ptr, 2); } ptr = _m3d_findnl(ptr); } } else /* action */ if(!memcmp(pe, "Action", 6)) { pe = _m3d_findarg(pe); if(!*pe || *pe == '\r' || *pe == '\n') goto asciiend; pe = _m3d_getint(pe, &k); pe = _m3d_findarg(pe); if(!*pe || *pe == '\r' || *pe == '\n') goto asciiend; pe = _m3d_safestr(pe, 0); if(!pe || !*pe) goto asciiend; i = model->numaction++; model->action = (m3da_t*)M3D_REALLOC(model->action, model->numaction * sizeof(m3da_t)); if(!model->action) goto memerr; a = &model->action[i]; a->name = pe; a->durationmsec = k; /* skip the first frame marker as there's always at least one frame */ a->numframe = 1; a->frame = (m3dfr_t*)M3D_MALLOC(sizeof(m3dfr_t)); if(!a->frame) goto memerr; a->frame[0].msec = 0; a->frame[0].numtransform = 0; a->frame[0].transform = NULL; i = 0; if(*ptr == 'f') ptr = _m3d_findnl(ptr); while(*ptr && *ptr != '\r' && *ptr != '\n') { if(*ptr == 'f') { i = a->numframe++; a->frame = (m3dfr_t*)M3D_REALLOC(a->frame, a->numframe * sizeof(m3dfr_t)); if(!a->frame) goto memerr; ptr = _m3d_findarg(ptr); ptr = _m3d_getint(ptr, &a->frame[i].msec); a->frame[i].numtransform = 0; a->frame[i].transform = NULL; } else { j = a->frame[i].numtransform++; a->frame[i].transform = (m3dtr_t*)M3D_REALLOC(a->frame[i].transform, a->frame[i].numtransform * sizeof(m3dtr_t)); if(!a->frame[i].transform) goto memerr; ptr = _m3d_getint(ptr, &k); ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; a->frame[i].transform[j].boneid = (M3D_INDEX)k; ptr = _m3d_getint(ptr, &k); ptr = _m3d_findarg(ptr); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; a->frame[i].transform[j].pos = (M3D_INDEX)k; ptr = _m3d_getint(ptr, &k); if(!*ptr || *ptr == '\r' || *ptr == '\n') goto asciiend; a->frame[i].transform[j].ori = (M3D_INDEX)k; model->vertex[k].skinid = M3D_INDEXMAX; } ptr = _m3d_findnl(ptr); } } else /* inlined assets chunk */ if(!memcmp(pe, "Assets", 6)) { while(*ptr && *ptr != '\r' && *ptr != '\n') { if(readfilecb) { pe = _m3d_safestr(ptr, 2); if(!pe || !*pe) goto asciiend; i = model->numinlined++; model->inlined = (m3di_t*)M3D_REALLOC(model->inlined, model->numinlined * sizeof(m3di_t)); if(!model->inlined) goto memerr; t = &model->inlined[i]; model->inlined[i].data = (*readfilecb)(pe, &model->inlined[i].length); if(model->inlined[i].data) { fn = strrchr(pe, '.'); if(fn && (fn[1] == 'p' || fn[1] == 'P') && (fn[2] == 'n' || fn[2] == 'N') && (fn[3] == 'g' || fn[3] == 'G')) *fn = 0; fn = strrchr(pe, '/'); if(!fn) fn = strrchr(pe, '\\'); if(!fn) fn = pe; else fn++; model->inlined[i].name = _m3d_safestr(fn, 0); } else model->numinlined--; M3D_FREE(pe); } ptr = _m3d_findnl(ptr); } } else /* extra chunks */ if(!memcmp(pe, "Extra", 5)) { pe = _m3d_findarg(pe); if(!*pe || *pe == '\r' || *pe == '\n') goto asciiend; buff = (unsigned char*)_m3d_findnl(ptr); k = ((uint32_t)((uintptr_t)buff - (uintptr_t)ptr) / 3) + 1; i = model->numextra++; model->extra = (m3dchunk_t**)M3D_REALLOC(model->extra, model->numextra * sizeof(m3dchunk_t*)); if(!model->extra) goto memerr; model->extra[i] = (m3dchunk_t*)M3D_MALLOC(k + sizeof(m3dchunk_t)); if(!model->extra[i]) goto memerr; memcpy(&model->extra[i]->magic, pe, 4); model->extra[i]->length = sizeof(m3dchunk_t); pe = (char*)model->extra[i] + sizeof(m3dchunk_t); while(*ptr && *ptr != '\r' && *ptr != '\n') { ptr = _m3d_gethex(ptr, &k); *pe++ = (uint8_t)k; model->extra[i]->length++; } } else goto asciiend; } model->errcode = M3D_SUCCESS; asciiend: setlocale(LC_NUMERIC, ol); goto postprocess; } #endif /* Binary variant */ len = ((m3dhdr_t*)data)->length - 8; data += 8; if(M3D_CHUNKMAGIC(data, 'P','R','V','W')) { /* optional preview chunk */ model->preview.length = ((m3dchunk_t*)data)->length; model->preview.data = data + sizeof(m3dchunk_t); data += model->preview.length; len -= model->preview.length; } if(!M3D_CHUNKMAGIC(data, 'H','E','A','D')) { buff = (unsigned char *)stbi_zlib_decode_malloc_guesssize_headerflag((const char*)data, len, 4096, (int*)&len, 1); if(!buff || !len || !M3D_CHUNKMAGIC(buff, 'H','E','A','D')) { if(buff) M3D_FREE(buff); M3D_FREE(model); return NULL; } buff = (unsigned char*)M3D_REALLOC(buff, len); model->flags |= M3D_FLG_FREERAW; /* mark that we have to free the raw buffer */ data = buff; #ifdef M3D_PROFILING gettimeofday(&tv1, NULL); tvd.tv_sec = tv1.tv_sec - tv0.tv_sec; tvd.tv_usec = tv1.tv_usec - tv0.tv_usec; if(tvd.tv_usec < 0) { tvd.tv_sec--; tvd.tv_usec += 1000000L; } printf(" Deflate model %ld.%06ld sec\n", tvd.tv_sec, tvd.tv_usec); memcpy(&tv0, &tv1, sizeof(struct timeval)); #endif } model->raw = (m3dhdr_t*)data; end = data + len; /* parse header */ data += sizeof(m3dhdr_t); M3D_LOG((char*)data); model->name = (char*)data; for(; data < end && *data; data++) {}; data++; model->license = (char*)data; for(; data < end && *data; data++) {}; data++; model->author = (char*)data; for(; data < end && *data; data++) {}; data++; model->desc = (char*)data; chunk = (unsigned char*)model->raw + model->raw->length; model->scale = (M3D_FLOAT)model->raw->scale; if(model->scale <= (M3D_FLOAT)0.0) model->scale = (M3D_FLOAT)1.0; model->vc_s = 1 << ((model->raw->types >> 0) & 3); /* vertex coordinate size */ model->vi_s = 1 << ((model->raw->types >> 2) & 3); /* vertex index size */ model->si_s = 1 << ((model->raw->types >> 4) & 3); /* string offset size */ model->ci_s = 1 << ((model->raw->types >> 6) & 3); /* color index size */ model->ti_s = 1 << ((model->raw->types >> 8) & 3); /* tmap index size */ model->bi_s = 1 << ((model->raw->types >>10) & 3); /* bone index size */ model->nb_s = 1 << ((model->raw->types >>12) & 3); /* number of bones per vertex */ model->sk_s = 1 << ((model->raw->types >>14) & 3); /* skin index size */ model->fc_s = 1 << ((model->raw->types >>16) & 3); /* frame counter size */ model->hi_s = 1 << ((model->raw->types >>18) & 3); /* shape index size */ model->fi_s = 1 << ((model->raw->types >>20) & 3); /* face index size */ model->vd_s = 1 << ((model->raw->types >>22) & 3); /* voxel dimension size */ model->vp_s = 1 << ((model->raw->types >>24) & 3); /* voxel pixel size */ if(model->ci_s == 8) model->ci_s = 0; /* optional indices */ if(model->ti_s == 8) model->ti_s = 0; if(model->bi_s == 8) model->bi_s = 0; if(model->sk_s == 8) model->sk_s = 0; if(model->fc_s == 8) model->fc_s = 0; if(model->hi_s == 8) model->hi_s = 0; if(model->fi_s == 8) model->fi_s = 0; /* variable limit checks */ if(sizeof(M3D_FLOAT) == 4 && model->vc_s > 4) { M3D_LOG("Double precision coordinates not supported, truncating to float..."); model->errcode = M3D_ERR_TRUNC; } if((sizeof(M3D_INDEX) == 2 && (model->vi_s > 2 || model->si_s > 2 || model->ci_s > 2 || model->ti_s > 2 || model->bi_s > 2 || model->sk_s > 2 || model->fc_s > 2 || model->hi_s > 2 || model->fi_s > 2)) || (sizeof(M3D_VOXEL) < (size_t)model->vp_s && model->vp_s != 8)) { M3D_LOG("32 bit indices not supported, unable to load model"); M3D_FREE(model); return NULL; } if(model->vi_s > 4 || model->si_s > 4 || model->vp_s == 4) { M3D_LOG("Invalid index size, unable to load model"); M3D_FREE(model); return NULL; } if(!M3D_CHUNKMAGIC(end - 4, 'O','M','D','3')) { M3D_LOG("Missing end chunk"); M3D_FREE(model); return NULL; } if(model->nb_s > M3D_NUMBONE) { M3D_LOG("Model has more bones per vertex than what importer was configured to support"); model->errcode = M3D_ERR_TRUNC; } /* look for inlined assets in advance, material and procedural chunks may need them */ buff = chunk; while(buff < end && !M3D_CHUNKMAGIC(buff, 'O','M','D','3')) { data = buff; len = ((m3dchunk_t*)data)->length; buff += len; if(len < sizeof(m3dchunk_t) || buff >= end) { M3D_LOG("Invalid chunk size"); break; } len -= sizeof(m3dchunk_t) + model->si_s; /* inlined assets */ if(M3D_CHUNKMAGIC(data, 'A','S','E','T') && len > 0) { M3D_LOG("Inlined asset"); i = model->numinlined++; model->inlined = (m3di_t*)M3D_REALLOC(model->inlined, model->numinlined * sizeof(m3di_t)); if(!model->inlined) { memerr: M3D_LOG("Out of memory"); model->errcode = M3D_ERR_ALLOC; return model; } data += sizeof(m3dchunk_t); t = &model->inlined[i]; M3D_GETSTR(t->name); M3D_LOG(t->name); t->data = (uint8_t*)data; t->length = len; } } /* parse chunks */ while(chunk < end && !M3D_CHUNKMAGIC(chunk, 'O','M','D','3')) { data = chunk; len = ((m3dchunk_t*)chunk)->length; chunk += len; if(len < sizeof(m3dchunk_t) || chunk >= end) { M3D_LOG("Invalid chunk size"); break; } len -= sizeof(m3dchunk_t); /* color map */ if(M3D_CHUNKMAGIC(data, 'C','M','A','P')) { M3D_LOG("Color map"); if(model->cmap) { M3D_LOG("More color map chunks, should be unique"); model->errcode = M3D_ERR_CMAP; continue; } if(!model->ci_s) { M3D_LOG("Color map chunk, shouldn't be any"); model->errcode = M3D_ERR_CMAP; continue; } model->numcmap = len / sizeof(uint32_t); model->cmap = (uint32_t*)(data + sizeof(m3dchunk_t)); } else /* texture map */ if(M3D_CHUNKMAGIC(data, 'T','M','A','P')) { M3D_LOG("Texture map"); if(model->tmap) { M3D_LOG("More texture map chunks, should be unique"); model->errcode = M3D_ERR_TMAP; continue; } if(!model->ti_s) { M3D_LOG("Texture map chunk, shouldn't be any"); model->errcode = M3D_ERR_TMAP; continue; } reclen = model->vc_s + model->vc_s; model->numtmap = len / reclen; model->tmap = (m3dti_t*)M3D_MALLOC(model->numtmap * sizeof(m3dti_t)); if(!model->tmap) goto memerr; for(i = 0, data += sizeof(m3dchunk_t); data < chunk; i++) { switch(model->vc_s) { case 1: model->tmap[i].u = (M3D_FLOAT)((uint8_t)data[0]) / (M3D_FLOAT)255.0; model->tmap[i].v = (M3D_FLOAT)((uint8_t)data[1]) / (M3D_FLOAT)255.0; break; case 2: model->tmap[i].u = (M3D_FLOAT)(*((uint16_t*)(data+0))) / (M3D_FLOAT)65535.0; model->tmap[i].v = (M3D_FLOAT)(*((uint16_t*)(data+2))) / (M3D_FLOAT)65535.0; break; case 4: model->tmap[i].u = (M3D_FLOAT)(*((float*)(data+0))); model->tmap[i].v = (M3D_FLOAT)(*((float*)(data+4))); break; case 8: model->tmap[i].u = (M3D_FLOAT)(*((double*)(data+0))); model->tmap[i].v = (M3D_FLOAT)(*((double*)(data+8))); break; } data += reclen; } } else /* vertex list */ if(M3D_CHUNKMAGIC(data, 'V','R','T','S')) { M3D_LOG("Vertex list"); if(model->vertex) { M3D_LOG("More vertex chunks, should be unique"); model->errcode = M3D_ERR_VRTS; continue; } if(model->ci_s && model->ci_s < 4 && !model->cmap) model->errcode = M3D_ERR_CMAP; reclen = model->ci_s + model->sk_s + 4 * model->vc_s; model->numvertex = len / reclen; model->vertex = (m3dv_t*)M3D_MALLOC(model->numvertex * sizeof(m3dv_t)); if(!model->vertex) goto memerr; memset(model->vertex, 0, model->numvertex * sizeof(m3dv_t)); for(i = 0, data += sizeof(m3dchunk_t); data < chunk && i < model->numvertex; i++) { switch(model->vc_s) { case 1: model->vertex[i].x = (M3D_FLOAT)((int8_t)data[0]) / (M3D_FLOAT)127.0; model->vertex[i].y = (M3D_FLOAT)((int8_t)data[1]) / (M3D_FLOAT)127.0; model->vertex[i].z = (M3D_FLOAT)((int8_t)data[2]) / (M3D_FLOAT)127.0; model->vertex[i].w = (M3D_FLOAT)((int8_t)data[3]) / (M3D_FLOAT)127.0; data += 4; break; case 2: model->vertex[i].x = (M3D_FLOAT)(*((int16_t*)(data+0))) / (M3D_FLOAT)32767.0; model->vertex[i].y = (M3D_FLOAT)(*((int16_t*)(data+2))) / (M3D_FLOAT)32767.0; model->vertex[i].z = (M3D_FLOAT)(*((int16_t*)(data+4))) / (M3D_FLOAT)32767.0; model->vertex[i].w = (M3D_FLOAT)(*((int16_t*)(data+6))) / (M3D_FLOAT)32767.0; data += 8; break; case 4: model->vertex[i].x = (M3D_FLOAT)(*((float*)(data+0))); model->vertex[i].y = (M3D_FLOAT)(*((float*)(data+4))); model->vertex[i].z = (M3D_FLOAT)(*((float*)(data+8))); model->vertex[i].w = (M3D_FLOAT)(*((float*)(data+12))); data += 16; break; case 8: model->vertex[i].x = (M3D_FLOAT)(*((double*)(data+0))); model->vertex[i].y = (M3D_FLOAT)(*((double*)(data+8))); model->vertex[i].z = (M3D_FLOAT)(*((double*)(data+16))); model->vertex[i].w = (M3D_FLOAT)(*((double*)(data+24))); data += 32; break; } switch(model->ci_s) { case 1: model->vertex[i].color = model->cmap ? model->cmap[data[0]] : 0; data++; break; case 2: model->vertex[i].color = model->cmap ? model->cmap[*((uint16_t*)data)] : 0; data += 2; break; case 4: model->vertex[i].color = *((uint32_t*)data); data += 4; break; /* case 8: break; */ } model->vertex[i].skinid = M3D_UNDEF; data = _m3d_getidx(data, model->sk_s, &model->vertex[i].skinid); } } else /* skeleton: bone hierarchy and skin */ if(M3D_CHUNKMAGIC(data, 'B','O','N','E')) { M3D_LOG("Skeleton"); if(model->bone) { M3D_LOG("More bone chunks, should be unique"); model->errcode = M3D_ERR_BONE; continue; } if(!model->bi_s) { M3D_LOG("Bone chunk, shouldn't be any"); model->errcode=M3D_ERR_BONE; continue; } if(!model->vertex) { M3D_LOG("No vertex chunk before bones"); model->errcode = M3D_ERR_VRTS; break; } data += sizeof(m3dchunk_t); model->numbone = 0; data = _m3d_getidx(data, model->bi_s, &model->numbone); if(model->numbone) { model->bone = (m3db_t*)M3D_MALLOC(model->numbone * sizeof(m3db_t)); if(!model->bone) goto memerr; } model->numskin = 0; data = _m3d_getidx(data, model->sk_s, &model->numskin); /* read bone hierarchy */ for(i = 0; data < chunk && i < model->numbone; i++) { data = _m3d_getidx(data, model->bi_s, &model->bone[i].parent); M3D_GETSTR(model->bone[i].name); data = _m3d_getidx(data, model->vi_s, &model->bone[i].pos); data = _m3d_getidx(data, model->vi_s, &model->bone[i].ori); model->bone[i].numweight = 0; model->bone[i].weight = NULL; } /* read skin definitions */ if(model->numskin) { model->skin = (m3ds_t*)M3D_MALLOC(model->numskin * sizeof(m3ds_t)); if(!model->skin) goto memerr; for(i = 0; data < chunk && i < model->numskin; i++) { for(j = 0; j < M3D_NUMBONE; j++) { model->skin[i].boneid[j] = M3D_UNDEF; model->skin[i].weight[j] = (M3D_FLOAT)0.0; } memset(&weights, 0, sizeof(weights)); if(model->nb_s == 1) weights[0] = 255; else { memcpy(&weights, data, model->nb_s); data += model->nb_s; } for(j = 0, w = (M3D_FLOAT)0.0; j < (unsigned int)model->nb_s; j++) { if(weights[j]) { if(j >= M3D_NUMBONE) data += model->bi_s; else { model->skin[i].weight[j] = (M3D_FLOAT)(weights[j]) / (M3D_FLOAT)255.0; w += model->skin[i].weight[j]; data = _m3d_getidx(data, model->bi_s, &model->skin[i].boneid[j]); } } } /* this can occur if model has more bones than what the importer is configured to handle */ if(w != (M3D_FLOAT)1.0 && w != (M3D_FLOAT)0.0) { for(j = 0; j < M3D_NUMBONE; j++) model->skin[i].weight[j] /= w; } } } } else /* material */ if(M3D_CHUNKMAGIC(data, 'M','T','R','L')) { data += sizeof(m3dchunk_t); M3D_GETSTR(name); M3D_LOG("Material"); M3D_LOG(name); if(model->ci_s < 4 && !model->numcmap) model->errcode = M3D_ERR_CMAP; for(i = 0; i < model->nummaterial; i++) if(!strcmp(name, model->material[i].name)) { model->errcode = M3D_ERR_MTRL; M3D_LOG("Multiple definitions for material"); M3D_LOG(name); name = NULL; break; } if(name) { i = model->nummaterial++; if(model->flags & M3D_FLG_MTLLIB) { m = model->material; model->material = (m3dm_t*)M3D_MALLOC(model->nummaterial * sizeof(m3dm_t)); if(!model->material) goto memerr; memcpy(model->material, m, (model->nummaterial - 1) * sizeof(m3dm_t)); if(model->texture) { tx = model->texture; model->texture = (m3dtx_t*)M3D_MALLOC(model->numtexture * sizeof(m3dtx_t)); if(!model->texture) goto memerr; memcpy(model->texture, tx, model->numtexture * sizeof(m3dm_t)); } model->flags &= ~M3D_FLG_MTLLIB; } else { model->material = (m3dm_t*)M3D_REALLOC(model->material, model->nummaterial * sizeof(m3dm_t)); if(!model->material) goto memerr; } m = &model->material[i]; m->numprop = 0; m->name = name; m->prop = (m3dp_t*)M3D_MALLOC((len / 2) * sizeof(m3dp_t)); if(!m->prop) goto memerr; while(data < chunk) { i = m->numprop++; m->prop[i].type = *data++; m->prop[i].value.num = 0; if(m->prop[i].type >= 128) k = m3dpf_map; else { for(k = 256, j = 0; j < sizeof(m3d_propertytypes)/sizeof(m3d_propertytypes[0]); j++) if(m->prop[i].type == m3d_propertytypes[j].id) { k = m3d_propertytypes[j].format; break; } } switch(k) { case m3dpf_color: switch(model->ci_s) { case 1: m->prop[i].value.color = model->cmap ? model->cmap[data[0]] : 0; data++; break; case 2: m->prop[i].value.color = model->cmap ? model->cmap[*((uint16_t*)data)] : 0; data += 2; break; case 4: m->prop[i].value.color = *((uint32_t*)data); data += 4; break; } break; case m3dpf_uint8: m->prop[i].value.num = *data++; break; case m3dpf_uint16:m->prop[i].value.num = *((uint16_t*)data); data += 2; break; case m3dpf_uint32:m->prop[i].value.num = *((uint32_t*)data); data += 4; break; case m3dpf_float: m->prop[i].value.fnum = *((float*)data); data += 4; break; case m3dpf_map: M3D_GETSTR(name); m->prop[i].value.textureid = _m3d_gettx(model, readfilecb, freecb, name); if(model->errcode == M3D_ERR_ALLOC) goto memerr; /* this error code only returned if readfilecb was specified */ if(m->prop[i].value.textureid == M3D_UNDEF) { M3D_LOG("Texture not found"); M3D_LOG(m->name); m->numprop--; } break; default: M3D_LOG("Unknown material property in"); M3D_LOG(m->name); model->errcode = M3D_ERR_UNKPROP; data = chunk; break; } } m->prop = (m3dp_t*)M3D_REALLOC(m->prop, m->numprop * sizeof(m3dp_t)); if(!m->prop) goto memerr; } } else /* face */ if(M3D_CHUNKMAGIC(data, 'P','R','O','C')) { /* procedural surface */ M3D_GETSTR(name); M3D_LOG("Procedural surface"); M3D_LOG(name); _m3d_getpr(model, readfilecb, freecb, name); } else if(M3D_CHUNKMAGIC(data, 'M','E','S','H')) { M3D_LOG("Mesh data"); if(!model->vertex) { M3D_LOG("No vertex chunk before mesh"); model->errcode = M3D_ERR_VRTS; } /* mesh */ data += sizeof(m3dchunk_t); mi = M3D_UNDEF; #ifdef M3D_VERTEXMAX pi = M3D_UNDEF; #endif am = model->numface; while(data < chunk) { k = *data++; n = k >> 4; k &= 15; if(!n) { if(!k) { /* use material */ mi = M3D_UNDEF; M3D_GETSTR(name); if(name) { for(j = 0; j < model->nummaterial; j++) if(!strcmp(name, model->material[j].name)) { mi = (M3D_INDEX)j; break; } if(mi == M3D_UNDEF) model->errcode = M3D_ERR_MTRL; } } else { /* use parameter */ M3D_GETSTR(name); #ifdef M3D_VERTEXMAX pi = M3D_UNDEF; if(name) { for(j = 0; j < model->numparam; j++) if(!strcmp(name, model->param[j].name)) { pi = (M3D_INDEX)j; break; } if(pi == M3D_UNDEF) { pi = model->numparam++; model->param = (m3dvi_t*)M3D_REALLOC(model->param, model->numparam * sizeof(m3dvi_t)); if(!model->param) goto memerr; model->param[pi].name = name; model->param[pi].count = 0; } } #endif } continue; } if(n != 3) { M3D_LOG("Only triangle mesh supported for now"); model->errcode = M3D_ERR_UNKMESH; return model; } i = model->numface++; if(model->numface > am) { am = model->numface + 4095; model->face = (m3df_t*)M3D_REALLOC(model->face, am * sizeof(m3df_t)); if(!model->face) goto memerr; } memset(&model->face[i], 255, sizeof(m3df_t)); /* set all index to -1 by default */ model->face[i].materialid = mi; #ifdef M3D_VERTEXMAX model->face[i].paramid = pi; #endif for(j = 0; data < chunk && j < n; j++) { /* vertex */ data = _m3d_getidx(data, model->vi_s, &model->face[i].vertex[j]); /* texcoord */ if(k & 1) data = _m3d_getidx(data, model->ti_s, &model->face[i].texcoord[j]); /* normal */ if(k & 2) data = _m3d_getidx(data, model->vi_s, &model->face[i].normal[j]); #ifndef M3D_NONORMALS if(model->face[i].normal[j] == M3D_UNDEF) neednorm = 1; #endif /* maximum */ if(k & 4) #ifdef M3D_VERTEXMAX data = _m3d_getidx(data, model->vi_s, &model->face[i].vertmax[j]); #else data += model->vi_s; #endif } if(j != n) { M3D_LOG("Invalid mesh"); model->numface = 0; model->errcode = M3D_ERR_UNKMESH; return model; } } model->face = (m3df_t*)M3D_REALLOC(model->face, model->numface * sizeof(m3df_t)); } else if(M3D_CHUNKMAGIC(data, 'V','O','X','T')) { /* voxel types */ M3D_LOG("Voxel types list"); if(model->voxtype) { M3D_LOG("More voxel type chunks, should be unique"); model->errcode = M3D_ERR_VOXT; continue; } if(model->ci_s && model->ci_s < 4 && !model->cmap) model->errcode = M3D_ERR_CMAP; reclen = model->ci_s + model->si_s + 3 + model->sk_s; k = len / reclen; model->voxtype = (m3dvt_t*)M3D_MALLOC(k * sizeof(m3dvt_t)); if(!model->voxtype) goto memerr; memset(model->voxtype, 0, k * sizeof(m3dvt_t)); model->numvoxtype = 0; for(i = 0, data += sizeof(m3dchunk_t); data < chunk && i < k; i++) { switch(model->ci_s) { case 1: model->voxtype[i].color = model->cmap ? model->cmap[data[0]] : 0; data++; break; case 2: model->voxtype[i].color = model->cmap ? model->cmap[*((uint16_t*)data)] : 0; data += 2; break; case 4: model->voxtype[i].color = *((uint32_t*)data); data += 4; break; /* case 8: break; */ } M3D_GETSTR(name); model->voxtype[i].materialid = M3D_UNDEF; if(name) { model->voxtype[i].name = name; /* for(j = 0; j < model->nummaterial; j++) if(!strcmp(name, model->material[j].name)) { model->voxtype[i].materialid = (M3D_INDEX)j; break; } */ } j = *data++; model->voxtype[i].rotation = j & 0xBF; model->voxtype[i].voxshape = ((j & 0x40) << 2) | *data++; model->voxtype[i].numitem = *data++; model->voxtype[i].skinid = M3D_UNDEF; data = _m3d_getidx(data, model->sk_s, &model->voxtype[i].skinid); if(model->voxtype[i].numitem) { model->voxtype[i].item = (m3dvi_t*)M3D_MALLOC(model->voxtype[i].numitem * sizeof(m3dvi_t)); if(!model->voxtype[i].item) goto memerr; memset(model->voxtype[i].item, 0, model->voxtype[i].numitem * sizeof(m3dvi_t)); for(j = 0; j < model->voxtype[i].numitem; j++) { model->voxtype[i].item[j].count = *data++; model->voxtype[i].item[j].count |= (*data++) << 8; M3D_GETSTR(model->voxtype[i].item[j].name); } } } model->numvoxtype = i; if(k != model->numvoxtype) { model->voxtype = (m3dvt_t*)M3D_REALLOC(model->voxtype, model->numvoxtype * sizeof(m3dvt_t)); if(!model->voxtype) goto memerr; } } else if(M3D_CHUNKMAGIC(data, 'V','O','X','D')) { /* voxel data */ data += sizeof(m3dchunk_t); M3D_GETSTR(name); M3D_LOG("Voxel Data Layer"); M3D_LOG(name); if(model->vd_s > 4 || model->vp_s > 2) { M3D_LOG("No voxel index size"); model->errcode = M3D_ERR_UNKVOX; continue; } if(!model->voxtype) { M3D_LOG("No voxel type chunk before voxel data"); model->errcode = M3D_ERR_VOXT; } i = model->numvoxel++; model->voxel = (m3dvx_t*)M3D_REALLOC(model->voxel, model->numvoxel * sizeof(m3dvx_t)); if(!model->voxel) goto memerr; memset(&model->voxel[i], 0, sizeof(m3dvx_t)); model->voxel[i].name = name; switch(model->vd_s) { case 1: model->voxel[i].x = (int32_t)((int8_t)data[0]); model->voxel[i].y = (int32_t)((int8_t)data[1]); model->voxel[i].z = (int32_t)((int8_t)data[2]); model->voxel[i].w = (uint32_t)(data[3]); model->voxel[i].h = (uint32_t)(data[4]); model->voxel[i].d = (uint32_t)(data[5]); data += 6; break; case 2: model->voxel[i].x = (int32_t)(*((int16_t*)(data+0))); model->voxel[i].y = (int32_t)(*((int16_t*)(data+2))); model->voxel[i].z = (int32_t)(*((int16_t*)(data+4))); model->voxel[i].w = (uint32_t)(*((uint16_t*)(data+6))); model->voxel[i].h = (uint32_t)(*((uint16_t*)(data+8))); model->voxel[i].d = (uint32_t)(*((uint16_t*)(data+10))); data += 12; break; case 4: model->voxel[i].x = *((int32_t*)(data+0)); model->voxel[i].y = *((int32_t*)(data+4)); model->voxel[i].z = *((int32_t*)(data+8)); model->voxel[i].w = *((uint32_t*)(data+12)); model->voxel[i].h = *((uint32_t*)(data+16)); model->voxel[i].d = *((uint32_t*)(data+20)); data += 24; break; } model->voxel[i].uncertain = *data++; model->voxel[i].groupid = *data++; k = model->voxel[i].w * model->voxel[i].h * model->voxel[i].d; model->voxel[i].data = (M3D_VOXEL*)M3D_MALLOC(k * sizeof(M3D_VOXEL)); if(!model->voxel[i].data) goto memerr; memset(model->voxel[i].data, 0xff, k * sizeof(M3D_VOXEL)); for(j = 0; data < chunk && j < k;) { l = ((*data++) & 0x7F) + 1; if(data[-1] & 0x80) { data = _m3d_getidx(data, model->vp_s, &mi); while(l-- && j < k) model->voxel[i].data[j++] = (M3D_VOXEL)mi; } else while(l-- && j < k) { data = _m3d_getidx(data, model->vp_s, &mi); model->voxel[i].data[j++] = (M3D_VOXEL)mi; } } } else if(M3D_CHUNKMAGIC(data, 'S','H','P','E')) { /* mathematical shape */ data += sizeof(m3dchunk_t); M3D_GETSTR(name); M3D_LOG("Mathematical Shape"); M3D_LOG(name); i = model->numshape++; model->shape = (m3dh_t*)M3D_REALLOC(model->shape, model->numshape * sizeof(m3dh_t)); if(!model->shape) goto memerr; h = &model->shape[i]; h->numcmd = 0; h->cmd = NULL; h->name = name; h->group = M3D_UNDEF; data = _m3d_getidx(data, model->bi_s, &h->group); if(h->group != M3D_UNDEF && h->group >= model->numbone) { M3D_LOG("Unknown bone id as shape group in shape"); M3D_LOG(name); h->group = M3D_UNDEF; model->errcode = M3D_ERR_SHPE; } while(data < chunk) { i = h->numcmd++; h->cmd = (m3dc_t*)M3D_REALLOC(h->cmd, h->numcmd * sizeof(m3dc_t)); if(!h->cmd) goto memerr; h->cmd[i].type = *data++; if(h->cmd[i].type & 0x80) { h->cmd[i].type &= 0x7F; h->cmd[i].type |= (*data++ << 7); } if(h->cmd[i].type >= (unsigned int)(sizeof(m3d_commandtypes)/sizeof(m3d_commandtypes[0]))) { M3D_LOG("Unknown shape command in"); M3D_LOG(h->name); model->errcode = M3D_ERR_UNKCMD; break; } cd = &m3d_commandtypes[h->cmd[i].type]; h->cmd[i].arg = (uint32_t*)M3D_MALLOC(cd->p * sizeof(uint32_t)); if(!h->cmd[i].arg) goto memerr; memset(h->cmd[i].arg, 0, cd->p * sizeof(uint32_t)); for(k = n = 0, l = cd->p; k < l; k++) switch(cd->a[((k - n) % (cd->p - n)) + n]) { case m3dcp_mi_t: h->cmd[i].arg[k] = M3D_NOTDEFINED; M3D_GETSTR(name); if(name) { for(n = 0; n < model->nummaterial; n++) if(!strcmp(name, model->material[n].name)) { h->cmd[i].arg[k] = n; break; } if(h->cmd[i].arg[k] == M3D_NOTDEFINED) model->errcode = M3D_ERR_MTRL; } break; case m3dcp_vc_t: f = 0.0f; switch(model->vc_s) { case 1: f = (float)((int8_t)data[0]) / 127; break; case 2: f = (float)(*((int16_t*)(data+0))) / 32767; break; case 4: f = (float)(*((float*)(data+0))); break; case 8: f = (float)(*((double*)(data+0))); break; } memcpy(&h->cmd[i].arg[k], &f, 4); data += model->vc_s; break; case m3dcp_hi_t: data = _m3d_getidx(data, model->hi_s, &h->cmd[i].arg[k]); break; case m3dcp_fi_t: data = _m3d_getidx(data, model->fi_s, &h->cmd[i].arg[k]); break; case m3dcp_ti_t: data = _m3d_getidx(data, model->ti_s, &h->cmd[i].arg[k]); break; case m3dcp_qi_t: case m3dcp_vi_t: data = _m3d_getidx(data, model->vi_s, &h->cmd[i].arg[k]); break; case m3dcp_i1_t: data = _m3d_getidx(data, 1, &h->cmd[i].arg[k]); break; case m3dcp_i2_t: data = _m3d_getidx(data, 2, &h->cmd[i].arg[k]); break; case m3dcp_i4_t: data = _m3d_getidx(data, 4, &h->cmd[i].arg[k]); break; case m3dcp_va_t: data = _m3d_getidx(data, 4, &h->cmd[i].arg[k]); n = k + 1; l += (h->cmd[i].arg[k] - 1) * (cd->p - k - 1); h->cmd[i].arg = (uint32_t*)M3D_REALLOC(h->cmd[i].arg, l * sizeof(uint32_t)); if(!h->cmd[i].arg) goto memerr; memset(&h->cmd[i].arg[k + 1], 0, (l - k - 1) * sizeof(uint32_t)); break; } } } else /* annotation label list */ if(M3D_CHUNKMAGIC(data, 'L','B','L','S')) { data += sizeof(m3dchunk_t); M3D_GETSTR(name); M3D_GETSTR(lang); M3D_LOG("Label list"); if(name) { M3D_LOG(name); } if(lang) { M3D_LOG(lang); } if(model->ci_s && model->ci_s < 4 && !model->cmap) model->errcode = M3D_ERR_CMAP; k = 0; switch(model->ci_s) { case 1: k = model->cmap ? model->cmap[data[0]] : 0; data++; break; case 2: k = model->cmap ? model->cmap[*((uint16_t*)data)] : 0; data += 2; break; case 4: k = *((uint32_t*)data); data += 4; break; /* case 8: break; */ } reclen = model->vi_s + model->si_s; i = model->numlabel; model->numlabel += len / reclen; model->label = (m3dl_t*)M3D_REALLOC(model->label, model->numlabel * sizeof(m3dl_t)); if(!model->label) goto memerr; memset(&model->label[i], 0, (model->numlabel - i) * sizeof(m3dl_t)); for(; data < chunk && i < model->numlabel; i++) { model->label[i].name = name; model->label[i].lang = lang; model->label[i].color = k; data = _m3d_getidx(data, model->vi_s, &model->label[i].vertexid); M3D_GETSTR(model->label[i].text); } } else /* action */ if(M3D_CHUNKMAGIC(data, 'A','C','T','N')) { M3D_LOG("Action"); i = model->numaction++; model->action = (m3da_t*)M3D_REALLOC(model->action, model->numaction * sizeof(m3da_t)); if(!model->action) goto memerr; a = &model->action[i]; data += sizeof(m3dchunk_t); M3D_GETSTR(a->name); M3D_LOG(a->name); a->numframe = *((uint16_t*)data); data += 2; if(a->numframe < 1) { model->numaction--; } else { a->durationmsec = *((uint32_t*)data); data += 4; a->frame = (m3dfr_t*)M3D_MALLOC(a->numframe * sizeof(m3dfr_t)); if(!a->frame) goto memerr; for(i = 0; data < chunk && i < a->numframe; i++) { a->frame[i].msec = *((uint32_t*)data); data += 4; a->frame[i].numtransform = 0; a->frame[i].transform = NULL; data = _m3d_getidx(data, model->fc_s, &a->frame[i].numtransform); if(a->frame[i].numtransform > 0) { a->frame[i].transform = (m3dtr_t*)M3D_MALLOC(a->frame[i].numtransform * sizeof(m3dtr_t)); for(j = 0; j < a->frame[i].numtransform; j++) { data = _m3d_getidx(data, model->bi_s, &a->frame[i].transform[j].boneid); data = _m3d_getidx(data, model->vi_s, &a->frame[i].transform[j].pos); data = _m3d_getidx(data, model->vi_s, &a->frame[i].transform[j].ori); } } } } } else { i = model->numextra++; model->extra = (m3dchunk_t**)M3D_REALLOC(model->extra, model->numextra * sizeof(m3dchunk_t*)); if(!model->extra) goto memerr; model->extra[i] = (m3dchunk_t*)data; } } /* calculate normals, normalize skin weights, create bone/vertex cross-references and calculate transform matrices */ #ifdef M3D_ASCII postprocess: #endif if(model) { M3D_LOG("Post-process"); #ifdef M3D_PROFILING gettimeofday(&tv1, NULL); tvd.tv_sec = tv1.tv_sec - tv0.tv_sec; tvd.tv_usec = tv1.tv_usec - tv0.tv_usec; if(tvd.tv_usec < 0) { tvd.tv_sec--; tvd.tv_usec += 1000000L; } printf(" Parsing chunks %ld.%06ld sec\n", tvd.tv_sec, tvd.tv_usec); #endif #ifndef M3D_NOVOXELS if(model->numvoxel && model->voxel) { M3D_LOG("Converting voxels into vertices and mesh"); /* add normals */ enorm = model->numvertex; model->numvertex += 6; model->vertex = (m3dv_t*)M3D_REALLOC(model->vertex, model->numvertex * sizeof(m3dv_t)); if(!model->vertex) goto memerr; memset(&model->vertex[enorm], 0, 6 * sizeof(m3dv_t)); for(l = 0; l < 6; l++) model->vertex[enorm+l].skinid = M3D_UNDEF; model->vertex[enorm+0].y = (M3D_FLOAT)-1.0; model->vertex[enorm+1].z = (M3D_FLOAT)-1.0; model->vertex[enorm+2].x = (M3D_FLOAT)-1.0; model->vertex[enorm+3].y = (M3D_FLOAT)1.0; model->vertex[enorm+4].z = (M3D_FLOAT)1.0; model->vertex[enorm+5].x = (M3D_FLOAT)1.0; /* this is a fast, not so memory efficient version, only basic face culling used */ min_x = min_y = min_z = 2147483647L; max_x = max_y = max_z = -2147483647L; for(i = 0; i < model->numvoxel; i++) { if(model->voxel[i].x + (int32_t)model->voxel[i].w > max_x) max_x = model->voxel[i].x + (int32_t)model->voxel[i].w; if(model->voxel[i].x < min_x) min_x = model->voxel[i].x; if(model->voxel[i].y + (int32_t)model->voxel[i].h > max_y) max_y = model->voxel[i].y + (int32_t)model->voxel[i].h; if(model->voxel[i].y < min_y) min_y = model->voxel[i].y; if(model->voxel[i].z + (int32_t)model->voxel[i].d > max_z) max_z = model->voxel[i].z + (int32_t)model->voxel[i].d; if(model->voxel[i].z < min_z) min_z = model->voxel[i].z; } i = (-min_x > max_x ? -min_x : max_x); j = (-min_y > max_y ? -min_y : max_y); k = (-min_z > max_z ? -min_z : max_z); if(j > i) i = j; if(k > i) i = k; if(i <= 1) i = 1; w = (M3D_FLOAT)1.0 / (M3D_FLOAT)i; if(i >= 254) model->vc_s = 2; if(i >= 65534) model->vc_s = 4; for(i = 0; i < model->numvoxel; i++) { sx = model->voxel[i].w; sz = model->voxel[i].d; sy = model->voxel[i].h; for(y = 0, j = 0; y < sy; y++) for(z = 0; z < sz; z++) for(x = 0; x < sx; x++, j++) if(model->voxel[i].data[j] < model->numvoxtype) { k = 0; /* 16__32 ____ * /| /| /|2 /| *64_128 | /_8_/ 32 * | 1_|_2 |4|_|_| * |/ |/ |/ 1|/ * 4___8 |16_| */ k = n = am = 0; if(!y || model->voxel[i].data[j - sx*sz] >= model->numvoxtype) { n++; am |= 1; k |= 1|2|4|8; } if(!z || model->voxel[i].data[j - sx] >= model->numvoxtype) { n++; am |= 2; k |= 1|2|16|32; } if(!x || model->voxel[i].data[j - 1] >= model->numvoxtype) { n++; am |= 4; k |= 1|4|16|64; } if(y == sy-1 || model->voxel[i].data[j + sx*sz] >= model->numvoxtype) { n++; am |= 8; k |= 16|32|64|128; } if(z == sz-1 || model->voxel[i].data[j + sx] >= model->numvoxtype) { n++; am |= 16; k |= 4|8|64|128; } if(x == sx-1 || model->voxel[i].data[j + 1] >= model->numvoxtype) { n++; am |= 32; k |= 2|8|32|128; } if(k) { memset(edge, 255, sizeof(edge)); for(l = 0, len = 1, reclen = model->numvertex; l < 8; l++, len <<= 1) if(k & len) edge[l] = model->numvertex++; model->vertex = (m3dv_t*)M3D_REALLOC(model->vertex, model->numvertex * sizeof(m3dv_t)); if(!model->vertex) goto memerr; memset(&model->vertex[reclen], 0, (model->numvertex-reclen) * sizeof(m3dv_t)); for(l = reclen; l < model->numvertex; l++) { model->vertex[l].skinid = model->voxtype[model->voxel[i].data[j]].skinid; model->vertex[l].color = model->voxtype[model->voxel[i].data[j]].color; } l = reclen; if(k & 1) { model->vertex[l].x = (model->voxel[i].x + x) * w; model->vertex[l].y = (model->voxel[i].y + y) * w; model->vertex[l].z = (model->voxel[i].z + z) * w; l++; } if(k & 2) { model->vertex[l].x = (model->voxel[i].x + x + 1) * w; model->vertex[l].y = (model->voxel[i].y + y) * w; model->vertex[l].z = (model->voxel[i].z + z) * w; l++; } if(k & 4) { model->vertex[l].x = (model->voxel[i].x + x) * w; model->vertex[l].y = (model->voxel[i].y + y) * w; model->vertex[l].z = (model->voxel[i].z + z + 1) * w; l++; } if(k & 8) { model->vertex[l].x = (model->voxel[i].x + x + 1) * w; model->vertex[l].y = (model->voxel[i].y + y) * w; model->vertex[l].z = (model->voxel[i].z + z + 1) * w; l++; } if(k & 16) { model->vertex[l].x = (model->voxel[i].x + x) * w; model->vertex[l].y = (model->voxel[i].y + y + 1) * w; model->vertex[l].z = (model->voxel[i].z + z) * w; l++; } if(k & 32) { model->vertex[l].x = (model->voxel[i].x + x + 1) * w; model->vertex[l].y = (model->voxel[i].y + y + 1) * w; model->vertex[l].z = (model->voxel[i].z + z) * w; l++; } if(k & 64) { model->vertex[l].x = (model->voxel[i].x + x) * w; model->vertex[l].y = (model->voxel[i].y + y + 1) * w; model->vertex[l].z = (model->voxel[i].z + z + 1) * w; l++; } if(k & 128) { model->vertex[l].x = (model->voxel[i].x + x + 1) * w; model->vertex[l].y = (model->voxel[i].y + y + 1) * w; model->vertex[l].z = (model->voxel[i].z + z + 1) * w; l++; } n <<= 1; l = model->numface; model->numface += n; model->face = (m3df_t*)M3D_REALLOC(model->face, model->numface * sizeof(m3df_t)); if(!model->face) goto memerr; memset(&model->face[l], 255, n * sizeof(m3df_t)); for(reclen = l; reclen < model->numface; reclen++) model->face[reclen].materialid = model->voxtype[model->voxel[i].data[j]].materialid; if(am & 1) { /* bottom */ model->face[l].vertex[0] = edge[0]; model->face[l].vertex[1] = edge[1]; model->face[l].vertex[2] = edge[2]; model->face[l+1].vertex[0] = edge[2]; model->face[l+1].vertex[1] = edge[1]; model->face[l+1].vertex[2] = edge[3]; model->face[l].normal[0] = model->face[l].normal[1] = model->face[l].normal[2] = model->face[l+1].normal[0] = model->face[l+1].normal[1] = model->face[l+1].normal[2] = enorm; l += 2; } if(am & 2) { /* north */ model->face[l].vertex[0] = edge[0]; model->face[l].vertex[1] = edge[4]; model->face[l].vertex[2] = edge[1]; model->face[l+1].vertex[0] = edge[1]; model->face[l+1].vertex[1] = edge[4]; model->face[l+1].vertex[2] = edge[5]; model->face[l].normal[0] = model->face[l].normal[1] = model->face[l].normal[2] = model->face[l+1].normal[0] = model->face[l+1].normal[1] = model->face[l+1].normal[2] = enorm+1; l += 2; } if(am & 4) { /* west */ model->face[l].vertex[0] = edge[0]; model->face[l].vertex[1] = edge[2]; model->face[l].vertex[2] = edge[4]; model->face[l+1].vertex[0] = edge[2]; model->face[l+1].vertex[1] = edge[6]; model->face[l+1].vertex[2] = edge[4]; model->face[l].normal[0] = model->face[l].normal[1] = model->face[l].normal[2] = model->face[l+1].normal[0] = model->face[l+1].normal[1] = model->face[l+1].normal[2] = enorm+2; l += 2; } if(am & 8) { /* top */ model->face[l].vertex[0] = edge[4]; model->face[l].vertex[1] = edge[6]; model->face[l].vertex[2] = edge[5]; model->face[l+1].vertex[0] = edge[5]; model->face[l+1].vertex[1] = edge[6]; model->face[l+1].vertex[2] = edge[7]; model->face[l].normal[0] = model->face[l].normal[1] = model->face[l].normal[2] = model->face[l+1].normal[0] = model->face[l+1].normal[1] = model->face[l+1].normal[2] = enorm+3; l += 2; } if(am & 16) { /* south */ model->face[l].vertex[0] = edge[2]; model->face[l].vertex[1] = edge[7]; model->face[l].vertex[2] = edge[6]; model->face[l+1].vertex[0] = edge[7]; model->face[l+1].vertex[1] = edge[2]; model->face[l+1].vertex[2] = edge[3]; model->face[l].normal[0] = model->face[l].normal[1] = model->face[l].normal[2] = model->face[l+1].normal[0] = model->face[l+1].normal[1] = model->face[l+1].normal[2] = enorm+4; l += 2; } if(am & 32) { /* east */ model->face[l].vertex[0] = edge[1]; model->face[l].vertex[1] = edge[5]; model->face[l].vertex[2] = edge[7]; model->face[l+1].vertex[0] = edge[1]; model->face[l+1].vertex[1] = edge[7]; model->face[l+1].vertex[2] = edge[3]; model->face[l].normal[0] = model->face[l].normal[1] = model->face[l].normal[2] = model->face[l+1].normal[0] = model->face[l+1].normal[1] = model->face[l+1].normal[2] = enorm+5; l += 2; } } } } } #endif #ifndef M3D_NONORMALS if(model->numface && model->face && neednorm) { /* if they are missing, calculate triangle normals into a temporary buffer */ norm = (m3dv_t*)M3D_MALLOC(model->numface * sizeof(m3dv_t)); if(!norm) goto memerr; for(i = 0, n = model->numvertex; i < model->numface; i++) if(model->face[i].normal[0] == M3D_UNDEF) { v0 = &model->vertex[model->face[i].vertex[0]]; v1 = &model->vertex[model->face[i].vertex[1]]; v2 = &model->vertex[model->face[i].vertex[2]]; va.x = v1->x - v0->x; va.y = v1->y - v0->y; va.z = v1->z - v0->z; vb.x = v2->x - v0->x; vb.y = v2->y - v0->y; vb.z = v2->z - v0->z; v0 = &norm[i]; v0->x = (va.y * vb.z) - (va.z * vb.y); v0->y = (va.z * vb.x) - (va.x * vb.z); v0->z = (va.x * vb.y) - (va.y * vb.x); w = _m3d_rsq((v0->x * v0->x) + (v0->y * v0->y) + (v0->z * v0->z)); v0->x *= w; v0->y *= w; v0->z *= w; model->face[i].normal[0] = model->face[i].vertex[0] + n; model->face[i].normal[1] = model->face[i].vertex[1] + n; model->face[i].normal[2] = model->face[i].vertex[2] + n; } /* this is the fast way, we don't care if a normal is repeated in model->vertex */ M3D_LOG("Generating normals"); model->flags |= M3D_FLG_GENNORM; model->numvertex <<= 1; model->vertex = (m3dv_t*)M3D_REALLOC(model->vertex, model->numvertex * sizeof(m3dv_t)); if(!model->vertex) goto memerr; memset(&model->vertex[n], 0, n * sizeof(m3dv_t)); for(i = 0; i < model->numface; i++) for(j = 0; j < 3; j++) { v0 = &model->vertex[model->face[i].vertex[j] + n]; v0->x += norm[i].x; v0->y += norm[i].y; v0->z += norm[i].z; } /* for each vertex, take the average of the temporary normals and use that */ for(i = 0, v0 = &model->vertex[n]; i < n; i++, v0++) { w = _m3d_rsq((v0->x * v0->x) + (v0->y * v0->y) + (v0->z * v0->z)); v0->x *= w; v0->y *= w; v0->z *= w; v0->skinid = M3D_UNDEF; } M3D_FREE(norm); } #endif if(model->numbone && model->bone && model->numskin && model->skin && model->numvertex && model->vertex) { #ifndef M3D_NOWEIGHTS M3D_LOG("Generating weight cross-reference"); for(i = 0; i < model->numvertex; i++) { if(model->vertex[i].skinid < model->numskin) { sk = &model->skin[model->vertex[i].skinid]; w = (M3D_FLOAT)0.0; for(j = 0; j < M3D_NUMBONE && sk->boneid[j] != M3D_UNDEF && sk->weight[j] > (M3D_FLOAT)0.0; j++) w += sk->weight[j]; for(j = 0; j < M3D_NUMBONE && sk->boneid[j] != M3D_UNDEF && sk->weight[j] > (M3D_FLOAT)0.0; j++) { sk->weight[j] /= w; b = &model->bone[sk->boneid[j]]; k = b->numweight++; b->weight = (m3dw_t*)M3D_REALLOC(b->weight, b->numweight * sizeof(m3da_t)); if(!b->weight) goto memerr; b->weight[k].vertexid = i; b->weight[k].weight = sk->weight[j]; } } } #endif #ifndef M3D_NOANIMATION M3D_LOG("Calculating bone transformation matrices"); for(i = 0; i < model->numbone; i++) { b = &model->bone[i]; if(model->bone[i].parent == M3D_UNDEF) { _m3d_mat((M3D_FLOAT*)&b->mat4, &model->vertex[b->pos], &model->vertex[b->ori]); } else { _m3d_mat((M3D_FLOAT*)&r, &model->vertex[b->pos], &model->vertex[b->ori]); _m3d_mul((M3D_FLOAT*)&b->mat4, (M3D_FLOAT*)&model->bone[b->parent].mat4, (M3D_FLOAT*)&r); } } for(i = 0; i < model->numbone; i++) _m3d_inv((M3D_FLOAT*)&model->bone[i].mat4); #endif } #ifdef M3D_PROFILING gettimeofday(&tv0, NULL); tvd.tv_sec = tv0.tv_sec - tv1.tv_sec; tvd.tv_usec = tv0.tv_usec - tv1.tv_usec; if(tvd.tv_usec < 0) { tvd.tv_sec--; tvd.tv_usec += 1000000L; } printf(" Post-process %ld.%06ld sec\n", tvd.tv_sec, tvd.tv_usec); #endif } return model; } /** * Calculates skeletons for animation frames, returns a working copy (should be freed after use) */ m3dtr_t *m3d_frame(m3d_t *model, M3D_INDEX actionid, M3D_INDEX frameid, m3dtr_t *skeleton) { unsigned int i; M3D_INDEX s = frameid; m3dfr_t *fr; if(!model || !model->numbone || !model->bone || (actionid != M3D_UNDEF && (!model->action || actionid >= model->numaction || frameid >= model->action[actionid].numframe))) { model->errcode = M3D_ERR_UNKFRAME; return skeleton; } model->errcode = M3D_SUCCESS; if(!skeleton) { skeleton = (m3dtr_t*)M3D_MALLOC(model->numbone * sizeof(m3dtr_t)); if(!skeleton) { model->errcode = M3D_ERR_ALLOC; return NULL; } goto gen; } if(actionid == M3D_UNDEF || !frameid) { gen: s = 0; for(i = 0; i < model->numbone; i++) { skeleton[i].boneid = i; skeleton[i].pos = model->bone[i].pos; skeleton[i].ori = model->bone[i].ori; } } if(actionid < model->numaction && (frameid || !model->action[actionid].frame[0].msec)) { for(; s <= frameid; s++) { fr = &model->action[actionid].frame[s]; for(i = 0; i < fr->numtransform; i++) { skeleton[fr->transform[i].boneid].pos = fr->transform[i].pos; skeleton[fr->transform[i].boneid].ori = fr->transform[i].ori; } } } return skeleton; } #ifndef M3D_NOANIMATION /** * Returns interpolated animation-pose, a working copy (should be freed after use) */ m3db_t *m3d_pose(m3d_t *model, M3D_INDEX actionid, uint32_t msec) { unsigned int i, j, l; M3D_FLOAT r[16], t, c, d, s; m3db_t *ret; m3dv_t *v, *p, *f; m3dtr_t *tmp; m3dfr_t *fr; if(!model || !model->numbone || !model->bone) { model->errcode = M3D_ERR_UNKFRAME; return NULL; } ret = (m3db_t*)M3D_MALLOC(model->numbone * sizeof(m3db_t)); if(!ret) { model->errcode = M3D_ERR_ALLOC; return NULL; } memcpy(ret, model->bone, model->numbone * sizeof(m3db_t)); for(i = 0; i < model->numbone; i++) _m3d_inv((M3D_FLOAT*)&ret[i].mat4); if(!model->action || actionid >= model->numaction) { model->errcode = M3D_ERR_UNKFRAME; return ret; } msec %= model->action[actionid].durationmsec; model->errcode = M3D_SUCCESS; fr = &model->action[actionid].frame[0]; for(j = l = 0; j < model->action[actionid].numframe && model->action[actionid].frame[j].msec <= msec; j++) { fr = &model->action[actionid].frame[j]; l = fr->msec; for(i = 0; i < fr->numtransform; i++) { ret[fr->transform[i].boneid].pos = fr->transform[i].pos; ret[fr->transform[i].boneid].ori = fr->transform[i].ori; } } if(l != msec) { model->vertex = (m3dv_t*)M3D_REALLOC(model->vertex, (model->numvertex + 2 * model->numbone) * sizeof(m3dv_t)); if(!model->vertex) { free(ret); model->errcode = M3D_ERR_ALLOC; return NULL; } tmp = (m3dtr_t*)M3D_MALLOC(model->numbone * sizeof(m3dtr_t)); if(tmp) { for(i = 0; i < model->numbone; i++) { tmp[i].pos = ret[i].pos; tmp[i].ori = ret[i].ori; } fr = &model->action[actionid].frame[j % model->action[actionid].numframe]; t = l >= fr->msec ? (M3D_FLOAT)1.0 : (M3D_FLOAT)(msec - l) / (M3D_FLOAT)(fr->msec - l); for(i = 0; i < fr->numtransform; i++) { tmp[fr->transform[i].boneid].pos = fr->transform[i].pos; tmp[fr->transform[i].boneid].ori = fr->transform[i].ori; } for(i = 0, j = model->numvertex; i < model->numbone; i++) { /* interpolation of position */ if(ret[i].pos != tmp[i].pos) { p = &model->vertex[ret[i].pos]; f = &model->vertex[tmp[i].pos]; v = &model->vertex[j]; v->x = p->x + t * (f->x - p->x); v->y = p->y + t * (f->y - p->y); v->z = p->z + t * (f->z - p->z); ret[i].pos = j++; } /* interpolation of orientation */ if(ret[i].ori != tmp[i].ori) { p = &model->vertex[ret[i].ori]; f = &model->vertex[tmp[i].ori]; v = &model->vertex[j]; d = p->w * f->w + p->x * f->x + p->y * f->y + p->z * f->z; if(d < 0) { d = -d; s = (M3D_FLOAT)-1.0; } else s = (M3D_FLOAT)1.0; #if 0 /* don't use SLERP, requires two more variables, libm linkage and it is slow (but nice) */ a = (M3D_FLOAT)1.0 - t; b = t; if(d < (M3D_FLOAT)0.999999) { c = acosf(d); b = 1 / sinf(c); a = sinf(a * c) * b; b *= sinf(t * c) * s; } v->x = p->x * a + f->x * b; v->y = p->y * a + f->y * b; v->z = p->z * a + f->z * b; v->w = p->w * a + f->w * b; #else /* approximated NLERP, original approximation by Arseny Kapoulkine, heavily optimized by me */ c = t - (M3D_FLOAT)0.5; t += t * c * (t - (M3D_FLOAT)1.0) * (((M3D_FLOAT)1.0904 + d * ((M3D_FLOAT)-3.2452 + d * ((M3D_FLOAT)3.55645 - d * (M3D_FLOAT)1.43519))) * c * c + ((M3D_FLOAT)0.848013 + d * ((M3D_FLOAT)-1.06021 + d * (M3D_FLOAT)0.215638))); v->x = p->x + t * (s * f->x - p->x); v->y = p->y + t * (s * f->y - p->y); v->z = p->z + t * (s * f->z - p->z); v->w = p->w + t * (s * f->w - p->w); d = _m3d_rsq(v->w * v->w + v->x * v->x + v->y * v->y + v->z * v->z); v->x *= d; v->y *= d; v->z *= d; v->w *= d; #endif ret[i].ori = j++; } } M3D_FREE(tmp); } } for(i = 0; i < model->numbone; i++) { if(ret[i].parent == M3D_UNDEF) { _m3d_mat((M3D_FLOAT*)&ret[i].mat4, &model->vertex[ret[i].pos], &model->vertex[ret[i].ori]); } else { _m3d_mat((M3D_FLOAT*)&r, &model->vertex[ret[i].pos], &model->vertex[ret[i].ori]); _m3d_mul((M3D_FLOAT*)&ret[i].mat4, (M3D_FLOAT*)&ret[ret[i].parent].mat4, (M3D_FLOAT*)&r); } } return ret; } #endif /* M3D_NOANIMATION */ #endif /* M3D_IMPLEMENTATION */ #if !defined(M3D_NODUP) && (!defined(M3D_NOIMPORTER) || defined(M3D_EXPORTER)) /** * Free the in-memory model */ void m3d_free(m3d_t *model) { unsigned int i, j; if(!model) return; #ifdef M3D_ASCII /* if model imported from ASCII, we have to free all strings as well */ if(model->flags & M3D_FLG_FREESTR) { if(model->name) M3D_FREE(model->name); if(model->license) M3D_FREE(model->license); if(model->author) M3D_FREE(model->author); if(model->desc) M3D_FREE(model->desc); if(model->bone) for(i = 0; i < model->numbone; i++) if(model->bone[i].name) M3D_FREE(model->bone[i].name); if(model->shape) for(i = 0; i < model->numshape; i++) if(model->shape[i].name) M3D_FREE(model->shape[i].name); if(model->numvoxtype) for(i = 0; i < model->numvoxtype; i++) { if(model->voxtype[i].name) M3D_FREE(model->voxtype[i].name); for(j = 0; j < model->voxtype[i].numitem; j++) if(model->voxtype[i].item[j].name) M3D_FREE(model->voxtype[i].item[j].name); } if(model->numvoxel) for(i = 0; i < model->numvoxel; i++) if(model->voxel[i].name) M3D_FREE(model->voxel[i].name); if(model->material) for(i = 0; i < model->nummaterial; i++) if(model->material[i].name) M3D_FREE(model->material[i].name); if(model->action) for(i = 0; i < model->numaction; i++) if(model->action[i].name) M3D_FREE(model->action[i].name); if(model->texture) for(i = 0; i < model->numtexture; i++) if(model->texture[i].name) M3D_FREE(model->texture[i].name); if(model->inlined) for(i = 0; i < model->numinlined; i++) { if(model->inlined[i].name) M3D_FREE(model->inlined[i].name); if(model->inlined[i].data) M3D_FREE(model->inlined[i].data); } if(model->extra) for(i = 0; i < model->numextra; i++) if(model->extra[i]) M3D_FREE(model->extra[i]); if(model->label) for(i = 0; i < model->numlabel; i++) { if(model->label[i].name) { for(j = i + 1; j < model->numlabel; j++) if(model->label[j].name == model->label[i].name) model->label[j].name = NULL; M3D_FREE(model->label[i].name); } if(model->label[i].lang) { for(j = i + 1; j < model->numlabel; j++) if(model->label[j].lang == model->label[i].lang) model->label[j].lang = NULL; M3D_FREE(model->label[i].lang); } if(model->label[i].text) M3D_FREE(model->label[i].text); } if(model->preview.data) M3D_FREE(model->preview.data); } #endif if(model->flags & M3D_FLG_FREERAW) M3D_FREE(model->raw); if(model->tmap) M3D_FREE(model->tmap); if(model->bone) { for(i = 0; i < model->numbone; i++) if(model->bone[i].weight) M3D_FREE(model->bone[i].weight); M3D_FREE(model->bone); } if(model->skin) M3D_FREE(model->skin); if(model->vertex) M3D_FREE(model->vertex); if(model->face) M3D_FREE(model->face); if(model->voxtype) { for(i = 0; i < model->numvoxtype; i++) if(model->voxtype[i].item) M3D_FREE(model->voxtype[i].item); M3D_FREE(model->voxtype); } if(model->voxel) { for(i = 0; i < model->numvoxel; i++) if(model->voxel[i].data) M3D_FREE(model->voxel[i].data); M3D_FREE(model->voxel); } if(model->shape) { for(i = 0; i < model->numshape; i++) { if(model->shape[i].cmd) { for(j = 0; j < model->shape[i].numcmd; j++) if(model->shape[i].cmd[j].arg) M3D_FREE(model->shape[i].cmd[j].arg); M3D_FREE(model->shape[i].cmd); } } M3D_FREE(model->shape); } if(model->material && !(model->flags & M3D_FLG_MTLLIB)) { for(i = 0; i < model->nummaterial; i++) if(model->material[i].prop) M3D_FREE(model->material[i].prop); M3D_FREE(model->material); } if(model->texture) { for(i = 0; i < model->numtexture; i++) if(model->texture[i].d) M3D_FREE(model->texture[i].d); M3D_FREE(model->texture); } if(model->action) { for(i = 0; i < model->numaction; i++) { if(model->action[i].frame) { for(j = 0; j < model->action[i].numframe; j++) if(model->action[i].frame[j].transform) M3D_FREE(model->action[i].frame[j].transform); M3D_FREE(model->action[i].frame); } } M3D_FREE(model->action); } if(model->label) M3D_FREE(model->label); if(model->inlined) M3D_FREE(model->inlined); if(model->extra) M3D_FREE(model->extra); free(model); } #endif #ifdef M3D_EXPORTER typedef struct { char *str; uint32_t offs; } m3dstr_t; typedef struct { m3dti_t data; M3D_INDEX oldidx; M3D_INDEX newidx; } m3dtisave_t; typedef struct { m3dv_t data; M3D_INDEX oldidx; M3D_INDEX newidx; unsigned char norm; } m3dvsave_t; typedef struct { m3ds_t data; M3D_INDEX oldidx; M3D_INDEX newidx; } m3dssave_t; typedef struct { m3df_t data; int group; uint8_t opacity; } m3dfsave_t; /* create unique list of strings */ static m3dstr_t *_m3d_addstr(m3dstr_t *str, uint32_t *numstr, char *s) { uint32_t i; if(!s || !*s) return str; if(str) { for(i = 0; i < *numstr; i++) if(str[i].str == s || !strcmp(str[i].str, s)) return str; } str = (m3dstr_t*)M3D_REALLOC(str, ((*numstr) + 1) * sizeof(m3dstr_t)); str[*numstr].str = s; str[*numstr].offs = 0; (*numstr)++; return str; } /* add strings to header */ m3dhdr_t *_m3d_addhdr(m3dhdr_t *h, m3dstr_t *s) { int i; char *safe = _m3d_safestr(s->str, 0); i = (int)strlen(safe); h = (m3dhdr_t*)M3D_REALLOC(h, h->length + i+1); if(!h) { M3D_FREE(safe); return NULL; } memcpy((uint8_t*)h + h->length, safe, i+1); s->offs = h->length - 16; h->length += i+1; M3D_FREE(safe); return h; } /* return offset of string */ static uint32_t _m3d_stridx(m3dstr_t *str, uint32_t numstr, char *s) { uint32_t i; char *safe; if(!s || !*s) return 0; if(str) { safe = _m3d_safestr(s, 0); if(!safe) return 0; if(!*safe) { free(safe); return 0; } for(i = 0; i < numstr; i++) if(!strcmp(str[i].str, s)) { free(safe); return str[i].offs; } free(safe); } return 0; } /* compare to faces by their material */ static int _m3d_facecmp(const void *a, const void *b) { const m3dfsave_t *A = (const m3dfsave_t*)a, *B = (const m3dfsave_t*)b; return A->group != B->group ? A->group - B->group : (A->opacity != B->opacity ? (int)B->opacity - (int)A->opacity : (int)A->data.materialid - (int)B->data.materialid); } /* compare face groups */ static int _m3d_grpcmp(const void *a, const void *b) { return *((uint32_t*)a) - *((uint32_t*)b); } /* compare UVs */ static int _m3d_ticmp(const void *a, const void *b) { return memcmp(a, b, sizeof(m3dti_t)); } /* compare skin groups */ static int _m3d_skincmp(const void *a, const void *b) { return memcmp(a, b, sizeof(m3ds_t)); } /* compare vertices */ static int _m3d_vrtxcmp(const void *a, const void *b) { int c = memcmp(a, b, 3 * sizeof(M3D_FLOAT)); if(c) return c; c = ((m3dvsave_t*)a)->norm - ((m3dvsave_t*)b)->norm; if(c) return c; return memcmp(a, b, sizeof(m3dv_t)); } /* compare labels */ static _inline int _m3d_strcmp(char *a, char *b) { if(a == NULL && b != NULL) return -1; if(a != NULL && b == NULL) return 1; if(a == NULL && b == NULL) return 0; return strcmp(a, b); } static int _m3d_lblcmp(const void *a, const void *b) { const m3dl_t *A = (const m3dl_t*)a, *B = (const m3dl_t*)b; int c = _m3d_strcmp(A->lang, B->lang); if(!c) c = _m3d_strcmp(A->name, B->name); if(!c) c = _m3d_strcmp(A->text, B->text); return c; } /* compare two colors by HSV value */ _inline static int _m3d_cmapcmp(const void *a, const void *b) { uint8_t *A = (uint8_t*)a, *B = (uint8_t*)b; _register int m, vA, vB; /* get HSV value for A */ m = A[2] < A[1]? A[2] : A[1]; if(A[0] < m) m = A[0]; vA = A[2] > A[1]? A[2] : A[1]; if(A[0] > vA) vA = A[0]; /* get HSV value for B */ m = B[2] < B[1]? B[2] : B[1]; if(B[0] < m) m = B[0]; vB = B[2] > B[1]? B[2] : B[1]; if(B[0] > vB) vB = B[0]; return vA - vB; } /* create sorted list of colors */ static uint32_t *_m3d_addcmap(uint32_t *cmap, uint32_t *numcmap, uint32_t color) { uint32_t i; if(cmap) { for(i = 0; i < *numcmap; i++) if(cmap[i] == color) return cmap; } cmap = (uint32_t*)M3D_REALLOC(cmap, ((*numcmap) + 1) * sizeof(uint32_t)); for(i = 0; i < *numcmap && _m3d_cmapcmp(&color, &cmap[i]) > 0; i++); if(i < *numcmap) memmove(&cmap[i+1], &cmap[i], ((*numcmap) - i)*sizeof(uint32_t)); cmap[i] = color; (*numcmap)++; return cmap; } /* look up a color and return its index */ static uint32_t _m3d_cmapidx(uint32_t *cmap, uint32_t numcmap, uint32_t color) { uint32_t i; if(numcmap >= 65536) return color; for(i = 0; i < numcmap; i++) if(cmap[i] == color) return i; return 0; } /* add index to output */ static unsigned char *_m3d_addidx(unsigned char *out, char type, uint32_t idx) { switch(type) { case 1: *out++ = (uint8_t)(idx); break; case 2: *((uint16_t*)out) = (uint16_t)(idx); out += 2; break; case 4: *((uint32_t*)out) = (uint32_t)(idx); out += 4; break; /* case 0: case 8: break; */ } return out; } /* round a vertex position */ static void _m3d_round(int quality, m3dv_t *src, m3dv_t *dst) { _register int t; /* copy additional attributes */ if(src != dst) memcpy(dst, src, sizeof(m3dv_t)); /* round according to quality */ switch(quality) { case M3D_EXP_INT8: t = (int)(src->x * 127 + (src->x >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); dst->x = (M3D_FLOAT)t / (M3D_FLOAT)127.0; t = (int)(src->y * 127 + (src->y >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); dst->y = (M3D_FLOAT)t / (M3D_FLOAT)127.0; t = (int)(src->z * 127 + (src->z >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); dst->z = (M3D_FLOAT)t / (M3D_FLOAT)127.0; t = (int)(src->w * 127 + (src->w >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); dst->w = (M3D_FLOAT)t / (M3D_FLOAT)127.0; break; case M3D_EXP_INT16: t = (int)(src->x * 32767 + (src->x >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); dst->x = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; t = (int)(src->y * 32767 + (src->y >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); dst->y = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; t = (int)(src->z * 32767 + (src->z >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); dst->z = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; t = (int)(src->w * 32767 + (src->w >= 0 ? (M3D_FLOAT)0.5 : (M3D_FLOAT)-0.5)); dst->w = (M3D_FLOAT)t / (M3D_FLOAT)32767.0; break; } if(dst->x == (M3D_FLOAT)-0.0) dst->x = (M3D_FLOAT)0.0; if(dst->y == (M3D_FLOAT)-0.0) dst->y = (M3D_FLOAT)0.0; if(dst->z == (M3D_FLOAT)-0.0) dst->z = (M3D_FLOAT)0.0; if(dst->w == (M3D_FLOAT)-0.0) dst->w = (M3D_FLOAT)0.0; } #ifdef M3D_ASCII /* add a bone to ascii output */ static char *_m3d_prtbone(char *ptr, m3db_t *bone, M3D_INDEX numbone, M3D_INDEX parent, uint32_t level, M3D_INDEX *vrtxidx) { uint32_t i, j; char *sn; if(level > M3D_BONEMAXLEVEL || !bone) return ptr; for(i = 0; i < numbone; i++) { if(bone[i].parent == parent) { for(j = 0; j < level; j++) *ptr++ = '/'; sn = _m3d_safestr(bone[i].name, 0); ptr += sprintf(ptr, "%d %d %s\r\n", vrtxidx[bone[i].pos], vrtxidx[bone[i].ori], sn); M3D_FREE(sn); ptr = _m3d_prtbone(ptr, bone, numbone, i, level + 1, vrtxidx); } } return ptr; } #endif /** * Function to encode an in-memory model into on storage Model 3D format */ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size) { #ifdef M3D_ASCII const char *ol; char *ptr; #endif char vc_s, vi_s, si_s, ci_s, ti_s, bi_s, nb_s, sk_s, fc_s, hi_s, fi_s, vd_s, vp_s; char *sn = NULL, *sl = NULL, *sa = NULL, *sd = NULL; unsigned char *out = NULL, *z = NULL, weights[M3D_NUMBONE < 8 ? 8 : M3D_NUMBONE], *norm = NULL; unsigned int i, j, k, l, n, o, len, chunklen, *length; int maxvox = 0, minvox = 0; M3D_FLOAT scale = (M3D_FLOAT)0.0, min_x, max_x, min_y, max_y, min_z, max_z; M3D_INDEX last, *vrtxidx = NULL, *mtrlidx = NULL, *tmapidx = NULL, *skinidx = NULL; #ifdef M3D_VERTEXMAX M3D_INDEX lastp; #endif uint32_t idx, numcmap = 0, *cmap = NULL, numvrtx = 0, maxvrtx = 0, numtmap = 0, maxtmap = 0, numproc = 0; uint32_t numskin = 0, maxskin = 0, numstr = 0, maxt = 0, maxbone = 0, numgrp = 0, maxgrp = 0, *grpidx = NULL; uint8_t *opa; m3dcd_t *cd; m3dc_t *cmd; m3dstr_t *str = NULL; m3dvsave_t *vrtx = NULL, vertex; m3dtisave_t *tmap = NULL, tcoord; m3dssave_t *skin = NULL, sk; m3dfsave_t *face = NULL; m3dhdr_t *h = NULL; m3dm_t *m; m3da_t *a; if(!model) { if(size) *size = 0; return NULL; } model->errcode = M3D_SUCCESS; #ifdef M3D_ASCII if(flags & M3D_EXP_ASCII) quality = M3D_EXP_DOUBLE; #endif vrtxidx = (M3D_INDEX*)M3D_MALLOC(model->numvertex * sizeof(M3D_INDEX)); if(!vrtxidx) goto memerr; memset(vrtxidx, 255, model->numvertex * sizeof(M3D_INDEX)); if(model->numvertex && !(flags & M3D_EXP_NONORMAL)){ norm = (unsigned char*)M3D_MALLOC(model->numvertex * sizeof(unsigned char)); if(!norm) goto memerr; memset(norm, 0, model->numvertex * sizeof(unsigned char)); } if(model->nummaterial && !(flags & M3D_EXP_NOMATERIAL)) { mtrlidx = (M3D_INDEX*)M3D_MALLOC(model->nummaterial * sizeof(M3D_INDEX)); if(!mtrlidx) goto memerr; memset(mtrlidx, 255, model->nummaterial * sizeof(M3D_INDEX)); opa = (uint8_t*)M3D_MALLOC(model->nummaterial * 2 * sizeof(M3D_INDEX)); if(!opa) goto memerr; memset(opa, 255, model->nummaterial * 2 * sizeof(M3D_INDEX)); } if(model->numtmap && !(flags & M3D_EXP_NOTXTCRD)) { tmapidx = (M3D_INDEX*)M3D_MALLOC(model->numtmap * sizeof(M3D_INDEX)); if(!tmapidx) goto memerr; memset(tmapidx, 255, model->numtmap * sizeof(M3D_INDEX)); } /** collect array elements that are actually referenced **/ if(!(flags & M3D_EXP_NOFACE)) { /* face */ if(model->numface && model->face) { M3D_LOG("Processing mesh face"); face = (m3dfsave_t*)M3D_MALLOC(model->numface * sizeof(m3dfsave_t)); if(!face) goto memerr; for(i = 0; i < model->numface; i++) { memcpy(&face[i].data, &model->face[i], sizeof(m3df_t)); face[i].group = 0; face[i].opacity = 255; if(!(flags & M3D_EXP_NOMATERIAL) && model->face[i].materialid < model->nummaterial) { if(model->material[model->face[i].materialid].numprop) { mtrlidx[model->face[i].materialid] = 0; if(opa[model->face[i].materialid * 2]) { m = &model->material[model->face[i].materialid]; for(j = 0; j < m->numprop; j++) if(m->prop[j].type == m3dp_Kd) { opa[model->face[i].materialid * 2 + 1] = ((uint8_t*)&m->prop[j].value.color)[3]; break; } for(j = 0; j < m->numprop; j++) if(m->prop[j].type == m3dp_d) { opa[model->face[i].materialid * 2 + 1] = (uint8_t)(m->prop[j].value.fnum * 255); break; } opa[model->face[i].materialid * 2] = 0; } face[i].opacity = opa[model->face[i].materialid * 2 + 1]; } else face[i].data.materialid = M3D_UNDEF; } for(j = 0; j < 3; j++) { k = model->face[i].vertex[j]; if(k < model->numvertex) vrtxidx[k] = 0; if(!(flags & M3D_EXP_NOCMAP)) { cmap = _m3d_addcmap(cmap, &numcmap, model->vertex[k].color); if(!cmap) goto memerr; } k = model->face[i].normal[j]; if(k < model->numvertex && !(flags & M3D_EXP_NONORMAL)) { vrtxidx[k] = 0; norm[k] = 1; } k = model->face[i].texcoord[j]; if(k < model->numtmap && !(flags & M3D_EXP_NOTXTCRD)) tmapidx[k] = 0; #ifdef M3D_VERTEXMAX k = model->face[i].vertmax[j]; if(k < model->numvertex && !(flags & M3D_EXP_NOVRTMAX)) vrtxidx[k] = 0; #endif } /* convert from CW to CCW */ if(flags & M3D_EXP_IDOSUCK) { j = face[i].data.vertex[1]; face[i].data.vertex[1] = face[i].data.vertex[2]; face[i].data.vertex[2] = j; j = face[i].data.normal[1]; face[i].data.normal[1] = face[i].data.normal[2]; face[i].data.normal[2] = j; j = face[i].data.texcoord[1]; face[i].data.texcoord[1] = face[i].data.texcoord[2]; face[i].data.texcoord[2] = j; #ifdef M3D_VERTEXMAX j = face[i].data.vertmax[1]; face[i].data.vertmax[1] = face[i].data.vertmax[2]; face[i].data.vertmax[2] = j; #endif } } } if((model->numvoxtype && model->voxtype) || (model->numvoxel && model->voxel)) { M3D_LOG("Processing voxel face"); for(i = 0; i < model->numvoxtype; i++) { str = _m3d_addstr(str, &numstr, model->voxtype[i].name); if(model->voxtype[i].name && !str) goto memerr; if(!(flags & M3D_EXP_NOCMAP)) { cmap = _m3d_addcmap(cmap, &numcmap, model->voxtype[i].color); if(!cmap) goto memerr; } for(j = 0; j < model->voxtype[i].numitem; j++) { str = _m3d_addstr(str, &numstr, model->voxtype[i].item[j].name); if(model->voxtype[i].item[j].name && !str) goto memerr; } } for(i = 0; i < model->numvoxel; i++) { str = _m3d_addstr(str, &numstr, model->voxel[i].name); if(model->voxel[i].name && !str) goto memerr; if(model->voxel[i].x < minvox) minvox = model->voxel[i].x; if(model->voxel[i].x + (int)model->voxel[i].w > maxvox) maxvox = model->voxel[i].x + model->voxel[i].w; if(model->voxel[i].y < minvox) minvox = model->voxel[i].y; if(model->voxel[i].y + (int)model->voxel[i].h > maxvox) maxvox = model->voxel[i].y + model->voxel[i].h; if(model->voxel[i].z < minvox) minvox = model->voxel[i].z; if(model->voxel[i].z + (int)model->voxel[i].d > maxvox) maxvox = model->voxel[i].z + model->voxel[i].d; } } if(model->numshape && model->shape) { M3D_LOG("Processing shape face"); for(i = 0; i < model->numshape; i++) { if(!model->shape[i].numcmd) continue; str = _m3d_addstr(str, &numstr, model->shape[i].name); if(model->shape[i].name && !str) goto memerr; for(j = 0; j < model->shape[i].numcmd; j++) { cmd = &model->shape[i].cmd[j]; if(cmd->type >= (unsigned int)(sizeof(m3d_commandtypes)/sizeof(m3d_commandtypes[0])) || !cmd->arg) continue; if(cmd->type == m3dc_mesh) { if(numgrp + 2 < maxgrp) { maxgrp += 1024; grpidx = (uint32_t*)realloc(grpidx, maxgrp * sizeof(uint32_t)); if(!grpidx) goto memerr; if(!numgrp) { grpidx[0] = 0; grpidx[1] = model->numface; numgrp += 2; } } grpidx[numgrp + 0] = cmd->arg[0]; grpidx[numgrp + 1] = cmd->arg[0] + cmd->arg[1]; numgrp += 2; } cd = &m3d_commandtypes[cmd->type]; for(k = n = 0, l = cd->p; k < l; k++) switch(cd->a[((k - n) % (cd->p - n)) + n]) { case m3dcp_mi_t: if(!(flags & M3D_EXP_NOMATERIAL) && cmd->arg[k] < model->nummaterial) mtrlidx[cmd->arg[k]] = 0; break; case m3dcp_ti_t: if(!(flags & M3D_EXP_NOTXTCRD) && cmd->arg[k] < model->numtmap) tmapidx[cmd->arg[k]] = 0; break; case m3dcp_qi_t: case m3dcp_vi_t: if(cmd->arg[k] < model->numvertex) vrtxidx[cmd->arg[k]] = 0; break; case m3dcp_va_t: n = k + 1; l += (cmd->arg[k] - 1) * (cd->p - k - 1); break; } } } } if(model->numface && face) { if(numgrp && grpidx) { qsort(grpidx, numgrp, sizeof(uint32_t), _m3d_grpcmp); for(i = j = 0; i < model->numface && j < numgrp; i++) { while(j < numgrp && grpidx[j] < i) j++; face[i].group = j; } } qsort(face, model->numface, sizeof(m3dfsave_t), _m3d_facecmp); } if(grpidx) { M3D_FREE(grpidx); grpidx = NULL; } if(model->numlabel && model->label) { M3D_LOG("Processing annotation labels"); for(i = 0; i < model->numlabel; i++) { str = _m3d_addstr(str, &numstr, model->label[i].name); str = _m3d_addstr(str, &numstr, model->label[i].lang); str = _m3d_addstr(str, &numstr, model->label[i].text); if(!(flags & M3D_EXP_NOCMAP)) { cmap = _m3d_addcmap(cmap, &numcmap, model->label[i].color); if(!cmap) goto memerr; } if(model->label[i].vertexid < model->numvertex) vrtxidx[model->label[i].vertexid] = 0; } qsort(model->label, model->numlabel, sizeof(m3dl_t), _m3d_lblcmp); } } else if(!(flags & M3D_EXP_NOMATERIAL)) { /* without a face, simply add all materials, because it can be an mtllib */ for(i = 0; i < model->nummaterial; i++) mtrlidx[i] = i; } /* bind-pose skeleton */ if(model->numbone && model->bone && !(flags & M3D_EXP_NOBONE)) { M3D_LOG("Processing bones"); for(i = 0; i < model->numbone; i++) { str = _m3d_addstr(str, &numstr, model->bone[i].name); if(!str) goto memerr; k = model->bone[i].pos; if(k < model->numvertex) vrtxidx[k] = 0; k = model->bone[i].ori; if(k < model->numvertex) vrtxidx[k] = 0; } } /* actions, animated skeleton poses */ if(model->numaction && model->action && !(flags & M3D_EXP_NOACTION)) { M3D_LOG("Processing action list"); for(j = 0; j < model->numaction; j++) { a = &model->action[j]; str = _m3d_addstr(str, &numstr, a->name); if(!str) goto memerr; if(a->numframe > 65535) a->numframe = 65535; for(i = 0; i < a->numframe; i++) { for(l = 0; l < a->frame[i].numtransform; l++) { k = a->frame[i].transform[l].pos; if(k < model->numvertex) vrtxidx[k] = 0; k = a->frame[i].transform[l].ori; if(k < model->numvertex) vrtxidx[k] = 0; } if(l > maxt) maxt = l; } } } /* add colors to color map and texture names to string table */ if(!(flags & M3D_EXP_NOMATERIAL)) { M3D_LOG("Processing materials"); for(i = k = 0; i < model->nummaterial; i++) { if(mtrlidx[i] == M3D_UNDEF || !model->material[i].numprop) continue; mtrlidx[i] = k++; m = &model->material[i]; str = _m3d_addstr(str, &numstr, m->name); if(!str) goto memerr; if(m->prop) for(j = 0; j < m->numprop; j++) { if(!(flags & M3D_EXP_NOCMAP) && m->prop[j].type < 128) { for(l = 0; l < sizeof(m3d_propertytypes)/sizeof(m3d_propertytypes[0]); l++) { if(m->prop[j].type == m3d_propertytypes[l].id && m3d_propertytypes[l].format == m3dpf_color) { ((uint8_t*)&m->prop[j].value.color)[3] = opa[i * 2 + 1]; cmap = _m3d_addcmap(cmap, &numcmap, m->prop[j].value.color); if(!cmap) goto memerr; break; } } } if(m->prop[j].type >= 128 && m->prop[j].value.textureid < model->numtexture && model->texture[m->prop[j].value.textureid].name) { str = _m3d_addstr(str, &numstr, model->texture[m->prop[j].value.textureid].name); if(!str) goto memerr; } } } } /* if there's only one black color, don't store it */ if(numcmap == 1 && cmap && !cmap[0]) numcmap = 0; /** compress lists **/ if(model->numtmap && !(flags & M3D_EXP_NOTXTCRD)) { M3D_LOG("Compressing tmap"); tmap = (m3dtisave_t*)M3D_MALLOC(model->numtmap * sizeof(m3dtisave_t)); if(!tmap) goto memerr; for(i = 0; i < model->numtmap; i++) { if(tmapidx[i] == M3D_UNDEF) continue; switch(quality) { case M3D_EXP_INT8: l = (unsigned int)(model->tmap[i].u * 255); tcoord.data.u = (M3D_FLOAT)l / (M3D_FLOAT)255.0; l = (unsigned int)(model->tmap[i].v * 255); tcoord.data.v = (M3D_FLOAT)l / (M3D_FLOAT)255.0; break; case M3D_EXP_INT16: l = (unsigned int)(model->tmap[i].u * 65535); tcoord.data.u = (M3D_FLOAT)l / (M3D_FLOAT)65535.0; l = (unsigned int)(model->tmap[i].v * 65535); tcoord.data.v = (M3D_FLOAT)l / (M3D_FLOAT)65535.0; break; default: tcoord.data.u = model->tmap[i].u; tcoord.data.v = model->tmap[i].v; break; } if(flags & M3D_EXP_FLIPTXTCRD) tcoord.data.v = (M3D_FLOAT)1.0 - tcoord.data.v; tcoord.oldidx = i; memcpy(&tmap[numtmap++], &tcoord, sizeof(m3dtisave_t)); } if(numtmap) { qsort(tmap, numtmap, sizeof(m3dtisave_t), _m3d_ticmp); memcpy(&tcoord.data, &tmap[0], sizeof(m3dti_t)); for(i = 0; i < numtmap; i++) { if(memcmp(&tcoord.data, &tmap[i].data, sizeof(m3dti_t))) { memcpy(&tcoord.data, &tmap[i].data, sizeof(m3dti_t)); maxtmap++; } tmap[i].newidx = maxtmap; tmapidx[tmap[i].oldidx] = maxtmap; } maxtmap++; } } if(model->numskin && model->skin && !(flags & M3D_EXP_NOBONE)) { M3D_LOG("Compressing skin"); skinidx = (M3D_INDEX*)M3D_MALLOC(model->numskin * sizeof(M3D_INDEX)); if(!skinidx) goto memerr; skin = (m3dssave_t*)M3D_MALLOC(model->numskin * sizeof(m3dssave_t)); if(!skin) goto memerr; memset(skinidx, 255, model->numskin * sizeof(M3D_INDEX)); for(i = 0; i < model->numvertex; i++) { if(vrtxidx[i] != M3D_UNDEF && model->vertex[i].skinid < model->numskin) skinidx[model->vertex[i].skinid] = 0; } for(i = 0; i < model->numskin; i++) { if(skinidx[i] == M3D_UNDEF) continue; memset(&sk, 0, sizeof(m3dssave_t)); for(j = 0, min_x = (M3D_FLOAT)0.0; j < M3D_NUMBONE && model->skin[i].boneid[j] != M3D_UNDEF && model->skin[i].weight[j] > (M3D_FLOAT)0.0; j++) { sk.data.boneid[j] = model->skin[i].boneid[j]; sk.data.weight[j] = model->skin[i].weight[j]; min_x += sk.data.weight[j]; } if(j > maxbone) maxbone = j; if(min_x != (M3D_FLOAT)1.0 && min_x != (M3D_FLOAT)0.0) for(j = 0; j < M3D_NUMBONE && sk.data.weight[j] > (M3D_FLOAT)0.0; j++) sk.data.weight[j] /= min_x; sk.oldidx = i; memcpy(&skin[numskin++], &sk, sizeof(m3dssave_t)); } if(numskin) { qsort(skin, numskin, sizeof(m3dssave_t), _m3d_skincmp); memcpy(&sk.data, &skin[0].data, sizeof(m3ds_t)); for(i = 0; i < numskin; i++) { if(memcmp(&sk.data, &skin[i].data, sizeof(m3ds_t))) { memcpy(&sk.data, &skin[i].data, sizeof(m3ds_t)); maxskin++; } skin[i].newidx = maxskin; skinidx[skin[i].oldidx] = maxskin; } maxskin++; } } M3D_LOG("Compressing vertex list"); min_x = min_y = min_z = (M3D_FLOAT)1e10; max_x = max_y = max_z = (M3D_FLOAT)-1e10; if(vrtxidx) { vrtx = (m3dvsave_t*)M3D_MALLOC(model->numvertex * sizeof(m3dvsave_t)); if(!vrtx) goto memerr; for(i = numvrtx = 0; i < model->numvertex; i++) { if(vrtxidx[i] == M3D_UNDEF) continue; _m3d_round(quality, &model->vertex[i], &vertex.data); vertex.norm = norm ? norm[i] : 0; if(vertex.data.skinid != M3D_INDEXMAX && !vertex.norm) { vertex.data.skinid = vertex.data.skinid != M3D_UNDEF && skinidx ? skinidx[vertex.data.skinid] : M3D_UNDEF; if(vertex.data.x > max_x) max_x = vertex.data.x; if(vertex.data.x < min_x) min_x = vertex.data.x; if(vertex.data.y > max_y) max_y = vertex.data.y; if(vertex.data.y < min_y) min_y = vertex.data.y; if(vertex.data.z > max_z) max_z = vertex.data.z; if(vertex.data.z < min_z) min_z = vertex.data.z; } #ifdef M3D_VERTEXTYPE vertex.data.type = 0; #endif vertex.oldidx = i; memcpy(&vrtx[numvrtx++], &vertex, sizeof(m3dvsave_t)); } if(numvrtx) { qsort(vrtx, numvrtx, sizeof(m3dvsave_t), _m3d_vrtxcmp); memcpy(&vertex.data, &vrtx[0].data, sizeof(m3dv_t)); for(i = 0; i < numvrtx; i++) { if(memcmp(&vertex.data, &vrtx[i].data, vrtx[i].norm ? 3 * sizeof(M3D_FLOAT) : sizeof(m3dv_t))) { memcpy(&vertex.data, &vrtx[i].data, sizeof(m3dv_t)); maxvrtx++; } vrtx[i].newidx = maxvrtx; vrtxidx[vrtx[i].oldidx] = maxvrtx; } maxvrtx++; } } if(norm) { M3D_FREE(norm); norm = NULL; } /* normalize to bounding cube */ if(numvrtx && !(flags & M3D_EXP_NORECALC)) { M3D_LOG("Normalizing coordinates"); if(min_x < (M3D_FLOAT)0.0) min_x = -min_x; if(max_x < (M3D_FLOAT)0.0) max_x = -max_x; if(min_y < (M3D_FLOAT)0.0) min_y = -min_y; if(max_y < (M3D_FLOAT)0.0) max_y = -max_y; if(min_z < (M3D_FLOAT)0.0) min_z = -min_z; if(max_z < (M3D_FLOAT)0.0) max_z = -max_z; scale = min_x; if(max_x > scale) scale = max_x; if(min_y > scale) scale = min_y; if(max_y > scale) scale = max_y; if(min_z > scale) scale = min_z; if(max_z > scale) scale = max_z; if(scale <= (M3D_FLOAT)0.0) scale = (M3D_FLOAT)1.0; if(scale != (M3D_FLOAT)1.0) { for(i = 0; i < numvrtx; i++) { if(vrtx[i].data.skinid == M3D_INDEXMAX) continue; vrtx[i].data.x /= scale; vrtx[i].data.y /= scale; vrtx[i].data.z /= scale; } } } if(model->scale > (M3D_FLOAT)0.0) scale = model->scale; if(scale <= (M3D_FLOAT)0.0) scale = (M3D_FLOAT)1.0; /* meta info */ sn = _m3d_safestr(model->name && *model->name ? model->name : (char*)"(noname)", 2); sl = _m3d_safestr(model->license ? model->license : (char*)"MIT", 2); sa = _m3d_safestr(model->author ? model->author : getenv("LOGNAME"), 2); if(!sn || !sl || !sa) { memerr: if(vrtxidx) M3D_FREE(vrtxidx); if(mtrlidx) M3D_FREE(mtrlidx); if(tmapidx) M3D_FREE(tmapidx); if(skinidx) M3D_FREE(skinidx); if(grpidx) M3D_FREE(grpidx); if(norm) M3D_FREE(norm); if(face) M3D_FREE(face); if(cmap) M3D_FREE(cmap); if(tmap) M3D_FREE(tmap); if(skin) M3D_FREE(skin); if(str) M3D_FREE(str); if(vrtx) M3D_FREE(vrtx); if(sn) M3D_FREE(sn); if(sl) M3D_FREE(sl); if(sa) M3D_FREE(sa); if(sd) M3D_FREE(sd); if(out) M3D_FREE(out); if(h) M3D_FREE(h); M3D_LOG("Out of memory"); model->errcode = M3D_ERR_ALLOC; return NULL; } M3D_LOG("Serializing model"); #ifdef M3D_ASCII if(flags & M3D_EXP_ASCII) { /* use CRLF to make model creators on Win happy... */ sd = _m3d_safestr(model->desc, 1); if(!sd) goto memerr; ol = setlocale(LC_NUMERIC, NULL); setlocale(LC_NUMERIC, "C"); /* header */ len = 64 + (unsigned int)(strlen(sn) + strlen(sl) + strlen(sa) + strlen(sd)); out = (unsigned char*)M3D_MALLOC(len); if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr = (char*)out; ptr += sprintf(ptr, "3dmodel %g\r\n%s\r\n%s\r\n%s\r\n%s\r\n\r\n", scale, sn, sl, sa, sd); M3D_FREE(sl); M3D_FREE(sa); M3D_FREE(sd); sl = sa = sd = NULL; /* preview chunk */ if(model->preview.data && model->preview.length) { sl = _m3d_safestr(sn, 0); if(sl) { ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)20 + strlen(sl)); out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Preview\r\n%s.png\r\n\r\n", sl); M3D_FREE(sl); sl = NULL; } } M3D_FREE(sn); sn = NULL; /* texture map */ if(numtmap && tmap && !(flags & M3D_EXP_NOTXTCRD) && !(flags & M3D_EXP_NOFACE)) { ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)(maxtmap * 32) + (uintptr_t)12); out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Textmap\r\n"); last = M3D_UNDEF; for(i = 0; i < numtmap; i++) { if(tmap[i].newidx == last) continue; last = tmap[i].newidx; ptr += sprintf(ptr, "%g %g\r\n", tmap[i].data.u, tmap[i].data.v); } ptr += sprintf(ptr, "\r\n"); } /* vertex chunk */ if(numvrtx && vrtx && !(flags & M3D_EXP_NOFACE)) { ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)(maxvrtx * 128) + (uintptr_t)10); out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Vertex\r\n"); last = M3D_UNDEF; for(i = 0; i < numvrtx; i++) { if(vrtx[i].newidx == last) continue; last = vrtx[i].newidx; ptr += sprintf(ptr, "%g %g %g %g", vrtx[i].data.x, vrtx[i].data.y, vrtx[i].data.z, vrtx[i].data.w); if(!(flags & M3D_EXP_NOCMAP) && vrtx[i].data.color) ptr += sprintf(ptr, " #%08x", vrtx[i].data.color); if(!(flags & M3D_EXP_NOBONE) && model->numbone && maxskin && vrtx[i].data.skinid < M3D_INDEXMAX) { if(skin[vrtx[i].data.skinid].data.weight[0] == (M3D_FLOAT)1.0) ptr += sprintf(ptr, " %d", skin[vrtx[i].data.skinid].data.boneid[0]); else for(j = 0; j < M3D_NUMBONE && skin[vrtx[i].data.skinid].data.boneid[j] != M3D_UNDEF && skin[vrtx[i].data.skinid].data.weight[j] > (M3D_FLOAT)0.0; j++) ptr += sprintf(ptr, " %d:%g", skin[vrtx[i].data.skinid].data.boneid[j], skin[vrtx[i].data.skinid].data.weight[j]); } ptr += sprintf(ptr, "\r\n"); } ptr += sprintf(ptr, "\r\n"); } /* bones chunk */ if(model->numbone && model->bone && !(flags & M3D_EXP_NOBONE)) { ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)9); for(i = 0; i < model->numbone; i++) { len += (unsigned int)strlen(model->bone[i].name) + 128; } out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Bones\r\n"); ptr = _m3d_prtbone(ptr, model->bone, model->numbone, M3D_UNDEF, 0, vrtxidx); ptr += sprintf(ptr, "\r\n"); } /* materials */ if(model->nummaterial && !(flags & M3D_EXP_NOMATERIAL)) { for(j = 0; j < model->nummaterial; j++) { if(mtrlidx[j] == M3D_UNDEF || !model->material[j].numprop || !model->material[j].prop) continue; m = &model->material[j]; sn = _m3d_safestr(m->name, 0); if(!sn) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)strlen(sn) + (uintptr_t)12); for(i = 0; i < m->numprop; i++) { if(m->prop[i].type < 128) len += 32; else if(m->prop[i].value.textureid < model->numtexture && model->texture[m->prop[i].value.textureid].name) len += (unsigned int)strlen(model->texture[m->prop[i].value.textureid].name) + 16; } out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Material %s\r\n", sn); M3D_FREE(sn); sn = NULL; for(i = 0; i < m->numprop; i++) { k = 256; if(m->prop[i].type >= 128) { for(l = 0; l < sizeof(m3d_propertytypes)/sizeof(m3d_propertytypes[0]); l++) if(m->prop[i].type == m3d_propertytypes[l].id) { sn = m3d_propertytypes[l].key; break; } if(!sn) for(l = 0; l < sizeof(m3d_propertytypes)/sizeof(m3d_propertytypes[0]); l++) if(m->prop[i].type - 128 == m3d_propertytypes[l].id) { sn = m3d_propertytypes[l].key; break; } k = sn ? m3dpf_map : 256; } else { for(l = 0; l < sizeof(m3d_propertytypes)/sizeof(m3d_propertytypes[0]); l++) if(m->prop[i].type == m3d_propertytypes[l].id) { sn = m3d_propertytypes[l].key; k = m3d_propertytypes[l].format; break; } } switch(k) { case m3dpf_color: ptr += sprintf(ptr, "%s #%08x\r\n", sn, m->prop[i].value.color); break; case m3dpf_uint8: case m3dpf_uint16: case m3dpf_uint32: ptr += sprintf(ptr, "%s %d\r\n", sn, m->prop[i].value.num); break; case m3dpf_float: ptr += sprintf(ptr, "%s %g\r\n", sn, m->prop[i].value.fnum); break; case m3dpf_map: if(m->prop[i].value.textureid < model->numtexture && model->texture[m->prop[i].value.textureid].name) { sl = _m3d_safestr(model->texture[m->prop[i].value.textureid].name, 0); if(!sl) { setlocale(LC_NUMERIC, ol); goto memerr; } if(*sl) ptr += sprintf(ptr, "map_%s %s\r\n", sn, sl); M3D_FREE(sn); M3D_FREE(sl); sl = NULL; } break; } sn = NULL; } ptr += sprintf(ptr, "\r\n"); } } /* procedural face */ if(model->numinlined && model->inlined && !(flags & M3D_EXP_NOFACE)) { /* all inlined assets which are not textures should be procedural surfaces */ for(j = 0; j < model->numinlined; j++) { if(!model->inlined[j].name || !*model->inlined[j].name || !model->inlined[j].length || !model->inlined[j].data || (model->inlined[j].data[1] == 'P' && model->inlined[j].data[2] == 'N' && model->inlined[j].data[3] == 'G')) continue; for(i = k = 0; i < model->numtexture; i++) { if(!strcmp(model->inlined[j].name, model->texture[i].name)) { k = 1; break; } } if(k) continue; sn = _m3d_safestr(model->inlined[j].name, 0); if(!sn) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)strlen(sn) + (uintptr_t)18); out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Procedural\r\n%s\r\n\r\n", sn); M3D_FREE(sn); sn = NULL; } } /* mesh face */ if(model->numface && face && !(flags & M3D_EXP_NOFACE)) { ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)(model->numface * 128) + (uintptr_t)6); last = M3D_UNDEF; #ifdef M3D_VERTEXMAX lastp = M3D_UNDEF; #endif if(!(flags & M3D_EXP_NOMATERIAL)) for(i = 0; i < model->numface; i++) { j = face[i].data.materialid < model->nummaterial ? face[i].data.materialid : M3D_UNDEF; if(j != last) { last = j; if(last < model->nummaterial) len += (unsigned int)strlen(model->material[last].name); len += 6; } #ifdef M3D_VERTEXMAX j = face[i].data.paramid < model->numparam ? face[i].data.paramid : M3D_UNDEF; if(j != lastp) { lastp = j; if(lastp < model->numparam) len += (unsigned int)strlen(model->param[lastp].name); len += 6; } #endif } out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Mesh\r\n"); last = M3D_UNDEF; #ifdef M3D_VERTEXMAX lastp = M3D_UNDEF; #endif for(i = 0; i < model->numface; i++) { j = face[i].data.materialid < model->nummaterial ? face[i].data.materialid : M3D_UNDEF; if(!(flags & M3D_EXP_NOMATERIAL) && j != last) { last = j; if(last < model->nummaterial) { sn = _m3d_safestr(model->material[last].name, 0); if(!sn) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "use %s\r\n", sn); M3D_FREE(sn); sn = NULL; } else ptr += sprintf(ptr, "use\r\n"); } #ifdef M3D_VERTEXMAX j = face[i].data.paramid < model->numparam ? face[i].data.paramid : M3D_UNDEF; if(!(flags & M3D_EXP_NOVRTMAX) && j != lastp) { lastp = j; if(lastp < model->numparam) { sn = _m3d_safestr(model->param[lastp].name, 0); if(!sn) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "par %s\r\n", sn); M3D_FREE(sn); sn = NULL; } else ptr += sprintf(ptr, "par\r\n"); } #endif /* hardcoded triangles. Should be repeated as many times as the number of edges in polygon */ for(j = 0; j < 3; j++) { ptr += sprintf(ptr, "%s%d", j?" ":"", vrtxidx[face[i].data.vertex[j]]); k = l = M3D_NOTDEFINED; if(!(flags & M3D_EXP_NOTXTCRD) && (face[i].data.texcoord[j] != M3D_UNDEF) && (tmapidx[face[i].data.texcoord[j]] != M3D_UNDEF)) { k = tmapidx[face[i].data.texcoord[j]]; ptr += sprintf(ptr, "/%d", k); } if(!(flags & M3D_EXP_NONORMAL) && (face[i].data.normal[j] != M3D_UNDEF)) { l = vrtxidx[face[i].data.normal[j]]; ptr += sprintf(ptr, "%s/%d", k == M3D_NOTDEFINED? "/" : "", l); } #ifdef M3D_VERTEXMAX if(!(flags & M3D_EXP_NOVRTMAX) && (face[i].data.vertmax[j] != M3D_UNDEF)) { ptr += sprintf(ptr, "%s%s/%d", k == M3D_NOTDEFINED? "/" : "", l == M3D_NOTDEFINED? "/" : "", vrtxidx[face[i].data.vertmax[j]]); } #endif } ptr += sprintf(ptr, "\r\n"); } ptr += sprintf(ptr, "\r\n"); } /* voxel face */ if(model->numvoxtype && model->voxtype && !(flags & M3D_EXP_NOFACE)) { ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)(model->numvoxtype * 128) + (uintptr_t)10); for(i = 0; i < model->numvoxtype; i++) { if(model->voxtype[i].name) len += (unsigned int)strlen(model->voxtype[i].name); for(j = 0; j < model->voxtype[i].numitem; j++) if(model->voxtype[i].item[j].name) len += (unsigned int)strlen(model->voxtype[i].item[j].name) + 6; } out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "VoxTypes\r\n"); for(i = 0; i < model->numvoxtype; i++) { ptr += sprintf(ptr, "#%08x", model->voxtype[i].color); if(model->voxtype[i].rotation) ptr += sprintf(ptr, "/%02x", model->voxtype[i].rotation); if(model->voxtype[i].voxshape) ptr += sprintf(ptr, "%s/%03x", model->voxtype[i].rotation ? "" : "/", model->voxtype[i].voxshape); sn = _m3d_safestr(model->voxtype[i].name, 0); if(!sn) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, " %s", sn && sn[0] ? sn : "-"); M3D_FREE(sn); sn = NULL; if(!(flags & M3D_EXP_NOBONE) && model->numbone && maxskin && model->voxtype[i].skinid < M3D_INDEXMAX) { if(skin[skinidx[model->voxtype[i].skinid]].data.weight[0] == (M3D_FLOAT)1.0) ptr += sprintf(ptr, " %d", skin[skinidx[model->voxtype[i].skinid]].data.boneid[0]); else for(j = 0; j < M3D_NUMBONE && skin[skinidx[model->voxtype[i].skinid]].data.boneid[j] != M3D_UNDEF && skin[skinidx[model->voxtype[i].skinid]].data.weight[j] > (M3D_FLOAT)0.0; j++) ptr += sprintf(ptr, " %d:%g", skin[skinidx[model->voxtype[i].skinid]].data.boneid[j], skin[skinidx[model->voxtype[i].skinid]].data.weight[j]); } if(model->voxtype[i].numitem && model->voxtype[i].item) { for(j = k = 0; j < model->voxtype[i].numitem; j++) { if(!model->voxtype[i].item[j].count || !model->voxtype[i].item[j].name || !model->voxtype[i].item[j].name[0]) continue; if(!k) { ptr += sprintf(ptr, " {"); k = 1; } sn = _m3d_safestr(model->voxtype[i].item[j].name, 0); if(!sn) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, " %d %s", model->voxtype[i].item[j].count, sn); M3D_FREE(sn); sn = NULL; } if(k) ptr += sprintf(ptr, " }"); } while(ptr[-1] == '-' || ptr[-1] == ' ') ptr--; ptr += sprintf(ptr, "\r\n"); } ptr += sprintf(ptr, "\r\n"); } if(model->numvoxel && model->voxel && !(flags & M3D_EXP_NOFACE)) { for(i = 0; i < model->numvoxel; i++) { ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)128); if(model->voxel[i].name) len += (unsigned int)strlen(model->voxel[i].name); len += model->voxel[i].h * ((model->voxel[i].w * 6 + 2) * model->voxel[i].d + 9); out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Voxel"); sn = _m3d_safestr(model->voxel[i].name, 0); if(!sn) { setlocale(LC_NUMERIC, ol); goto memerr; } if(sn && sn[0]) ptr += sprintf(ptr, " %s", sn); M3D_FREE(sn); sn = NULL; ptr += sprintf(ptr, "\r\n"); if(model->voxel[i].uncertain) ptr += sprintf(ptr, "uncertain %d %d\r\n", (model->voxel[i].uncertain * 100) / 255, model->voxel[i].groupid); if(model->voxel[i].x || model->voxel[i].y || model->voxel[i].z) ptr += sprintf(ptr, "pos %d %d %d\r\n", model->voxel[i].x, model->voxel[i].y, model->voxel[i].z); ptr += sprintf(ptr, "dim %d %d %d\r\n", model->voxel[i].w, model->voxel[i].h, model->voxel[i].d); for(j = n = 0; j < model->voxel[i].h; j++) { ptr += sprintf(ptr, "layer\r\n"); for(k = 0; k < model->voxel[i].d; k++) { for(l = 0; l < model->voxel[i].w; l++, n++) { switch(model->voxel[i].data[n]) { case M3D_VOXCLEAR: *ptr++ = '-'; break; case M3D_VOXUNDEF: *ptr++ = '.'; break; default: ptr += sprintf(ptr, "%d", model->voxel[i].data[n]); break; } *ptr++ = ' '; } ptr--; ptr += sprintf(ptr, "\r\n"); } } ptr += sprintf(ptr, "\r\n"); } } /* mathematical shapes face */ if(model->numshape && model->numshape && !(flags & M3D_EXP_NOFACE)) { for(j = 0; j < model->numshape; j++) { sn = _m3d_safestr(model->shape[j].name, 0); if(!sn) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)strlen(sn) + (uintptr_t)33); out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Shape %s\r\n", sn); M3D_FREE(sn); sn = NULL; if(model->shape[j].group != M3D_UNDEF && !(flags & M3D_EXP_NOBONE)) ptr += sprintf(ptr, "group %d\r\n", model->shape[j].group); for(i = 0; i < model->shape[j].numcmd; i++) { cmd = &model->shape[j].cmd[i]; if(cmd->type >= (unsigned int)(sizeof(m3d_commandtypes)/sizeof(m3d_commandtypes[0])) || !cmd->arg) continue; cd = &m3d_commandtypes[cmd->type]; ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)strlen(cd->key) + (uintptr_t)3); for(k = 0; k < cd->p; k++) switch(cd->a[k]) { case m3dcp_mi_t: if(cmd->arg[k] != M3D_NOTDEFINED) { len += (unsigned int)strlen(model->material[cmd->arg[k]].name) + 1; } break; case m3dcp_va_t: len += cmd->arg[k] * (cd->p - k - 1) * 16; k = cd->p; break; default: len += 16; break; } out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "%s", cd->key); for(k = n = 0, l = cd->p; k < l; k++) { switch(cd->a[((k - n) % (cd->p - n)) + n]) { case m3dcp_mi_t: if(cmd->arg[k] != M3D_NOTDEFINED) { sn = _m3d_safestr(model->material[cmd->arg[k]].name, 0); if(!sn) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, " %s", sn); M3D_FREE(sn); sn = NULL; } break; case m3dcp_vc_t: ptr += sprintf(ptr, " %g", *((float*)&cmd->arg[k])); break; case m3dcp_va_t: ptr += sprintf(ptr, " %d[", cmd->arg[k]); n = k + 1; l += (cmd->arg[k] - 1) * (cd->p - k - 1); break; default: ptr += sprintf(ptr, " %d", cmd->arg[k]); break; } } ptr += sprintf(ptr, "%s\r\n", l > cd->p ? " ]" : ""); } ptr += sprintf(ptr, "\r\n"); } } /* annotation labels */ if(model->numlabel && model->label && !(flags & M3D_EXP_NOFACE)) { for(i = 0, j = 3, length = NULL; i < model->numlabel; i++) { if(model->label[i].name) j += (unsigned int)strlen(model->label[i].name); if(model->label[i].lang) j += (unsigned int)strlen(model->label[i].lang); if(model->label[i].text) j += (unsigned int)strlen(model->label[i].text); j += 40; } ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)j); out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } for(i = 0; i < model->numlabel; i++) { if(!i || _m3d_strcmp(sl, model->label[i].lang) || _m3d_strcmp(sn, model->label[i].name)) { sl = model->label[i].lang; sn = model->label[i].name; sd = _m3d_safestr(sn, 0); if(!sd) { setlocale(LC_NUMERIC, ol); sn = sl = NULL; goto memerr; } if(i) ptr += sprintf(ptr, "\r\n"); ptr += sprintf(ptr, "Labels %s\r\n", sd); M3D_FREE(sd); sd = NULL; if(model->label[i].color) ptr += sprintf(ptr, "color #0x%08x\r\n", model->label[i].color); if(sl && *sl) { sd = _m3d_safestr(sl, 0); if(!sd) { setlocale(LC_NUMERIC, ol); sn = sl = NULL; goto memerr; } ptr += sprintf(ptr, "lang %s\r\n", sd); M3D_FREE(sd); sd = NULL; } } sd = _m3d_safestr(model->label[i].text, 2); if(!sd) { setlocale(LC_NUMERIC, ol); sn = sl = NULL; goto memerr; } ptr += sprintf(ptr, "%d %s\r\n", model->label[i].vertexid, sd); M3D_FREE(sd); sd = NULL; } ptr += sprintf(ptr, "\r\n"); sn = sl = NULL; } /* actions */ if(model->numaction && model->action && !(flags & M3D_EXP_NOACTION)) { for(j = 0; j < model->numaction; j++) { a = &model->action[j]; sn = _m3d_safestr(a->name, 0); if(!sn) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)strlen(sn) + (uintptr_t)48); for(i = 0; i < a->numframe; i++) len += a->frame[i].numtransform * 128 + 8; out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Action %d %s\r\n", a->durationmsec, sn); M3D_FREE(sn); sn = NULL; for(i = 0; i < a->numframe; i++) { ptr += sprintf(ptr, "frame %d\r\n", a->frame[i].msec); for(k = 0; k < a->frame[i].numtransform; k++) { ptr += sprintf(ptr, "%d %d %d\r\n", a->frame[i].transform[k].boneid, vrtxidx[a->frame[i].transform[k].pos], vrtxidx[a->frame[i].transform[k].ori]); } } ptr += sprintf(ptr, "\r\n"); } } /* inlined assets */ if(model->numinlined && model->inlined) { for(i = j = 0; i < model->numinlined; i++) if(model->inlined[i].name) j += (unsigned int)strlen(model->inlined[i].name) + 6; if(j > 0) { ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)j + (uintptr_t)16); out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Assets\r\n"); for(i = 0; i < model->numinlined; i++) if(model->inlined[i].name) ptr += sprintf(ptr, "%s%s\r\n", model->inlined[i].name, strrchr(model->inlined[i].name, '.') ? "" : ".png"); ptr += sprintf(ptr, "\r\n"); } } /* extra info */ if(model->numextra && (flags & M3D_EXP_EXTRA)) { for(i = 0; i < model->numextra; i++) { if(model->extra[i]->length < 9) continue; ptr -= (uintptr_t)out; len = (unsigned int)((uintptr_t)ptr + (uintptr_t)17 + (uintptr_t)(model->extra[i]->length * 3)); out = (unsigned char*)M3D_REALLOC(out, len); ptr += (uintptr_t)out; if(!out) { setlocale(LC_NUMERIC, ol); goto memerr; } ptr += sprintf(ptr, "Extra %c%c%c%c\r\n", model->extra[i]->magic[0] > ' ' ? model->extra[i]->magic[0] : '_', model->extra[i]->magic[1] > ' ' ? model->extra[i]->magic[1] : '_', model->extra[i]->magic[2] > ' ' ? model->extra[i]->magic[2] : '_', model->extra[i]->magic[3] > ' ' ? model->extra[i]->magic[3] : '_'); for(j = 0; j < model->extra[i]->length; j++) ptr += sprintf(ptr, "%02x ", *((unsigned char *)model->extra + sizeof(m3dchunk_t) + j)); ptr--; ptr += sprintf(ptr, "\r\n\r\n"); } } setlocale(LC_NUMERIC, ol); len = (unsigned int)((uintptr_t)ptr - (uintptr_t)out); out = (unsigned char*)M3D_REALLOC(out, len + 1); if(!out) goto memerr; out[len] = 0; } else #endif { /* stricly only use LF (newline) in binary */ sd = _m3d_safestr(model->desc, 3); if(!sd) goto memerr; /* header */ h = (m3dhdr_t*)M3D_MALLOC(sizeof(m3dhdr_t) + strlen(sn) + strlen(sl) + strlen(sa) + strlen(sd) + 4); if(!h) goto memerr; memcpy((uint8_t*)h, "HEAD", 4); h->length = sizeof(m3dhdr_t); h->scale = scale; i = (unsigned int)strlen(sn); memcpy((uint8_t*)h + h->length, sn, i+1); h->length += i+1; M3D_FREE(sn); i = (unsigned int)strlen(sl); memcpy((uint8_t*)h + h->length, sl, i+1); h->length += i+1; M3D_FREE(sl); i = (unsigned int)strlen(sa); memcpy((uint8_t*)h + h->length, sa, i+1); h->length += i+1; M3D_FREE(sa); i = (unsigned int)strlen(sd); memcpy((uint8_t*)h + h->length, sd, i+1); h->length += i+1; M3D_FREE(sd); sn = sl = sa = sd = NULL; if(model->inlined) for(i = 0; i < model->numinlined; i++) { if(model->inlined[i].name && *model->inlined[i].name && model->inlined[i].length > 0) { str = _m3d_addstr(str, &numstr, model->inlined[i].name); if(!str) goto memerr; } } if(str) for(i = 0; i < numstr; i++) { h = _m3d_addhdr(h, &str[i]); if(!h) goto memerr; } vc_s = quality == M3D_EXP_INT8? 1 : (quality == M3D_EXP_INT16? 2 : (quality == M3D_EXP_DOUBLE? 8 : 4)); vi_s = maxvrtx < 254 ? 1 : (maxvrtx < 65534 ? 2 : 4); si_s = h->length - 16 < 254 ? 1 : (h->length - 16 < 65534 ? 2 : 4); ci_s = !numcmap || !cmap ? 0 : (numcmap < 254 ? 1 : (numcmap < 65534 ? 2 : 4)); ti_s = !maxtmap || !tmap ? 0 : (maxtmap < 254 ? 1 : (maxtmap < 65534 ? 2 : 4)); bi_s = !model->numbone || !model->bone || (flags & M3D_EXP_NOBONE)? 0 : (model->numbone < 254 ? 1 : (model->numbone < 65534 ? 2 : 4)); nb_s = maxbone < 2 ? 1 : (maxbone == 2 ? 2 : (maxbone <= 4 ? 4 : 8)); sk_s = !bi_s || !maxskin || !skin ? 0 : (maxskin < 254 ? 1 : (maxskin < 65534 ? 2 : 4)); fc_s = maxt < 254 ? 1 : (maxt < 65534 ? 2 : 4); hi_s = !model->numshape || !model->shape || (flags & M3D_EXP_NOFACE)? 0 : (model->numshape < 254 ? 1 : (model->numshape < 65534 ? 2 : 4)); fi_s = !model->numface || !model->face || (flags & M3D_EXP_NOFACE)? 0 : (model->numface < 254 ? 1 : (model->numface < 65534 ? 2 : 4)); vd_s = !model->numvoxel || !model->voxel || (flags & M3D_EXP_NOFACE)? 0 : (minvox >= -128 && maxvox <= 127 ? 1 : (minvox >= -32768 && maxvox <= 32767 ? 2 : 4)); vp_s = !model->numvoxtype || !model->voxtype || (flags & M3D_EXP_NOFACE)? 0 : (model->numvoxtype < 254 ? 1 : (model->numvoxtype < 65534 ? 2 : 4)); h->types = (vc_s == 8 ? (3<<0) : (vc_s == 2 ? (1<<0) : (vc_s == 1 ? (0<<0) : (2<<0)))) | (vi_s == 2 ? (1<<2) : (vi_s == 1 ? (0<<2) : (2<<2))) | (si_s == 2 ? (1<<4) : (si_s == 1 ? (0<<4) : (2<<4))) | (ci_s == 2 ? (1<<6) : (ci_s == 1 ? (0<<6) : (ci_s == 4 ? (2<<6) : (3<<6)))) | (ti_s == 2 ? (1<<8) : (ti_s == 1 ? (0<<8) : (ti_s == 4 ? (2<<8) : (3<<8)))) | (bi_s == 2 ? (1<<10): (bi_s == 1 ? (0<<10): (bi_s == 4 ? (2<<10) : (3<<10)))) | (nb_s == 2 ? (1<<12): (nb_s == 1 ? (0<<12): (2<<12))) | (sk_s == 2 ? (1<<14): (sk_s == 1 ? (0<<14): (sk_s == 4 ? (2<<14) : (3<<14)))) | (fc_s == 2 ? (1<<16): (fc_s == 1 ? (0<<16): (2<<16))) | (hi_s == 2 ? (1<<18): (hi_s == 1 ? (0<<18): (hi_s == 4 ? (2<<18) : (3<<18)))) | (fi_s == 2 ? (1<<20): (fi_s == 1 ? (0<<20): (fi_s == 4 ? (2<<20) : (3<<20)))) | (vd_s == 2 ? (1<<22): (vd_s == 1 ? (0<<22): (vd_s == 4 ? (2<<22) : (3<<22)))) | (vp_s == 2 ? (1<<24): (vp_s == 1 ? (0<<24): (vp_s == 4 ? (2<<24) : (3<<24)))); len = h->length; /* color map */ if(numcmap && cmap && ci_s < 4 && !(flags & M3D_EXP_NOCMAP)) { chunklen = 8 + numcmap * sizeof(uint32_t); h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "CMAP", 4); *((uint32_t*)((uint8_t*)h + len + 4)) = chunklen; memcpy((uint8_t*)h + len + 8, cmap, chunklen - 8); len += chunklen; } else numcmap = 0; /* texture map */ if(numtmap && tmap && !(flags & M3D_EXP_NOTXTCRD) && !(flags & M3D_EXP_NOFACE)) { chunklen = 8 + maxtmap * vc_s * 2; h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "TMAP", 4); length = (uint32_t*)((uint8_t*)h + len + 4); out = (uint8_t*)h + len + 8; last = M3D_UNDEF; for(i = 0; i < numtmap; i++) { if(tmap[i].newidx == last) continue; last = tmap[i].newidx; switch(vc_s) { case 1: *out++ = (uint8_t)(tmap[i].data.u * 255); *out++ = (uint8_t)(tmap[i].data.v * 255); break; case 2: *((uint16_t*)out) = (uint16_t)(tmap[i].data.u * 65535); out += 2; *((uint16_t*)out) = (uint16_t)(tmap[i].data.v * 65535); out += 2; break; case 4: *((float*)out) = tmap[i].data.u; out += 4; *((float*)out) = tmap[i].data.v; out += 4; break; case 8: *((double*)out) = tmap[i].data.u; out += 8; *((double*)out) = tmap[i].data.v; out += 8; break; } } *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t*)h + len)); out = NULL; len += *length; } /* vertex */ if(numvrtx && vrtx) { chunklen = 8 + maxvrtx * (ci_s + sk_s + 4 * vc_s); h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "VRTS", 4); length = (uint32_t*)((uint8_t*)h + len + 4); out = (uint8_t*)h + len + 8; last = M3D_UNDEF; for(i = 0; i < numvrtx; i++) { if(vrtx[i].newidx == last) continue; last = vrtx[i].newidx; switch(vc_s) { case 1: *out++ = (int8_t)(vrtx[i].data.x * 127); *out++ = (int8_t)(vrtx[i].data.y * 127); *out++ = (int8_t)(vrtx[i].data.z * 127); *out++ = (int8_t)(vrtx[i].data.w * 127); break; case 2: *((int16_t*)out) = (int16_t)(vrtx[i].data.x * 32767); out += 2; *((int16_t*)out) = (int16_t)(vrtx[i].data.y * 32767); out += 2; *((int16_t*)out) = (int16_t)(vrtx[i].data.z * 32767); out += 2; *((int16_t*)out) = (int16_t)(vrtx[i].data.w * 32767); out += 2; break; case 4: *((float*)out) = vrtx[i].data.x; out += 4; *((float*)out) = vrtx[i].data.y; out += 4; *((float*)out) = vrtx[i].data.z; out += 4; *((float*)out) = vrtx[i].data.w; out += 4; break; case 8: *((double*)out) = vrtx[i].data.x; out += 8; *((double*)out) = vrtx[i].data.y; out += 8; *((double*)out) = vrtx[i].data.z; out += 8; *((double*)out) = vrtx[i].data.w; out += 8; break; } idx = _m3d_cmapidx(cmap, numcmap, vrtx[i].data.color); switch(ci_s) { case 1: *out++ = (uint8_t)(idx); break; case 2: *((uint16_t*)out) = (uint16_t)(idx); out += 2; break; case 4: *((uint32_t*)out) = vrtx[i].data.color; out += 4; break; } out = _m3d_addidx(out, sk_s, vrtx[i].data.skinid); } *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t*)h + len)); out = NULL; len += *length; } /* bones chunk */ if(model->numbone && model->bone && !(flags & M3D_EXP_NOBONE)) { i = 8 + bi_s + sk_s + model->numbone * (bi_s + si_s + 2*vi_s); chunklen = i + numskin * nb_s * (bi_s + 1); h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "BONE", 4); length = (uint32_t*)((uint8_t*)h + len + 4); out = (uint8_t*)h + len + 8; out = _m3d_addidx(out, bi_s, model->numbone); out = _m3d_addidx(out, sk_s, maxskin); for(i = 0; i < model->numbone; i++) { out = _m3d_addidx(out, bi_s, model->bone[i].parent); out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->bone[i].name)); out = _m3d_addidx(out, vi_s, vrtxidx[model->bone[i].pos]); out = _m3d_addidx(out, vi_s, vrtxidx[model->bone[i].ori]); } if(numskin && skin && sk_s) { last = M3D_UNDEF; for(i = 0; i < numskin; i++) { if(skin[i].newidx == last) continue; last = skin[i].newidx; memset(&weights, 0, nb_s); for(j = 0; j < (uint32_t)nb_s && skin[i].data.boneid[j] != M3D_UNDEF && skin[i].data.weight[j] > (M3D_FLOAT)0.0; j++) weights[j] = (uint8_t)(skin[i].data.weight[j] * 255); switch(nb_s) { case 1: weights[0] = 255; break; case 2: memcpy(out, weights, 2); out += 2; break; case 4: memcpy(out, weights, 4); out += 4; break; case 8: memcpy(out, weights, 8); out += 8; break; } for(j = 0; j < (uint32_t)nb_s && skin[i].data.boneid[j] != M3D_UNDEF && weights[j]; j++) { out = _m3d_addidx(out, bi_s, skin[i].data.boneid[j]); *length += bi_s; } } } *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t*)h + len)); out = NULL; len += *length; } /* materials */ if(model->nummaterial && !(flags & M3D_EXP_NOMATERIAL)) { for(j = 0; j < model->nummaterial; j++) { if(mtrlidx[j] == M3D_UNDEF || !model->material[j].numprop || !model->material[j].prop) continue; m = &model->material[j]; chunklen = 12 + si_s + m->numprop * 5; h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "MTRL", 4); length = (uint32_t*)((uint8_t*)h + len + 4); out = (uint8_t*)h + len + 8; out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, m->name)); for(i = 0; i < m->numprop; i++) { if(m->prop[i].type >= 128) { if(m->prop[i].value.textureid >= model->numtexture || !model->texture[m->prop[i].value.textureid].name) continue; k = m3dpf_map; } else { for(k = 256, l = 0; l < sizeof(m3d_propertytypes)/sizeof(m3d_propertytypes[0]); l++) if(m->prop[i].type == m3d_propertytypes[l].id) { k = m3d_propertytypes[l].format; break; } } if(k == 256) continue; *out++ = m->prop[i].type; switch(k) { case m3dpf_color: if(!(flags & M3D_EXP_NOCMAP)) { idx = _m3d_cmapidx(cmap, numcmap, m->prop[i].value.color); switch(ci_s) { case 1: *out++ = (uint8_t)(idx); break; case 2: *((uint16_t*)out) = (uint16_t)(idx); out += 2; break; case 4: *((uint32_t*)out) = (uint32_t)(m->prop[i].value.color); out += 4; break; } } else out--; break; case m3dpf_uint8: *out++ = m->prop[i].value.num; break; case m3dpf_uint16: *((uint16_t*)out) = m->prop[i].value.num; out += 2; break; case m3dpf_uint32: *((uint32_t*)out) = m->prop[i].value.num; out += 4; break; case m3dpf_float: *((float*)out) = m->prop[i].value.fnum; out += 4; break; case m3dpf_map: idx = _m3d_stridx(str, numstr, model->texture[m->prop[i].value.textureid].name); out = _m3d_addidx(out, si_s, idx); break; } } *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t*)h + len)); len += *length; out = NULL; } } /* procedural face */ if(model->numinlined && model->inlined && !(flags & M3D_EXP_NOFACE)) { /* all inlined assets which are not textures should be procedural surfaces */ for(j = 0; j < model->numinlined; j++) { if(!model->inlined[j].name || !model->inlined[j].name[0] || model->inlined[j].length < 4 || !model->inlined[j].data || (model->inlined[j].data[1] == 'P' && model->inlined[j].data[2] == 'N' && model->inlined[j].data[3] == 'G')) continue; for(i = k = 0; i < model->numtexture; i++) { if(!strcmp(model->inlined[j].name, model->texture[i].name)) { k = 1; break; } } if(k) continue; numproc++; chunklen = 8 + si_s; h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "PROC", 4); *((uint32_t*)((uint8_t*)h + len + 4)) = chunklen; out = (uint8_t*)h + len + 8; out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->inlined[j].name)); out = NULL; len += chunklen; } } /* mesh face */ if(model->numface && face && !(flags & M3D_EXP_NOFACE)) { chunklen = 8 + si_s + model->numface * (6 * vi_s + 3 * ti_s + si_s + 1); h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "MESH", 4); length = (uint32_t*)((uint8_t*)h + len + 4); out = (uint8_t*)h + len + 8; last = M3D_UNDEF; #ifdef M3D_VERTEXMAX lastp = M3D_UNDEF; #endif for(i = 0; i < model->numface; i++) { if(!(flags & M3D_EXP_NOMATERIAL) && face[i].data.materialid != last) { last = face[i].data.materialid; idx = last < model->nummaterial ? _m3d_stridx(str, numstr, model->material[last].name) : 0; *out++ = 0; out = _m3d_addidx(out, si_s, idx); } #ifdef M3D_VERTEXMAX if(!(flags & M3D_EXP_NOVRTMAX) && face[i].data.paramid != lastp) { lastp = face[i].data.paramid; idx = lastp < model->numparam ? _m3d_stridx(str, numstr, model->param[lastp].name) : 0; *out++ = 0; out = _m3d_addidx(out, si_s, idx); } #endif /* hardcoded triangles. */ k = (3 << 4) | (((flags & M3D_EXP_NOTXTCRD) || !ti_s || face[i].data.texcoord[0] == M3D_UNDEF || face[i].data.texcoord[1] == M3D_UNDEF || face[i].data.texcoord[2] == M3D_UNDEF) ? 0 : 1) | (((flags & M3D_EXP_NONORMAL) || face[i].data.normal[0] == M3D_UNDEF || face[i].data.normal[1] == M3D_UNDEF || face[i].data.normal[2] == M3D_UNDEF) ? 0 : 2) #ifdef M3D_VERTEXMAX | (((flags & M3D_EXP_NOVRTMAX) || face[i].data.vertmax[0] == M3D_UNDEF || face[i].data.vertmax[1] == M3D_UNDEF || face[i].data.vertmax[2] == M3D_UNDEF) ? 0 : 4) #endif ; *out++ = k; for(j = 0; j < 3; j++) { out = _m3d_addidx(out, vi_s, vrtxidx[face[i].data.vertex[j]]); if(k & 1) out = _m3d_addidx(out, ti_s, tmapidx[face[i].data.texcoord[j]]); if(k & 2) out = _m3d_addidx(out, vi_s, vrtxidx[face[i].data.normal[j]]); #ifdef M3D_VERTEXMAX if(k & 4) out = _m3d_addidx(out, vi_s, vrtxidx[face[i].data.vertmax[j]]); #endif } } *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t*)h + len)); len += *length; out = NULL; } /* voxel face */ if(model->numvoxtype && model->voxtype && !(flags & M3D_EXP_NOFACE)) { chunklen = 8 + si_s + model->numvoxtype * (ci_s + si_s + 3 + sk_s); for(i = 0; i < model->numvoxtype; i++) chunklen += model->voxtype[i].numitem * (2 + si_s); h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "VOXT", 4); length = (uint32_t*)((uint8_t*)h + len + 4); out = (uint8_t*)h + len + 8; for(i = 0; i < model->numvoxtype; i++) { if(!(flags & M3D_EXP_NOCMAP)) { idx = _m3d_cmapidx(cmap, numcmap, model->voxtype[i].color); switch(ci_s) { case 1: *out++ = (uint8_t)(idx); break; case 2: *((uint16_t*)out) = (uint16_t)(idx); out += 2; break; case 4: *((uint32_t*)out) = (uint32_t)(model->voxtype[i].color); out += 4; break; } } out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->voxtype[i].name)); *out++ = (model->voxtype[i].rotation & 0xBF) | (((model->voxtype[i].voxshape >> 8) & 1) << 6); *out++ = model->voxtype[i].voxshape; *out++ = model->voxtype[i].numitem; if(!(flags & M3D_EXP_NOBONE) && model->numbone && maxskin) out = _m3d_addidx(out, sk_s, skinidx[model->voxtype[i].skinid]); for(j = 0; j < model->voxtype[i].numitem; j++) { out = _m3d_addidx(out, 2, model->voxtype[i].item[j].count); out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->voxtype[i].item[j].name)); } } *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t*)h + len)); len += *length; out = NULL; } if(model->numvoxel && model->voxel && !(flags & M3D_EXP_NOFACE)) { for(j = 0; j < model->numvoxel; j++) { chunklen = 8 + si_s + 6 * vd_s + 2 + model->voxel[j].w * model->voxel[j].h * model->voxel[j].d * 3; h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "VOXD", 4); length = (uint32_t*)((uint8_t*)h + len + 4); out = (uint8_t*)h + len + 8; out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->voxel[j].name)); out = _m3d_addidx(out, vd_s, model->voxel[j].x); out = _m3d_addidx(out, vd_s, model->voxel[j].y); out = _m3d_addidx(out, vd_s, model->voxel[j].z); out = _m3d_addidx(out, vd_s, model->voxel[j].w); out = _m3d_addidx(out, vd_s, model->voxel[j].h); out = _m3d_addidx(out, vd_s, model->voxel[j].d); *out++ = model->voxel[j].uncertain; *out++ = model->voxel[j].groupid; /* RLE compress voxel data */ n = model->voxel[j].w * model->voxel[j].h * model->voxel[j].d; k = o = 0; out[o++] = 0; for(i = 0; i < n; i++) { for(l = 1; l < 128 && i + l < n && model->voxel[j].data[i] == model->voxel[j].data[i + l]; l++); if(l > 1) { l--; if(out[k]) { out[k]--; out[o++] = 0x80 | l; } else out[k] = 0x80 | l; switch(vp_s) { case 1: out[o++] = model->voxel[j].data[i]; break; default: *((uint16_t*)(out + o)) = model->voxel[j].data[i]; o += 2; break; } k = o; out[o++] = 0; i += l; continue; } out[k]++; switch(vp_s) { case 1: out[o++] = model->voxel[j].data[i]; break; default: *((uint16_t*)(out + o)) = model->voxel[j].data[i]; o += 2; break; } if(out[k] > 127) { out[k]--; k = o; out[o++] = 0; } } if(!(out[k] & 0x80)) { if(out[k]) out[k]--; else o--; } *length = (uint32_t)((uintptr_t)out + (uintptr_t)o - (uintptr_t)((uint8_t*)h + len)); len += *length; out = NULL; } } /* mathematical shapes face */ if(model->numshape && model->shape && !(flags & M3D_EXP_NOFACE)) { for(j = 0; j < model->numshape; j++) { chunklen = 12 + si_s + model->shape[j].numcmd * (M3D_CMDMAXARG + 1) * 4; h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "SHPE", 4); length = (uint32_t*)((uint8_t*)h + len + 4); out = (uint8_t*)h + len + 8; out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->shape[j].name)); out = _m3d_addidx(out, bi_s, model->shape[j].group); for(i = 0; i < model->shape[j].numcmd; i++) { cmd = &model->shape[j].cmd[i]; if(cmd->type >= (unsigned int)(sizeof(m3d_commandtypes)/sizeof(m3d_commandtypes[0])) || !cmd->arg) continue; cd = &m3d_commandtypes[cmd->type]; *out++ = (cmd->type & 0x7F) | (cmd->type > 127 ? 0x80 : 0); if(cmd->type > 127) *out++ = (cmd->type >> 7) & 0xff; for(k = n = 0, l = cd->p; k < l; k++) { switch(cd->a[((k - n) % (cd->p - n)) + n]) { case m3dcp_mi_t: out = _m3d_addidx(out, si_s, cmd->arg[k] < model->nummaterial ? _m3d_stridx(str, numstr, model->material[cmd->arg[k]].name) : 0); break; case m3dcp_vc_t: min_x = *((float*)&cmd->arg[k]); switch(vc_s) { case 1: *out++ = (int8_t)(min_x * 127); break; case 2: *((int16_t*)out) = (int16_t)(min_x * 32767); out += 2; break; case 4: *((float*)out) = min_x; out += 4; break; case 8: *((double*)out) = min_x; out += 8; break; } break; case m3dcp_hi_t: out = _m3d_addidx(out, hi_s, cmd->arg[k]); break; case m3dcp_fi_t: out = _m3d_addidx(out, fi_s, cmd->arg[k]); break; case m3dcp_ti_t: out = _m3d_addidx(out, ti_s, cmd->arg[k]); break; case m3dcp_qi_t: case m3dcp_vi_t: out = _m3d_addidx(out, vi_s, cmd->arg[k]); break; case m3dcp_i1_t: out = _m3d_addidx(out, 1, cmd->arg[k]); break; case m3dcp_i2_t: out = _m3d_addidx(out, 2, cmd->arg[k]); break; case m3dcp_i4_t: out = _m3d_addidx(out, 4, cmd->arg[k]); break; case m3dcp_va_t: out = _m3d_addidx(out, 4, cmd->arg[k]); n = k + 1; l += (cmd->arg[k] - 1) * (cd->p - k - 1); break; } } } *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t*)h + len)); len += *length; out = NULL; } } /* annotation labels */ if(model->numlabel && model->label) { for(i = 0, length = NULL; i < model->numlabel; i++) { if(!i || _m3d_strcmp(sl, model->label[i].lang) || _m3d_strcmp(sn, model->label[i].name)) { sl = model->label[i].lang; sn = model->label[i].name; if(length) { *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t*)h + len)); len += *length; } chunklen = 8 + 2 * si_s + ci_s + model->numlabel * (vi_s + si_s); h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) { sn = NULL; sl = NULL; goto memerr; } memcpy((uint8_t*)h + len, "LBLS", 4); length = (uint32_t*)((uint8_t*)h + len + 4); out = (uint8_t*)h + len + 8; out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->label[l].name)); out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->label[l].lang)); idx = _m3d_cmapidx(cmap, numcmap, model->label[i].color); switch(ci_s) { case 1: *out++ = (uint8_t)(idx); break; case 2: *((uint16_t*)out) = (uint16_t)(idx); out += 2; break; case 4: *((uint32_t*)out) = model->label[i].color; out += 4; break; } } out = _m3d_addidx(out, vi_s, vrtxidx[model->label[i].vertexid]); out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->label[l].text)); } if(length) { *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t*)h + len)); len += *length; } out = NULL; sn = sl = NULL; } /* actions */ if(model->numaction && model->action && model->numbone && model->bone && !(flags & M3D_EXP_NOACTION)) { for(j = 0; j < model->numaction; j++) { a = &model->action[j]; chunklen = 14 + si_s + a->numframe * (4 + fc_s + maxt * (bi_s + 2 * vi_s)); h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "ACTN", 4); length = (uint32_t*)((uint8_t*)h + len + 4); out = (uint8_t*)h + len + 8; out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, a->name)); *((uint16_t*)out) = (uint16_t)(a->numframe); out += 2; *((uint32_t*)out) = (uint32_t)(a->durationmsec); out += 4; for(i = 0; i < a->numframe; i++) { *((uint32_t*)out) = (uint32_t)(a->frame[i].msec); out += 4; out = _m3d_addidx(out, fc_s, a->frame[i].numtransform); for(k = 0; k < a->frame[i].numtransform; k++) { out = _m3d_addidx(out, bi_s, a->frame[i].transform[k].boneid); out = _m3d_addidx(out, vi_s, vrtxidx[a->frame[i].transform[k].pos]); out = _m3d_addidx(out, vi_s, vrtxidx[a->frame[i].transform[k].ori]); } } *length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t*)h + len)); len += *length; out = NULL; } } /* inlined assets */ if(model->numinlined && model->inlined && (numproc || (flags & M3D_EXP_INLINE))) { for(j = 0; j < model->numinlined; j++) { if(!model->inlined[j].name || !model->inlined[j].name[0] || model->inlined[j].length<4 || !model->inlined[j].data) continue; if(!(flags & M3D_EXP_INLINE)) { if(model->inlined[j].data[1] == 'P' && model->inlined[j].data[2] == 'N' && model->inlined[j].data[3] == 'G') continue; for(i = k = 0; i < model->numtexture; i++) { if(!strcmp(model->inlined[j].name, model->texture[i].name)) { k = 1; break; } } if(k) continue; } chunklen = 8 + si_s + model->inlined[j].length; h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, "ASET", 4); *((uint32_t*)((uint8_t*)h + len + 4)) = chunklen; out = (uint8_t*)h + len + 8; out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->inlined[j].name)); memcpy(out, model->inlined[j].data, model->inlined[j].length); out = NULL; len += chunklen; } } /* extra chunks */ if(model->numextra && model->extra && (flags & M3D_EXP_EXTRA)) { for(j = 0; j < model->numextra; j++) { if(!model->extra[j] || model->extra[j]->length < 8) continue; chunklen = model->extra[j]->length; h = (m3dhdr_t*)M3D_REALLOC(h, len + chunklen); if(!h) goto memerr; memcpy((uint8_t*)h + len, model->extra[j], chunklen); len += chunklen; } } /* add end chunk */ h = (m3dhdr_t*)M3D_REALLOC(h, len + 4); if(!h) goto memerr; memcpy((uint8_t*)h + len, "OMD3", 4); len += 4; /* zlib compress */ if(!(flags & M3D_EXP_NOZLIB)) { M3D_LOG("Deflating chunks"); z = stbi_zlib_compress((unsigned char *)h, len, (int*)&l, 9); if(z && l > 0 && l < len) { len = l; M3D_FREE(h); h = (m3dhdr_t*)z; } } /* add file header at the begining */ len += 8; out = (unsigned char*)M3D_MALLOC(len); if(!out) goto memerr; memcpy(out, "3DMO", 4); *((uint32_t*)(out + 4)) = len; /* preview image chunk, must be the first if exists */ if(model->preview.data && model->preview.length) { chunklen = 8 + model->preview.length; out = (unsigned char*)M3D_REALLOC(out, len + chunklen); if(!out) goto memerr; memcpy((uint8_t*)out + 8, "PRVW", 4); *((uint32_t*)((uint8_t*)out + 8 + 4)) = chunklen; memcpy((uint8_t*)out + 8 + 8, model->preview.data, model->preview.length); *((uint32_t*)(out + 4)) += chunklen; } else chunklen = 0; memcpy(out + 8 + chunklen, h, len - 8); } if(size) *size = out ? len : 0; if(vrtxidx) M3D_FREE(vrtxidx); if(mtrlidx) M3D_FREE(mtrlidx); if(tmapidx) M3D_FREE(tmapidx); if(skinidx) M3D_FREE(skinidx); if(norm) M3D_FREE(norm); if(face) M3D_FREE(face); if(cmap) M3D_FREE(cmap); if(tmap) M3D_FREE(tmap); if(skin) M3D_FREE(skin); if(str) M3D_FREE(str); if(vrtx) M3D_FREE(vrtx); if(h) M3D_FREE(h); return out; } #endif #endif #ifdef __cplusplus } #ifdef M3D_CPPWRAPPER #include <vector> #include <string> #include <memory> /*** C++ wrapper class ***/ namespace M3D { #ifdef M3D_IMPLEMENTATION class Model { public: m3d_t *model; public: Model() { this->model = (m3d_t*)malloc(sizeof(m3d_t)); memset(this->model, 0, sizeof(m3d_t)); } Model(_unused const std::string &data, _unused m3dread_t ReadFileCB, _unused m3dfree_t FreeCB, _unused M3D::Model mtllib) { #ifndef M3D_NOIMPORTER this->model = m3d_load((unsigned char *)data.data(), ReadFileCB, FreeCB, mtllib.model); #else Model(); #endif } Model(_unused const std::vector<unsigned char> data, _unused m3dread_t ReadFileCB, _unused m3dfree_t FreeCB, _unused M3D::Model mtllib) { #ifndef M3D_NOIMPORTER this->model = m3d_load((unsigned char *)&data[0], ReadFileCB, FreeCB, mtllib.model); #else Model(); #endif } Model(_unused const unsigned char *data, _unused m3dread_t ReadFileCB, _unused m3dfree_t FreeCB, _unused M3D::Model mtllib) { #ifndef M3D_NOIMPORTER this->model = m3d_load((unsigned char*)data, ReadFileCB, FreeCB, mtllib.model); #else Model(); #endif } ~Model() { m3d_free(this->model); } public: m3d_t *getCStruct() { return this->model; } std::string getName() { return std::string(this->model->name); } void setName(std::string name) { this->model->name = (char*)name.c_str(); } std::string getLicense() { return std::string(this->model->license); } void setLicense(std::string license) { this->model->license = (char*)license.c_str(); } std::string getAuthor() { return std::string(this->model->author); } void setAuthor(std::string author) { this->model->author = (char*)author.c_str(); } std::string getDescription() { return std::string(this->model->desc); } void setDescription(std::string desc) { this->model->desc = (char*)desc.c_str(); } float getScale() { return this->model->scale; } void setScale(float scale) { this->model->scale = scale; } std::vector<unsigned char> getPreview() { return this->model->preview.data ? std::vector<unsigned char>(this->model->preview.data, this->model->preview.data + this->model->preview.length) : std::vector<unsigned char>(); } std::vector<uint32_t> getColorMap() { return this->model->cmap ? std::vector<uint32_t>(this->model->cmap, this->model->cmap + this->model->numcmap) : std::vector<uint32_t>(); } std::vector<m3dti_t> getTextureMap() { return this->model->tmap ? std::vector<m3dti_t>(this->model->tmap, this->model->tmap + this->model->numtmap) : std::vector<m3dti_t>(); } std::vector<m3dtx_t> getTextures() { return this->model->texture ? std::vector<m3dtx_t>(this->model->texture, this->model->texture + this->model->numtexture) : std::vector<m3dtx_t>(); } std::string getTextureName(int idx) { return idx >= 0 && (unsigned int)idx < this->model->numtexture ? std::string(this->model->texture[idx].name) : nullptr; } std::vector<m3db_t> getBones() { return this->model->bone ? std::vector<m3db_t>(this->model->bone, this->model->bone + this->model->numbone) : std::vector<m3db_t>(); } std::string getBoneName(int idx) { return idx >= 0 && (unsigned int)idx < this->model->numbone ? std::string(this->model->bone[idx].name) : nullptr; } std::vector<m3dm_t> getMaterials() { return this->model->material ? std::vector<m3dm_t>(this->model->material, this->model->material + this->model->nummaterial) : std::vector<m3dm_t>(); } std::string getMaterialName(int idx) { return idx >= 0 && (unsigned int)idx < this->model->nummaterial ? std::string(this->model->material[idx].name) : nullptr; } int getMaterialPropertyInt(int idx, int type) { if (idx < 0 || (unsigned int)idx >= this->model->nummaterial || type < 0 || type >= 127 || !this->model->material[idx].prop) return -1; for (int i = 0; i < this->model->material[idx].numprop; i++) { if (this->model->material[idx].prop[i].type == type) return this->model->material[idx].prop[i].value.num; } return -1; } uint32_t getMaterialPropertyColor(int idx, int type) { return this->getMaterialPropertyInt(idx, type); } float getMaterialPropertyFloat(int idx, int type) { if (idx < 0 || (unsigned int)idx >= this->model->nummaterial || type < 0 || type >= 127 || !this->model->material[idx].prop) return -1.0f; for (int i = 0; i < this->model->material[idx].numprop; i++) { if (this->model->material[idx].prop[i].type == type) return this->model->material[idx].prop[i].value.fnum; } return -1.0f; } m3dtx_t* getMaterialPropertyMap(int idx, int type) { if (idx < 0 || (unsigned int)idx >= this->model->nummaterial || type < 128 || type > 255 || !this->model->material[idx].prop) return nullptr; for (int i = 0; i < this->model->material[idx].numprop; i++) { if (this->model->material[idx].prop[i].type == type) return this->model->material[idx].prop[i].value.textureid < this->model->numtexture ? &this->model->texture[this->model->material[idx].prop[i].value.textureid] : nullptr; } return nullptr; } std::vector<m3dv_t> getVertices() { return this->model->vertex ? std::vector<m3dv_t>(this->model->vertex, this->model->vertex + this->model->numvertex) : std::vector<m3dv_t>(); } std::vector<m3df_t> getFace() { return this->model->face ? std::vector<m3df_t>(this->model->face, this->model->face + this->model->numface) : std::vector<m3df_t>(); } std::vector<m3dvt_t> getVoxelTypes() { return this->model->voxtype ? std::vector<m3dvt_t>(this->model->voxtype, this->model->voxtype + this->model->numvoxtype) : std::vector<m3dvt_t>(); } std::string getVoxelTypeName(int idx) { return idx >= 0 && (unsigned int)idx < this->model->numvoxtype && this->model->voxtype[idx].name && this->model->voxtype[idx].name[0] ? std::string(this->model->voxtype[idx].name) : nullptr; } std::vector<m3dvi_t> getVoxelTypeItems(int idx) { return idx >= 0 && (unsigned int)idx < this->model->numvoxtype && this->model->voxtype[idx].item ? std::vector<m3dvi_t>(this->model->voxtype[idx].item, this->model->voxtype[idx].item + this->model->voxtype[idx].numitem) : std::vector<m3dvi_t>(); } std::vector<m3dvx_t> getVoxelBlocks() { return this->model->voxel ? std::vector<m3dvx_t>(this->model->voxel, this->model->voxel + this->model->numvoxel) : std::vector<m3dvx_t>(); } std::string getVoxelBlockName(int idx) { return idx >= 0 && (unsigned int)idx < this->model->numvoxel && this->model->voxel[idx].name && this->model->voxel[idx].name[0] ? std::string(this->model->voxel[idx].name) : nullptr; } std::vector<M3D_VOXEL> getVoxelBlockData(int idx) { return idx >= 0 && (unsigned int)idx < this->model->numvoxel && this->model->voxel[idx].data ? std::vector<M3D_VOXEL>(this->model->voxel[idx].data, this->model->voxel[idx].data + this->model->voxel[idx].w*this->model->voxel[idx].h*this->model->voxel[idx].d) : std::vector<M3D_VOXEL>(); } std::vector<m3dh_t> getShape() { return this->model->shape ? std::vector<m3dh_t>(this->model->shape, this->model->shape + this->model->numshape) : std::vector<m3dh_t>(); } std::string getShapeName(int idx) { return idx >= 0 && (unsigned int)idx < this->model->numshape && this->model->shape[idx].name && this->model->shape[idx].name[0] ? std::string(this->model->shape[idx].name) : nullptr; } unsigned int getShapeGroup(int idx) { return idx >= 0 && (unsigned int)idx < this->model->numshape ? this->model->shape[idx].group : 0xFFFFFFFF; } std::vector<m3dc_t> getShapeCommands(int idx) { return idx >= 0 && (unsigned int)idx < this->model->numshape && this->model->shape[idx].cmd ? std::vector<m3dc_t>(this->model->shape[idx].cmd, this->model->shape[idx].cmd + this->model->shape[idx].numcmd) : std::vector<m3dc_t>(); } std::vector<m3dl_t> getAnnotationLabels() { return this->model->label ? std::vector<m3dl_t>(this->model->label, this->model->label + this->model->numlabel) : std::vector<m3dl_t>(); } std::vector<m3ds_t> getSkin() { return this->model->skin ? std::vector<m3ds_t>(this->model->skin, this->model->skin + this->model->numskin) : std::vector<m3ds_t>(); } std::vector<m3da_t> getActions() { return this->model->action ? std::vector<m3da_t>(this->model->action, this->model->action + this->model->numaction) : std::vector<m3da_t>(); } std::string getActionName(int aidx) { return aidx >= 0 && (unsigned int)aidx < this->model->numaction ? std::string(this->model->action[aidx].name) : nullptr; } unsigned int getActionDuration(int aidx) { return aidx >= 0 && (unsigned int)aidx < this->model->numaction ? this->model->action[aidx].durationmsec : 0; } std::vector<m3dfr_t> getActionFrames(int aidx) { return aidx >= 0 && (unsigned int)aidx < this->model->numaction ? std::vector<m3dfr_t>(this->model->action[aidx].frame, this->model->action[aidx].frame + this->model->action[aidx].numframe) : std::vector<m3dfr_t>(); } unsigned int getActionFrameTimestamp(int aidx, int fidx) { return aidx >= 0 && (unsigned int)aidx < this->model->numaction? (fidx >= 0 && (unsigned int)fidx < this->model->action[aidx].numframe ? this->model->action[aidx].frame[fidx].msec : 0) : 0; } std::vector<m3dtr_t> getActionFrameTransforms(int aidx, int fidx) { return aidx >= 0 && (unsigned int)aidx < this->model->numaction ? ( fidx >= 0 && (unsigned int)fidx < this->model->action[aidx].numframe ? std::vector<m3dtr_t>(this->model->action[aidx].frame[fidx].transform, this->model->action[aidx].frame[fidx].transform + this->model->action[aidx].frame[fidx].numtransform) : std::vector<m3dtr_t>()) : std::vector<m3dtr_t>(); } std::vector<m3dtr_t> getActionFrame(int aidx, int fidx, std::vector<m3dtr_t> skeleton) { m3dtr_t *pose = m3d_frame(this->model, (unsigned int)aidx, (unsigned int)fidx, skeleton.size() ? &skeleton[0] : nullptr); return std::vector<m3dtr_t>(pose, pose + this->model->numbone); } std::vector<m3db_t> getActionPose(int aidx, unsigned int msec) { m3db_t *pose = m3d_pose(this->model, (unsigned int)aidx, (unsigned int)msec); return std::vector<m3db_t>(pose, pose + this->model->numbone); } std::vector<m3di_t> getInlinedAssets() { return this->model->inlined ? std::vector<m3di_t>(this->model->inlined, this->model->inlined + this->model->numinlined) : std::vector<m3di_t>(); } std::vector<std::unique_ptr<m3dchunk_t>> getExtras() { return this->model->extra ? std::vector<std::unique_ptr<m3dchunk_t>>(this->model->extra, this->model->extra + this->model->numextra) : std::vector<std::unique_ptr<m3dchunk_t>>(); } std::vector<unsigned char> Save(_unused int quality, _unused int flags) { #ifdef M3D_EXPORTER unsigned int size; unsigned char *ptr = m3d_save(this->model, quality, flags, &size); return ptr && size ? std::vector<unsigned char>(ptr, ptr + size) : std::vector<unsigned char>(); #else return std::vector<unsigned char>(); #endif } }; #else class Model { private: m3d_t *model; public: Model(const std::string &data, m3dread_t ReadFileCB, m3dfree_t FreeCB); Model(const std::vector<unsigned char> data, m3dread_t ReadFileCB, m3dfree_t FreeCB); Model(const unsigned char *data, m3dread_t ReadFileCB, m3dfree_t FreeCB); Model(); ~Model(); public: m3d_t *getCStruct(); std::string getName(); void setName(std::string name); std::string getLicense(); void setLicense(std::string license); std::string getAuthor(); void setAuthor(std::string author); std::string getDescription(); void setDescription(std::string desc); float getScale(); void setScale(float scale); std::vector<unsigned char> getPreview(); std::vector<uint32_t> getColorMap(); std::vector<m3dti_t> getTextureMap(); std::vector<m3dtx_t> getTextures(); std::string getTextureName(int idx); std::vector<m3db_t> getBones(); std::string getBoneName(int idx); std::vector<m3dm_t> getMaterials(); std::string getMaterialName(int idx); int getMaterialPropertyInt(int idx, int type); uint32_t getMaterialPropertyColor(int idx, int type); float getMaterialPropertyFloat(int idx, int type); m3dtx_t* getMaterialPropertyMap(int idx, int type); std::vector<m3dv_t> getVertices(); std::vector<m3df_t> getFace(); std::vector<m3dvt_t> getVoxelTypes(); std::string getVoxelTypeName(int idx); std::vector<m3dvi_t> getVoxelTypeItems(int idx); std::vector<m3dvx_t> getVoxelBlocks(); std::string getVoxelBlockName(int idx); std::vector<M3D_VOXEL> getVoxelBlockData(int idx); std::vector<m3dh_t> getShape(); std::string getShapeName(int idx); unsigned int getShapeGroup(int idx); std::vector<m3dc_t> getShapeCommands(int idx); std::vector<m3dl_t> getAnnotationLabels(); std::vector<m3ds_t> getSkin(); std::vector<m3da_t> getActions(); std::string getActionName(int aidx); unsigned int getActionDuration(int aidx); std::vector<m3dfr_t> getActionFrames(int aidx); unsigned int getActionFrameTimestamp(int aidx, int fidx); std::vector<m3dtr_t> getActionFrameTransforms(int aidx, int fidx); std::vector<m3dtr_t> getActionFrame(int aidx, int fidx, std::vector<m3dtr_t> skeleton); std::vector<m3db_t> getActionPose(int aidx, unsigned int msec); std::vector<m3di_t> getInlinedAssets(); std::vector<std::unique_ptr<m3dchunk_t>> getExtras(); std::vector<unsigned char> Save(int quality, int flags); }; #endif /* impl */ } #endif #endif /* __cplusplus */ #endif
/* * m3d.h * https://gitlab.com/bztsrc/model3d * * Copyright (C) 2020 bzt (bztsrc@gitlab) * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * @brief ANSI C89 / C++11 single header importer / exporter SDK for the Model 3D (.M3D) format * https://gitlab.com/bztsrc/model3d * * PNG decompressor included from (with minor modifications to make it C89 valid): * stb_image - v2.13 - public domain image loader - http://nothings.org/stb_image.h * * @version: 1.0.0 */
echo_client.ml
open Ex_common open Lwt let cached_session : Tls.Core.epoch_data = let hex = Cstruct.of_hex in { Tls.Core.protocol_version = `TLS_1_3 ; ciphersuite = `DHE_RSA_WITH_AES_128_GCM_SHA256 ; peer_random = hex "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ; peer_certificate = None ; peer_certificate_chain = [] ; peer_name = None ; trust_anchor = None ; received_certificates = [] ; own_random = hex "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ; own_certificate = [] ; own_private_key = None ; own_name = None ; master_secret = hex "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ; session_id = Cstruct.create 0 ; extended_ms = true ; alpn_protocol = None ; state = `Established ; } let echo_client ?ca hostname port = let open Lwt_io in auth ?ca () >>= fun authenticator -> X509_lwt.private_of_pems ~cert:server_cert ~priv_key:server_key >>= fun certificate -> Tls_lwt.connect_ext Tls.Config.(client ~authenticator ~cached_session ~certificates:(`Single certificate) ~ciphers:Ciphers.supported ()) (hostname, port) >>= fun (ic, oc) -> Lwt.join [ lines ic |> Lwt_stream.iter_s (printf "+ %s\n%!") ; lines stdin |> Lwt_stream.iter_s (write_line oc) ] let jump _ port host ca = try Lwt_main.run (echo_client ?ca host port) with | Tls_lwt.Tls_alert alert as exn -> print_alert "remote end" alert ; raise exn | Tls_lwt.Tls_failure alert as exn -> print_fail "our end" alert ; raise exn open Cmdliner let port = let doc = "Port to connect to" in Arg.(value & opt int 443 & info [ "port" ] ~doc) let host = let doc = "Host to connect to" in Arg.(value & opt string "" & info [ "host" ] ~doc) let trust = let doc = "Trust anchor" in Arg.(value & opt (some string) None & info [ "trust" ] ~doc) let cmd = let term = Term.(const jump $ setup_log $ port $ host $ trust) and info = Cmd.info "server" ~version:"0.17.0" in Cmd.v info term let () = exit (Cmd.eval cmd)
CLI_common.ml
(* Shared parameters, options, and help messages for the semgrep CLI. *) open Cmdliner let help_page_bottom = [ `S Manpage.s_authors; `P "r2c <support@r2c.dev>"; `S Manpage.s_bugs; `P "If you encounter an issue, please report it at\n\ \ https://github.com/returntocorp/semgrep/issues"; ] (* Small wrapper around Cmdliner.Cmd.eval_value. * Note that I didn't put this helper function in Cmdliner_helpers.ml because * it's using Exit_code.ml and Error.ml which are semgrep-specific. *) let eval_value ~argv cmd = (* the ~catch:false is to let non-cmdliner exn (e.g., Error.Semgrep_error) * to bubble up; those exns will then be caught in CLI.safe_run. *) match Cmd.eval_value ~catch:false ~argv cmd with (* alt: could define a new Exit_code for those kinds of errors *) | Error (`Term | `Parse) -> Error.exit Exit_code.fatal (* this should never happen, because of the ~catch:false above *) | Error `Exn -> assert false | Ok ok -> ( match ok with | `Ok config -> config | `Version | `Help -> Error.exit Exit_code.ok)
(* Shared parameters, options, and help messages for the semgrep CLI. *)
ruby_log.ml
open Format type pos = Lexing.position type ctx = | Ctx_Empty | Ctx_Pos of pos * ctx | Ctx_Msg of string * ctx | Ctx_Merge of ctx * ctx let empty = Ctx_Empty let loc pos ctx = Ctx_Pos (pos, ctx) let of_loc pos = loc pos Ctx_Empty let of_tok _x = raise Common.Todo let msg str ctx = Ctx_Msg (str, ctx) let of_msg str = msg str Ctx_Empty let merge c1 c2 = Ctx_Merge (c1, c2) let rec exists msg pos = function | Ctx_Empty -> false | Ctx_Msg (msg', Ctx_Pos (pos', rest)) -> if msg = msg' && pos = pos' then true else exists msg pos rest | Ctx_Pos (_, rest) | Ctx_Msg (_, rest) -> exists msg pos rest | Ctx_Merge (c1, c2) -> exists msg pos c1 || exists msg pos c2 let rec append c1 c2 = match c1 with | Ctx_Empty -> c2 | Ctx_Msg (msg, Ctx_Pos (pos, rest)) -> if exists msg pos c2 then append rest c2 else Ctx_Msg (msg, Ctx_Pos (pos, append rest c2)) | Ctx_Pos (p, ctx) -> Ctx_Pos (p, append ctx c2) | Ctx_Msg (s, ctx) -> Ctx_Msg (s, append ctx c2) | Ctx_Merge _ -> Ctx_Merge (c1, c2) let kfsprintf f fmt = let b = Buffer.create 127 in let ppf = Format.formatter_of_buffer b in Format.pp_set_margin ppf (*(Format.pp_get_margin std_formatter ())*) 80; Format.kfprintf (fun ppf -> Format.pp_print_flush ppf (); f (Buffer.contents b)) ppf fmt let in_ctx ctx ?pos fmt = match pos with | None -> kfsprintf (fun msg -> Ctx_Msg (msg, ctx)) fmt | Some p -> kfsprintf (fun msg -> Ctx_Msg (msg, Ctx_Pos (p, ctx))) fmt let format_pos ppf pos = fprintf ppf "%s:%d " (*Filename.basename*) pos.Lexing.pos_fname pos.Lexing.pos_lnum let lvl _i = (*conf.debug_level >= i*) true let stderr_ppf = formatter_of_out_channel stderr (* let fake_ppf = make_formatter (fun s pos len -> ()) (fun () -> ()) *) let dup_tbl = Hashtbl.create 12373 (* prime *) let rec format_ctx ppf ctx = let rec work ppf = function | Ctx_Empty -> () | Ctx_Pos (pos, Ctx_Empty) -> fprintf ppf "at %a" format_pos pos | Ctx_Msg (msg, Ctx_Pos (pos, Ctx_Empty)) -> fprintf ppf "@[<v 0>in %s@,at %a@]" msg format_pos pos | Ctx_Msg (msg, Ctx_Empty) -> fprintf ppf "in %s" msg | Ctx_Pos (pos, ctx) -> fprintf ppf "at %a@," format_pos pos; work ppf ctx | Ctx_Msg (msg, Ctx_Pos (pos, ctx)) -> fprintf ppf "in %s@,at %a@," msg format_pos pos; work ppf ctx | Ctx_Msg (msg, ctx) -> fprintf ppf "in %s@," msg; work ppf ctx | Ctx_Merge (ctx1, ctx2) -> fprintf ppf "@[<v 0>@[<v 0>in MERGING@, %a@]@,@[<v 0>AND@, %a@]@]" format_ctx ctx2 format_ctx ctx1 in fprintf ppf "@[<v>%a@]" work ctx let output_header cont code fmt = kfsprintf cont ("@[<v 2>[%s] " ^^ fmt ^^ "@]") code let output_msg_ctx ppf msg ctx = fprintf ppf "@[<v 0>%s@, @[<v>%a@]@]@\n@.%!" msg format_ctx ctx let show b no_dup ctx code fmt = output_header (fun msg -> if b then let buf = Buffer.create 127 in let ppf = Format.formatter_of_buffer buf in let () = output_msg_ctx ppf msg ctx in if no_dup then let full_msg = Buffer.contents buf in if Hashtbl.mem dup_tbl full_msg then () else ( Hashtbl.add dup_tbl full_msg (); pp_print_string stderr_ppf full_msg) else Buffer.output_buffer stderr buf) code fmt let flush () = Format.pp_print_flush stderr_ppf () let () = at_exit flush let fixme ?(ctx = Ctx_Empty) fmt = show true (*conf.no_dup_errors*) true ctx "FIXME" fmt let debug ?pos fmt = match pos with | None -> show (lvl 10) false Ctx_Empty "DEBUG" fmt | Some p -> show (lvl 10) false (of_loc p) "DEBUG" fmt let note ?(ctx = Ctx_Empty) fmt = show (lvl 10) false ctx "NOTE" fmt let warn ?(ctx = Ctx_Empty) fmt = show (lvl 1) false ctx "WARNING" fmt let show_raise ctx code fmt = let fail m = if not (*conf.error_raises_exc*) false then output_msg_ctx stderr_ppf m ctx; Format.pp_print_flush stderr_ppf (); failwith m in output_header fail code fmt let err ?(ctx = Ctx_Empty) fmt = if (*conf.error_raises_exc *) false then show_raise ctx "ERROR" fmt else show true (*conf.no_dup_errors*) true ctx "ERROR" fmt let fatal ctx fmt = (*conf.print_error_ctx <- true;*) show_raise ctx "FATAL" fmt
conduit_xenstore.ml
open Sexplib.Conv type direct = [ `Direct of int * Vchan.Port.t ] let ( >>= ) = Lwt.( >>= ) let ( / ) = Filename.concat let fail fmt = Printf.ksprintf (fun m -> Lwt.fail (Failure m)) fmt let err_peer_not_found = fail "Conduit_xenstore: %s peer not found" let err_no_entry_found () = fail "No /conduit Xenstore entry found. Run `xenstore-conduit-init`" let err_port = fail "%s: invalid port" module Make (Xs : Xs_client_lwt.S) = struct type t = { xs : (Xs.client[@sexp.opaque]); name : string } [@@deriving sexp_of] let get_my_id xs = Xs.(immediate xs (fun h -> read h "domid")) let xenstore_register xs myname = get_my_id xs >>= fun domid -> Xs.(immediate xs (fun h -> write h ("/conduit" / myname) domid)) let get_peer_id xs name = Lwt.catch (fun () -> Xs.(immediate xs (fun h -> read h ("/conduit" / name)))) (fun _ -> err_peer_not_found name) let readdir h d = Xs.(directory h d) >>= fun dirs -> let dirs = List.filter (fun p -> p <> "") dirs in match dirs with | [] -> Lwt.fail Xs_protocol.Eagain | hd :: _ -> Lwt.return hd let register name = Xs.make () >>= fun xs -> (* Check that a /conduit directory exists *) Lwt.catch (fun () -> Xs.(immediate xs (fun h -> read h "/conduit")) >>= fun _ -> Lwt.return_unit) (fun _ -> err_no_entry_found ()) >>= fun () -> xenstore_register xs name >>= fun () -> Lwt.return { xs; name } let accept { xs; name } = let waitfn h = readdir h ("/conduit" / name) >>= fun remote_name -> readdir h ("/conduit" / name / remote_name) >>= fun port -> Xs.read h ("/conduit" / remote_name) >>= fun remote_domid -> let remote_domid = int_of_string remote_domid in Xs.rm h ("/conduit" / name / remote_name) >>= fun () -> match Vchan.Port.of_string port with | Error (`Msg e) -> err_port e | Ok port -> Lwt.return (`Direct (remote_domid, port)) in Xs.wait xs waitfn let listen ({ name; _ } as v) = (* TODO cancellation *) let conn, push_conn = Lwt_stream.create () in Printf.printf "Conduit_xenstore: listen on %s\n%!" name; let rec loop () = accept v >>= fun c -> push_conn (Some c); loop () in Lwt.ignore_result (loop ()); Lwt.return conn let connect { xs; name } ~remote_name ~port = let port_str = Vchan.Port.to_string port in get_peer_id xs remote_name >>= fun remote_domid -> let remote_domid = int_of_string remote_domid in let path = "/conduit" / remote_name / name / port_str in Xs.(immediate xs (fun h -> write h path port_str)) >>= fun () -> Lwt.return (`Direct (remote_domid, port)) end
(* * Copyright (c) 2014-2015 Anil Madhavapeddy <anil@recoil.org> * Copyright (c) 2015 Thomas Gazagnaire <thomas@gazagnaire.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * *)
test.mli
type t module M : sig module type N = sig type u end end
t-factor_berlekamp.c
#include "fq_poly.h" #ifdef T #undef T #endif #define T fq #define CAP_T FQ #include "fq_poly_factor_templates/test/t-factor_berlekamp.c" #undef CAP_T #undef T
/* Copyright (C) 2013 Mike Hansen This file is part of FLINT. FLINT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>. */
test_date_unix.mli
(*_ This signature is deliberately empty. *)
(*_ This signature is deliberately empty. *)
bzlaembed.c
#include "preprocess/bzlaembed.h" #include "bzlacore.h" #include "bzladbg.h" #include "bzlalog.h" #include "bzlasubst.h" #include "utils/bzlautil.h" void bzla_process_embedded_constraints(Bzla *bzla) { assert(bzla); BzlaPtrHashTableIterator it; BzlaNodePtrStack ec; double start, delta; BzlaNode *cur; uint32_t count; if (bzla->embedded_constraints->count == 0u) { return; } BZLALOG(1, "start embedded constraint processing"); start = bzla_util_time_stamp(); count = 0; BZLA_INIT_STACK(bzla->mm, ec); bzla_iter_hashptr_init(&it, bzla->embedded_constraints); while (bzla_iter_hashptr_has_next(&it)) { cur = bzla_node_copy(bzla, bzla_iter_hashptr_next(&it)); assert(bzla_node_real_addr(cur)->constraint); BZLA_PUSH_STACK(ec, cur); if (bzla_node_real_addr(cur)->parents > 0) { bzla->stats.ec_substitutions++; } } bzla_substitute_and_rebuild(bzla, bzla->embedded_constraints); while (!BZLA_EMPTY_STACK(ec)) { cur = BZLA_POP_STACK(ec); if (bzla_hashptr_table_get(bzla->embedded_constraints, cur)) { count++; bzla_hashptr_table_remove(bzla->embedded_constraints, cur, 0, 0); bzla_node_release(bzla, cur); } bzla_node_release(bzla, cur); } BZLA_RELEASE_STACK(ec); delta = bzla_util_time_stamp() - start; bzla->time.embedded += delta; BZLA_MSG(bzla->msg, 1, "replaced %u embedded constraints in %1.f seconds", count, delta); assert(bzla_dbg_check_all_hash_tables_proxy_free(bzla)); assert(bzla_dbg_check_all_hash_tables_simp_free(bzla)); assert(bzla_dbg_check_unique_table_children_proxy_free(bzla)); BZLALOG(1, "end embedded constraint processing"); }
/*** * Bitwuzla: Satisfiability Modulo Theories (SMT) solver. * * This file is part of Bitwuzla. * * Copyright (C) 2007-2021 by the authors listed in the AUTHORS file. * * See COPYING for more information on using this software. */
pack_value.ml
include Irmin_pack.Pack_value module type Persistent = sig type hash include S with type hash := hash and type key = hash Pack_key.t end
(* * Copyright (c) 2022-2022 Tarides <contact@tarides.com> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)
listTrafficPolicyVersions.mli
open Types type input = ListTrafficPolicyVersionsRequest.t type output = ListTrafficPolicyVersionsResponse.t type error = Errors_internal.t include Aws.Call with type input := input and type output := output and type error := error
cache_costs.ml
module S = Saturation_repr (* Computed by typing the contract "{parameter unit; storage unit; code FAILWITH}" and evaluating [(8 * Obj.reachable_words (Obj.repr typed_script))] where [typed_script] is of type [ex_script] *) let minimal_size_of_typed_contract_in_bytes = 688 let approximate_cardinal bytes = S.safe_int (bytes / minimal_size_of_typed_contract_in_bytes) let log2 x = S.safe_int (1 + S.numbits x) let cache_update_constant = S.safe_int 600 let cache_update_coeff = S.safe_int 57 (* Cost of calling [Environment_cache.update]. *) let cache_update ~cache_size_in_bytes = let approx_card = approximate_cardinal cache_size_in_bytes in Gas_limit_repr.atomic_step_cost S.(add cache_update_constant (mul cache_update_coeff (log2 approx_card))) (* Cost of calling [Environment_cache.find]. This overapproximates [cache_find] slightly. *) let cache_find = cache_update
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2021 Nomadic Labs <contact@nomadic-labs.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
device.mli
type t = Torch_core.Device.t = | Cpu | Cuda of int val cuda_if_available : unit -> t val is_cuda : t -> bool val get_num_threads : unit -> int val set_num_threads : int -> unit
metavar_typed_generic.c
int test_equal(int a, int *p, char *x) { int b = 2; if (a == b) return 1; if (3 == 4) return 2; char c = 'a'; char d = 'b'; if (c == d) return 0; int *q = malloc(sizeof(int)); //ERROR: match if (p == q) return 1; //ERROR: match if (p == NULL) return 1; if (p == b) return 2; char *y = "bye"; //ERROR: match if (x == y) return 2; //ERROR: match if (x == "nope") return 3; //ERROR: match if ("lit1" == "lit2") return 4; //ERROR: match if (NULL == NULL) return 5; return 0; }
dune
(library (name dune_rpc_lwt) (public_name dune-rpc-lwt) (libraries result csexp dune_rpc lwt lwt.unix unix))
t-mul.c
#include <stdio.h> #include <stdlib.h> #include "fq_zech.h" #include "ulong_extras.h" #include "long_extras.h" int main(void) { int j, i, result; fq_zech_ctx_t ctx; FLINT_TEST_INIT(state); flint_printf("mul... "); fflush(stdout); for (j = 0; j < 10; j++) { fq_zech_ctx_randtest(ctx, state); /* Check aliasing: a = a * b */ for (i = 0; i < 200; i++) { fq_zech_t a, b, c; fq_zech_init(a, ctx); fq_zech_init(b, ctx); fq_zech_init(c, ctx); fq_zech_randtest(a, state, ctx); fq_zech_randtest(b, state, ctx); fq_zech_mul(c, a, b, ctx); fq_zech_mul(a, a, b, ctx); result = (fq_zech_equal(a, c, ctx)); if (!result) { flint_printf("FAIL:\n\n"); flint_printf("a = "), fq_zech_print_pretty(a, ctx), flint_printf("\n"); flint_printf("b = "), fq_zech_print_pretty(b, ctx), flint_printf("\n"); flint_printf("c = "), fq_zech_print_pretty(c, ctx), flint_printf("\n"); fflush(stdout); flint_abort(); } fq_zech_clear(a, ctx); fq_zech_clear(b, ctx); fq_zech_clear(c, ctx); } /* Check aliasing: b = a * b */ for (i = 0; i < 200; i++) { fq_zech_t a, b, c; fq_zech_init(a, ctx); fq_zech_init(b, ctx); fq_zech_init(c, ctx); fq_zech_randtest(a, state, ctx); fq_zech_randtest(b, state, ctx); fq_zech_mul(c, a, b, ctx); fq_zech_mul(b, a, b, ctx); result = (fq_zech_equal(b, c, ctx)); if (!result) { flint_printf("FAIL:\n\n"); flint_printf("a = "), fq_zech_print_pretty(a, ctx), flint_printf("\n"); flint_printf("b = "), fq_zech_print_pretty(b, ctx), flint_printf("\n"); flint_printf("c = "), fq_zech_print_pretty(c, ctx), flint_printf("\n"); fflush(stdout); flint_abort(); } fq_zech_clear(a, ctx); fq_zech_clear(b, ctx); fq_zech_clear(c, ctx); } /* Check aliasing: a = a * a */ for (i = 0; i < 200; i++) { fq_zech_t a, c; fq_zech_init(a, ctx); fq_zech_init(c, ctx); fq_zech_randtest(a, state, ctx); fq_zech_mul(c, a, a, ctx); fq_zech_mul(a, a, a, ctx); result = (fq_zech_equal(a, c, ctx)); if (!result) { flint_printf("FAIL:\n\n"); flint_printf("a = "), fq_zech_print_pretty(a, ctx), flint_printf("\n"); flint_printf("c = "), fq_zech_print_pretty(c, ctx), flint_printf("\n"); fflush(stdout); flint_abort(); } fq_zech_clear(a, ctx); fq_zech_clear(c, ctx); } /* Check that a * b == b * a */ for (i = 0; i < 200; i++) { fq_zech_t a, b, c1, c2; fq_zech_init(a, ctx); fq_zech_init(b, ctx); fq_zech_init(c1, ctx); fq_zech_init(c2, ctx); fq_zech_randtest(a, state, ctx); fq_zech_randtest(b, state, ctx); fq_zech_mul(c1, a, b, ctx); fq_zech_mul(c2, b, a, ctx); result = (fq_zech_equal(c1, c2, ctx)); if (!result) { flint_printf("FAIL:\n\n"); flint_printf("a = "), fq_zech_print_pretty(a, ctx), flint_printf("\n"); flint_printf("b = "), fq_zech_print_pretty(b, ctx), flint_printf("\n"); flint_printf("c1 = "), fq_zech_print_pretty(c1, ctx), flint_printf("\n"); flint_printf("c2 = "), fq_zech_print_pretty(c2, ctx), flint_printf("\n"); fflush(stdout); flint_abort(); } fq_zech_clear(a, ctx); fq_zech_clear(b, ctx); fq_zech_clear(c1, ctx); fq_zech_clear(c2, ctx); } /* Check that (a * b) * c == a * (b * c) */ for (i = 0; i < 200; i++) { fq_zech_t a, b, c, lhs, rhs; fq_zech_init(a, ctx); fq_zech_init(b, ctx); fq_zech_init(c, ctx); fq_zech_init(lhs, ctx); fq_zech_init(rhs, ctx); fq_zech_randtest(a, state, ctx); fq_zech_randtest(b, state, ctx); fq_zech_randtest(c, state, ctx); fq_zech_mul(lhs, a, b, ctx); fq_zech_mul(lhs, lhs, c, ctx); fq_zech_mul(rhs, b, c, ctx); fq_zech_mul(rhs, a, rhs, ctx); result = (fq_zech_equal(lhs, rhs, ctx)); if (!result) { flint_printf("FAIL (a * b) * c == a * (b * c) :\n\n"); fq_zech_ctx_print(ctx); flint_printf("\n"); flint_printf("a = "), fq_zech_print_pretty(a, ctx), flint_printf("\n"); flint_printf("b = "), fq_zech_print_pretty(b, ctx), flint_printf("\n"); flint_printf("c = "), fq_zech_print_pretty(c, ctx), flint_printf("\n"); flint_printf("lhs = "), fq_zech_print_pretty(lhs, ctx), flint_printf("\n"); flint_printf("rhs = "), fq_zech_print_pretty(rhs, ctx), flint_printf("\n"); fflush(stdout); flint_abort(); } fq_zech_clear(a, ctx); fq_zech_clear(b, ctx); fq_zech_clear(c, ctx); fq_zech_clear(lhs, ctx); fq_zech_clear(rhs, ctx); } fq_zech_ctx_clear(ctx); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return EXIT_SUCCESS; }
/* Copyright (C) 2013 Mike Hansen This file is part of FLINT. FLINT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>. */
Time_limit.mli
(* Contains the name given by the user to the timer and the time limit *) type timeout_info (* If ever caught, this exception must be re-raised immediately so as to not interfere with the timeout handler. See function 'set_timeout'. *) exception Timeout of timeout_info (* Show name and time limit in a compact format for debugging purposes. *) val string_of_timeout_info : timeout_info -> string (* Launch the specified computation and abort if it takes longer than specified (in seconds). This uses a global timer. An Invalid_argument exception will be raised if the timer is already running. tl;dr nesting will fail *) val set_timeout : name:string -> float -> (unit -> 'a) -> 'a option (* Only set a timer if a time limit is specified. Uses 'set_timeout'. *) val set_timeout_opt : name:string -> float option -> (unit -> 'a) -> 'a option
(* Contains the name given by the user to the timer and the time limit *) type timeout_info
why3printer.mli
(********************************************************************) (* *) (* The Why3 Verification Platform / The Why3 Development Team *) (* Copyright 2010-2023 -- Inria - CNRS - Paris-Saclay University *) (* *) (* This software is distributed under the terms of the GNU Lesser *) (* General Public License version 2.1, with the special exception *) (* on linking described in file LICENSE. *) (* *) (********************************************************************)
external.mli
external foo : unit -> unit = "bar" (** Foo {e bar}. *)
var_queue.h
#pragma once #include "util/heap.h" class var_queue { typedef unsigned var; struct lt { svector<unsigned> & m_activity; lt(svector<unsigned> & act):m_activity(act) {} bool operator()(var v1, var v2) const { return m_activity[v1] > m_activity[v2]; } }; heap<lt> m_queue; public: var_queue(svector<unsigned> & act):m_queue(128, lt(act)) {} void activity_increased_eh(var v) { if (m_queue.contains(v)) m_queue.decreased(v); } void activity_changed_eh(var v, bool up) { if (m_queue.contains(v)) { if (up) m_queue.decreased(v); else m_queue.increased(v); } } void mk_var_eh(var v) { m_queue.reserve(v+1); unassign_var_eh(v); } void del_var_eh(var v) { if (m_queue.contains(v)) m_queue.erase(v); } void unassign_var_eh(var v) { if (!m_queue.contains(v)) m_queue.insert(v); } void reset() { m_queue.reset(); } bool empty() const { return m_queue.empty(); } var next_var() { SASSERT(!empty()); return m_queue.erase_min(); } var min_var() { SASSERT(!empty()); return m_queue.min_value(); } bool more_active(var v1, var v2) const { return m_queue.less_than(v1, v2); } std::ostream& display(std::ostream& out) const { bool first = true; for (auto v : m_queue) { if (first) { first = false; } else { out << " "; } out << v; } return out; } }; inline std::ostream& operator<<(std::ostream& out, var_queue const& queue) { return queue.display(out); }
/*++ Copyright (c) 2011 Microsoft Corporation Module Name: var_queue.h Abstract: SAT variable priority queue. Author: Leonardo de Moura (leonardo) 2011-05-21. Revision History: --*/
main.mli
(*_ This signature is deliberately empty. *)
(*_ This signature is deliberately empty. *)
dune
(tests (names gnuplot_test example) (libraries prbnmcn-gnuplot) )
bits.mli
(** Assuming [x >= 0], [numbits x] is the number of bits needed to represent [x]. This is also the unique [k] such that [2^{k - 1} <= x < 2^k] if [x > 0] and [0] otherwise. *) val numbits : int -> int
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2021 Nomadic Labs. <contact@nomadic-labs.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
dune
(library (public_name dream.graphiql) (name dream__graphiql)) (rule (targets dream__graphiql.ml) (deps (:bundle index.bundle.html)) (action (with-stdout-to %{targets} (progn (echo "let content = {html|") (cat %{bundle}) (echo "|html}"))))) (data_only_dirs node_modules)
test_immediate.ml
open! Base open! Import let%expect_test "[Base.Hash.state] is still immediate" = require_no_allocation [%here] (fun () -> ignore (Sys.opaque_identity (Base.Hash.create ()))); [%expect {| |}] let%expect_test _ = print_s [%sexp (Caml.Obj.is_int (Caml.Obj.repr (Base.Hash.create ~seed:1 ())) : bool)]; [%expect {| true |}]; ;;
sorted_records.ml
open Lens_utility open Lens_utility.O module Value = Phrase_value module E = struct type t = Unsupported_phrase_value_cmp of { v1 : Value.t; v2 : Value.t } let pp f v = match v with | Unsupported_phrase_value_cmp { v1; v2 } -> Format.fprintf f "Unsupported phrase value comparison between '%a' and '%a' by lens \ sorted records module." Value.pp v1 Value.pp v2 let show v = Format.asprintf "%a" pp v exception E of t let raise v = raise (E v) let () = let f v = match v with | E v -> Some (show v) | _ -> None in Printexc.register_printer f end module Simple_record = struct (** simplified record type drops column names for efficiency *) type t = Value.t list let compare_val v1 v2 = match (v1, v2) with | Value.Bool b1, Value.Bool b2 -> compare b1 b2 | Value.Char c1, Value.Char c2 -> compare c1 c2 | Value.Float f1, Value.Float f2 -> compare f1 f2 | Value.Int i1, Value.Int i2 -> compare i1 i2 | Value.String i1, Value.String i2 -> compare i1 i2 | Value.Serial s1, Value.Serial s2 -> ( match (s1, s2) with | `NewKeyMapped _, `Key _ -> 1 | `Key _, `NewKeyMapped _ -> -1 | `NewKeyMapped v1, `NewKeyMapped v2 -> compare v1 v2 | `Key v1, `Key v2 -> compare v1 v2 | _ -> E.Unsupported_phrase_value_cmp { v1; v2 } |> E.raise) | _, _ -> E.Unsupported_phrase_value_cmp { v1; v2 } |> E.raise let equal_val a b = compare_val a b = 0 let rec compare a b = match (a, b) with | x :: xs, y :: ys -> let res = compare_val x y in if res = 0 then compare xs ys else res | _, _ -> 0 (* if either of the lists are empty, return match this allows us to perform partial matching *) let map ~f v = List.map ~f v let find_index rs ~record = let rec pivot s e = if s > e then None else let m = (s + e) / 2 in let r = compare rs.(m) record in match r with | a when a > 0 -> pivot s (m - 1) | a when a < 0 -> pivot (m + 1) e | _ -> Some r in let r = pivot 0 (Array.length rs - 1) in r let find_record rs ~record = find_index rs ~record |> Option.map ~f:(Array.get rs) let find_all_index rs ~record = let rec pivot s e b = if s > e then if b then e else s else let m = (s + e) / 2 in let res = compare rs.(m) record in match res with | a when a > 0 -> pivot s (m - 1) b | a when a < 0 -> pivot (m + 1) e b | _ -> if b then pivot (m + 1) e b else pivot s (m - 1) b in let b = pivot 0 (Array.length rs - 1) false in let e = pivot 0 (Array.length rs - 1) true in (b, e) let find_all_record rs ~record = let b, e = find_all_index rs ~record in Array.sub rs b (e + 1 - b) let to_value t ~columns = Value.box_record (List.zip_exn columns t) let equal v1 v2 = List.for_all2 equal_val v1 v2 end type t = { columns : string list; plus_rows : Simple_record.t array; neg_rows : Simple_record.t array; } module Inconsistent_columns_error = struct exception E of string list * string list let () = Printexc.register_printer (function | E (l1, l2) -> Format.asprintf "Lens set columns inconsistent: %a != %a" (Format.pp_comma_list Format.pp_print_string) l1 (Format.pp_comma_list Format.pp_print_string) l2 |> Option.return | _ -> None) end let construct_cols ~columns ~records = let recs = List.map ~f:Value.unbox_record records in let col_val a r = try List.find_exn ~f:(fst >> ( = ) a) r |> snd with | _ -> Inconsistent_columns_error.E (columns, List.map ~f:fst r) |> raise in let simpl_rec r = List.map2 (fun a (k, v) -> if a = k then v else col_val a r) columns r in let plus_rows = Array.of_list (List.map ~f:simpl_rec recs) in Array.sort compare plus_rows; { columns; plus_rows; neg_rows = [||] } let construct ~records = let recs = List.map ~f:Value.unbox_record records in let columns = List.map ~f:(fun (k, _v) -> k) (List.hd recs) in construct_cols ~columns ~records let sort rs = Array.sort Simple_record.compare rs.plus_rows; Array.sort Simple_record.compare rs.neg_rows let construct_full ~columns ~plus ~neg = let v = { columns; plus_rows = Array.of_list plus; neg_rows = Array.of_list neg } in sort v; v let columns t = t.columns let plus_rows t = t.plus_rows let neg_rows t = t.neg_rows let is_positive t = Array.length t.neg_rows = 0 let total_size a = Array.length a.plus_rows + Array.length a.neg_rows let pp_value f v = match v with | Value.String s -> Format.fprintf f "\"%s\"" s | Value.Int i -> Format.fprintf f "%d" i | Value.Float v -> Format.fprintf f "%f" v | Value.Bool b -> Format.fprintf f "%b" b | Value.Char c -> Format.fprintf f "%c" c | _ -> Value.pp f v let pp b rs = let cols = rs.columns in let pp_val b (k, v) = Format.fprintf b "%s: %a" k pp_value v in let pp_record b row = Format.fprintf b "(%a)" (Format.pp_comma_list pp_val) (List.zip_exn cols row) in Format.fprintf b "%a" (Format.pp_newline_list pp_record) (rs.plus_rows |> Array.to_list) let pp_tabular f rs = let pp_sep f () = Format.pp_print_string f "| " in let pp_list pp f v = Format.pp_print_list ~pp_sep pp f v in let pp_val f v = Format.pp_padded ~length:8 pp_value f v in let pp_row f v = pp_list pp_val f v in let pp_rows f v = Format.pp_newline_list pp_row f @@ Array.to_list v in let pp_padded f v = Format.pp_padded ~length:8 f v in let pp_header f v = pp_list (pp_padded Format.pp_print_string) f v in let pp_v_sep f () = let pp_sep f () = Format.pp_print_string f "--" in let pp_str f v = Format.pp_print_string f @@ String.make (String.length v) '-' in Format.pp_print_list ~pp_sep pp_str f rs.columns in Format.fprintf f "%a\n%a\n%a\n%a\n%a" pp_header rs.columns pp_v_sep () pp_rows rs.plus_rows pp_v_sep () pp_rows rs.neg_rows let find rs ~record = Simple_record.find_index rs.plus_rows ~record |> Option.is_some let map_values ~f rs = let { plus_rows; neg_rows; columns } = rs in let plus_rows = Array.map (Simple_record.map ~f) plus_rows in let neg_rows = Array.map (Simple_record.map ~f) neg_rows in { plus_rows; neg_rows; columns } (** Construct a function which returns the nth value of a list, correspodning to the position of that column in cols *) let get_col_map_list cols col = let rec fn cols = match cols with | x :: xs -> ( if x = col then Some (fun x -> List.hd x) else let fn2 = fn xs in match fn2 with | Some fn2 -> Some (fun x -> fn2 (List.tl x)) | None -> None) | _ -> None in fn cols let get_col_map rs ~column = get_col_map_list rs.columns column let get_cols_map rs ~columns = let maps = List.filter_map ~f:(fun column -> get_col_map rs ~column) columns in fun r -> List.map ~f:(fun mp -> mp r) maps let sort_uniq rs = let fn r = Array.of_list (List.sort_uniq compare (Array.to_list r)) in { rs with plus_rows = fn rs.plus_rows; neg_rows = fn rs.neg_rows } let negate rs = { rs with plus_rows = rs.neg_rows; neg_rows = rs.plus_rows } let negative rs = { rs with plus_rows = [||] } (* filter out the records which don't satisfy pred *) let filter rs ~predicate = let getv column = get_col_map rs ~column in let get_col_val row col = match getv col with | Some a -> a row | None -> failwith ("Column " ^ col ^ " not in record set.") in let filter rows = Array.of_list (List.filter (fun r -> Phrase.eval predicate (get_col_val r) = Value.box_bool true) (Array.to_list rows)) in { columns = rs.columns; plus_rows = filter rs.plus_rows; neg_rows = filter rs.neg_rows; } (* ensures that all columns in contains are in cols *) let cols_contain cols contains = List.for_all ~f:(List.mem ~equal:String.equal cols) contains let zip_delta_merge left right = let rec do_next left right = match (left, right) with | x :: xs, y :: ys -> ( match compare x y with | a when a < 0 -> (* x < y, so take x and see if can find y *) let left, right = do_next xs right in (x :: left, right) | a when a > 0 -> (* x > y, so take y and try find x *) let left, right = do_next left ys in (left, y :: right) | _ -> (* x = y, so skip both *) do_next xs ys) | _ -> (left, right) (* one of them is empty so return rest *) in let left, right = do_next left right in (List.sort_uniq compare left, List.sort_uniq compare right) let project_onto rs ~columns = let maps v = get_cols_map rs ~columns v in let plus_rows = Array.map maps rs.plus_rows |> Array.to_list in let neg_rows = Array.map maps rs.neg_rows |> Array.to_list in let columns = maps rs.columns in let plus_rows, neg_rows = zip_delta_merge plus_rows neg_rows in let plus_rows, neg_rows = (Array.of_list plus_rows, Array.of_list neg_rows) in { columns; plus_rows; neg_rows } let project_onto_set rs ~onto = project_onto rs ~columns:onto.columns let merge rs1 rs2 = let proj = project_onto_set rs2 ~onto:rs1 in let plus = List.append (Array.to_list rs1.plus_rows) (Array.to_list proj.plus_rows) in let plus = List.sort compare plus in let neg = List.append (Array.to_list rs1.neg_rows) (Array.to_list proj.neg_rows) in let neg = List.sort compare neg in let plus, neg = zip_delta_merge plus neg in { columns = rs1.columns; plus_rows = Array.of_list plus; neg_rows = Array.of_list neg; } let minus rs1 rs2 = if is_positive rs2 |> not then failwith "Cannot subtract from negative multiplicities" else let proj = project_onto_set rs2 ~onto:rs1 in let map = get_cols_map rs1 ~columns:proj.columns in let plus_rows = List.filter (fun r -> find proj ~record:(map r)) @@ Array.to_list rs1.plus_rows |> Array.of_list in { rs1 with plus_rows } module Reorder_error = struct type t = Not_subset of { first : string list; cols : string list } let pp f v = match v with | Not_subset { first; cols } -> Format.fprintf f "Could not reorder the columns { %a } to the left as they are not a \ subset of { %a }." Format.pp_comma_string_list first Format.pp_comma_string_list cols end let reorder_cols cols ~first = if not (cols_contain cols first) then Reorder_error.Not_subset { first; cols } |> Result.error else let rest = List.filter (fun a -> not (List.mem ~equal:String.equal first a)) cols in List.append first rest |> Result.return let reorder t ~first = let open Result.O in reorder_cols (columns t) ~first >>| fun columns -> project_onto t ~columns let reorder_exn t ~first = reorder t ~first |> Result.ok_internal ~pp:Reorder_error.pp let subtract_cols cols remove = List.filter (fun a -> not (List.mem ~equal:String.equal remove a)) cols module Join_error = struct type elt = t type t = | Reorder_error of { error : Reorder_error.t; left : elt; right : elt } let pp f v = let pp_data f (left, right) = Format.fprintf f "\n\njoin left:\n%a\n\njoin right:\n%a" pp_tabular left pp_tabular right in match v with | Reorder_error { error; left; right } -> Format.fprintf f "Error reordering columns: %a%a" Reorder_error.pp error pp_data (left, right) end let join left right ~on = let open Result.O in let on_out, on_left, on_right = List.unzip3 on in reorder_cols right.columns ~first:on_right |> Result.map_error ~f:(fun error -> Join_error.Reorder_error { left; right; error }) >>| fun right_cols -> let right = project_onto right ~columns:right_cols in let lmap = get_cols_map left ~columns:on_left in let rjoinmap_right = get_cols_map right ~columns:(subtract_cols right_cols on_right) in let rjoinmap_right' = get_cols_map right ~columns:(subtract_cols right_cols on_right) in let join_list l1 l2 = let joined = List.map ~f:(fun r1 -> let proj = lmap r1 in let matching = Simple_record.find_all_record l2 ~record:proj in let joined = List.map ~f:(fun r2 -> List.flatten [ r1; rjoinmap_right r2 ]) (Array.to_list matching) in joined) (Array.to_list l1) in List.flatten joined in let pos = join_list left.plus_rows right.plus_rows in let pos = List.sort compare pos in let neg = List.flatten [ join_list left.plus_rows right.neg_rows; join_list left.neg_rows right.plus_rows; join_list left.neg_rows right.neg_rows; ] in let neg = List.sort compare neg in let pos, neg = zip_delta_merge pos neg in let l_map = String.Map.from_alist (List.zip_nofail on_left on_out) in let l_cols = List.map ~f:(fun v -> String.Map.find_opt v l_map |> Option.value ~default:v) left.columns in let columns = List.flatten [ l_cols; rjoinmap_right' right_cols ] in { columns; plus_rows = Array.of_list pos; neg_rows = Array.of_list neg } let join_exn left right ~on = join left right ~on |> Result.ok_internal ~pp:Join_error.pp let to_value ts = if is_positive ts then Array.map (Simple_record.to_value ~columns:ts.columns) ts.plus_rows |> Array.to_list else failwith "Cannot convert a non positive delta to a value type." let project_fun_dep ts ~fun_dep = let fdl, fdr = (Fun_dep.left fun_dep, Fun_dep.right fun_dep) in let cols_l = Alias.Set.elements fdl in let cols_r = Alias.Set.elements fdr in let fdl_map = get_cols_map ts ~columns:cols_l in let fdr_map = get_cols_map ts ~columns:cols_r in let map r = (fdl_map r, fdr_map r) in ((cols_l, cols_r), Array.map map ts.plus_rows, Array.map map ts.neg_rows) let calculate_fd_changelist data ~fun_deps = (* get the key of the row for finding complements *) let rec loop fds = if Fun_dep.Set.is_empty fds then [] else let fun_dep = Fun_dep.Set.root_fds fds |> fun v -> List.hd v in let cols, changeset_pos, _ = project_fun_dep data ~fun_dep in let changeset = Array.to_list changeset_pos in (* remove duplicates and sort *) let changeset = List.sort_uniq (fun (a, _) (a', _) -> Simple_record.compare a a') changeset in let fds = Fun_dep.Set.remove fun_dep fds in (cols, changeset) :: loop fds in let res = loop fun_deps in (* reverse the list, so that the FD roots appear first *) List.rev res let relational_update t ~fun_deps ~update_with = let changelist = calculate_fd_changelist ~fun_deps update_with in let changes = List.map ~f:(fun ((cols_l, _cols_r), _l) -> (* get a map from simp rec to col value *) let col_maps = List.map ~f:(fun column -> get_col_map t ~column) cols_l in let col_maps = List.flatten (List.map ~f:(fun mp -> match mp with | None -> [] | Some a -> [ a ]) col_maps) in (* get a function which compares column with change *) let comp record change_key = List.for_all2 (fun mp1 key -> mp1 record = key) col_maps change_key in comp) changelist in (* each entry in changelist is a functional dependency, and then the corresponding records *) (* generate a function for every change list entry, which can replace the columns in the * right side of the functional dependency of a record in res *) let apply_changes = List.map ~f:(fun ((_cols_l, cols_r), _l) -> (* upd cols returns a function which, given a record another record containing cols_r, * replaces every column value in the first record from that in the second record if it * matches *) let rec upd cols = match cols with | [] -> fun _r _target -> [] | x :: xs -> ( let fn = upd xs in (* get a function which maps a row to the x's value *) let map = get_col_map_list cols_r x in match map with | None -> (* the column does not have to be replaced *) fun yl target -> List.hd yl :: fn (List.tl yl) target | Some mp -> (* the column has been found, replace *) fun yl target -> mp target :: fn (List.tl yl) target) in columns t |> upd) changelist in let update arr = Array.map (fun r -> let r' = List.fold_left (fun r ((check, update), (_, changes)) -> let upd = List.find ~f:(fun (left, _right) -> check r left) changes in match upd with | None -> r | Some (_left, right) -> update r right) r (List.zip_exn (List.zip_exn changes apply_changes) changelist) in r') arr in let plus_rows = update t.plus_rows in let neg_rows = [||] in let res = { t with neg_rows; plus_rows } in sort_uniq res let abs t = let plus_rows = t.plus_rows in let columns = t.columns in { plus_rows; columns; neg_rows = [||] } let relational_merge t ~fun_deps ~update_with = let updated = relational_update t ~fun_deps ~update_with in merge updated @@ abs update_with let relational_extend t ~key ~by ~data ~default = let open Result.O in let colmap = get_cols_map t ~columns:[ key ] in reorder data ~first:[ key ] >>| fun data -> let relevant_value_map = Option.value_exn (get_col_map data ~column:by) in let extend row = let find = colmap row in let rel = Simple_record.find_record data.plus_rows ~record:find in let v = match rel with | None -> default | Some r -> relevant_value_map r in List.append row [ v ] in let plus_rows = Array.map extend t.plus_rows in let neg_rows = Array.map extend t.neg_rows in let columns = List.append t.columns [ by ] in { columns; plus_rows; neg_rows } let relational_extend_exn t ~key ~by ~data ~default = relational_extend t ~key ~by ~data ~default |> Result.ok_internal ~pp:Reorder_error.pp let all_values t = let recs = List.append (Array.to_list t.plus_rows) (Array.to_list t.neg_rows) in List.sort_uniq Simple_record.compare recs let to_diff t ~key = let open Result.O in let key_len = List.length key in reorder t ~first:key >>| fun t -> let insert_vals, update_vals = List.partition (fun row -> let key_vals = List.take row ~n:key_len in let row = Simple_record.find_index t.neg_rows ~record:key_vals in Option.is_none row) (Array.to_list t.plus_rows) in let delete_vals = Array.to_list t.neg_rows |> List.filter (fun row -> let key_vals = List.take row ~n:key_len in let row = Simple_record.find_index t.plus_rows ~record:key_vals in Option.is_none row) in (columns t, (insert_vals, update_vals, delete_vals)) let to_diff_exn t ~key = to_diff t ~key |> Result.ok_internal ~pp:Reorder_error.pp let force_positive t = let t = { t with plus_rows = Array.append t.plus_rows t.neg_rows; neg_rows = [||] } in sort_uniq t
parsing_hacks_php.mli
val fix_tokens : Parser_php.token list -> Parser_php.token list
salsa20_tests.ml
let test_salsa20 ~hash ~key ~nonce ~input ~output0 ~output1 ~output2 ~output3 ~offset0 ~offset1 ~offset2 ~offset3 = let open Cstruct in let open Alcotest in let key = of_hex key and nonce = of_hex nonce and input = of_hex input and output0 = output0 |> of_hex |> to_string and output1 = output1 |> of_hex |> to_string and output2 = output2 |> of_hex |> to_string and output3 = output3 |> of_hex |> to_string in (fun () -> let stream = Salsa20.create ~hash key nonce |> Salsa20.encrypt input |> to_string in check int "Salsa20 test output length" (Cstruct.length input) (String.length stream); check string "Salsa20 test block 0 value" (String.sub stream offset0 64) output0; check string "Salsa20 test block 1 value" (String.sub stream offset1 64) output1; check string "Salsa20 test block 2 value" (String.sub stream offset2 64) output2; check string "Salsa20 test block 3 value" (String.sub stream offset3 64) output3) let salsa20_8_tests = [ (* TODO *) ] let salsa20_12_tests = [ (* TODO *) ] let test_salsa20_20 ~key ~nonce ~input ~output0 ~output1 ~output2 ~output3 = let short = String.length input == 1024 in let offset0 = 0 and offset1 = if short then 192 else 65472 and offset2 = if short then 256 else 65536 and offset3 = if short then 448 else 131008 in test_salsa20 ~hash:Salsa20_core.salsa20_20_core ~key ~nonce ~input ~output0 ~output1 ~output2 ~output3 ~offset0 ~offset1 ~offset2 ~offset3 let salsa20_20_128bit_ecrypt_set1_vector0_test = test_salsa20_20 ~key:"80000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("4DFA5E481DA23EA09A31022050859936" ^ "DA52FCEE218005164F267CB65F5CFD7F" ^ "2B4F97E0FF16924A52DF269515110A07" ^ "F9E460BC65EF95DA58F740B7D1DBB0AA") ~output1:("DA9C1581F429E0A00F7D67E23B730676" ^ "783B262E8EB43A25F55FB90B3E753AEF" ^ "8C6713EC66C51881111593CCB3E8CB8F" ^ "8DE124080501EEEB389C4BCB6977CF95") ~output2:("7D5789631EB4554400E1E025935DFA7B" ^ "3E9039D61BDC58A8697D36815BF1985C" ^ "EFDF7AE112E5BB81E37ECF0616CE7147" ^ "FC08A93A367E08631F23C03B00A8DA2F") ~output3:("B375703739DACED4DD4059FD71C3C47F" ^ "C2F9939670FAD4A46066ADCC6A564578" ^ "3308B90FFB72BE04A6B147CBE38CC0C3" ^ "B9267C296A92A7C69873F9F263BE9703") let salsa20_20_128bit_ecrypt_set1_vector9_test = test_salsa20_20 ~key:"00400000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("0471076057830FB99202291177FBFE5D" ^ "38C888944DF8917CAB82788B91B53D1C" ^ "FB06D07A304B18BB763F888A61BB6B75" ^ "5CD58BEC9C4CFB7569CB91862E79C459") ~output1:("D1D7E97556426E6CFC21312AE3811425" ^ "9E5A6FB10DACBD88E4354B0472556935" ^ "2B6DA5ACAFACD5E266F9575C2ED8E6F2" ^ "EFE4B4D36114C3A623DD49F4794F865B") ~output2:("AF06FAA82C73291231E1BD916A773DE1" ^ "52FD2126C40A10C3A6EB40F22834B8CC" ^ "68BD5C6DBD7FC1EC8F34165C517C0B63" ^ "9DB0C60506D3606906B8463AA0D0EC2F") ~output3:("AB3216F1216379EFD5EC589510B8FD35" ^ "014D0AA0B613040BAE63ECAB90A9AF79" ^ "661F8DA2F853A5204B0F8E72E9D9EB4D" ^ "BA5A4690E73A4D25F61EE7295215140C") let salsa20_20_128bit_ecrypt_set1_vector18_test = test_salsa20_20 ~key:"00002000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("BACFE4145E6D4182EA4A0F59D4076C7E" ^ "83FFD17E7540E5B7DE70EEDDF9552006" ^ "B291B214A43E127EED1DA1540F33716D" ^ "83C3AD7D711CD03251B78B2568F2C844") ~output1:("56824347D03D9084ECCF358A0AE410B9" ^ "4F74AE7FAD9F73D2351E0A44DF127434" ^ "3ADE372BDA2971189623FD1EAA4B723D" ^ "76F5B9741A3DDC7E5B3E8ED4928EF421") ~output2:("999F4E0F54C62F9211D4B1F1B79B227A" ^ "FB3116C9CF9ADB9715DE856A8EB31084" ^ "71AB40DFBF47B71389EF64C20E1FFDCF" ^ "018790BCE8E9FDC46527FE1545D3A6EA") ~output3:("76F1B87E93EB9FEFEC3AED69210FE4AB" ^ "2ED577DECE01A75FD364CD1CD7DE1027" ^ "5A002DDBC494EE8350E8EEC1D8D6925E" ^ "FD6FE7EA7F610512F1F0A83C8949AEB1") let salsa20_20_128bit_ecrypt_set1_vector27_test = test_salsa20_20 ~key:"00000010000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("24F4E317B675336E68A8E2A3A04CA967" ^ "AB96512ACBA2F832015E9BE03F08830F" ^ "CF32E93D14FFBD2C901E982831ED8062" ^ "21D7DC8C32BBC8E056F21BF9BDDC8020") ~output1:("E223DE7299E51C94623F8EAD3A6DB045" ^ "4091EE2B54A498F98690D7D84DB7EFD5" ^ "A2A8202435CAC1FB34C842AEECF643C6" ^ "3054C424FAC5A632502CD3146278498A") ~output2:("5A111014076A6D52E94C364BD7311B64" ^ "411DE27872FC8641D92C9D811F2B5185" ^ "94935F959D064A9BE806FAD06517819D" ^ "2321B248E1F37E108E3412CE93FA8970") ~output3:("8A9AB11BD5360D8C7F34887982B3F658" ^ "6C34C1D6CB49100EA5D09A24C6B835D5" ^ "77C1A1C776902D785CB5516D74E87480" ^ "79878FDFDDF0126B1867E762546E4D72") let salsa20_20_128bit_ecrypt_set1_vector36_test = test_salsa20_20 ~key:"00000000080000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("9907DB5E2156427AD15B167BEB0AD445" ^ "452478AFEE3CF71AE1ED8EAF43E001A1" ^ "C8199AF9CFD88D2B782AA2F39845A26A" ^ "7AC54E5BE15DB7BDFBF873E16BC05A1D") ~output1:("EBA0DCC03E9EB60AE1EE5EFE3647BE45" ^ "6E66733AA5D6353447981184A05F0F0C" ^ "B0AD1CB630C35DC253DE3FEBD10684CA" ^ "DBA8B4B85E02B757DED0FEB1C31D71A3") ~output2:("BD24858A3DB0D9E552345A3C3ECC4C69" ^ "BBAE4901016A944C0D7ECCAAB9027738" ^ "975EEA6A4240D94DA183A74D649B789E" ^ "24A0849E26DC367BDE4539ADCCF0CAD8") ~output3:("EE20675194FA404F54BAB7103F6821C1" ^ "37EE2347560DC31D338B01026AB6E571" ^ "65467215315F06360D85F3C5FE7A359E" ^ "80CBFE735F75AA065BC18EFB2829457D") let salsa20_20_128bit_ecrypt_set1_vector45_test = test_salsa20_20 ~key:"00000000000400000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("A59CE982636F2C8C912B1E8105E2577D" ^ "9C86861E61FA3BFF757D74CB9EDE6027" ^ "D7D6DE775643FAF5F2C04971BDCB56E6" ^ "BE8144366235AC5E01C1EDF8512AF78B") ~output1:("DF8F13F1059E54DEF681CD554439BAB7" ^ "24CDE604BE5B77D85D2829B3EB137F4F" ^ "2466BEADF4D5D54BA4DC36F1254BEC4F" ^ "B2B367A59EA6DDAC005354949D573E68") ~output2:("B3F542ECBAD4ACA0A95B31D281B930E8" ^ "021993DF5012E48A333316E712C4E19B" ^ "58231AAE7C90C91C9CC135B12B490BE4" ^ "2CF9C9A2727621CA81B2C3A081716F76") ~output3:("F64A6449F2F13030BE554DB00D24CD50" ^ "A89F80CCFE97435EBF0C49EB08747BF7" ^ "B2C89BE612629F231C1B3398D8B4CC3F" ^ "35DBECD1CF1CFDFDECD481B72A51276A") let salsa20_20_128bit_ecrypt_set1_vector54_test = test_salsa20_20 ~key:"00000000000002000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("7A8131B777F7FBFD33A06E396FF32D7D" ^ "8C3CEEE9573F405F98BD6083FE57BAB6" ^ "FC87D5F34522D2440F649741D9F87849" ^ "BC8751EF432DEE5DCC6A88B34B6A1EA9") ~output1:("6573F813310565DB22219984E0919445" ^ "9E5BB8613237F012EBB8249666582ACA" ^ "751ED59380199117DDB29A5298F95FF0" ^ "65D271AB66CF6BC6CDE0EA5FC4D304EB") ~output2:("0E65CB6944AFBD84F5B5D00F307402B8" ^ "399BF02852ED2826EA9AA4A55FB56DF2" ^ "A6B83F7F228947DFAB2E0B10EAAA09D7" ^ "5A34F165ECB4D06CE6AB4796ABA3206A") ~output3:("11F69B4D034B1D7213B9560FAE89FF2A" ^ "53D9D0C9EAFCAA7F27E9D119DEEEA299" ^ "AC8EC0EA0529846DAF90CF1D9BFBE406" ^ "043FE03F1713F249084BDD32FD98CD72") let salsa20_20_128bit_ecrypt_set1_vector63_test = test_salsa20_20 ~key:"00000000000000010000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("FE4DF972E982735FFAEC4D66F929403F" ^ "7246FB5B2794118493DF068CD310DEB6" ^ "3EEEF12344E221A2D163CC666F5685B5" ^ "02F4883142FA867B0BA46BF17D011984") ~output1:("4694F79AB2F3877BD590BA09B413F1BD" ^ "F394C4D8F2C20F551AA5A07207433204" ^ "C2BC3A3BA014886A08F4EC5E4D91CDD0" ^ "1D7A039C5B815754198B2DBCE68D25EA") ~output2:("D1340204FB4544EFD5DAF28EDCC6FF03" ^ "B39FBEE708CAEF6ABD3E2E3AB5738B32" ^ "04EF38CACCC40B9FBD1E6F0206A2B564" ^ "E2F9EA05E10B6DD061F6AB94374681C0") ~output3:("BB802FB53E11AFDC3104044D70448079" ^ "41FDAEF1042E0D35972D80CE77B4D560" ^ "083EB4113CDBC4AC56014D7FF94291DC" ^ "9387CEF74A0E165042BC12373C6E020C") let salsa20_20_128bit_ecrypt_set1_vector72_test = test_salsa20_20 ~key:"00000000000000000080000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("8F8121BDD7B286465F03D64CA45A4A15" ^ "4BDF44560419A40E0B482CED194C4B32" ^ "4F2E9295C452B73B292BA7F55A692DEE" ^ "A5129A49167BA7AABBEED26E39B25E7A") ~output1:("7E4388EDBBA6EC5882E9CBF01CFA6786" ^ "0F10F0A5109FCA7E865C3814EB007CC8" ^ "9585C2653BDCE30F667CF95A2AA425D3" ^ "5A531F558180EF3E32A9543AE50E8FD6") ~output2:("527FF72879B1B809C027DFB7B39D02B3" ^ "04D648CD8D70F4E0465615B334ED9E2D" ^ "59703745467F1168A8033BA861841DC0" ^ "0E7E1AB5E96469F6DA01B8973D0D414A") ~output3:("82653E0949A5D8E32C4D0A81BBF96F6A" ^ "7249D4D1E0DCDCC72B90565D9AF4D0AC" ^ "461C1EAC85E254DD5E567A009EEB3897" ^ "9A2FD1E4F32FAD15D177D766932190E1") let salsa20_20_128bit_ecrypt_set1_vector81_test = test_salsa20_20 ~key:"00000000000000000000400000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("52FA8BD042682CD5AA21188EBF3B9E4A" ^ "EE3BE38AE052C5B37730E52C6CEE33C9" ^ "1B492F95A67F2F6C15425A8623C0C2AE" ^ "7275FFD0FCF13A0A293A784289BEACB4") ~output1:("5F43C508BA6F728D032841618F96B103" ^ "19B094027E7719C28A8A8637D4B0C4D2" ^ "25D602EA23B40D1541A3F8487F25B14A" ^ "8CBD8D2001AC28EADFDC0325BA2C140E") ~output2:("5C802C813FF09CAF632CA8832479F891" ^ "FB1016F2F44EFA81B3C872E37468B818" ^ "3EB32D8BD8917A858AEF47524FCC05D3" ^ "688C551FC8A42C8D9F0509018706E40E") ~output3:("4CDD40DC6E9C0E4F84810ABE712003F6" ^ "4B23C6D0C88E61D1F303C3BBD89B58AA" ^ "098B44B5CD82EDCFC618D324A41317AC" ^ "6FED20C9A0C54A9ED1F4DA3BF2EC3C66") let salsa20_20_128bit_ecrypt_set1_vector90_test = test_salsa20_20 ~key:"00000000000000000000002000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("6262315C736E88717E9627EECF4F6B55" ^ "BD10D5960A9961D572EFC7CBDB9A1F01" ^ "1733D3E17E4735BEFA16FE6B148F8661" ^ "4C1E37065A48ACF287FFE65C9DC44A58") ~output1:("B43439584FB2FAF3B2937838D8000AC4" ^ "CD4BC4E582212A7741A0192F71C1F11B" ^ "58D7F779CA0E6E4B8BD58E00B50C3C53" ^ "DAF843467064A2DBE2FAD6FF6F40ECD8") ~output2:("EE51EE875F6F1B8AF0334F509DF5692B" ^ "9B43CC63A586C2380AF3AE490DCD6CFF" ^ "7907BC3724AE3BBEAD79D436E6DADDB2" ^ "2141B3BA46C9BEC0E01B9D4F7657B387") ~output3:("E5A4FE4A2FCA9A9ED779A9574283DC21" ^ "C85216D54486D9B182300D0593B1E2B0" ^ "10814F7066AEB955C057609CE9AF0D63" ^ "F057E17B19F57FFB7287EB2067C43B8D") let salsa20_20_128bit_ecrypt_set1_vector99_test = test_salsa20_20 ~key:"00000000000000000000000010000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("82FD629BD82C3BE22910951E2E41F8FE" ^ "187E2BD198F6113AFF44B9B0689AA520" ^ "C8CCE4E8D3FBA69EDE748BCF18397214" ^ "F98D7ACF4424866A8670E98EBAB715A3") ~output1:("342D80E30E2FE7A00B02FC62F7090CDD" ^ "ECBDFD283D42A00423113196A87BEFD8" ^ "B9E8AAF61C93F73CC6CBE9CC5AEC182F" ^ "3948B7857F96B017F3477A2EEC3AEB3B") ~output2:("8233712B6D3CCB572474BE200D67E540" ^ "3FC62128D74CE5F790202C696BFFB7EE" ^ "3CAD255324F87291273A7719278FA313" ^ "1ABA12342692A2C0C58D27BA3725761B") ~output3:("782600E7357AC69EA158C725B3E1E940" ^ "51A0CB63D0D1B4B3DF5F5037E3E1DE45" ^ "850578E9D513B90B8E5882D4DCA9F42B" ^ "E32621F4DCC1C77B38F1B0AC1227C196") let salsa20_20_128bit_ecrypt_set1_vector108_test = test_salsa20_20 ~key:"00000000000000000000000000080000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("D244F87EB315A7EEF02CA314B440777E" ^ "C6C44660020B43189693500F3279FA01" ^ "7257BE0AB087B81F85FD55AAC5845189" ^ "C66E259B5412C4BDFD0EBE805FC70C8A") ~output1:("5A2D8D3E431FB40E60856F05C7976206" ^ "42B35DAB0255764D986740699040702F" ^ "6CDE058458E842CB6E1843EBD336D374" ^ "23833EC01DFFF9086FEECAB8A165D29F") ~output2:("443CEF4570C83517ED55C2F57058BB70" ^ "294CC8D7342597E2CD850F6C02E355CA" ^ "EB43C0A41F4BB74FFE9F6B0D25799140" ^ "D03792D667601AD7954D21BD7C174C43") ~output3:("959C8B16A0ADEC58B544BE33CCF03277" ^ "E48C7916E333F549CDE16E2B4B6DCE2D" ^ "8D76C50718C0E77BFBEB3A3CB3CA14BF" ^ "40F65EBFAE1A5001EAB36E531414E87F") let salsa20_20_128bit_ecrypt_set1_vector117_test = test_salsa20_20 ~key:"00000000000000000000000000000400" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("44A74D35E73A7E7C37B009AE712783AC" ^ "86ACE0C02CB175656AF79023D91C909E" ^ "D2CB2F5C94BF8593DDC5E054D7EB726E" ^ "0E867572AF954F88E05A4DAFD00CCF0A") ~output1:("FEC113A0255391D48A37CDF607AE1226" ^ "86305DDAD4CF1294598F2336AB6A5A02" ^ "9D927393454C2E014868137688C0417A" ^ "2D31D0FE9540D7246FE2F84D6052DE40") ~output2:("79C2F7431D69E54C0474D8160113F364" ^ "8156A8963817C34AC9A9AD222543666E" ^ "7EAF03AF4EE03271C3ECED262E7B4C66" ^ "B0F618BAF3395423274DD1F73E2675E3") ~output3:("75C1295C871B1100F27DAF19E5D5BF8D" ^ "880B9A54CEFDF1561B4351A32898F3C2" ^ "6A04AB1149C24FBFA2AC963388E64C43" ^ "65D716BCE8330BC03FA178DBE5C1E6B0") let salsa20_20_128bit_ecrypt_set1_vector126_test = test_salsa20_20 ~key:"00000000000000000000000000000002" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("E23A3638C836B1ACF7E27296E1F5A241" ^ "3C4CC351EFEF65E3672E7C2FCD1FA105" ^ "2D2C26778DB774B8FBA29ABED72D058E" ^ "E35EBA376BA5BC3D84F8E44ABD5DC2CC") ~output1:("2A8BEB3C372A6570F54EB429FA7F562D" ^ "6EF14DF725861EDCE8132620EAA00D8B" ^ "1DFEF653B64E9C328930904A0EEB0132" ^ "B277BB3D9888431E1F28CDB0238DE685") ~output2:("CCBEB5CA57104B95BF7BA5B12C8B8553" ^ "4CE9548F628CF53EF02C337D788BCE71" ^ "D2D3D9C355E7D5EB75C56D079CB7D99D" ^ "6AF0C8A86024B3AF5C2FC8A028413D93") ~output3:("D00A5FDCE01A334C37E75634A8037B49" ^ "BEC06ACBD2243320E2CA41FB5619E6D8" ^ "75AB2007310D4149379C91EF4E199805" ^ "BE261E5C744F0DF21737E01243B7116F") let salsa20_20_128bit_ecrypt_set2_vector0_test = test_salsa20_20 ~key:"00000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("6513ADAECFEB124C1CBE6BDAEF690B4F" ^ "FB00B0FCACE33CE806792BB414801998" ^ "34BFB1CFDD095802C6E95E251002989A" ^ "C22AE588D32AE79320D9BD7732E00338") ~output1:("75E9D0493CA05D2820408719AFC75120" ^ "692040118F76B8328AC279530D846670" ^ "65E735C52ADD4BCFE07C9D93C0091790" ^ "2B187D46A25924767F91A6B29C961859") ~output2:("0E47D68F845B3D31E8B47F3BEA660E2E" ^ "CA484C82F5E3AE00484D87410A1772D0" ^ "FA3B88F8024C170B21E50E0989E94A26" ^ "69C91973B3AE5781D305D8122791DA4C") ~output3:("CCBA51D3DB400E7EB780C0CCBD3D2B5B" ^ "B9AAD82A75A1F746824EE5B9DAF7B794" ^ "7A4B808DF48CE94830F6C9146860611D" ^ "A649E735ED5ED6E3E3DFF7C218879D63") let salsa20_20_128bit_ecrypt_set2_vector9_test = test_salsa20_20 ~key:"09090909090909090909090909090909" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("169060CCB42BEA7BEE4D8012A02F3635" ^ "EB7BCA12859FA159CD559094B3507DB8" ^ "01735D1A1300102A9C9415546829CBD2" ^ "021BA217B39B81D89C55B13D0C603359") ~output1:("23EF24BB24195B9FD574823CD8A40C29" ^ "D86BD35C191E2038779FF696C712B6D8" ^ "2E7014DBE1AC5D527AF076C088C4A8D4" ^ "4317958189F6EF54933A7E0816B5B916") ~output2:("D8F12ED8AFE9422B85E5CC9B8ADEC9D6" ^ "CFABE8DBC1082BCCC02F5A7266AA074C" ^ "A284E583A35837798CC0E69D4CE93765" ^ "3B8CDD65CE414B89138615CCB165AD19") ~output3:("F70A0FF4ECD155E0F033604693A51E23" ^ "63880E2ECF98699E7174AF7C2C6B0FC6" ^ "59AE329599A3949272A37B9B2183A091" ^ "0922A3F325AE124DCBDD735364055CEB") let salsa20_20_128bit_ecrypt_set2_vector18_test = test_salsa20_20 ~key:"12121212121212121212121212121212" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("05835754A1333770BBA8262F8A84D0FD" ^ "70ABF58CDB83A54172B0C07B6CCA5641" ^ "060E3097D2B19F82E918CB697D0F347D" ^ "C7DAE05C14355D09B61B47298FE89AEB") ~output1:("5525C22F425949A5E51A4EAFA18F62C6" ^ "E01A27EF78D79B073AEBEC436EC8183B" ^ "C683CD3205CF80B795181DAFF3DC9848" ^ "6644C6310F09D865A7A75EE6D5105F92") ~output2:("2EE7A4F9C576EADE7EE325334212196C" ^ "B7A61D6FA693238E6E2C8B53B900FF1A" ^ "133A6E53F58AC89D6A695594CE03F775" ^ "8DF9ABE981F23373B3680C7A4AD82680") ~output3:("CB7A0595F3A1B755E9070E8D3BACCF95" ^ "74F881E4B9D91558E19317C4C254988F" ^ "42184584E5538C63D964F8EF61D86B09" ^ "D983998979BA3F44BAF527128D3E5393") let salsa20_20_128bit_ecrypt_set2_vector27_test = test_salsa20_20 ~key:"1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("72A8D26F2DF3B6713C2A053B3354DBA6" ^ "C10743C7A8F19261CF0E7957905748DD" ^ "D6D3333E2CBC6611B68C458D5CDBA2A2" ^ "30AC5AB03D59E71FE9C993E7B8E7E09F") ~output1:("7B6132DC5E2990B0049A5F7F357C9D99" ^ "7733948018AE1D4F9DB999F4605FD78C" ^ "B548D75AC4657D93A20AA451B8F35E0A" ^ "3CD08880CCED7D4A508BA7FB49737C17") ~output2:("EF7A7448D019C76ED0B9C18B5B2867CF" ^ "9AD84B789FB037E6B107B0A4615737B5" ^ "C1C113F91462CDA0BCB9ADDC09E8EA6B" ^ "99E4835FED25F5CC423EEFF56D851838") ~output3:("6B75BDD0EC8D581CB7567426F0B92C9B" ^ "B5057A89C3F604583DB700A46D6B8DE4" ^ "1AF315AE99BB5C1B52C76272D1E262F9" ^ "FC7022CE70B435C27AE443284F5F84C1") let salsa20_20_128bit_ecrypt_set2_vector36_test = test_salsa20_20 ~key:"24242424242424242424242424242424" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("76240D13C7E59CBD4183D162834A5D36" ^ "37CD09EE4F5AFE9C28CFA9466A4089F6" ^ "5C80C224A87F956459B173D720274D09" ^ "C573FCD128498D810460FDA1BB50F934") ~output1:("71AF115217F3B7F77A05B56E32AD0889" ^ "BFA470B6DDC256D852C63B45688D7BC8" ^ "DC610D347A2600D7769C67B28D1FA25F" ^ "1AACFB8F9BB68BFE17357335D8FAC993") ~output2:("6573CC1ADC0DE744F6694E5FBB59E5BF" ^ "5939CE5D13793E2F683C7F2C7DD9A460" ^ "575746688A0F17D419FE3E5F88654559" ^ "7B6705E1390542B4F953D568025F5BB3") ~output3:("809179FAD4AD9B5C355A09E99C8BE931" ^ "4B9DF269F162C1317206EB3580CAE58A" ^ "B93A408C23739EF9538730FE687C8DAC" ^ "1CE95290BA4ACBC886153E63A613857B") let salsa20_20_128bit_ecrypt_set2_vector45_test = test_salsa20_20 ~key:"2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("3117FD618A1E7821EA08CDED410C8A67" ^ "BDD8F7BE3FCA9649BD3E297FD83A80AD" ^ "814C8904C9D7A2DC0DCAA641CFFF502D" ^ "78AFF1832D34C263C1938C1ADF01238F") ~output1:("1E8CB540F19EC7AFCB366A25F74C0004" ^ "B682E06129030617527BECD16E3E3E00" ^ "27D818F035EDCDF56D8D4752AEF28BDB" ^ "FA0D3B008235173475F5FA105B91BEED") ~output2:("637C3B4566BBEBBE703E4BF1C978CCD2" ^ "77AE3B8768DB97DF01983CDF3529B3EC" ^ "6B1137CA6F231047C13EA38649D0058E" ^ "BE5EF7B7BBA140F22338E382F1D6AB3F") ~output3:("D407259B6355C343D64A5130DA55C057" ^ "E4AF722B70AC8A074262233677A457AF" ^ "EAA34E7FD6F15959A4C781C4C978F7B3" ^ "BC571BF66674F015A1EA5DB262E25BDC") let salsa20_20_128bit_ecrypt_set2_vector54_test = test_salsa20_20 ~key:"36363636363636363636363636363636" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("7FED83B9283449AD8EBFC935F5F36407" ^ "5C9008ADE8626D350770E2DBD058F053" ^ "F7E5300B088B1341EC54C2BEE72A520C" ^ "35C673E79CC4ED0A6D8F4C15FBDD090B") ~output1:("D780206A2537106610D1C95BF7E9121B" ^ "EDE1F0B8DFBE83CBC49C2C653DD187F7" ^ "D84A2F4607BF99A96B3B84FB792340D4" ^ "E67202FB74EC24F38955F345F21CF3DB") ~output2:("6CA21C5DC289674C13CFD4FCBDEA8356" ^ "0A90F53BB54F16DBF274F5CC56D7857C" ^ "D3E3B06C81C70C828DC30DADEBD92F38" ^ "BB8C24136F37797A647584BCEE68DF91") ~output3:("471936CE9C84E131C4C5792B769654B8" ^ "9644BFAFB1149130E580FD805A325B62" ^ "8CDE5FAE0F5C7CFFEF0D931F8F517A92" ^ "9E892D3789B74217A81BAEFE441E47ED") let salsa20_20_128bit_ecrypt_set2_vector63_test = test_salsa20_20 ~key:"3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("C224F33B124D6692263733DFD5BF5271" ^ "7D1FB45EC1CEDCA6BF92BA44C1EADA85" ^ "F7B031BCC581A890FD275085C7AD1C3D" ^ "652BCA5F4D7597DECDB2232318EABC32") ~output1:("090325F54C0350AD446C19ABDCAEFF52" ^ "EC57F5A13FB55FEDE4606CEC44EC658B" ^ "BB13163481D2C84BF9409313F6470A0D" ^ "A9803936094CC29A8DE7613CBFA77DD5") ~output2:("1F66F5B70B9D12BC7092C1846498A2A0" ^ "730AA8FA8DD97A757BBB878320CE6633" ^ "E5BCC3A5090F3F75BE6E72DD1E8D95B0" ^ "DE7DBFDD764E484E1FB854B68A7111C6") ~output3:("F8AE560041414BE888C7B5EB3082CC7C" ^ "4DFBBA5FD103F522FBD95A7166B91DE6" ^ "C78FB47413576EC83F0EDE6338C9EDDB" ^ "81757B58C45CBD3A3E29E491DB1F04E2") let salsa20_20_128bit_ecrypt_set2_vector72_test = test_salsa20_20 ~key:"48484848484848484848484848484848" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("11BF31E22D7458C189092A1DE3A4905B" ^ "A2FA36858907E3511FB63FDFF2C5C2A1" ^ "5B651B2C2F1A3A43A718642152806967" ^ "2B6BB0AEC10452F1DAA9FC73FF5A396A") ~output1:("D1E1619E4BD327D2A124FC52BC15B194" ^ "0B05394ECE5926E1E1ADE7D3FC8C6E91" ^ "E43889F6F9C1FD5C094F6CA25025AE4C" ^ "CC4FDC1824936373DBEE16D62B81112D") ~output2:("F900E9B0665F84C939D5FE4946FA7B41" ^ "E34F06058522A2DB49E210E3E5385E58" ^ "97C24F6350C6CCA578285325CC16F558" ^ "6DC662FFBEA41BAC68996BAAB9F32D1F") ~output3:("40587ECAD15841F1BD1D236A61051574" ^ "A974E15292F777ABDED64D2B761892BE" ^ "F3DD69E479DE0D02CC73AF76E81E8A77" ^ "F3CEE74180CB5685ACD4F0039DFFC3B0") let salsa20_20_128bit_ecrypt_set2_vector81_test = test_salsa20_20 ~key:"51515151515151515151515151515151" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("EBC464423EADEF13E845C595A9795A58" ^ "5064F478A1C8582F07A4BA68E81329CB" ^ "26A13C2EA0EFE9094B0A749FDB1CC6F9" ^ "C2D293F0B395E14EB63075A39A2EDB4C") ~output1:("F4BBBBCE9C5869DE6BAF5FD4AE835DBE" ^ "5B7F1752B2972086F3383E9D180C2FE5" ^ "5618846B10EB68AC0EB0865E0B167C6D" ^ "3A843B29336BC1100A4AB7E8A3369959") ~output2:("3CEB39E3D740771BD49002EA8CD99851" ^ "8A8C70772679ECAF2030583AED43F77F" ^ "565FECDBEF333265A2E1CC42CB606980" ^ "AEF3B24C436A12C85CBDC5EBD97A9177") ~output3:("EF651A98A98C4C2B61EA8E7A673F5D4F" ^ "D832D1F9FD19EE4537B6FEC7D11C6B2F" ^ "3EF5D764EEAD396A7A2E32662647BFC0" ^ "7F02A557BA6EF046C8DE3781D74332B0") let salsa20_20_128bit_ecrypt_set2_vector90_test = test_salsa20_20 ~key:"5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("F40253BAA835152E1582646FD5BD3FED" ^ "638EB3498C80BFB941644A7750BBA565" ^ "3130CC97A937A2B27AFBB3E679BC42BE" ^ "87F83723DC6F0D61DCE9DE8608AC62AA") ~output1:("A5A1CD35A230ED57ADB8FE16CD2D2EA6" ^ "055C32D3E621A0FD6EB6717AA916D478" ^ "57CD987C16E6112EDE60CCB0F7014642" ^ "2788017A6812202362691FDA257E5856") ~output2:("81F0D04A929DB4676F6A3E6C15049779" ^ "C4EC9A12ACF80168D7E9AA1D6FA9C13E" ^ "F2956CEE750A89103B48F22C06439C5C" ^ "E9129996455FAE2D7775A1D8D39B00CE") ~output3:("3F6D60A0951F0747B94E4DDE3CA4ED4C" ^ "96694B7534CD9ED97B96FAAD3CF00D4A" ^ "EF12919D410CD9777CD5F2F3F2BF160E" ^ "BBA3561CC24345D9A09978C3253F6DCB") let salsa20_20_128bit_ecrypt_set2_vector99_test = test_salsa20_20 ~key:"63636363636363636363636363636363" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("ED5FF13649F7D8EDFC783EFDF2F843B3" ^ "68776B19390AF110BEF12EAC8EC58A2E" ^ "8CDAB6EC9049FBDA23A615C536C3A313" ^ "799E21668C248EC864D5D5D99DED80B3") ~output1:("845ACE9B870CF9D77597201988552DE5" ^ "3FD40D2C8AC51ABE1335F6A2D0035DF8" ^ "B10CACAD851E000BAC6EA8831B2FBCFE" ^ "B7C94787E41CC541BAC3D9D26DB4F19D") ~output2:("981580764B81A4E12CA1F36634B59136" ^ "5E4BDB6C12DE13F2F337E72E018029C5" ^ "A0BECDA7B6723DD609D81A314CE39619" ^ "0E82848893E5A44478B08340F90A73F3") ~output3:("4CD3B072D5720E6C64C9476552D1CFF4" ^ "D4EF68DCBD11E8D516F0C248F9250B57" ^ "1990DD3AFC0AE8452896CCCC0BD0EFDF" ^ "17B616691AB3DF9AF6A42EDCA54BF9CD") let salsa20_20_128bit_ecrypt_set2_vector108_test = test_salsa20_20 ~key:"6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("78ED06021C5C7867D176DA2A96C4BBAA" ^ "494F451F21875446393E9688205ED63D" ^ "EA8ADEB1A2381201F576C5A541BC8887" ^ "4078608CA8F2C2A6BDCDC1081DD254CC") ~output1:("C1747F85DB1E4FB3E29621015314E3CB" ^ "261808FA6485E59057B60BE82851CFC9" ^ "48966763AF97CB9869567B763C745457" ^ "5022249DFE729BD5DEF41E6DBCC68128") ~output2:("1EE4C7F63AF666D8EDB2564268ECD127" ^ "B4D015CB59487FEAF87D0941D42D0F8A" ^ "24BD353D4EF765FCCF07A3C3ACF71B90" ^ "E03E8AEA9C3F467FE2DD36CEC00E5271") ~output3:("7AFF4F3A284CC39E5EAF07BA6341F065" ^ "671147CA0F073CEF2B992A7E21690C82" ^ "71639ED678D6A675EBDAD48336584213" ^ "15A2BA74754467CCCE128CCC62668D0D") let salsa20_20_128bit_ecrypt_set2_vector117_test = test_salsa20_20 ~key:"75757575757575757575757575757575" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("D935C93A8EBB90DB53A27BF9B41B3345" ^ "23E1DFDE3BFFC09EA97EFB9376D38C7D" ^ "6DC67AAB21EA3A5C07B6503F986F7E8D" ^ "9E11B3150BF0D38F36C284ADB31FACF8") ~output1:("DA88C48115010D3CD5DC0640DED2E652" ^ "0399AAFED73E573CBAF552C6FE06B1B3" ^ "F3ADE3ADC19DA311B675A6D83FD48E38" ^ "46825BD36EB88001AE1BD69439A0141C") ~output2:("14EA210224DAF4FC5D647C78B6BFEF7D" ^ "724DC56DCDF832B496DEAD31DD948DB1" ^ "944E17AB2966973FD7CCB1BC9EC0335F" ^ "35326D5834EE3B08833358C4C28F70DE") ~output3:("D5346E161C083E00E247414F44E0E737" ^ "5B435F426B58D482A37694331D7C5DC9" ^ "7D8953E6A852625282973ECCFD012D66" ^ "4C0AFA5D481A59D7688FDB54C55CD04F") let salsa20_20_128bit_ecrypt_set2_vector126_test = test_salsa20_20 ~key:"7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("45A43A587C45607441CE3AE200467977" ^ "88879C5B77FDB90B76F7D2DF27EE8D94" ^ "28A5B5AF35E2AAE242E6577BEC92DA09" ^ "29A6AFB3CB8F8496375C98085460AB95") ~output1:("14AE0BA973AE19E6FD674413C276AB9D" ^ "99AA0048822AFB6F0B68A2741FB5CE2F" ^ "64F3D862106EF2BDE19B39209F75B92B" ^ "DBE9015D63FDFD7B9E8A776291F4E831") ~output2:("C26FA1812FFC32EFF2954592A0E1E5B1" ^ "26D5A2196624156E3DFD0481205B24D5" ^ "613B0A75AF3CBC8BBE5911BE93125BD3" ^ "D3C50C92910DBA05D80666632E5DF9EF") ~output3:("AD0DABE5AF74AB4F62B4699E0D667BBF" ^ "01B4DCF0A45514554CAC4DFDE453EFF1" ^ "E51BE5B74B37512C40E3608FB0E65A3F" ^ "D4EAFA27A3BB0D6E1300C594CB0D1254") let salsa20_20_128bit_ecrypt_set2_vector135_test = test_salsa20_20 ~key:"87878787878787878787878787878787" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("09E15E82DFA9D821B8F68789978D0940" ^ "48892C624167BA88AD767CAEFDE80E25" ^ "F57467156B8054C8E88F3478A2897A20" ^ "344C4B05665E7438AD1836BE86A07B83") ~output1:("2D752E53C3FCA8D3CC4E760595D588A6" ^ "B321F910B8F96459DBD42C6635063246" ^ "60A527C66A53B406709262B0E42F11CB" ^ "0AD2450A1FB2F48EA85C1B39D4408DB9") ~output2:("1EC94A21BD2C0408D3E15104FA25D15D" ^ "6E3E0D3F8070D84184D35B6302BF62AE" ^ "A282E3640820CC09E1528B684B740018" ^ "0598D6960EC92E4EC4C9E533E1BA06F1") ~output3:("D0AC302C5CC256351E24CFFD11F0BD8A" ^ "0BE1277EDDCB3EE4D530E051712A710D" ^ "F4513FD6438B7A355CCF4FEDA9A60F2A" ^ "C375508F998C642E6C51724FE9462F7F") let salsa20_20_128bit_ecrypt_set2_vector144_test = test_salsa20_20 ~key:"90909090909090909090909090909090" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("EA869D49E7C75E07B551C24EBE351B4E" ^ "7FD9CB26413E55A8A977B766650F81EF" ^ "CA06E30107F76DC97EA9147FFA7CA66A" ^ "FD4D4DA538CDA1C27E8D948CC406FB89") ~output1:("436A8EC10421116CD03BF95A4DAAE630" ^ "1BB8C724B3D481099C70B26109971CCE" ^ "ACBCE35C8EE98BBB0CD553B5C4181125" ^ "00262C7EA10FAAC8BA9A30A04222D8E2") ~output2:("47487A34DE325E79838475B1757D5D29" ^ "3C931F9E57579FCA5E04A40E4A0A38CF" ^ "D1614F9CEF75F024FFF5D972BD671DC9" ^ "FB2A80F64E8A2D82C3BAA5DDFD1E6821") ~output3:("3FDCAD4E7B069391FAB74C836D58DE23" ^ "95B27FFAE47D633912AE97E7E3E60264" ^ "CA0DC540D33122320311C5CFC9E26D63" ^ "2753AC45B6A8E81AC816F5CA3BBDB1D6") let salsa20_20_128bit_ecrypt_set2_vector153_test = test_salsa20_20 ~key:"99999999999999999999999999999999" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("7B3AA4599561C9059739C7D18D342CF2" ^ "E73B3B9E1E85D38EDB41AEFADD81BF24" ^ "1580885078CA10D338598D18B3E4B693" ^ "155D12D362D533494BA48142AB068F68") ~output1:("D27864FC30D5FD278A9FB83FADADFD2F" ^ "E72CE78A2563C031791D55FF31CF5946" ^ "4BE7422C81968A70E040164603DC0B0A" ^ "EEE93AC497CC0B770779CE6058BE80CF") ~output2:("4C5A87029660B65782FD616F48CFD600" ^ "6DFB158682DC80E085E52163BE2947E2" ^ "70A0FD74DC8DC2F5920E59F28E225280" ^ "FAC96BA78B8007E3D0DF6EF7BF835993") ~output3:("F5A2ECD04452358970E4F8914FC08E82" ^ "926ECFF33D9FC0977F10241E7A50E528" ^ "996A7FB71F79FC30BF881AF6BA19016D" ^ "DC077ED22C58DC57E2BDBDA1020B30B2") let salsa20_20_128bit_ecrypt_set2_vector162_test = test_salsa20_20 ~key:"A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("9776A232A31A22E2F10D203A2A1B60B9" ^ "D28D64D6D0BF32C8CCA1BBF6B57B1482" ^ "BCC9FCF7BBE0F8B61C4BF64C540474BC" ^ "F1F9C1C808CCBE6693668632A4E8653B") ~output1:("5C746D64A3195079079028D74CE029A8" ^ "7F72B30B34B6C7459998847C42F2E44D" ^ "843CF196229EED471B6BBDBA63BE3B52" ^ "9B8AF4B5846EB0AB008261E161707B76") ~output2:("F780FE5204AC188A680F41068A9F5018" ^ "2D9154D6D5F1886034C270A8C3AF61DF" ^ "945381B7ADCA546E153DBF0E6EA2DDDA" ^ "4EDA3E7F7CF4E2043C5E20AF659282B4") ~output3:("71D24CD8B4A70554906A32A5EFDFA8B8" ^ "34C324E6F35240257A0A27485103616D" ^ "D41C8F4108D1FC76AB72AF166100AB17" ^ "212492A72099ACF6F9EB53AC50BD8B8B") let salsa20_20_128bit_ecrypt_set2_vector171_test = test_salsa20_20 ~key:"ABABABABABABABABABABABABABABABAB" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("62DF49A919AF1367D2AAF1EB608DE1FD" ^ "F8B93C2026389CEBE93FA389C6F28458" ^ "48EBBE70B3A3C8E79061D78E9ED24ED9" ^ "AA7BB6C1D726AA060AEFC4FFE70F0169") ~output1:("E7A4DF0D61453F612FB558D1FAE198AA" ^ "B1979F91E1792C99423E0C5733459365" ^ "70915B60210F1F9CA8845120E6372659" ^ "B02A179A4D679E8EDDDDF8843ABAB7A4") ~output2:("C9501A02DD6AFB536BD2045917B016B8" ^ "3C5150A7232E945A53B4A61F90C5D0FB" ^ "6E6AC45182CBF428772049B32C825D1C" ^ "33290DBEEC9EF3FE69F5EF4FAC95E9B1") ~output3:("B8D487CDD057282A0DDF21CE3F421E2A" ^ "C9696CD36416FA900D12A20199FE0018" ^ "86C904AB629194AECCC28E59A54A1357" ^ "47B7537D4E017B66538E5B1E83F88367") let salsa20_20_128bit_ecrypt_set2_vector180_test = test_salsa20_20 ~key:"B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("6F703F3FF0A49665AC70CD9675902EE7" ^ "8C60FF8BEB931011FC89B0F28D6E176A" ^ "9AD4D494693187CB5DB08FF727477AE6" ^ "4B2EF7383E76F19731B9E23186212720") ~output1:("AD26886ABF6AD6E0CA4E305E468DA1B3" ^ "69F0ADD3E14364C8A95BD78C5F2762B7" ^ "2915264A022AD11B3C6D312B5F6526E0" ^ "183D581B57973AFB824945BFB78CEB8F") ~output2:("FE29F08A5C157B87C600CE4458F274C9" ^ "86451983FE5AE561DF56139FF33755D7" ^ "1100286068A32559B169D8C2161E215D" ^ "BC32FAEA11B652284795C144CF3E693E") ~output3:("7974578366C3E999028FA8318D82AAAA" ^ "8ED3FD4DFB111CBF0F529C251BA91DC6" ^ "ACFA9795C90C954CEA287D23AD979028" ^ "E974393B4C3ABA251BCB6CECCD09210E") let salsa20_20_128bit_ecrypt_set2_vector189_test = test_salsa20_20 ~key:"BDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBD" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("61900F2EF2BEA2F59971C82CDFB52F27" ^ "9D81B444833FF02DD0178A53A8BFB9E1" ^ "FF3B8D7EC799A7FBB60EADE8B1630C12" ^ "1059AA3E756702FEF9EEE7F233AFC79F") ~output1:("D27E0784038D1B13833ACD396413FF10" ^ "D35F3C5C04A710FC58313EEBC1113B2C" ^ "FA20CBD1AEA4433C6650F16E7C3B6830" ^ "2E5F6B58D8E4F26D91F19FE981DEF939") ~output2:("B658FB693E80CE50E3F64B910B660BEB" ^ "142B4C4B61466424A9884D22EB80B8B4" ^ "0C26BEA869118ED068DCC83F9E4C68F1" ^ "7A3597D0FE0E36700D01B4252EE0010E") ~output3:("9FC658A20D3107A34680CC75EB3F76D6" ^ "A2150490E9F6A3428C9AD57F2A252385" ^ "C956B01C31C978E219BE351A534DB23B" ^ "99908DACC6726196742D0B7E1D88472C") let salsa20_20_128bit_ecrypt_set2_vector198_test = test_salsa20_20 ~key:"C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("42D1C40F11588014006445E81C8219C4" ^ "370E55E06731E09514956834B2047EE2" ^ "8A9DAECC7EB25F34A311CC8EA28EDCD2" ^ "4A539160A0D8FDAA1A26E9F0CDFE0BE3") ~output1:("976201744266DEABBA3BFE206295F40E" ^ "8D9D169475C11659ADA3F6F25F11CEF8" ^ "CD6B851B1F72CD3E7D6F0ABAF8FB929D" ^ "DB7CF0C7B128B4E4C2C977297B2C5FC9") ~output2:("D3601C4CD44BBEEFD5DAD1BDFF12C190" ^ "A5F0B0CE95C019972863F4309CE566DE" ^ "62BECB0C5F43360A9A09EB5BAB87CF13" ^ "E7AB42D71D5E1229AF88667D95E8C96F") ~output3:("69EAA4BAAAA795BCF3B96E79C931A1F2" ^ "D2DD16A242714358B106F38C1234A5BB" ^ "D269E68A03539EFAFA79455ADBE1B984" ^ "E9766B0720947E1365FDF076F73639CD") let salsa20_20_128bit_ecrypt_set2_vector207_test = test_salsa20_20 ~key:"CFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCF" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("9C09F353BF5ED33EDEF88D73985A14DB" ^ "C1390F08236461F08FDCAF9A7699FD7C" ^ "4C602BE458B3437CEB1464F451ED021A" ^ "0E1C906BA59C73A8BA745979AF213E35") ~output1:("437E3C1DE32B0DB2F0A57E41A7282670" ^ "AC223D9FD958D111A8B45A70A1F863E2" ^ "989A97386758D44060F6BFFF5434C908" ^ "88B4BB4EDAE6528AAADC7B81B8C7BEA3") ~output2:("94007100350C946B6D12B7C6A2FD1215" ^ "682C867257C12C74E343B79E3DE79A78" ^ "2D74663347D8E633D8BE9D288A2A64A8" ^ "55C71B4496587ADECCB4F30706BB4BD9") ~output3:("585D0C2DB901F4004846ADBAA754BCA8" ^ "2B66A94C9AF06C914E3751243B87581A" ^ "FAE281312A492DBEE8D6BB64DD748F44" ^ "5EF88F82AB44CBA33D767678914BDE77") let salsa20_20_128bit_ecrypt_set2_vector216_test = test_salsa20_20 ~key:"D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("4965F30797EE95156A0C141D2ACA5232" ^ "04DD7C0F89C6B3F5A2AC1C59B8CF0DA4" ^ "01B3906A6A3C94DA1F1E0046BD895052" ^ "CB9E95F667407B4EE9E579D7A2C91861") ~output1:("8EDF23D6C8B062593C6F32360BF271B7" ^ "ACEC1A4F7B66BF964DFB6C0BD93217BB" ^ "C5FACC720B286E93D3E9B31FA8C4C762" ^ "DF1F8A3836A8FD8ACBA384B8093E0817") ~output2:("44FA82E9E469170BA6E5E8833117DAE9" ^ "E65401105C5F9FEA0AF682E53A627B4A" ^ "4A621B63F7CE5265D3DFADFBFD4A2B6C" ^ "2B40D2249EB0385D959F9FE73B37D67D") ~output3:("828BA57593BC4C2ACB0E8E4B8266C1CC" ^ "095CE9A761FB68FC57D7A2FCFF768EFB" ^ "39629D3378549FEE08CCF48A4A4DC2DD" ^ "17E72A1454B7FA82E2ACF90B4B8370A7") let salsa20_20_128bit_ecrypt_set2_vector225_test = test_salsa20_20 ~key:"E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("5C7BA38DF4789D45C75FCC71EC9E5751" ^ "B3A60AD62367952C6A87C0657D6DB3E7" ^ "1053AC73E75FF4B66177B3325B1BBE69" ^ "AEE30AD5867D68B660603FE4F0BF8AA6") ~output1:("B9C7460E3B6C313BA17F7AE115FC6A8A" ^ "499943C70BE40B8EF9842C8A934061E1" ^ "E9CB9B4ED3503165C528CA6E0CF2622B" ^ "B1F16D24657BDAEDB9BA8F9E193B65EB") ~output2:("406CD92883E991057DFD80BC8201067F" ^ "35700264A4DFC28CF23EE32573DCB420" ^ "91FEF27548613999E5C5463E840FE957" ^ "60CF80CC5A05A74DE49E7724273C9EA6") ~output3:("F13D615B49786D74B6591BA6887A7669" ^ "136F34B69D31412D4A9CB90234DAFCC4" ^ "1551743113701EF6191A577C7DB72E2C" ^ "B723C738317848F7CC917E1510F02791") let salsa20_20_128bit_ecrypt_set2_vector234_test = test_salsa20_20 ~key:"EAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEA" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("5B06F5B01529B8C57B73A410A61DD757" ^ "FE5810970AA0CBFAD3404F17E7C7B645" ^ "9DD7F615913A0EF2DCC91AFC57FA660D" ^ "6C7352B537C65CD090F1DE51C1036AB5") ~output1:("0F613F9E9F03199DF0D0A5C5BE253CDF" ^ "138903876DE7F7B0F40B2F840F322F27" ^ "0C0618D05ABB1F013D8744B231555A8E" ^ "CB14A9E9C9AF39EDA91D36700F1C25B3") ~output2:("4D9FAB87C56867A687A03BF3EDCC224A" ^ "C54D04450AB6F78A642715AF62CF5192" ^ "15E2CDF5338E45554B852B6FB552BCAF" ^ "5C599BDF9FA679962F038976CDA2DEFA") ~output3:("E0F80A9BF168EB523FD9D48F19CA96A1" ^ "8F89C1CF11A3ED6EC8AEAB99082DE99B" ^ "E46DE2FB23BE4A305F185CF3A8EA377C" ^ "CA1EF46FD3192D03DCAE13B79960FEF4") let salsa20_20_128bit_ecrypt_set2_vector243_test = test_salsa20_20 ~key:"F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("E7BC9C13F83F51E8855E83B81AF1FFB9" ^ "676300ABAB85986B0B44441DDEFAB83B" ^ "8569C4732D8D991696BD7B6694C6CB20" ^ "872A2D4542192BE81AA7FF8C1634FC61") ~output1:("0B429A2957CBD422E94012B49C443CBC" ^ "2E13EFDE3B867C6018BABFDE9ED3B803" ^ "6A913C770D77C60DCD91F23E03B3A576" ^ "66847B1CACFCBCFF57D9F2A2BAD6131D") ~output2:("EA2CBD32269BB804DD2D641452DC09F9" ^ "64CB2BCD714180E94609C1209A8C26D1" ^ "256067F1B86AA4F886BB3602CF96B4DD" ^ "7039F0326CD24D7C2D69DE22D9E24624") ~output3:("CA0DD398EA7E543F1F680BF83E2B773B" ^ "BB5B0A931DEADDEC0884F7B823FC686E" ^ "71D7E4C033C65B03B292426CE4E1A7A8" ^ "A9D037303E6D1F0F45FDFB0FFE322F93") let salsa20_20_128bit_ecrypt_set2_vector252_test = test_salsa20_20 ~key:"FCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFC" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("C93DA97CB6851BCB95ABFAF547C20DF8" ^ "A54836178971F748CF6D49AEF3C9CE8C" ^ "E7D284571D871EFD51B6A897AF698CD8" ^ "F2B050B6EB21A1A58A9FC77200B1A032") ~output1:("5B4144FD0C46CEE4348B598EEF76D16B" ^ "1A71CBF85F4D9926402133846136C59F" ^ "BE577B8B7EB8D6A67A48358573C06876" ^ "6AC76A308A14154E2FA9BD9DCA8842E6") ~output2:("3BF67A79DF6FE3C32DA7A53CD0D37237" ^ "16A99BF7D168A25C93C29DF2945D9BCB" ^ "F78B669195411BD86D3F890A462734AB" ^ "10F488E9952334D7242E51AC6D886D60") ~output3:("65629AA9654930681578EEC971A48D83" ^ "90FBF82469A385B8BCF28B2C1E9F13CE" ^ "FC06F54335B4D5DE011F3DCE2B94D38F" ^ "1A04871E273FCD2A8FA32C0E08710E69") let salsa20_20_128bit_ecrypt_set3_vector0_test = test_salsa20_20 ~key:"000102030405060708090A0B0C0D0E0F" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("2DD5C3F7BA2B20F76802410C68868889" ^ "5AD8C1BD4EA6C9B140FB9B90E21049BF" ^ "583F527970EBC1A4C4C5AF117A5940D9" ^ "2B98895B1902F02BF6E9BEF8D6B4CCBE") ~output1:("AB56CC2C5BFFEF174BBE28C48A17039E" ^ "CB795F4C2541E2F4AE5C69CA7FC2DED4" ^ "D39B2C7B936ACD5C2ECD4719FD6A3188" ^ "323A14490281CBE8DAC48E4664FF3D3B") ~output2:("9A18E827C33633E932FC431D697F0775" ^ "B4C5B0AD26D1ACD5A643E3A01A065821" ^ "42A43F48E5D3D9A91858887310D39969" ^ "D65E7DB788AFE27D03CD985641967357") ~output3:("752357191E8041ABB8B5761FAF9CB9D7" ^ "3072E10B4A3ED8C6ADA2B05CBBAC298F" ^ "2ED6448360F63A51E073DE02338DBAF2" ^ "A8384157329BC31A1036BBB4CBFEE660") let salsa20_20_128bit_ecrypt_set3_vector9_test = test_salsa20_20 ~key:"090A0B0C0D0E0F101112131415161718" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("0F8DB5661F92FB1E7C760741430E15BB" ^ "36CD93850A901F88C40AB5D03C3C5FCE" ^ "71E8F16E239795862BEC37F63490335B" ^ "B13CD83F86225C8257AB682341C2D357") ~output1:("002734084DF7F9D6613508E587A4DD42" ^ "1D317B45A6918B48E007F53BEB3685A9" ^ "235E5F2A7FACC41461B1C22DC55BF82B" ^ "54468C8523508167AAF83ABBFC39C67B") ~output2:("3C9F43ED10724681186AC02ACFEC1A3A" ^ "090E6C9AC1D1BC92A5DBF407664EBCF4" ^ "563676257518554C90656AC1D4F167B8" ^ "B0D3839EB8C9E9B127665DCE0B1FD78C") ~output3:("46B7C56E7ED713AAB757B24056AF58C6" ^ "AD3C86270CFEAE4AADB35F0DB2D96932" ^ "1A38388D00ED9C2AD3A3F6D8BE0DE7F7" ^ "ADA068F67525A0996DE5E4DF490DF700") let salsa20_20_128bit_ecrypt_set3_vector18_test = test_salsa20_20 ~key:"12131415161718191A1B1C1D1E1F2021" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("4B135E9A5C9D54E6E019B5A2B48B9E6E" ^ "17F6E6667B9D43BC3F892AD6ED64C584" ^ "4FE52F75BD67F5C01523EE026A385108" ^ "3FBA5AC0B6080CE3E6A2F5A65808B0AC") ~output1:("E45A7A605BCFBBE77E781BBE78C270C5" ^ "AC7DAD21F015E90517672F1553724DDA" ^ "12692D23EC7E0B420A93D249C4383566" ^ "22D45809034A1A92B3DE34AEB4421168") ~output2:("14DEA7F82A4D3C1796C3911ABC2EFE9D" ^ "C9EB79C42F72691F8CB8C353ECBCC0DC" ^ "6159EC13DFC08442F99F0F68355D704E" ^ "5649D8B34836B5D2C46F8999CD570B17") ~output3:("CA6A357766527EA439B56C970E2E089C" ^ "30C94E62CB07D7FE1B1403540C2DA9A6" ^ "362732811EF811C9D04ED4880DC0038D" ^ "5FDCE22BDE2668CD75107D7926EC98B5") let salsa20_20_128bit_ecrypt_set3_vector27_test = test_salsa20_20 ~key:"1B1C1D1E1F202122232425262728292A" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("E04A423EF2E928DCA81E10541980CDE5" ^ "C8054CC3CF437025B629C13677D41167" ^ "21123EE13F889A991C03A2E5ADC0B12B" ^ "9BBC63CB60A23543445919AF49EBC829") ~output1:("F6E1D7DBD22E05430EBFBEA15E751C83" ^ "76B4743681DE6AC3E257A3C3C1F9EC6A" ^ "63D0A04BF3A07F64E6B167A49CD3FDAA" ^ "B89A05E438B1847E0DC6E9108A8D4C71") ~output2:("FC2B2A1A96CF2C73A8901D334462ED56" ^ "D57ABD985E4F2210D7366456D2D1CDF3" ^ "F99DFDB271348D00C7E3F51E6738218D" ^ "9CD0DDEFF12341F295E762C50A50D228") ~output3:("1F324485CC29D2EAEC7B31AE7664E8D2" ^ "C97517A378A9B8184F50801524867D37" ^ "6652416A0CA96EE64DDF26138DB5C58A" ^ "3B22EF9037E74A9685162EE3DB174A0E") let salsa20_20_128bit_ecrypt_set3_vector36_test = test_salsa20_20 ~key:"2425262728292A2B2C2D2E2F30313233" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("361A977EEB47543EC9400647C0C16978" ^ "4C852F268B34C5B163BCA81CFC5E746F" ^ "10CDB464A4B1365F3F44364331568DB2" ^ "C4707BF81AA0E0B3AB585B9CE6621E64") ~output1:("E0F8B9826B20AEEC540EABA9D12AB8EB" ^ "636C979B38DE75B87102C9B441876C39" ^ "C2A5FD54E3B7AB28BE342E377A328895" ^ "6C1A2645B6B76E8B1E21F871699F627E") ~output2:("850464EEED2251D2B5E2FE6AE2C11663" ^ "E63A02E30F59186172D625CFF2A646FA" ^ "CB85DC275C7CA2AF1B61B95F22A5554F" ^ "BAD63C0DCC4B5B333A29D270B6366AEF") ~output3:("4387292615C564C860AE78460BBEC30D" ^ "ECDFBCD60AD2430280E3927353CEBC21" ^ "DF53F7FD16858EF7542946442A26A1C3" ^ "DA4CEFF5C4B781AD6210388B7905D2C7") let salsa20_20_128bit_ecrypt_set3_vector45_test = test_salsa20_20 ~key:"2D2E2F303132333435363738393A3B3C" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("9F25D8BD7FBC7102A61CB590CC69D1C7" ^ "2B31425F11A685B80EAC771178030AF0" ^ "52802311ED605FF07E81AD7AAC79B6A8" ^ "1B24113DB5B4F927E6481E3F2D750AB2") ~output1:("DAEF37444CB2B068124E074BAD188195" ^ "3D61D5BA3BFBF37B21BC47935D74820E" ^ "9187086CEF67EB86C88DDD62C48B9089" ^ "A9381750DC55EA4736232AE3EDB9BFFE") ~output2:("B6C621F00A573B60571990A95A4FEC4A" ^ "C2CA889C70D662BB4FF54C8FAAE0B7C4" ^ "5B8EC5414AE0F080B68E2943ABF76EA2" ^ "ABB83F9F93EF94CB3CFE9A4CEED337CD") ~output3:("6F17EAE9346878BB98C97F6C81DD2E41" ^ "5FDEB54305FE2DF74AFC65627C376359" ^ "FB2E7841FF75744A715DF952851C1CBC" ^ "DD241BADF37B3618E0097B3A084E1B54") let salsa20_20_128bit_ecrypt_set3_vector54_test = test_salsa20_20 ~key:"363738393A3B3C3D3E3F404142434445" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("3466360F26B76484D0C4FD63965E5561" ^ "8BDBFDB2213D8CA5A72F2FE6E0A13548" ^ "D06E87C8A6EEA392FE52D3F5E0F6559D" ^ "331828E96A07D99C6C0A42EFC24BA96D") ~output1:("AB7184066D8E0AB537BB24D777088BC4" ^ "41E00481834B5DD5F6297D6F221532BC" ^ "56F638A8C84D42F322767D3D1E11A3C6" ^ "5085A8CA239A4FDD1CDF2AC72C1E354F") ~output2:("55F29F112B07544EDA3EBB5892DBB91E" ^ "46F8CBC905D0681D8E7109DF816ABFB8" ^ "AE6A0F9833CDF34A29F25D67A60D3633" ^ "8A10346FEBE72CCF238D8670C9F2B59C") ~output3:("0657453B7806D9EA777FFFBE05028C76" ^ "DCFF718BC9B6402A3CAEC3BCCB7231E6" ^ "D3DDB00D5A9637E1E714F47221FFCC11" ^ "B1425D9653F7D777292B146556A89787") let salsa20_20_128bit_ecrypt_set3_vector63_test = test_salsa20_20 ~key:"3F404142434445464748494A4B4C4D4E" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("40AD59C99464D95702727406E4C82C85" ^ "7FA48911319A3FCC231DC91C990E19D4" ^ "D9D5972B6A6F21BD12C118365ECAABC8" ^ "9F9C3B63FFF77D8EA3C55B2322B57D0E") ~output1:("DBF23042C787DDF6FFCE32A792E39DF9" ^ "E0332B0A2A2F2A5F96A14F51FAAB7C27" ^ "14E07C3ADCA32D0DE5F8968870C7F0E8" ^ "1FE263352C1283965F8C210FC25DE713") ~output2:("455E3D1F5F44697DA562CC6BF77B9309" ^ "9C4AFAB9F7F300B44AD9783A9622BD54" ^ "3EFDB027D8E71236B52BEE57DD2FB3EE" ^ "1F5B9022AB96A59AE7DF50E6933B3209") ~output3:("F11D47D8C57BBF862E0D6238BC0BF6A5" ^ "2500A62BB037B3A33E87525259B8E547" ^ "35F664FCEDF11BA2C0F3AEB9C944BCE7" ^ "7FFD26D604674DF8905A73CB7E230A4F") let salsa20_20_128bit_ecrypt_set3_vector72_test = test_salsa20_20 ~key:"48494A4B4C4D4E4F5051525354555657" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("D8B1A4CB2A5A8DE1F798254A41F61DD4" ^ "FB1226A1B4C62FD70E87B6ED7D57902A" ^ "69642E7E21A71C6DC6D5430DCE89F16F" ^ "CCC9AAD48743974473753A6FF7663FD9") ~output1:("D4BA9BC857F74A28CACC734844849C3E" ^ "DCB9FB952023C97E80F5BFA445178CAB" ^ "92B4D9AA8A6D4E79B81993B831C73765" ^ "10E74E30E7E68AD3188F8817DA8243F2") ~output2:("B7039E6F6C4D5D7F750ED014E6501188" ^ "17994F0D3C31B071CC16932A412E627D" ^ "2486CCB9E43FCA79039D3E0F63577406" ^ "F5B6420F5587CF9DAC40118AA6F170A8") ~output3:("1ABA14E7E9E6BA4821774CBC2B63F410" ^ "381E4D661F82BAB1B182005B6D42900D" ^ "C658C6224F959E05095BC8081920C8AD" ^ "11148D4F8BD746B3F0059E15C47B9414") let salsa20_20_128bit_ecrypt_set3_vector81_test = test_salsa20_20 ~key:"5152535455565758595A5B5C5D5E5F60" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("235E55E2759C6781BBB947133EDD4D91" ^ "C9746E7E4B2E5EF833A92BE6086C57C6" ^ "729655D4C4253EC17ACF359012E80175" ^ "7E7A6EB0F713DEC40491266604B83311") ~output1:("247BEAAC4A785EF1A55B469A1AEE8530" ^ "27B2D37C74B8DA58A8B92F1360968513" ^ "C0296585E6745E727C34FFCE80F5C72F" ^ "850B999721E3BF1B6C3A019DBEE464C1") ~output2:("E7DDB25678BF6EECA2DA2390C9F333EB" ^ "61CD899DD823E7C19474643A4DA31335" ^ "2556E44A9C0006C8D54B1FD0313D574A" ^ "08B86138394BA1194E140A62A96D7F01") ~output3:("DB417F9C1D9FD49FC96DB5E981F0C3F8" ^ "484E3BDC559473963D12D982FEA287A3" ^ "9A36D69DDBBCF1CA2C9FB7F4B2B37F3D" ^ "A755838A67C48822F4C1E82E65A07151") let salsa20_20_128bit_ecrypt_set3_vector90_test = test_salsa20_20 ~key:"5A5B5C5D5E5F60616263646566676869" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("F27A0A59FA3D1274D934EACCFA0038AF" ^ "C3B866D2BFA4A8BA81D698DBCA5B65D5" ^ "2F3A1AC9855BEEEB3B41C510F7489E35" ^ "AB22CB4444816208C282C461FF16A7BC") ~output1:("522594154A2E4843083ABCA886102DA8" ^ "14500C5AADAAB0C8FB40381B1D750F9D" ^ "A9A1831D8000B30BD1EFA854DC903D63" ^ "D53CD80A10D642E332DFFC9523792150") ~output2:("5D092D8E8DDA6C878A3CFBC1EC8DD13F" ^ "2A1B073916097AEC4C3E56A229D8E282" ^ "DDB656DAD60DBC7DF44DF124B19920FC" ^ "C27FCADB1782F1B73E0A78C161270700") ~output3:("8F75BF72995AD23E9ADFEA351F26E42B" ^ "E2BE8D67FB810ABCBD5FAE552DC10D1E" ^ "281D94D5239A4EA311784D7AC7A764FA" ^ "88C7FD7789E803D11E65DD6AC0F9E563") let salsa20_20_128bit_ecrypt_set3_vector99_test = test_salsa20_20 ~key:"636465666768696A6B6C6D6E6F707172" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("654037B9120AEB60BD08CC07FFEC5985" ^ "C914DAD04CD1277312B4264582A4D85A" ^ "4CB7B6CC0EB8AD16475AD8AE99888BC3" ^ "FDE6A5B744851C5FC77EAB50CFAD021D") ~output1:("E52D332CD0DE31F44CDCAB6C71BD38C9" ^ "4417870829D3E2CFDAC40137D066EA48" ^ "2786F146137491B8B9BC05675C4F88A8" ^ "B58686E18D63BE71B6FEFEF8E46D0273") ~output2:("28959548CE505007768B1AA6867D2C00" ^ "9F969675D6E6D54496F0CC1DC8DD1AFB" ^ "A739E8565323749EAA7B03387922C50B" ^ "982CB8BC7D602B9B19C05CD2B87324F9") ~output3:("D420AEC936801FEE65E7D6542B37C919" ^ "0E7DB10A5934D3617066BEA8CC80B8EA" ^ "AAFC82F2860FA760776418B4FF148DFD" ^ "58F21D322909E7BF0EC19010A168FAF7") let salsa20_20_128bit_ecrypt_set3_vector108_test = test_salsa20_20 ~key:"6C6D6E6F707172737475767778797A7B" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("0DB7EA55A79C045818C29E99D8A4B664" ^ "33E4C77DF532D71BA720BD5D82629F12" ^ "76EF0BF93E636A6F71F91B947DFA7CAA" ^ "A1B0512AA531603197B86ABA2B0829D1") ~output1:("A62EAFD63CED0D5CE9763609697E78A7" ^ "59A797868B94869EC54B44887D907F01" ^ "542028DEDDF420496DE84B5DA9C6A401" ^ "2C3D39DF6D46CE90DD45AF10FA0F8AAF") ~output2:("7C2AD3F01023BC8E49C5B36AFE7E67DC" ^ "A26CCD504C222BD6AF467D4C6B07B792" ^ "61E9714FDD1E35C31DA4B44DB8D4FC05" ^ "69F885F880E63B5ABB6BA0BFEE2CE80C") ~output3:("066D3C8D46F45891430A85852FF53744" ^ "8EBDD6CE8A799CCF7EAF88425FBD60D3" ^ "2A1741B39CC3C73371C2C9A36544D3C3" ^ "B0F02D2596ACC61C60A6671F112F185E") let salsa20_20_128bit_ecrypt_set3_vector117_test = test_salsa20_20 ~key:"75767778797A7B7C7D7E7F8081828384" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("3FE4BD60364BAB4F323DB8097EC189E2" ^ "A43ACD0F5FFA5D65D8BDB0D79588AA9D" ^ "86669E143FD5915C31F7283F1180FCAB" ^ "CDCB64B680F2B63BFBA2AF3FC9836307") ~output1:("F1788B6CA473D314F6310675FC716252" ^ "8285A538B4C1BE58D45C97349C8A3605" ^ "7774A4F0E057311EEA0D41DFDF131D47" ^ "32E2EAACA1AB09233F8124668881E580") ~output2:("FEF434B35F024801A77400B31BD0E735" ^ "22BEC7D10D8BF8743F991322C660B4FD" ^ "2CEE5A9FDE0D614DE8919487CBD5C6D1" ^ "3FEB55C254F96094378C72D8316A8936") ~output3:("338FD71531C8D07732FD7F9145BBC368" ^ "932E3F3E4C72D2200A4F780AF7B2C3AA" ^ "91C1ED44DBEAA9A2F1B3C64DCE8DCD27" ^ "B307A4104D5C755693D848BEA2C2D23B") let salsa20_20_128bit_ecrypt_set3_vector126_test = test_salsa20_20 ~key:"7E7F808182838485868788898A8B8C8D" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("062187DAA84742580D76E1D55EE4DE2E" ^ "3B0C454F383CFDDE567A008E4E8DAA3C" ^ "E645D5BEDA64A23F0522D8C15E6DA0AD" ^ "88421577A78F2A4466BD0BFA243DA160") ~output1:("4CC379C5CF66AA9FB0850E50ED8CC58B" ^ "72E8441361904449DAABF04D3C464DE4" ^ "D56B22210B4336113DAA1A19E1E15339" ^ "F047DA5A55379C0E1FE448A20BC10266") ~output2:("BD2C0F58DBD757240AEB55E06D5526FE" ^ "7088123CE2F7386699C3E2780F5C3F86" ^ "374B7CB9505299D639B89D7C717BA8A2" ^ "AEED0C529F22F8C5006913D1BE647275") ~output3:("54D61231409D85E46023ED5EFF8FDC1F" ^ "7A83CACDDB82DD8D1FA7CDEA0E088A61" ^ "D02BCE7FA7EC3B73B66953DA467BE4B9" ^ "12EBE2A46B56A8BF0D925A919B7B22E3") let salsa20_20_128bit_ecrypt_set3_vector135_test = test_salsa20_20 ~key:"8788898A8B8C8D8E8F90919293949596" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("1A74C21E0C929282548AD36F5D6AD360" ^ "E3A9100933D871388F34DAFB286471AE" ^ "D6ACC48B470476DC5C2BB593F59DC17E" ^ "F772F56922391BF23A0B2E80D65FA193") ~output1:("B9C8DAC399EF111DE678A9BD8EC24F34" ^ "0F6F785B19984328B13F78072666955A" ^ "B837C4E51AC95C36ECBEFFC07D9B37F2" ^ "EE9981E8CF49FD5BA0EADDE2CA37CC8D") ~output2:("3B0283B5A95280B58CEC0A8D65328A7A" ^ "8F3655A4B39ECBE88C6322E93011E13C" ^ "FF0A370844851F4C5605504E8266B301" ^ "DD9B915CA8DCD72E169AEA2033296D7F") ~output3:("4F9CA1676901DDC313D4EE17B815F6B5" ^ "AC11AF03BF02517FB3B10E9302FCBF67" ^ "C284B5C7612BBE7249365BCAC07FD4C2" ^ "C7AE78F3FDA1880B2DAA20E4EC70F93B") let salsa20_20_128bit_ecrypt_set3_vector144_test = test_salsa20_20 ~key:"909192939495969798999A9B9C9D9E9F" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("0281FB6B767A90231AB6A19EB1E4FB76" ^ "A041063FE23AC835797DFA178CC2D7C2" ^ "8DFAD591D2EAF26A985332F8DC74537D" ^ "F7E0A5F26946BCF7D70B6C3D9DD859D2") ~output1:("088ED6D7AB26EEC97518EBF387B0644F" ^ "D22266E578F141A7218F94AE2EE5885A" ^ "67A9FA304F6880A781EE05C1251A7EAD" ^ "4C3025D833B59739C68D3D7F3A844148") ~output2:("6B48D13EC0EB1CD0CDAC5D5E09DC7BE4" ^ "AE02BE4283DDC7FA68E802A31508E6EA" ^ "7197E5AC10805FDEB6824AEEF8178BAA" ^ "45D7E419CF9237155D379B38F994EF98") ~output3:("7E71823935822D048B67103FF56A709A" ^ "25517DCE5CFBB807B496EEF79EFFBCD1" ^ "0D23BAD02758814F593B2CD4AC062699" ^ "AEC02B25A7E0D1BAE598AFDBE4333FE7") let salsa20_20_128bit_ecrypt_set3_vector153_test = test_salsa20_20 ~key:"999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("D4ACE9BF4A76822D685E93E7F77F2A79" ^ "46A76E3BF0910854C960331A41835D40" ^ "902BC1CF3F8A30D4C8391087EC3A03D8" ^ "81E4734A5B830EFD55DA84159879D97F") ~output1:("5BD8BB7ED009652150E62CF6A17503BA" ^ "E55A9F4ECD45B5E2C60DB74E9AE6C8BF" ^ "44C71000912442E24ED2816243A7794D" ^ "5B1203A246E40BE02F285294399388B1") ~output2:("55433BDEA349E8849D7DF899193F029A" ^ "9F09405D7AFE842CB2C79F0E55C88913" ^ "B0776825D8D036A69DDDCD6AFCA6588F" ^ "69F0946A86D32C3585F3813B8CCB56AF") ~output3:("0B67F00FA0BB7D1ED5E4B46A68794864" ^ "5239422656F77EF2AFEA34FFF98DA7A8" ^ "90970F09137AF0FABD754C296DD3C6F2" ^ "7539BC3AE78FFA6CDCCC75E944660BB4") let salsa20_20_128bit_ecrypt_set3_vector162_test = test_salsa20_20 ~key:"A2A3A4A5A6A7A8A9AAABACADAEAFB0B1" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("92A067C3724F662120C25FAF4B9EC419" ^ "C392D98E5CB8C5EE5842C1D5C704DE87" ^ "8C8C68C55BA83D63C5DEEC24CFF7230D" ^ "3F6FBF6E49520C20CFE422798C676A47") ~output1:("133C9A30B917C583D84FB0AAC2C63B5F" ^ "6758AC8C2951196E9460ADBE3417D914" ^ "90F0A195DC5682F984069506CA75DC1D" ^ "79A7AE1DCDF9E0219D4E6A005BA72EDD") ~output2:("091D38749503B63238B1E3260855B76C" ^ "5CFE9D012265FB7F58EB8CAA76B45645" ^ "9C54F051274DDAE06BEC6D7EB8B9FF59" ^ "5302D9D68F2AF1057581D5EE97CCEEDD") ~output3:("3FCCB960792B7136768BBA4C3D69C597" ^ "88F04602C10848A7BCBED112F860998D" ^ "9E9A788998D1DC760F7ECF40597446D8" ^ "F39CD4D4013F472BB125DE6A43E9799D") let salsa20_20_128bit_ecrypt_set3_vector171_test = test_salsa20_20 ~key:"ABACADAEAFB0B1B2B3B4B5B6B7B8B9BA" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("AC3DE1B9F6DF6D6117B671A639BF0761" ^ "24A0A6D293B107554E9D662A8BFC3F34" ^ "17C59437C981A0FDF9853EDF5B9C38FE" ^ "74072C8B78FE5EBA6B8B970FE0CE8F1F") ~output1:("23112BD4E7F978D15F8B16F6EDB130D7" ^ "2F377233C463D710F302B9D7844C8A47" ^ "FB2DFDD60235572859B7AF100149C87F" ^ "6ED6CE2344CDF917D3E94700B05E2EEF") ~output2:("E8DDFE8916B97519B6FCC881AEDDB42F" ^ "39EC77F64CAB75210B15FBE104B02FC8" ^ "02A775C681E79086D0802A49CE6212F1" ^ "77BF925D10425F7AD199AB06BD4D9802") ~output3:("F9D681342E65348868500712C2CA8481" ^ "D08B7176A751EF880014391A54680992" ^ "6597B10E85761664558F34DA486D3D44" ^ "54829C2D337BBA3483E62F2D72A0A521") let salsa20_20_128bit_ecrypt_set3_vector180_test = test_salsa20_20 ~key:"B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("21BD228837BFB3ACB2DFC2B6556002B6" ^ "A0D63A8A0637533947615E61FE567471" ^ "B26506B3D3B23F3FDB90DFAC6515961D" ^ "0F07FD3D9E25B5F31B07E29657E000BF") ~output1:("2CF15E4DC1192CA86AA3B3F64841D8C5" ^ "CD7067696674B6D6AB36533284DA3ABF" ^ "D96DD87830AE8FA723457BE53CB3404B" ^ "7A0DCBB4AF48A40FC946C5DEB7BD3A59") ~output2:("E3B15D2A87F61C2CE8F37DCEB896B5CA" ^ "28D1DA6A3A71704309C0175BB6116911" ^ "9D5CBE34FC8F052961FF15F2C8F06CD6" ^ "F8E889694E2C69E918DD29C33F125D31") ~output3:("CCD1C951D6339694972E902166A13033" ^ "A1B0C07313DC5927FE9FB3910625332C" ^ "4F0C96A8896E3FC26EFF2AF9484D28B8" ^ "CB36FF4883634B40C2891FA53B6620B1") let salsa20_20_128bit_ecrypt_set3_vector189_test = test_salsa20_20 ~key:"BDBEBFC0C1C2C3C4C5C6C7C8C9CACBCC" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("7943AD4AA5F62E08E1AE450E84CFF27D" ^ "E3B204A2BCA315B981906D5A13F68AB0" ^ "34D3396EA8A41001AF49834368805B37" ^ "D5380FB14821E3F7F4B44231784306F3") ~output1:("415F5381C9A58A29045E77A1E91E6726" ^ "DFCEBC71E4F52B36DBD7432D158F2ADB" ^ "31CF5F52D8456952C09B45A16B289B7A" ^ "32687716B8EDFF0B1E5D0FC16DCCFA88") ~output2:("CE317CB853E2AFA22392D4B8AE345A91" ^ "0807F8DE3A14A820CDA771C2F2F3629A" ^ "65A1CC7A54DDEC182E29B4DACEA5FBFA" ^ "4FAC8F54338C7B854CD58ABA74A2ACFF") ~output3:("5804F61C5C07EC3C2D37DF746E4C96A1" ^ "AD5E004C2585F3F401CB3AF62CB975F8" ^ "64375BE3A7117079810418B07DABCCEE" ^ "61B6EC98EA4F28B0D88941CB6BE2B9D2") let salsa20_20_128bit_ecrypt_set3_vector198_test = test_salsa20_20 ~key:"C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("A4FB9A02500A1F86145956E16D04975E" ^ "2A1F9D2283D8AD55C17A9BD6E0C8B561" ^ "6658132B8928F908FEC7C6D08DBFBC55" ^ "73449F28AA0EF2884E3A7637233E45CD") ~output1:("74D169573560C14692BBE2498FDA0ED7" ^ "866A11EE4F26BB5B2E9E2559F089B35E" ^ "C9972634C5A969DD16EB4341782C6C29" ^ "FBBF4D11ECB4133D1F9CA576963973EB") ~output2:("D28966E675759B82EDE324ABA1121B82" ^ "EAB964AB3E10F0FE9DF3FCC04AFC8386" ^ "3A43FD6B7FC0AD592C93B80BE99207CB" ^ "A8A55DDEA56DD811AAD3560B9A26DE82") ~output3:("E362A817CCD304126E214D7A0C8E9EB9" ^ "3B33EB15DE324DDDFB5C870EA22279C7" ^ "8E28EFF95974C2B935FC9F1BF531D372" ^ "EF7244D2CC620CEBDE5D8096AD7926B3") let salsa20_20_128bit_ecrypt_set3_vector207_test = test_salsa20_20 ~key:"CFD0D1D2D3D4D5D6D7D8D9DADBDCDDDE" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("FF879F406EAF43FABC6BE563ADA47C27" ^ "872647F244C7FAE428E4130F17B47138" ^ "0E1E1CD06C50309760FDEE0BC91C31D0" ^ "CA797E07B173C6202D2916EEBA9B6D1C") ~output1:("61E724B288AECF393483371C1BE653F3" ^ "7BBA313D220173A43459F0BCE195E45C" ^ "49B3B5FB1B0539DE43B5B4F2960D8E6E" ^ "5BC81DAF07E9EFBB760881441FA8823B") ~output2:("F77AC22945ECD60EBCAF4BA19A59B078" ^ "B3C3BC36D1DDA6B9969B458C2019D68E" ^ "FD04D75DDC6041BBCD69747651D2DA7F" ^ "BED721081F8147367585CABB1C50CF0C") ~output3:("7475DCD3545B810445AFCA0C0AFA93A9" ^ "11EA99991A5D639AB32DDF69AA21C45A" ^ "53DCB998FDAE5F9A82EC8501123EAE3D" ^ "99351C43311F8430DB3D230E12DA77D2") let salsa20_20_128bit_ecrypt_set3_vector216_test = test_salsa20_20 ~key:"D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("2B4C4185E2FDFAE75DABFF32632FB5D9" ^ "823359F15E2D17FF74FAC844E5016A4A" ^ "64C2C47498A15029FBEB6E4893381E65" ^ "6D2A2B9712524827B151C6E67D990388") ~output1:("D870A94C4856EF818C5D93B2187F09C7" ^ "32E4491103B8A49B14CDC118F1607E2D" ^ "8443740F20220DF076B981D90436E9C3" ^ "09282C1CEAAE6375002AD1CA9CCF720C") ~output2:("5091AE53E13948DAE57F6B0BE95B8F46" ^ "A1F53553767B98F9799A0F0AC468AEB3" ^ "40C20E23FA1A8CAE7387CEA127A7A0F3" ^ "635667BF028DE15179093B706306B99C") ~output3:("02323B1FA2C863D3B4A89CFC143013A6" ^ "EEA8265BBD1B8FE243DEA2F4B19A5726" ^ "593564E7E7021FD042F58077A5821C2F" ^ "415BC38D6DD2BE29A5400E4B1D65B2A2") let salsa20_20_128bit_ecrypt_set3_vector225_test = test_salsa20_20 ~key:"E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("9A5509AB6D2AB05C7DBA61B0CC9DD844" ^ "B352A293E7D96B5C0066ACDB548DB857" ^ "0459E989B83AF10A2C48E9C00E02671F" ^ "436B39C174494787D1ECEB3417C3A533") ~output1:("8A913EBA25B4D5B485E67F97E83E10E0" ^ "B858780D482A6840C88E7981F59DC51F" ^ "2A86109E9CD526FCFA5DBF30D4AB5753" ^ "51027E5A1C923A00007260CE7948C53D") ~output2:("0A901AB3EBC2B0E4CBC154821FB7A0E7" ^ "2682EC9876144C4DC9E05098B6EFCCCB" ^ "90E2F03837553C579CDD0A647D6A6963" ^ "50000CA57628B1E48E96242226A92ECC") ~output3:("9CDB39B79A464F2CCA3637F04EBAEA35" ^ "7A229FC6A9BA5B83171A0A8945B6F117" ^ "56EBC9F4201D0BA09C39F97767213046" ^ "32AA6A68ADE5B90268AEE335E13B1D39") let salsa20_20_128bit_ecrypt_set3_vector234_test = test_salsa20_20 ~key:"EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("37EDAFA4F5EDC64EBF5F74E543493A53" ^ "93353DE345A70467A9EC9F61EEFE0ED4" ^ "532914B3EA6C2D889DA9E22D45A7DD32" ^ "1EA5F1F6978A7B2E2A15D705DE700CE4") ~output1:("C415739777C22430DAB2037F6287E516" ^ "B1CE142111456D8919E8CD19C2B2D30D" ^ "8A1B662C26137F20F87C2802A2F3E66D" ^ "8CEB9D3C1B4368195856249A379BD880") ~output2:("0381733EC9B2073F9E4E995447118411" ^ "2D99B23FA4A87B4025C6AF955E93E0D5" ^ "7DD37011E1624175F970BDA7D625224B" ^ "AB0F021E6453DBA894A5074C447D24BC") ~output3:("F9D45C7E0E7A26F2E7E2C07F68AF1191" ^ "CC699964C01654522924A98D6790A946" ^ "A04CD9586455D5A537CBA4D10B3C2718" ^ "745C24875156483FE662B11E0634EAEA") let salsa20_20_128bit_ecrypt_set3_vector243_test = test_salsa20_20 ~key:"F3F4F5F6F7F8F9FAFBFCFDFEFF000102" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("B935A7B6D798932D879795A182E7C194" ^ "BECEFF32522C2F3FFF55A5C6D32A91D2" ^ "BA9F144DB280ABA7BA8A7921AFA3BD82" ^ "CA742DDBEAF8AF72299936E9C2FEA59E") ~output1:("6F32248B6EF4CDAE06864B6477893440" ^ "F0E0217421D7081D1F0DA197B5263674" ^ "0E9BDD59068BEDE48BF52C43446C12CD" ^ "4F10ED22BFDDFA915FA0FB1A73F9139C") ~output2:("BF01A4ED868EF9080DF80689E589897C" ^ "021DCA18073F9291E1D158DC26266556" ^ "728DD130629D3760F541439147F4C1CA" ^ "279FB98040E9FCE50998E42D6259DE1F") ~output3:("0F2B116CD687C91FBA1EDEAD586411E9" ^ "66D9EA1076863EC3FDFC254DD5C93ED6" ^ "AE1B01982F63A8EB13D839B2510AD02C" ^ "DE24210D97A7FA9623CAC00F4C5A1107") let salsa20_20_128bit_ecrypt_set3_vector252_test = test_salsa20_20 ~key:"FCFDFEFF000102030405060708090A0B" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("09D36BFFDDCD3ADC8EB0ABEEB3794CE1" ^ "FFBDED9CFC315D21A53C221B27722FE3" ^ "F10E20D47DDCFD3CCDE9C1BAAF01F551" ^ "1D3F14F88BF741A7F6578C3BC9024B2B") ~output1:("552502A1B2D0F29806DE512F3314FC8E" ^ "19518E35D9DB1EBC9034EA46E5815AB9" ^ "DF0F403E997E676BF47C0116D5E9B817" ^ "26B99D65AA4315F1E5906F6E39B1297E") ~output2:("6BF351A501E8D1B4BAF4BFD04726DC4F" ^ "50200463DCC13FF3BE93E6C4D4304CE0" ^ "9E6A1CEA41BFB93D6DBAD713298F79CF" ^ "F6F5BB81F456E33A3396D02F2E33BDC5") ~output3:("715F8FFB2BC25CD89E46B706EF871207" ^ "EFE736AA3CB961B06E7B439E8E4F76E2" ^ "944AF7BD49EEC47B4A2FD716D191E858" ^ "59C74FD0B4A505ACE9F80EEB39403A1F") let salsa20_20_128bit_ecrypt_set4_vector0_test = test_salsa20_20 ~key:"0053A6F94C9FF24598EB3E91E4378ADD" ~nonce:"0000000000000000" ~input:(String.make 262144 '0') ~output0:("BE4EF3D2FAC6C4C3D822CE67436A407C" ^ "C237981D31A65190B51053D13A19C89F" ^ "C90ACB45C8684058733EDD259869C58E" ^ "EF760862BEFBBCA0F6E675FD1FA25C27") ~output1:("F5666B7BD1F4BC8134E0E45CDB69876D" ^ "1D0ADAE6E3C17BFBFE4BCE02461169C5" ^ "4B787C6EF602AF92BEBBD66321E0CAF0" ^ "44E1ADA8CCB9F9FACFC4C1031948352E") ~output2:("292EEB202F1E3A353D9DC6188C5DB434" ^ "14C9EF3F479DF988125EC39B30C014A8" ^ "09683084FBCDD5271165B1B1BF54DAB4" ^ "40577D864CD186867876F7FDA5C79653") ~output3:("C012E8E03878A6E7D236FEC001A9F895" ^ "B4F58B2AF2F3D237A944D93273F5F3B5" ^ "45B1220A6A2C732FC85E7632921F2D36" ^ "6B3290C7B0A73FB61D49BC7616FC02B8") let salsa20_20_128bit_ecrypt_set4_vector1_test = test_salsa20_20 ~key:"0558ABFE51A4F74A9DF04396E93C8FE2" ~nonce:"0000000000000000" ~input:(String.make 262144 '0') ~output0:("BA1A48247B8C44AAF12F5645D65FF7F4" ^ "E4D7C404EE0CBB691355FAEB82D03B99" ^ "AD0FDFC20A1E593973E5B8F0264F7FB0" ^ "538292A4C8FE8218A1DA3EB7B71EEA64") ~output1:("03A24E89D69D5E1DA98B0367CF626F33" ^ "D558B1208AB120B6B1778BFF640F56DA" ^ "715FE1B681D8CC0F305D6645B439BA81" ^ "D3C446A428B31BB18E9DA1E2A900B0FD") ~output2:("6A28ADD4F926759CEBB0AFC5D5DA5243" ^ "1F2E7ECBBD1E9DEAF368137E35F1AFBD" ^ "65852214FA06310C3175FCF364810F62" ^ "7E3703E9AC5458A8B681EB03CEECD872") ~output3:("E8D8AB5E245B9A83A77B30F19E3706F0" ^ "37272E42F9C6CD7E8156C923535EF119" ^ "B633E896E97C404C6D87565EEA08EB7F" ^ "F6319FF3E631B6CDD18C53EE92CCEEA0") let salsa20_20_128bit_ecrypt_set4_vector2_test = test_salsa20_20 ~key:"0A5DB00356A9FC4FA2F5489BEE4194E7" ~nonce:"0000000000000000" ~input:(String.make 262144 '0') ~output0:("8313F4A86F697AAC985182862E4FC623" ^ "3511C46B6DAEEDB94B63461111CB4768" ^ "72F1BC3B4E8EE80A4ADE7D1A8CD49C17" ^ "1D3A550D3F39B7775734225579B8B60A") ~output1:("6AFA6F539C0F3B0B9DEB0235E7EB2E14" ^ "B111615D4FBC5BF7FFE75E160DEDA3D9" ^ "932125469AEC00539ECE8FCF8067CB0F" ^ "B542C2064267BEA7D9AD6365314D5C2C") ~output2:("296F2B5D22F5C96DA78304F5800E0C87" ^ "C56BC1BACD7A85D35CFECE17427393E1" ^ "611975CC040D27DF6A5FABC89ADDE328" ^ "AE8E9CB4F64CFA0CB38FE525E39BDFE4") ~output3:("86C8139FD7CED7B5432E16911469C7A5" ^ "6BDD8567E8A8993BA9FA1394348C2283" ^ "F2DF5F56E207D52A1DA070ABF7B516CF" ^ "2A03C6CD42D6EA2C217EC02DF8DDCA9C") let salsa20_20_128bit_ecrypt_set4_vector3_test = test_salsa20_20 ~key:"0F62B5085BAE0154A7FA4DA0F34699EC" ~nonce:"0000000000000000" ~input:(String.make 262144 '0') ~output0:("62765613D127804ECD0F82D208D70156" ^ "3B1685EEF67945DAE2900307CDB14EA6" ^ "2474A439D8BAE8005493455471E7BCB9" ^ "DB75F0596F3FB47E65B94DC909FDE140") ~output1:("00A0D5B2CE7B95E142D21B57B187C29C" ^ "19B101CD063196D9B32A3075FB5D54A2" ^ "0D3CE57CBEC6CA684CB0E5306D5E21E5" ^ "657F35B8FB419A0251EA5CD94113E23B") ~output2:("AAC2D29404A015047DEFB4F11460958D" ^ "A989141026FE9325F15954363FC78898" ^ "D4A20F6870F4D2B124590973F6956096" ^ "940E2324F7C63384A85BACF53F7755E3") ~output3:("0A543607FE352336ACFEDFE6B74359E0" ^ "B26B19FD45A8938C6C0A6DB68A137749" ^ "5B65211558D0CB9ECA9DA2C0E50702B6" ^ "88B2DEC53AAA2FBF11BD149F4F445696") let salsa20_20_128bit_ecrypt_set5_vector0_test = test_salsa20_20 ~key:"00000000000000000000000000000000" ~nonce:"8000000000000000" ~input:(String.make 1024 '0') ~output0:("B66C1E4446DD9557E578E223B0B76801" ^ "7B23B267BB0234AE4626BF443F219776" ^ "436FB19FD0E8866FCD0DE9A9538F4A09" ^ "CA9AC0732E30BCF98E4F13E4B9E201D9") ~output1:("462920041C5543954D6230C531042B99" ^ "9A289542FEB3C129C5286E1A4B4CF118" ^ "7447959785434BEF0D05C6EC8950E469" ^ "BBA6647571DDD049C72D81AC8B75D027") ~output2:("DD84E3F631ADDC4450B9813729BD8E7C" ^ "C8909A1E023EE539F12646CFEC03239A" ^ "68F3008F171CDAE514D20BCD584DFD44" ^ "CBF25C05D028E51870729E4087AA025B") ~output3:("5AC8474899B9E28211CC7137BD0DF290" ^ "D3E926EB32D8F9C92D0FB1DE4DBE452D" ^ "E3800E554B348E8A3D1B9C59B9C77B09" ^ "0B8E3A0BDAC520E97650195846198E9D") let salsa20_20_128bit_ecrypt_set5_vector9_test = test_salsa20_20 ~key:"00000000000000000000000000000000" ~nonce:"0040000000000000" ~input:(String.make 1024 '0') ~output0:("1A643637B9A9D868F66237163E2C7D97" ^ "6CEDC2ED0E18C98916614C6C0D435B44" ^ "8105B355AE1937A3F718733CE1526231" ^ "6FA3243A27C9E93D29745C1B4DE6C17B") ~output1:("CDDB6BD210D7E92FBFDD18B22A03D66C" ^ "C695A93F34FB033DC14605536EEEA06F" ^ "FC4F1E4BACFCD6EB9DA65E36C46B26A9" ^ "3F60EAA9EC43307E2EA5C7A68558C01A") ~output2:("5FC02B90B39F3E90B8AEC15776F2A94F" ^ "D8C26B140F798C93E1759957F99C613B" ^ "8B4177A7B877D80A9B9C76C2B84E21A6" ^ "DF803F0DB651E1D0C88FB3743A79938F") ~output3:("B4BC18F7279AC64BB6140A586F45AC96" ^ "E549C0CA497F59B875C614DE605A8BFF" ^ "63AB3F1E00DAEAE7A5CC7A7796E9BACC" ^ "DD469E9100EABCD6E69301EA59C4B76A") let salsa20_20_128bit_ecrypt_set5_vector18_test = test_salsa20_20 ~key:"00000000000000000000000000000000" ~nonce:"0000200000000000" ~input:(String.make 1024 '0') ~output0:("94B7B07E184BC24A0904290B2601FC3A" ^ "C70BEAD7B1FC3294360ED4EF16813453" ^ "0B4D1F3F28A3C3B248B2E914A8DCBD53" ^ "26A240C9BB361A8A93D023725BDCD4E3") ~output1:("27C7A2C4EAA1E2E8798CA71EA50B7E5A" ^ "CD9FC82263D11781EFC16142CFD21A63" ^ "4DB2B860B54A9979AFA187CE0667D176" ^ "23FC91EC1E5E6C31A8089628AC76F9F0") ~output2:("C2CD243516E5919D6C5C478469260813" ^ "ABE8E6F54BE8E11D48FEC043CDADA19B" ^ "EFE9CB0C22A9BB30B98E4CFCF1A55EF1" ^ "263B209CE15FEAEF8237CFAF7E5286D6") ~output3:("84489BD680FB11E5CAA0F5535ABA86DC" ^ "FF30AC031CEFED9897F2528035977726" ^ "70E1E164FA06A28DD9BAF625B576166A" ^ "4C4BF4CADD003D5DF2B0E6D9142DD8B3") let salsa20_20_128bit_ecrypt_set5_vector27_test = test_salsa20_20 ~key:"00000000000000000000000000000000" ~nonce:"0000001000000000" ~input:(String.make 1024 '0') ~output0:("2E6C8BE7DD335292EE9152641B0E4EFB" ^ "43D27434E4BE70EAC4CAFAE5C38B2E5B" ^ "06E70B9966F4EDD9B4C4589E18E61F05" ^ "B78E7849B6496F33E2FCA3FC8360824C") ~output1:("1006D6A04165A951C7EE31EEB0F6C32B" ^ "D0B089683C001942886FCEF9E700D15A" ^ "DB117652735C546D30177DC14FA68708" ^ "D591C3254C05B84BF0DCBC3105F06A6F") ~output2:("2196ADA05BED2BD097A43E4C5BE6C940" ^ "4A353689939DCB9C4F82278BDB0EB505" ^ "F70FFD9921B46645EDDFCF47405FD3E6" ^ "7CAE732B367A0B0F2B57A503161FA5DE") ~output3:("4A3504DAC25F59489C769090D822E89E" ^ "1338AC73F22DB2614B43D640525EF996" ^ "9D6B7E3900ADCBE056AB818E0FF708E3" ^ "B0A8E63531F252C384DD3DE7318EA866") let salsa20_20_128bit_ecrypt_set5_vector36_test = test_salsa20_20 ~key:"00000000000000000000000000000000" ~nonce:"0000000008000000" ~input:(String.make 1024 '0') ~output0:("1D3FD8BAF2A13BCD2A49B50F8DFB0522" ^ "8E366B4FD2ECD6973DFF116289D7E0AF" ^ "55EFB875345204B5FCE27A1C6DF79531" ^ "B3175647526BF5C028C454BADEFBECD6") ~output1:("F639D0D23CC5817501517216ADA14241" ^ "D08495F17CDEAFB883CE619A3255EC3F" ^ "EAADFA224CF354C425A74D3DDAAA0C86" ^ "E44016238C142B36944EF53A1EC7DF92") ~output2:("9CAE4D4639696A188E08BC1B01774608" ^ "5D18418F82DC90742BB6D172414ACC13" ^ "A4721B018B2CC002CB6E6FFE4A4E252C" ^ "C4BF5DE975684C8805036F4C76660DC8") ~output3:("CB2A2CB3136F5CC71FD95A4A242B15E5" ^ "1C8E3BAE52FEC9C1B591B86DFDDC2442" ^ "353DF500B2B9868A6C609655FC1A3E03" ^ "347608D12D3923457EEEB34960F4DB31") let salsa20_20_128bit_ecrypt_set5_vector45_test = test_salsa20_20 ~key:"00000000000000000000000000000000" ~nonce:"0000000000040000" ~input:(String.make 1024 '0') ~output0:("2DCAD75F5621A673A471FDE8728FACF6" ^ "D3146C10A0903DE12FBDCE134CC0F11B" ^ "2D2ABBDBADFA19303E264011A1B9EFEC" ^ "AB4DFBC37E3D0F090D6B069505525D3A") ~output1:("02C401ACF6D160CC1D80E11CB4F3038A" ^ "4C5B61C995CD94E15D7F95A0A18C49D5" ^ "DA265F6D88D68A39B55DB3505039D13E" ^ "AB9DEBD408CE7A79C375FD3FEBEF86C8") ~output2:("83D92AF769F5BF1FA894613D3DF447EB" ^ "D461CFFC0CA3A9843E8441EC91DEBC67" ^ "BE9162EABC5607A6D3FCAD4426EF4F9F" ^ "3B42CEC8C287C194B2211DEA4549D5D5") ~output3:("D3F86930112EAFC7AA430444693BAE77" ^ "3F014D0798CAF3652A3432460F326DA8" ^ "8E82BE1E08C220B5FCBCE238B982E37D" ^ "1E60DCBF1747D437D42DB21ADF5EECF2") let salsa20_20_128bit_ecrypt_set5_vector54_test = test_salsa20_20 ~key:"00000000000000000000000000000000" ~nonce:"0000000000000200" ~input:(String.make 1024 '0') ~output0:("D8E137C510CDBB1C788677F44F3D3F2E" ^ "4C19FCEB51E7C2ECBDB175E933F44625" ^ "C7B0168E446CCCA900B9DB12D53E89E1" ^ "B917A69BDB888935B3B795D743D0D0E6") ~output1:("E168F81B5BFB769F3380690D423E251E" ^ "0F4BEEBE0B02F19AFFADBD94212B8063" ^ "D77A665FD53F8F1A1CC682599C74F415" ^ "3642EC7DADA034403A90E1E5DA40C896") ~output2:("574774CFB8452E82777371616E0AC224" ^ "E29939E725B99EA8CFB4A9BF459A70D6" ^ "AB1991E85E06905ACCDA8D1911F82835" ^ "9C4FD7614A55C1E30171934412D46B3E") ~output3:("21FE9B1F82E865CC305F04FA2C69EA97" ^ "6D90A41590A3BD242337D87D28E3041D" ^ "3D0F74CA24A74453CB679FDFFEE45AA6" ^ "3B2DDE513D3F9E28E86346D9A4114CD7") let salsa20_20_128bit_ecrypt_set5_vector63_test = test_salsa20_20 ~key:"00000000000000000000000000000000" ~nonce:"0000000000000001" ~input:(String.make 1024 '0') ~output0:("42DCF10EA1BCBA82C88DDCDF905C9C78" ^ "42A78AE57117F09CE51517C0C70063CF" ^ "1F6BC955EF8806300972BD5FC715B0ED" ^ "38A111610A81EBA855BB5CD1AEA0D74E") ~output1:("261E70245994E208CDF3E868A19E26D3" ^ "B74DBFCB6416DE95E202228F18E56622" ^ "521759F43A9A71EB5F8F705932B0448B" ^ "42987CEC39A4DF03E62D2C24501B4BDE") ~output2:("9E433A4BF223AA0126807E8041179CC4" ^ "760516D3537109F72124E3534A24EA7D" ^ "B225C60063190FD57FF8595D60B2A8B4" ^ "AE37384BB4FCD5B65234EE4FB0A1EBEA") ~output3:("3F9803DD763449758F008D77C8940F8A" ^ "FB755833ED080A10513D800BA3A83B1C" ^ "028A53AED0A65177C58B116E574745D0" ^ "F28506A9DACD6F8A3D81613E00B12FDB") let salsa20_20_128bit_ecrypt_set6_vector0_test = test_salsa20_20 ~key:"0053A6F94C9FF24598EB3E91E4378ADD" ~nonce:"0D74DB42A91077DE" ~input:(String.make 262144 '0') ~output0:("05E1E7BEB697D999656BF37C1B978806" ^ "735D0B903A6007BD329927EFBE1B0E2A" ^ "8137C1AE291493AA83A821755BEE0B06" ^ "CD14855A67E46703EBF8F3114B584CBA") ~output1:("1A70A37B1C9CA11CD3BF988D3EE4612D" ^ "15F1A08D683FCCC6558ECF2089388B8E" ^ "555E7619BF82EE71348F4F8D0D2AE464" ^ "339D66BFC3A003BF229C0FC0AB6AE1C6") ~output2:("4ED220425F7DDB0C843232FB03A7B1C7" ^ "616A50076FB056D3580DB13D2C295973" ^ "D289CC335C8BC75DD87F121E85BB9981" ^ "66C2EF415F3F7A297E9E1BEE767F84E2") ~output3:("E121F8377E5146BFAE5AEC9F422F474F" ^ "D3E9C685D32744A76D8B307A682FCA1B" ^ "6BF790B5B51073E114732D3786B985FD" ^ "4F45162488FEEB04C8F26E27E0F6B5CD") let salsa20_20_128bit_ecrypt_set6_vector1_test = test_salsa20_20 ~key:"0558ABFE51A4F74A9DF04396E93C8FE2" ~nonce:"167DE44BB21980E7" ~input:(String.make 262144 '0') ~output0:("EF5236C33EEEC2E337296AB237F99F56" ^ "A48639744788E128BC05275D4873B9F0" ^ "FAFDA8FAF24F0A61C2903373F3DE3E45" ^ "9928CD6F2172EA6CDBE7B0FBF45D3DAD") ~output1:("29412152F2750DC2F951EC969B4E9587" ^ "DCD2A23DAADCBC20677DDFE89096C883" ^ "E65721FC8F7BFC2D0D1FD6143D8504CB" ^ "7340E06FE324CE3445081D3B7B72F3B3") ~output2:("49BFE800381794D264028A2E32D318E7" ^ "F6FD9B377ED3A12274CE21D40CCEF04D" ^ "55791AF99849989C21D00E7D4E7B9FF4" ^ "D46AABC44AED676B5C69CF32BE386205") ~output3:("C3E16260DD666D8D8FBF1529D0E8151A" ^ "931663D75FA0046132E4AD78D8BE7F8D" ^ "7F41AAEFDE58BA80B962B8B68762CDF3" ^ "E4B06E05D73D22CC33F1E1592D5116F4") let salsa20_20_128bit_ecrypt_set6_vector2_test = test_salsa20_20 ~key:"0A5DB00356A9FC4FA2F5489BEE4194E7" ~nonce:"1F86ED54BB2289F0" ~input:(String.make 262144 '0') ~output0:("8B354C8F8384D5591EA0FF23E7960472" ^ "B494D04B2F787FC87B6569CB9021562F" ^ "F5B1287A4D89FB316B69971E9B861A10" ^ "9CF9204572E3DE7EAB4991F4C7975427") ~output1:("B8B26382B081B45E135DF7F8C468ACEA" ^ "56EB33EC38F292E3246F5A90233DDDC1" ^ "CD977E0996641C3FA4BB42E7438EE04D" ^ "8C275C57A69EEA872A440FC6EE39DB21") ~output2:("C0BA18C9F84D6A2E10D2CCCC041D736A" ^ "943592BB626D2832A9A6CCC1005DDB9E" ^ "A1694370FF15BD486B77629BB363C3B1" ^ "21811BCCFB18537502712A63061157D8") ~output3:("870355A6A03D4BC9038EA0CB2F4B8006" ^ "B42D70914FBFF76A80D2567BE8404B03" ^ "C1124BCE2FD863CE7438A5680D23C5E1" ^ "F8ED3C8A6DB656BFF7B060B8A8966E09") let salsa20_20_128bit_ecrypt_set6_vector3_test = test_salsa20_20 ~key:"0F62B5085BAE0154A7FA4DA0F34699EC" ~nonce:"288FF65DC42B92F9" ~input:(String.make 262144 '0') ~output0:("71DAEE5142D0728B41B6597933EBF467" ^ "E43279E30978677078941602629CBF68" ^ "B73D6BD2C95F118D2B3E6EC955DABB6D" ^ "C61C4143BC9A9B32B99DBE6866166DC0") ~output1:("906258725DDD0323D8E3098CBDAD6B7F" ^ "941682A4745E4A42B3DC6EDEE565E6D9" ^ "C65630610CDB14B5F110425F5A6DBF18" ^ "70856183FA5B91FC177DFA721C5D6BF0") ~output2:("09033D9EBB07648F92858913E220FC52" ^ "8A10125919C891CCF8051153229B958B" ^ "A9236CADF56A0F328707F7E9D5F76CCB" ^ "CAF5E46A7BB9675655A426ED377D660E") ~output3:("F9876CA5B5136805445520CDA425508A" ^ "E0E36DE975DE381F80E77D951D885801" ^ "CEB354E4F45A2ED5F51DD61CE0994227" ^ "7F493452E0768B2624FACA4D9E0F7BE4") let salsa20_20_256bit_ecrypt_set1_vector0_test = test_salsa20_20 ~key:"8000000000000000000000000000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("E3BE8FDD8BECA2E3EA8EF9475B29A6E7" ^ "003951E1097A5C38D23B7A5FAD9F6844" ^ "B22C97559E2723C7CBBD3FE4FC8D9A07" ^ "44652A83E72A9C461876AF4D7EF1A117") ~output1:("57BE81F47B17D9AE7C4FF15429A73E10" ^ "ACF250ED3A90A93C711308A74C6216A9" ^ "ED84CD126DA7F28E8ABF8BB63517E1CA" ^ "98E712F4FB2E1A6AED9FDC73291FAA17") ~output2:("958211C4BA2EBD5838C635EDB81F513A" ^ "91A294E194F1C039AEEC657DCE40AA7E" ^ "7C0AF57CACEFA40C9F14B71A4B3456A6" ^ "3E162EC7D8D10B8FFB1810D71001B618") ~output3:("696AFCFD0CDDCC83C7E77F11A649D79A" ^ "CDC3354E9635FF137E929933A0BD6F53" ^ "77EFA105A3A4266B7C0D089D08F1E855" ^ "CC32B15B93784A36E56A76CC64BC8477") let salsa20_20_256bit_ecrypt_set1_vector9_test = test_salsa20_20 ~key:"0040000000000000000000000000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("01F191C3A1F2CC6EBED78095A05E062E" ^ "1228154AF6BAE80A0E1A61DF2AE15FBC" ^ "C37286440F66780761413F23B0C2C9E4" ^ "678C628C5E7FB48C6EC1D82D47117D9F") ~output1:("86D6F824D58012A14A19858CFE137D76" ^ "8E77597B96A4285D6B65D88A7F1A8778" ^ "4BF1A3E44FC9D3525DDC784F5D99BA22" ^ "2712420181CABAB00C4B91AAEDFF521C") ~output2:("287A9DB3C4EEDCC96055251B73ED361B" ^ "A727C2F326EF6944F9449FB7A3DDC396" ^ "A88D9D0D853FADE365F82789D57F9B40" ^ "10F963BC498F176A93FD51723FCD4D55") ~output3:("E0D62E2E3B37FDD906C934FAA35D5E8A" ^ "89A517DD0F24CF33DE8495C5FF24F4B1" ^ "476B3E826A1C90D74507C3991CEF4067" ^ "E316A04B97AEFFA5E9D1F33CB0609B9E") let salsa20_20_256bit_ecrypt_set1_vector18_test = test_salsa20_20 ~key:"0000200000000000000000000000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("C29BA0DA9EBEBFACDEBBDD1D16E5F598" ^ "7E1CB12E9083D437EAAAA4BA0CDC909E" ^ "53D052AC387D86ACDA8D956BA9E6F654" ^ "3065F6912A7DF710B4B57F27809BAFE3") ~output1:("77DE29C19136852CC5DF78B5903CAC7B" ^ "8C91345350CF97529D90F18055ECB75A" ^ "C86A922B2BD3BD1DE3E2FB6DF9153166" ^ "09BDBAB298B37EA0C5ECD917788E2216") ~output2:("1985A31AA8484383B885418C78210D0E" ^ "84CBC7070A2ED22DCAAC6A739EAD5881" ^ "8E5F7755BE3BF0723A27DC69612F18DC" ^ "8BF9709077D22B78A365CE6131744651") ~output3:("9618FCA736A8ECA00BD1194FC9855085" ^ "526ECD47A8DE1F8DB298AD49FCE935EA" ^ "63B548597092ABAD6338F41AF87586A7" ^ "0505F2537902B81F55E53599DABA84CC") let salsa20_20_256bit_ecrypt_set1_vector27_test = test_salsa20_20 ~key:"0000001000000000000000000000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("FF852567EB72687DC56C122D61B2FB2A" ^ "4FB9E8E8DA62313B618D10F8E0DA521B" ^ "176E879CD78E641043F0FA4A22211566" ^ "429B7C68EC645FF5E44B2505D61A2D71") ~output1:("E5B040B199C3DFC8DB1F41C74C798AE2" ^ "62105477AEB1CE761D6FFF1CAB15AA1A" ^ "7B7CE26B9CCE6DC33FD4522BF8F73E70" ^ "B843D67FC06FA2258F9709DB14FBD54C") ~output2:("55706075E5FED81E2205994609868EFC" ^ "383B3E4CC295C4214356BA41FC72BFE5" ^ "4E6936FE6684EAF93C5973DDCD8E8F23" ^ "767B82D783953F89AF4E808C90BEEABD") ~output3:("7ECE71883742EE852C94F01AD85EA1A6" ^ "76CC7CBC6EDFCF1BAE751455A923FAAC" ^ "806BB72E6A982EC7A38F112445E25EB6" ^ "BC5B49C5E6C22DC8748DEE0942F6E8B2") let salsa20_20_256bit_ecrypt_set1_vector36_test = test_salsa20_20 ~key:"0000000008000000000000000000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("AF6E2EE1D5021675A92F02C764AFD94A" ^ "F3097F53532FC965EB861D6D12A3A012" ^ "ABA683A5281238CE76E3AF3944736752" ^ "AD86A5FD16E7DAFAF241ECFB0ADBBDFE") ~output1:("19444E6D7C3D8BEC0957C3E785E1EEFD" ^ "56B857F21CF8D325A4285F8DEF5078FF" ^ "7B7EFB5E3B20F6E0906265B6F7580A04" ^ "9CEC5DF1872DCCB54081054C0FC15514") ~output2:("7EB544ADBF57D042E3A6753B13C65843" ^ "0399764CF90D007E48DAFE3DA1FE3F90" ^ "8EF4BFA6AF96DCD54197DA0D3A10FA35" ^ "6A374DA08B9A84044E70EC70ED050D46") ~output3:("57224DA912C62801DB393D5E3F4EDFF7" ^ "D61BA895F88C7391FE5C943B88CC4642" ^ "0D11C3F1884B628F03C04A3C10F03FFB" ^ "CFC652D066BFD8DBF52DA2A72B9B9AC5") let salsa20_20_256bit_ecrypt_set1_vector45_test = test_salsa20_20 ~key:"0000000000040000000000000000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("D203CC523351942C94E215F6D5CC1425" ^ "C5FFB2EA9A916C0D4F7B343333A58D94" ^ "1DE20B5F543E3EE63C29D981469ACE48" ^ "86ED9DEF839D4FBD20CDF9D001F1B89B") ~output1:("9E37D2BE6473F4FA87ED294765816BB0" ^ "8CCA625418155F6704CB48082A860581" ^ "A9CF69D9145D0DCB2621E1515013DD3E" ^ "18819BEC5C186628ED545BFF7E4AC1C2") ~output2:("B8648B92B5A7B3B991722F0053909A3F" ^ "052E8F7DABE7FE0E34498C1C550DE9D5" ^ "3CE0818DDBA82F0616B3F79AD72B0BF9" ^ "B5FA2F2B8032B1860FAB0804934FBD00") ~output3:("0CD554D10A975BEA79AEAC663F5FF984" ^ "15883EB558925C5ECFA53D77FAB4B884" ^ "FE4D705B1E1B34A938C1C2D8528E1FAB" ^ "4C9A7512F12707B78F2B6BFEE8D76E57") let salsa20_20_256bit_ecrypt_set1_vector54_test = test_salsa20_20 ~key:"0000000000000200000000000000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("C45E28A2C9A80AC07A760580DCD96340" ^ "26651B25BA2332FDAFC9AA16998317B9" ^ "751A446302CDE95525C709E79CB55951" ^ "4E4A54FD73ADAAF0AB3A3F1ADDABBADA") ~output1:("17937670127CBF691AFDAD6D36994F0A" ^ "40B3F369C21691B887CFE20B0F63D125" ^ "8896C88CAB669ED6FABE464A700DA937" ^ "C43AABB45E60F14E6EBA69FBC9F2FCF3") ~output2:("2690AB8F4616302C49D79CFE3AE29AA7" ^ "9C4D1036E0CBB1D24C4682BCA0E1C1A5" ^ "80904001185286AC3C63BFBF909F4A36" ^ "525D2A732D7D166A52E087444DE24469") ~output3:("9E5E91D8BE1E46B0BAD46ED9ACCD440A" ^ "01882556B51C2B7CCC987A6C554201FC" ^ "6CE8DA0B1CD42C011A085EB8FBA0F8F2" ^ "623B6B9627EAEB91C05CFA3090A28040") let salsa20_20_256bit_ecrypt_set1_vector63_test = test_salsa20_20 ~key:"0000000000000001000000000000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("5F7B6B86B0C197B960D8250B5106CFEB" ^ "F6F4DE0D94D3958945FA979534AFE19C" ^ "D5305C55A1404C59302F05ACC819D3A3" ^ "B0BDB9D154A45C0DEE52F25012DAA445") ~output1:("20F99149AA74F631D22BEA8D85EC84A6" ^ "57C2E8703B45ED36458F0ED47408C3C7" ^ "E6624A184E7CED17C93CBC9960914A61" ^ "E71083308CB7A55D7723C2B9E6A2F087") ~output2:("EBB0F7194EA7AE5D28B916D361B19394" ^ "A163A6EB124D37A372A798135E4F2FDF" ^ "2EF422997F5AA1F9DFA3B1826431AA62" ^ "99E0AEB44D844E297604D27974EAAD6B") ~output3:("65CA9CAE36B65F58085D561A91CFDBE1" ^ "EA0400CDEB4AA1B987FAC06702590D8B" ^ "39B6228E6F4B81BB91852971DE2D3436" ^ "C8C24FA193BC10BFC5534BF5915A245B") let salsa20_20_256bit_ecrypt_set1_vector72_test = test_salsa20_20 ~key:"0000000000000000008000000000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("B96FCF5A182789AD14E53FB2E981E496" ^ "B47C6B44BE7EF95692F19AE24E193219" ^ "6E180778AC04A0EB2497497680587FEB" ^ "F412BB3A67E9538CA5B2A373E16E60F3") ~output1:("953544577886B26F2F8D7BD237D7AE8E" ^ "5D425523F6180C9591206E10E166C7E3" ^ "06537355EFD9C32FF1C8808537BA12D5" ^ "B0E303DBCEC7DB3DA6E3A16DACB1E7FB") ~output2:("9B416AA89BDC5589A1C9046D2D308B8A" ^ "CA852008C6503B373250C2639C693D9E" ^ "164FC0E94FCFBB35D67D45DE1A3D838F" ^ "302915E78470EB47654B87540AADF90A") ~output3:("3911737593809A1A9FD14F57950AEFCA" ^ "66E1E45475D39335DC01FFA72E431A85" ^ "01E146994FAA64BA37AF255F1951B33F" ^ "CB28AAC76BB08AA0917B53B9ED64CDAD") let salsa20_20_256bit_ecrypt_set1_vector81_test = test_salsa20_20 ~key:"0000000000000000000040000000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("2B08D82E92AC352247211D5F0791DAC9" ^ "D585ABF67DADFBD7B5AC60EB2EEF4C72" ^ "F6F71CA110DEE4CB2F19FABE4F442B2F" ^ "5F9FB1C94FBD553C21CD5B0CEF139880") ~output1:("AAD0055BF85562F06118CB260CB0BD5F" ^ "374CD798021593F03A67134EA8A73B22" ^ "F00F09BAB770D1287FFF17CCF5F1CF32" ^ "86833B57F4397B16A9F8351922042810") ~output2:("724D557F9D7DA4AFCB5DC6D1040DD8BF" ^ "A14A0CC61F7206606BC99385D15BFED8" ^ "9C4D69EFE5711A9E256C908AFF2734D6" ^ "501C9D1AEB7CCD1029413BF7FA40848C") ~output3:("8960F4D83E21984B3A6D5D1B667944ED" ^ "12814CD390B107A502A4BBA620E3CE9F" ^ "6DAF2D4629C828C59E86F09F1F435B4D" ^ "40A1595C3D5B6E0744FFA546B22EF865") let salsa20_20_256bit_ecrypt_set1_vector90_test = test_salsa20_20 ~key:"0000000000000000000000200000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("C9969A75572ABFAA28FBE769A287A676" ^ "3B534AF50B697C31B7F4CD8F50DDF2F2" ^ "17B3C5532E95F73AF11B0693D5A33A34" ^ "DAFBB64635A195EC9477FDFD69AE7540") ~output1:("6B358B53A60B9542F582FDE14B2711F2" ^ "6CD1B7421B4D872B95E347CDD7D763C8" ^ "73C2A8730A802AECA326FD63C8C4205C" ^ "FC1A6E2F4DF7A6ACF1E22A2BCA5379A9") ~output2:("AF64A04DB6B9CA63429E0D81CE975FD0" ^ "2A5E3BB8C1A0C3D35636AE22F3733201" ^ "2DF59549BAC23E992A1E4DD481F91956" ^ "40C4D6EE0E083702DB18328D42D93BF7") ~output3:("3F3FD5559C9C0CE3B5B484BD15E75CAB" ^ "B252CC44961C1ACA86B1722FCF205408" ^ "EF9841F947224170ECAC6503F7A8FEAE" ^ "7281ED1D9A18C4C00D12C8E40F21876F") let salsa20_20_256bit_ecrypt_set1_vector99_test = test_salsa20_20 ~key:"0000000000000000000000001000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("698BFC90B147715FB9F0CA1DDC94EE10" ^ "3082316701CDD1DF2EAE752BA485F585" ^ "9E131D0D9233B16890BD5946CBCF116D" ^ "B50E8E2DCAE104162C7B76CB3D11445C") ~output1:("07D49AB7BA8451A2A68DF473C6D1E91D" ^ "407038568FADA2DB948ABFBBE408401F" ^ "DF5960241325F2981DC17EAF1C333CDC" ^ "91E27EC064734234656AED7A944AD78A") ~output2:("C152FCF951DAECBD48EC1D0122A4EA00" ^ "9FB8FD03E35E283109DAA4E033783990" ^ "DADE92932BC6410CE1B6ADE414AAF782" ^ "8DA024FB2C3F4135DF6C42A347BD3E25") ~output3:("BD0CD02750FE445A0C03D2EA30D73684" ^ "07DF4B13CBE8E3CE2DE2780F9A90983B" ^ "9EB919DEF1EC22EBEE10F584B6FE8F99" ^ "1374666D378C7C20CB5AD1771FA7C799") let salsa20_20_256bit_ecrypt_set1_vector108_test = test_salsa20_20 ~key:"0000000000000000000000000008000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("07AE6801D7A94836ED52CCD69D9E97F6" ^ "34B136A234B978BAE4302F475B0A6B0E" ^ "A7905CEE090F648962BB969CB4D65228" ^ "03E1ACD1DCBEFC2E7482C0D426E4BD95") ~output1:("145DF9D539C59467F55E67D959FC8C8B" ^ "2CB0397F64D6F122C3F2F1A19E0D67B6" ^ "9696EADDC6DDA6E80D5A0C0AC1F555A9" ^ "21C054E0E75EBB246C8E20A854A38E93") ~output2:("2BF710E9709B5178E5E50B421BAAF59E" ^ "B1F267F41C60E9E91695D658BAD32497" ^ "B56868B8738BAA6A15BDE89D69900ED2" ^ "742F26285504C3D4748F77EECC0D4A67") ~output3:("E93A249CE755F099C81FA40B5DA6256E" ^ "E185FA1EFC475EB404BB68C13A921FA5" ^ "78785537DD65964B9BF77F68DBAE4926" ^ "9F5061B19AF08B82C372AC69EB64D762") let salsa20_20_256bit_ecrypt_set1_vector117_test = test_salsa20_20 ~key:"0000000000000000000000000000040000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("A374C1F86586B0D5A121E1F734EE70CC" ^ "7072284B322BF61F88336EBE84B53219" ^ "F4D1FEE2C5EECC4A421BA8AEA9D108E7" ^ "21A7A82DD979F2559BB0E45CC88C8780") ~output1:("B0CA15C769D66B26CA4A6D4772AE3521" ^ "AEA4696890998954F33ACA8638FA50E2" ^ "9981C2F84596D9371644D18E3EB267E8" ^ "FCCC98D95A2FB38639D32468A3013B5F") ~output2:("1CC3AE9293EE9CA19C12D9ABD7000F99" ^ "047B86A868E82A839DD95418EECB23CB" ^ "4B4A08E3EF69CC639DBADF3F5F33FAD5" ^ "0762C2603DFC48882EE8D2346FDB426B") ~output3:("0D6EC570BB04230AC35B49A1271336CA" ^ "721E0395F63D306554158154CA12FB62" ^ "E8D45CF5E21A311554DE9DF5D90CA99E" ^ "9B7FAFEFAD3597B50A17FEEDD9966884") let salsa20_20_256bit_ecrypt_set1_vector126_test = test_salsa20_20 ~key:"0000000000000000000000000000000200000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("19F23D5CB3C7303D56AFF18413835EF3" ^ "DF7405C30BE5F19C72FE8746BA04610D" ^ "D5D261FB3A0E8C11D2478F4A4D6CF820" ^ "9730187BB1386C03229F4EB02C5B4422") ~output1:("7B814D9DB8DC9C8397C23550DE194BE2" ^ "74694399A8B2BEF6B8095704C2A29E00" ^ "DEED66C8191F67BA9C048CA41DA4DB05" ^ "FDEAECBBD0727AD9664563991A22EA46") ~output2:("7B4DC904BA9FC0CBB054FB57DAE11C58" ^ "C9505A98E319B43FBB9C30DA2CA7E6B8" ^ "7A42F1E40774A6657EB3EB2C33B5D365" ^ "BB92A8CA0CCD5B71C17F7022DD840E14") ~output3:("5B2DB8E73DB53C289E8479F524953BAF" ^ "D881E8A366899440175CB2B93F8EBF25" ^ "3911652B3C7EA35B41B409B4BBD0BD93" ^ "95AE5A2AE2368B7A43A0F9844239E3C2") let salsa20_20_256bit_ecrypt_set1_vector135_test = test_salsa20_20 ~key:"0000000000000000000000000000000001000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("B18CFBA23F81884FBFEA037648B1715C" ^ "EFAEF1D8CD5C98957353E82B838FE332" ^ "672B3D7C2905979698F6F6D98EAAE8F9" ^ "8DA16EF393CB150228FE6438440C5759") ~output1:("BF285CEEEE6D66ED9A401AF86B4F1B0E" ^ "69B5ABF625D0C35220F9E6198FF5C225" ^ "A728EEBF67EDC8690ADFB6A2E43ED7BD" ^ "2956A4915A8FF4BC584C803C87B03956") ~output2:("0FBE7818D981B60177DD1C7ED21FC23F" ^ "F088EEB3A36A3DB18E37BAA312642BE6" ^ "481F6FBD4C6A3DCF6990D3F5E0F02813" ^ "F66F42B4384F3821E9F2A5CC7AC37029") ~output3:("A72F53B68BF3E6972515790869B97667" ^ "E353E1CC089AFA194B8ACFCC4C033567" ^ "4B2E9E0290501D24D87B80AF12C636B9" ^ "3902F09252F77812802151798FDB831D") let salsa20_20_256bit_ecrypt_set1_vector144_test = test_salsa20_20 ~key:"0000000000000000000000000000000000008000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("0EEF3E17B6B9388FB55C2C0AEF9716CB" ^ "106786EEB0E606E124C41AB552EF3389" ^ "7902AA2AE93D9E4628E785B356C53AC9" ^ "70BDEE2A7DDBAB427371903EF3EC9FA5") ~output1:("BA437BE85A1152B673AB7F39345534C2" ^ "6B53227FC8E99B6EEBCBBDC00B436DBD" ^ "E6AEF836EC78AC581F251D0C61F56404" ^ "D275B1DF39294B26CF24F4AC0792D176") ~output2:("381C3C583CFB20763CDBE072668FD1A2" ^ "557A35901CDC8595393181AF1610300E" ^ "D751154C050D8CE0354EFD30D05251A9" ^ "7F215A48F8924B4A68FD475C793A0543") ~output3:("15E30D96D2A42C99DB1030B5280A6313" ^ "2AA665B57DEB3AC6AAC8DDC1450C899B" ^ "D0DAE783A224134232687459917CC525" ^ "6D76929A153950DBFF7D12CA21EE77C9") let salsa20_20_256bit_ecrypt_set1_vector153_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000040000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("AE5572D5E61A992162AEEE513815339C" ^ "93A994DB12576D087EA4A9A98EA5946C" ^ "F58794B43515A4B55C5E9B28A882DADE" ^ "7D3BFE82B32EC3B604D2C1E1B37B1B99") ~output1:("247616FFD99152BBFA71D2225AB667DD" ^ "1999ED6E2AC64F60F43B3DD1EA5E574A" ^ "47C52B82E3FBA3443996EB1E842D11EF" ^ "78572638CA556157674B0A38ADF26F8C") ~output2:("1BE7BBE4FA4078886183F1DC9E296911" ^ "96106D005F5D653AAE744B2506401723" ^ "30F38DA7C5CA81F38A879D79FAED5B23" ^ "37045434875074B65D7E126DAF8B728F") ~output3:("89048CF63BC3AC13B4637487735B9976" ^ "2707C4161EBD6788289F2BAE38D3B68D" ^ "14C9A49E26573E3604D8D9907D151C75" ^ "6728F3D9A2A6BC118E62390BC0DBACA9") let salsa20_20_256bit_ecrypt_set1_vector162_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000200000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("BA66E5BA75AD8C4030AE54B554E07A97" ^ "29685FDF033CCC35A153334E9FC93A90" ^ "3C79F281907BADF6F37123819ACA25E1" ^ "F03BA0AC69D9B2D5E447F59F31A7A402") ~output1:("6B0FC33710282B08A33917D23186B1CE" ^ "0964104B5B8FC229CFD79BAEFF04FF97" ^ "07AD12904B3673B15B72428BB3FDC0FD" ^ "DECFF9AF8606456774B1B3B53AE74C5F") ~output2:("FFD0D5ECE17F9C1890199A4F201333F3" ^ "D55A0AE07B1DBC50A704FE66493B71AC" ^ "F802534FCD7BAF86B140CF87C582BC02" ^ "59EFE52CB2D1A64524F948A86F756E21") ~output3:("81EF72B6DD7F8043A078486BF0DFA634" ^ "7CF53FF6432432B45CC740533243D6E8" ^ "E936A5E6C1CB688388D6D97BFE48C430" ^ "0325A4B5DE69825E6CB5409FE9518708") let salsa20_20_256bit_ecrypt_set1_vector171_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000001000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("59DBEE08FB86EBCBEBFFBF087F9DD881" ^ "2AFFFD75414B5162B5E7AE540BFA8777" ^ "5BEC4982E1F4B6985DC8B2B25F061947" ^ "61BD6BC5EFD66B2A1EB12833733E5490") ~output1:("C54CDD55BBBC09038A772D1FEE876EF1" ^ "88110319FD6D7B306E9F5ACBF3C47824" ^ "9E4CD2C8C11900DBAA39F8F7D57724E3" ^ "70606016AFC49DEF5248964A416E0DC8") ~output2:("EE1C6E2F9DA5404012821C3DBE703D47" ^ "1FF717042C20DDB4743246448F431DE1" ^ "53BADF69A059D161189D20B8F22F1F7C" ^ "C491B5B2F5CDFE7A779A0F9DB0C60586") ~output3:("85E92E3EA90E7EB79A9D3894D0B21153" ^ "DA80FCC6DA7631A1C38EB38C78A1BEF2" ^ "321265349CB5FCFA22E5FD02648BB37E" ^ "74D3152011F7640A0FD42DCC9457B2AC") let salsa20_20_256bit_ecrypt_set1_vector180_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000008000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("FD1D039AE6D953654A63334A92CEC647" ^ "A671CAB6374DB63B89DA1A12B99C231D" ^ "C7B9418D44210CB0C88F114EAA54AE4A" ^ "096FEFCCBF51062E8EFD169715677F28") ~output1:("119152E46B97338C5E50A28DB78757E6" ^ "B21C9C03AA9D96B5FDAC9D352AADF2F9" ^ "FA0FCA07649582E7288297E9CC765846" ^ "2D929ACED1F14E3AEE634CD2086D1762") ~output2:("F9C91CA01A70253BC6D88A8DFA00537C" ^ "E635634769E8867B279C1A052A921F14" ^ "8810FC8854BDF58F99E36FEDBC6E6E6F" ^ "78BC8F82DCD18D408B3B4F8BFEF12F12") ~output3:("C22A3D49E727785EA32E83E79E349D62" ^ "C2647AC6D531BA2D466CCD7CF29D04D1" ^ "015D41A79C9BE4B0AE1844DBDBCD7FE6" ^ "765EB95A0D5E121F48840937AB399C6E") let salsa20_20_256bit_ecrypt_set1_vector189_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000040000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("72491EC81A704E3694C83FCCC47CF5E8" ^ "7B66F7B7979F78D8150A606ACDCB4492" ^ "F64A9D7D9DAD5042F8738DB462F4728C" ^ "2475F5FDEE985CD3601FA31F576712C3") ~output1:("17566EFAC19AFD1ADDEC66F42695006C" ^ "EDFBA525E8F41DB02BE50D2AC4CB497E" ^ "A10C6DA38ACF39BB608F40AD854F69C4" ^ "4A0FC6696F6FA8361CF26D5411B1C7C9") ~output2:("E3CE396F970BC54C9E46B6129B48616D" ^ "F7FBD0293B1EFEB772D99CA90BCE12A4" ^ "AF729DA0B94223A3D2F0B9605DC04BF9" ^ "AE82E065C1B963039802BE6354D3EB2C") ~output3:("C0B2081FF9B7F2DDD59EE6808F6181F0" ^ "4CD19D4B0D3F032D5FC0EA2B81D49276" ^ "BD6E540648576CEAE720411523889D3C" ^ "F14BF05DA43D8D6155B7D98B021F269E") let salsa20_20_256bit_ecrypt_set1_vector198_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000200000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("E3D058FC000427B4F0802300E5D7FE9F" ^ "8E3F68E9E8339E9F4C5DE62252E14857" ^ "71371DE4D2E1C97DC4172AA378924AB4" ^ "2CADF887136B88D6FEB6514538EBA847") ~output1:("80CE800DC11805A7522E3B423699D68B" ^ "51BCCE201ECA4F8E465C5A58A558A71F" ^ "019A22593CBC148A76647A527E635A23" ^ "4096EB22F081F39B5A9DC7649277726B") ~output2:("30A91E7D2CDB7D1B080750B433A14F7B" ^ "6EE602EB53D67AC65B7E4219B533AA6C" ^ "CBC1FCAC070270D595CF9E90FD3C2D02" ^ "A707F7C1F97059DB3644F50D236933B0") ~output3:("79FA6D08B8DF687EFE868E67643CB5A9" ^ "FC5FECEEC258E67D831D20AD3C8CBECB" ^ "51F1712A0BAE64202FBF66A1FAE767C1" ^ "68A9B0C4BE89FCF2F6D2DBC5CA96A4BB") let salsa20_20_256bit_ecrypt_set1_vector207_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000001000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("FF0D93064CDBD91A8D6BD0B9267A4F93" ^ "DF7D3C76BAA5D0D14798812203C55A34" ^ "3BD50E6931394DAB88F514F44E2A1FB5" ^ "8EF3A915F3B60DAB35E36174AD92B3B1") ~output1:("074A711F8BB92EA6953D21F9FD7AAEA9" ^ "1C12D18A2B18E8D325DB04029B5E8EBA" ^ "43C408D3D4EBE049440CFB716BC3ECA9" ^ "1929E009ED7EA0EA7273E32C13F44346") ~output2:("6BD5DE42827A81941C72012219EED591" ^ "BE1AFE19DF91C8B7284DF2AF4050D7EB" ^ "674DBE78680EF4F8963D59ACB05B43D6" ^ "A52B7CEBEBDED9D3268D0500699A036F") ~output3:("9748C1BA603FE3DD4435A25F2ABF18B4" ^ "9F25ECEBC3514785406425E03ACD369A" ^ "EC91463FDD5F3611F06870D513B10DB7" ^ "730F3328C22312DE7329DF8CB43DA5C2") let salsa20_20_256bit_ecrypt_set1_vector216_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000008000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("DCC597DC08E1AD1451E69D857AF803BB" ^ "DBF7CD6D510D5C59C9D6C66EB153CC79" ^ "F9A6228ADEE570983E959788628F174E" ^ "5833B5CFA350C0C2D8A18F7FE46BB4E1") ~output1:("8CCB839CB382DB591B5C80F6DD7EAE7E" ^ "AECB3C8BF29C9C6074058A5EA04E2E58" ^ "675B4537B8FD061BA7E4195AD2A3EC29" ^ "FD260FD19F0AAB3DCB7BD483ED8FB860") ~output2:("73E92E3449C863E55E9A41B0DB35805F" ^ "344FB07E4C3CEFF25B261819140C849B" ^ "E90639644C542880946582842CE5B1D9" ^ "FA2DF07B5589C8C68BED84E15DED4AF2") ~output3:("693C7F397D23C831431264E9BF4EE963" ^ "B8A43C6ED939B324FCB8AF1032BAC678" ^ "C71F1DE8BA3A8090948872FA9C747AB7" ^ "67F7D162FD8B6F484B81AA54151612A6") let salsa20_20_256bit_ecrypt_set1_vector225_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000040000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("C94A72C1B17F8B9F26420BF06B3A5445" ^ "20C658D5F77ED7D62CC65AF824BD5678" ^ "98EE4928AF0E2BEDEA64D5A7C22749C3" ^ "C16369D274EFD2A6DF2CFCCB130A1144") ~output1:("2130A7225D4C78BBBB8C5122C18851A9" ^ "32A78E360E62E56058027C624DA49EEC" ^ "34DCE5ED9F66D78B44334CE0E3317AFF" ^ "5BC78261FA4C96A642E846CDCEA4C242") ~output2:("575EAB318220A54E5B2B0A8EC7F54429" ^ "0719FE422C646E1114D807201416F37E" ^ "B5CECDB278AFC7CDE84E6DB5CA164840" ^ "2BF9654D1C4E96A3E7BF5C19C84CDA71") ~output3:("EAFC6C17BF190180FFD817644D7933C2" ^ "F86989ADF705A72B04CDF8227A164596" ^ "7BADE4A0E706039BD84702395B9A44DC" ^ "7368E198B01335577A28028FE2F6056D") let salsa20_20_256bit_ecrypt_set1_vector234_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000200000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("832A824C044E27605AD9A3201EF106C1" ^ "A19B6FC6EA5B328DC1D1FC59086C498D" ^ "47E7568CFA9616D7D5E63D9C087CC426" ^ "B4276752E0FF14D7F1E258F9A28A54BA") ~output1:("CFC021E1EDACD733768D3412C0DA7177" ^ "7AF74D147D075BD5497BAD89B84D0A66" ^ "F7F4D0E46B77510AE3FB57C0DB9F9922" ^ "111337BDFF89A9169DB16B38F305BEC8") ~output2:("CE311109342E1A41ADA17363B0AB030D" ^ "1BE9C62F15C2A5D8FEE2BC9819F2E064" ^ "6880D350E547824BDDFD5BE89C43F23D" ^ "FFA366BE34629F6EE929E2701EFA6829") ~output3:("DCE864E5E336A7B51A7FFE9E4C8C1FBE" ^ "F5F4755A0877EE91D61D1F20F29485FA" ^ "A879323F2566590917417C4AC0076CB9" ^ "81EE78C58741506F725BC58743957CAC") let salsa20_20_256bit_ecrypt_set1_vector243_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000001000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("28DD9E566F018FDA0251E1E648057E85" ^ "211831E215AE21525E04C932736245C2" ^ "288AD4A197E4ECA04003B85C3B80D02A" ^ "9B82C28E7662A34467946A34257D8D0B") ~output1:("DDC4A6A1AAF92AB32D2958DE67BBA593" ^ "338D7EE4E3A412C2374A5D63E6CD7F56" ^ "51F518251CEEFE1E63636DB2F432F407" ^ "88D4C0163738446515A62637695D782E") ~output2:("107AAEEDD6C459411921177468E3D013" ^ "50C40AEB41EE50AE196754BBCE5559B9" ^ "7276957DC73141981DC087209378F87F" ^ "89C8423ACE0EAE8C5EFEEDEBCBB20618") ~output3:("A3FE61185B31AA80EA384B36CEC7F41F" ^ "19F2E55614BE22852E796963326B9F49" ^ "72E8A316D4A6653CCE3FE06014C0F5BB" ^ "6E4E64B439109608FEC6A44C15384C13") let salsa20_20_256bit_ecrypt_set1_vector252_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000000008" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("E48C2F264BF9E8374B78FB652BAFF1E3" ^ "3ECB4B1C635D76A64ECFC4BDE00EE5C8" ^ "77E1094D6480CA382815CCCD5CC36770" ^ "46E801C29A860EB032420DCAEEBC36F4") ~output1:("D2EEE83D63F96B0B7E6D8E0C72B6581D" ^ "50AF4081017CD62A73789C8C2DC5483F" ^ "CB4067C71FDBFD6EA8882FFBAC63BC9C" ^ "5E4F438A2ECBC71627646539A5BFE1DD") ~output2:("BDDA0B90B24A4FF5D535E12D075DCE84" ^ "6D6741F809D105DC03552A3F13AC88B2" ^ "F98411A1C19CB32FA3F595CDD8F87608" ^ "3C057E42BDD903A055F13182CA080F4D") ~output3:("44E931EF73A9AFA565EB9A8E6AB1AA3B" ^ "9F14FC198B41909CB31B532F9EB776FA" ^ "B51FFD895E7F266D1D275463282BD7F6" ^ "62FBBBB5629890A4C68B6F6CF8200623") let salsa20_20_256bit_ecrypt_set2_vector0_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000000000" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("9A97F65B9B4C721B960A672145FCA8D4" ^ "E32E67F9111EA979CE9C4826806AEEE6" ^ "3DE9C0DA2BD7F91EBCB2639BF989C625" ^ "1B29BF38D39A9BDCE7C55F4B2AC12A39") ~output1:("2F3C3E10649160B44321B7F830D7D222" ^ "699FAE0E834C76C3997985B5404808AB" ^ "7E6E99AA1FEC2730749213E7F37A291A" ^ "A6B5AFD2E524C2D608F34D4959930436") ~output2:("8598D1FA94516B474B69DA83E3C1312C" ^ "49A05B8283B880B31872CD1EA7D8F1B2" ^ "D60A86CBA8184F949EA7AE8502A582DB" ^ "392E85C4D70D3D17B2E57D817A98ED6E") ~output3:("F86C7489712FB77896706FC892D9A1C8" ^ "4BB53D081F6EB4AE1C68B1190CBB0B41" ^ "484E9E2B6FEA0A31BF124415921E5CF3" ^ "7C26493A5BC08F7620A8C80503C4C76F") let salsa20_20_256bit_ecrypt_set2_vector9_test = test_salsa20_20 ~key:"0909090909090909090909090909090909090909090909090909090909090909" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("7041E747CEB22ED7812985465F503331" ^ "24F971DA1C5D6EFE5CA201B886F31046" ^ "E757E5C3EC914F60ED1F6BCE2819B681" ^ "0953F12B8BA1199BF82D746A8B8A88F1") ~output1:("4EE90AFB713AE7E01295C74381180A38" ^ "16D7020D5A396C0D97AAA783EAABB6EC" ^ "44D5111157F2212D1B1B8FCA7893E8B5" ^ "20CD482418C272AB119B569A2B9598EB") ~output2:("355624D12E79ADAB81153B58CD22EAF1" ^ "B2A32395DEDC4A1C66F4D274070B9800" ^ "EA95766F0245A8295F8AADB36DDBBDFA" ^ "936417C8DBC6235D19494036964D3E70") ~output3:("5CF38C1232023E6A6EF66C315BCB2A43" ^ "28642FAABB7CA1E889E039E7C444B34B" ^ "B3443F596AC730F3DF3DFCDB343C307C" ^ "80F76E43E8898C5E8F43DC3BB280ADD0") let salsa20_20_256bit_ecrypt_set2_vector18_test = test_salsa20_20 ~key:"1212121212121212121212121212121212121212121212121212121212121212" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("7BCD4C5528F4BEAE0FC9F164CEBEC73E" ^ "D89CE32DA46EB68CA3CEDAA7C7A580FB" ^ "1C50D291F31C38DB2811864F6654098E" ^ "141A2213828593A98B7D0020BF0D6D93") ~output1:("87DCAB67C8D5A90D17AF198D3A22D432" ^ "BC82C06872F0E61B3A3D1A1FC14527D1" ^ "E8C3C9CA50E5BF529621C2860ED304F2" ^ "7E6E427A9BC64D0FC6E2E16BD40C434C") ~output2:("121F38D31A0ED8A6D72F4C6A4678A7B0" ^ "D3054A6268D02C9C6766069427722606" ^ "36CD6D79F81C64412A93F10DB68D1B86" ^ "962DFC41434B1C65AF4770F7D185514A") ~output3:("BEDDFB9B60B204E0332726D7D7E90640" ^ "FF29318A164A9551D9FA477D7E437273" ^ "A0E08EC35046CAE10BDAEB959F44E9C2" ^ "A09FFFBAA7A89B7B9F1AF34948FFFE9D") let salsa20_20_256bit_ecrypt_set2_vector27_test = test_salsa20_20 ~key:"1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("944B67EAB62DF3756085CEE577D0C1DA" ^ "4DD7CD17B85F9B9C51004107C8AA6935" ^ "7E413AEA37BB512BD8246F2D03E2748D" ^ "3BB24B60C1FBE4D1A55237FFE3D4D604") ~output1:("A9574AD5FC6A0D4A57FBE98AB5122A54" ^ "E2C355524AAC38580C659AE4E906F14C" ^ "3FB5A096586FA808F5F266182D26C784" ^ "72B116652EE1874CB5CF007DF2E2BB5A") ~output2:("EE5A306A60C83E209ACC5F3D60E17D90" ^ "FDDC0D790BBB7B1EEB635924A4C7AEBF" ^ "3ADE18F1F2F03C1E74093847B8F9225A" ^ "9588E92A826444BDD143B38CC3934FBD") ~output3:("33DDC526B91BD452296DC8ABAEE7C65A" ^ "E7D8CA37FE66166B67570726639841C8" ^ "559405236A37A104FAA3F5A1A1932D57" ^ "FFE36EC16D439B1C291DD11638C50730") let salsa20_20_256bit_ecrypt_set2_vector36_test = test_salsa20_20 ~key:"2424242424242424242424242424242424242424242424242424242424242424" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("0FDF243C21DA8B291097C9F385DFF2AD" ^ "4FDCA5EB4FA7E4C23CC61FA1A582EB23" ^ "5AE23454DF6F19B259E498F746F9EF35" ^ "491F77DC53BD596AACCB9FB7B5EE8ABC") ~output1:("A92CE971EA8E2ED7614325F0C47CE1D7" ^ "200B94EEB7FB4E31CDE640696ED6449F" ^ "B29A9F19EABE323B776EE9460C2448E2" ^ "DF83206A401074E3254C5AD6C194BD99") ~output2:("6F988009D4C82F523611DE08FEA23680" ^ "02FA5A615E8EA831A76C7CABCC92E1BC" ^ "C02249FD76DDEA5C00FEBC391613857C" ^ "97CD684B23C6D9B40F1C5254404F7CA4") ~output3:("61503589A014A6F800A5D93803517581" ^ "988262122B30755A337F81EF3B326125" ^ "51ABCE838C0A57795EED2F26173DE6B7" ^ "E4BB6E37EE7F98383658A7BC47976321") let salsa20_20_256bit_ecrypt_set2_vector45_test = test_salsa20_20 ~key:"2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("3D9EA1F4A3036C92CF9E0D6BB20824C0" ^ "F57818B3C84DF65AE4A1DE2A058F8BEE" ^ "242F9BEA42A78383F98AC998BE4B1EA5" ^ "401BEA5250611CFE6505AA5F43C9A262") ~output1:("8C2F23B3E0255982DB921D035B507433" ^ "2EB98C31143E19F5FAA40547D0819157" ^ "BBA1B6B5C3177AE45074CF5E711195F9" ^ "281A71E62617F3A1E582D4F89FDAEC4F") ~output2:("5D1ED872FD20FDE0C98FD76503F538B7" ^ "538F5061D3A3B12385B4BAE7C8CECA20" ^ "E47EBD5C96F88D78230B5D3909CA9B0A" ^ "4BDDA1FD1F561ABEC60524C51559EF45") ~output3:("EA2F040B9DD538FB258C9289F5CB76B2" ^ "335C7D05F5B9B2CD591B55AC8FAB882D" ^ "07EC54EDD33D4B24D6AD69841C219C5D" ^ "26DDC827C67D0A6AC12D0A4E0DBE9A78") let salsa20_20_256bit_ecrypt_set2_vector54_test = test_salsa20_20 ~key:"3636363636363636363636363636363636363636363636363636363636363636" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("E0E9C87C82202453CDE753D368DA1842" ^ "9279F0B97446FB12A0436C6BE1AA7514" ^ "3E98B740F6F9CEC72A1EA38D4EF2BC65" ^ "E1AF3AE13C5ADF6DA16A2131739C0084") ~output1:("A43046BAE6A4A2C288CA187C72A21E88" ^ "047CE98C64147F2F853617A54A3057C7" ^ "0F48823ECA4B82609924CC9453D57F1D" ^ "3ACF7D302592BCF9B1439F28B3EE5F34") ~output2:("08DFF1999015561E0817C20CED5E979C" ^ "6BED0512A69CCB4C6F6FA480CCE4348A" ^ "076F549355D22DDC52728F833447DAED" ^ "83D7012F3F59A8BE495078B72B299753") ~output3:("C66109B099BAD13AF2F36F5AED7AA0F0" ^ "0320D8B109EABC7428362B7CC43C284D" ^ "04EC23DFA4F2A5ED2A7BE2A64CF42F9B" ^ "F973C6F2AFDB1AB7B7E5F9499B9DE964") let salsa20_20_256bit_ecrypt_set2_vector63_test = test_salsa20_20 ~key:"3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("18B631E89190A2C763AD5F1DBC57B565" ^ "EAD588F7DC85C3DD75E7D7E74C1D4429" ^ "E2FB3C6CB687A620EB7050CCD49B54D0" ^ "F147302BFB7ADC6D1EB235A60338D190") ~output1:("FE2017B0E26C72416B6789071D0EABE4" ^ "8DA7531CAD058597AB3742792C791678" ^ "44C84243B910FCA131C4EB3D39BD6341" ^ "842F96F4059261438A81423586EEE459") ~output2:("5FA44FAD6149C7E80BA6A98A8C861993" ^ "F7D39F1CAEAD07CEB96CBB9BD9153C97" ^ "8B8957C82F88EC2EDD1BCC207627CDB7" ^ "029AFC907BBEAFAA14444F66CB9A20EA") ~output3:("CF4DD50E4D99B8A26A9ED0F8CEE5FC10" ^ "E8410C7071CCFD6939C09AE576C3A5ED" ^ "D2F03412E40C8BAD8DC72FAFD2ED76A1" ^ "AF3BDD674EC5428BD400E2D4AE9026EF") let salsa20_20_256bit_ecrypt_set2_vector72_test = test_salsa20_20 ~key:"4848484848484848484848484848484848484848484848484848484848484848" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("82492EEE44E22AD4DFCA2032BA401F73" ^ "7D4BC35CE8546EB6314EDC25E69DAC16" ^ "C8A9EBED6EAB895B7D72BFACEAA14E36" ^ "3F9A9773E43B077A1991EAC1EEA83EC5") ~output1:("CB11B43F7E98D75576BB1B1AB33A4E6E" ^ "CD9CBCEEB36718B22C14F430A8BE7BCA" ^ "BCBCDE60D775DF441FCD808E79D05FAF" ^ "E3AA199D45DC174272EA3DD0057D9BD4") ~output2:("7D237FF28E20F0FDCAE42A7D0D7AEFEC" ^ "8AF23CF2906E305341FDF8FF75C0B9CB" ^ "C8F19696CE8D31D15E27EAB0AFFCE92A" ^ "AFD1BC29E9B80895B3A7CF57ED434D96") ~output3:("5ED806ACF2490F17AB82438484FCBF61" ^ "6A17015069B88DFC2C4CE76A2F564E4C" ^ "5786A7514CE542709E90101094DEBBF4" ^ "8954F9BF8F4773E06DEE7FB9231AA457") let salsa20_20_256bit_ecrypt_set2_vector81_test = test_salsa20_20 ~key:"5151515151515151515151515151515151515151515151515151515151515151" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("C7FC0F8C8D2064FE05BEC4A641560FCB" ^ "C41A60718B1DF62AA297E754756CDB68" ^ "48C5BF60721B49A854A7A4D4BF2D36EE" ^ "943A3B3922A638293B32F15A7E9A1357") ~output1:("987A15FE80E62B043B2C7C0953A27D04" ^ "83B2A7ECC03AD33C2F99FAB7FD2A7EE7" ^ "0181F7913429F89027E392FC3B73F4A7" ^ "5E475BA1D7DD4DA0F32D776BBABF270C") ~output2:("CEBF798ED076B963AC8EA9465F7EBB90" ^ "6E09F80247C1FE09C86D1BEF3DE4F4AF" ^ "94B51FECC1C58E1E8CD225C2F68CCEAF" ^ "C36C029DDCE9380AE9FBC867E145F658") ~output3:("FD7E885A72C796E642EA628C6ECDC508" ^ "9F465F57E55D51170C039B253B14EB9D" ^ "195A3712CDEA2624A5382880192DE3FA" ^ "0DA2A86EF3A61220DB949596FE1C318F") let salsa20_20_256bit_ecrypt_set2_vector90_test = test_salsa20_20 ~key:"5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("6C3645C8621D8E7286911278BAB37C5E" ^ "EBAA2AD321AB8ECA62D13372156F8B87" ^ "FB87FBE02B1EFE39AB0EBE41553E5348" ^ "073053048A0D4DBDA1880230CD23A4F1") ~output1:("BB161E8441B29DE15C9A02F447766354" ^ "E7E590B42AE566935F0A6D7E864AF5EB" ^ "B288C0C63812B0917970547225899573" ^ "7C804E58F7BEA1596B7343B0CBDC6AA3") ~output2:("6EC6A41251D6FE041CD87EB3996369F1" ^ "390E649F012712F9DA4D1F4DFF96CF74" ^ "91CAA6836C09BA8C55ABB656B4F51F7B" ^ "4AF829B5DC89F460287EFAD064C44F28") ~output3:("3D54A399D5B92252CCF9E6A0C054D4A5" ^ "EDBFA58A3B53981BBA50EE9BB379D71A" ^ "C9775A0D793AFC79A64C708D0F9A7D7B" ^ "E061D5A5D50DBF32480AABEBC128D198") let salsa20_20_256bit_ecrypt_set2_vector99_test = test_salsa20_20 ~key:"6363636363636363636363636363636363636363636363636363636363636363" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("D417644E8A37FF8840772A55960C4B06" ^ "4DA371869EA07FD02D7F8EFEF0BDB7CE" ^ "308173B8BAFDCA6064CEBE09609377B6" ^ "542CE73D44A0134C95C452D9B83A4B35") ~output1:("2974AF76C0EB09874EFAF061BFD45636" ^ "E6AD9C2BA71A1B4FAE493C04205B5CCA" ^ "A1D361DED0F1BF8C2FF2DE70F4B68E1E" ^ "B1B6E63B19EE1842DA4ABC52C88714D8") ~output2:("934392340254B83FA7A9888D1CA9959B" ^ "A221FF1C487B214FE6703C4BCE02EF62" ^ "4DE46A76670712B381E2EE017B67DBAA" ^ "3726CE1CFB39038FD0059EFCB2346385") ~output3:("F234ED6FEFF11821E19D73E31BFAF745" ^ "126D80E0743623A179303C5A7827582A" ^ "ACFEE4845E8D3FD98AB990C710020B42" ^ "542DAB392D6A1BFE058E200FEFA00006") let salsa20_20_256bit_ecrypt_set2_vector108_test = test_salsa20_20 ~key:"6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("1456A98D271F43A5FF29B3D0BCC35B78" ^ "50C4D9DA5BBA43B752A1A541A4FC88DC" ^ "0FC4C89F35ACF1B540F5C3207A0BF359" ^ "490D482232936E5C0B818C3DE6EF2012") ~output1:("E8DFC363183330BBCC8498913A28545C" ^ "6905F858D314939FA148C4C6600CD23A" ^ "941F88F2FF08D7567202F335F5A90A0E" ^ "A92B9D73A2C710CFE22BE0D180BA1A42") ~output2:("77ACAD59AC794EC38C13805E9638F145" ^ "DEE96C36C9C07A1811DCC1531A462144" ^ "AC1F4B2245A570C42B25EB646D4655D6" ^ "EA646776B0445C8B5670AB2B11203823") ~output3:("9A1BBE72AEC868E45B28B9FE3570381D" ^ "A759D1484B710A2AFB385DB7EAC5A2C6" ^ "5E2EFF9204C5DF6A684ED55C2D09FBD1" ^ "7E2FB6B4FF4BAD3ABD201DCEE340305A") let salsa20_20_256bit_ecrypt_set2_vector117_test = test_salsa20_20 ~key:"7575757575757575757575757575757575757575757575757575757575757575" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("8F04C8F40319569CB4B04458528135E8" ^ "35AF2C69561F0F0F5B6009B540B85ED1" ^ "BC7612C9EC7A200B08AEDF07DB08ABC3" ^ "9FA48E63AC81974175AE3A4AC9429985") ~output1:("DD98FBC3465BBD56ED0BF2F2367498B0" ^ "E2854E514A27C7410AAF8E0B44117EAF" ^ "A5EDA0C7FA2106C03DB8AF62E5ED136B" ^ "4BCA0B82CF2EA19FDADE4101C57117E2") ~output2:("7CA321B64434A90CE08E00A99D9456CB" ^ "7A0779D4F0FC12346C01A5A1310528DD" ^ "2E0EA2F58A8795BD138687645A7054DC" ^ "2FA74835B1B45F4B68E3CEAAA315C250") ~output3:("076AB5564DB74D830CF96E6B90897E5F" ^ "2E597619B47FF74B190C16735E902BDF" ^ "111FA384ED3F8055343F4561C731F783" ^ "7072FAB81825304DC3D4CC02404E539D") let salsa20_20_256bit_ecrypt_set2_vector126_test = test_salsa20_20 ~key:"7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("DFD428440260E1B64579A6940EE53907" ^ "8CF48977E4B61DD0C708B52B42A607AB" ^ "C0A0774F49FD8599E4A4CA3B7C54FEDC" ^ "353D2467DEECDB9FFC8350C79414CFBB") ~output1:("F4C7C343C6DFB6F7EA25DBF6DFBD31D2" ^ "595C45C4CD1C057308FFA60C1AF1BBCA" ^ "888C6C8097E97319566A7EBD80DA4F0E" ^ "DDBD22015CC363E5AC01BE42770660C8") ~output2:("F1792B445D52BD4FC99557ABBECBCE74" ^ "257A62EEA110EF9CB3CB0388922A7FBB" ^ "5FCBCE5BCE44818F930284E4E360973D" ^ "49607E1B0E1D97C618EBA4D909A50375") ~output3:("7A2EB3ABE2F83C4B40A15F4AAA89D5C9" ^ "72B911AAFFF5069FA3E7396162CFDBBB" ^ "6A16E222C15878D9C8A00AD8201F1889" ^ "9F060851A3147AC2F3385FD8144BCD32") let salsa20_20_256bit_ecrypt_set2_vector135_test = test_salsa20_20 ~key:"8787878787878787878787878787878787878787878787878787878787878787" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("47756F1D1EEDDF06790A5E39083186D3" ^ "16E3258B9C5B7D25E478E817308E2B90" ^ "A5DC4A8C03A38AE1757B6EFAE73B058A" ^ "7CEA675CEE9A01E9BBC7B15DC5424E64") ~output1:("FE6FB2E0BDF120B585D082602D2648D6" ^ "D95D14C3E8DF44F7D9BF650709578C0A" ^ "A5D775BAA12A3C1153CF44AE2A3BAC49" ^ "534210F8BB8AAE7F54DF049AE368678F") ~output2:("DA0D9214302984F36B92EDCA76765B8D" ^ "5E748EE13176CFA41345AB0EFBD7CB54" ^ "737DC606DE60E4355233E63B1EDAF48A" ^ "B84DF854E47D1D746B3AA5CCC0A5DA62") ~output3:("8373EFD791B51A07B840A7FACA4307CE" ^ "9F5FB71A0C7891CEF7E7754A414B61D6" ^ "593A5EEB782FBF28998F4174C63733BF" ^ "A7EE172290A0A854AD6C36757AEE0911") let salsa20_20_256bit_ecrypt_set2_vector144_test = test_salsa20_20 ~key:"9090909090909090909090909090909090909090909090909090909090909090" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("6AB7A8C769386FB6067059D0EE3DBC97" ^ "1EFAEF4AC10C74A2F17527EA5A8C6E0C" ^ "DF1FA10F27A29911BB57BF3E7A6DBDCE" ^ "4AF3E7BB730F47AC79DC917DA646A8B7") ~output1:("1DD701A2698617855C38017B0ADE1E17" ^ "D22D9717E21AD8635CE6A40CECC7EE43" ^ "83D5483F414B9F2285D200500CCA85C3" ^ "D45F4F25550E3701B675D7E1B8266C6B") ~output2:("5D331C1544CFD44E3588C2EA0D889F44" ^ "D5742E7AFE9581CAF23CB668B0530C84" ^ "A89D63F948969DBC0D0574911EC0307E" ^ "CE9CF38C5FCDE75462D1C472455A78ED") ~output3:("A55713DFAA272076529BC5A33558A7D5" ^ "206C1C070648DBAA348C78556631AD99" ^ "F8F16DDDA2E5779B155DD9377A8E575C" ^ "257FE7E08ABE9B3A378027EA06539810") let salsa20_20_256bit_ecrypt_set2_vector153_test = test_salsa20_20 ~key:"9999999999999999999999999999999999999999999999999999999999999999" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("E548ECEAF4B4AF1F8572F7113C7D8FF9" ^ "61837C15ECC6BEAAB80F38CB15022B50" ^ "BCB1FA414A798C954DAFB572CF22A9A4" ^ "D82F7561186C31BA0199EAE1678CC4CF") ~output1:("9E5D061279348E0D5DA552A82DDD3795" ^ "37F928DCA393AE75AED13F63BD60DEE4" ^ "32C96D1B2365B59FEE3C0E18515966D6" ^ "642F2E156C30C704A77DCB5629AC6167") ~output2:("9CDCAD9CB247AB21BA9E93C936936994" ^ "C6C320841C745D6DFC85110367B36C88" ^ "67CFAB60F6A67A1656C645BFDBF196AC" ^ "974A4165BF81FBE715CB6C3954E217FD") ~output3:("FE5134E8B0BC016D3ED3594B6EEF2F06" ^ "FAFE2F4C89CB4E2627B232BACFDCA8A4" ^ "80B1C55DF4C0AF1E630A617CEDE0A48F" ^ "900A9CF815362C098A76D29360414735") let salsa20_20_256bit_ecrypt_set2_vector162_test = test_salsa20_20 ~key:"A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("D0854334E4619E3EFBB2A53D59F89866" ^ "F67220CE00A3116313FB9CB645339766" ^ "0CA976A8B3477F76FF8FA485D61E3758" ^ "3DA5F35A8FAD678B7C2B9EC97321DFD0") ~output1:("92D4924C3E682EECBF9AD3A5453BE7BD" ^ "56D9FD73F16BA0CA09FBD0C136BCD595" ^ "2FE55744B1871E4C8726611F291B282C" ^ "2219C817C88086A5A7BDC513DCCA473D") ~output2:("CAC309E4AA3ED635D68E5AFD9F4CB0BA" ^ "DB229E8EB560B16645CA2A71B35B7C3D" ^ "757C156983F7D053B0430F9634402B8E" ^ "4FDE6926135473BA8560C3AE1FD5BF48") ~output3:("980DB26FDBF49D5D890B65EB01AAEBD5" ^ "CC118812BDE441A71871206D67683889" ^ "828622C6336DEA09DB6ADE0772A3D091" ^ "F77B1F3115E1341EF11F41F7CD0505D6") let salsa20_20_256bit_ecrypt_set2_vector171_test = test_salsa20_20 ~key:"ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("6CD6B451B1C793485006B3B51470E6AB" ^ "20163502C30240C4A3C6406482A2770D" ^ "550AD77D0091632C719BA33769823D2D" ^ "8147396466F1A2A857060A42ECCE0A0E") ~output1:("81298474E6D86A66AE4CBCEE495D8740" ^ "502CBE5CC91174865A615B193B55BA4F" ^ "CD2337667292D3F3C428B9FEF090207E" ^ "2DEF037917A2244FFD3AE8161CEBA42A") ~output2:("367B062DFFD72A6EF6CEB3AE7FE59684" ^ "690F40A9F276E8021994ED475BE1F08F" ^ "A5C99E3A1AE1E68A92D02C5C14BE0E67" ^ "A1B989E7033274993D1685D4B2DAE6D0") ~output3:("43C53B82CFBB199FFF9C5719ED1EF470" ^ "AAAD578C5778A9DD3C2D77C7BAF41CC3" ^ "0F5F7B4C91FED81E9A661093EE20FC3B" ^ "BA55FF8447C899C6E12A0A0F5ECE3BA3") let salsa20_20_256bit_ecrypt_set2_vector180_test = test_salsa20_20 ~key:"B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4B4" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("EE879D01C8E20CE8CACDDB464348F69C" ^ "6551F70383A82933C3A765B8AC138581" ^ "8D67C69841FF2B4B8BC209ECFC0FE765" ^ "C44C42C9CD6EFF90E0A6DAB153F52D04") ~output1:("8D7D377A3072E9571F9AE00D25E875A4" ^ "D9BAB98A3EA348BF823F12F44DABAE28" ^ "317BAA3A71EB3D7C4C2EC3EF87E828CB" ^ "862FBFC99C7ECBC629D22DB8EB82156D") ~output2:("97B547A3E920FB054416A5787EAB5C76" ^ "38FA6CCDEC816613FC855EAAFB4887C1" ^ "3A38094D89570BF17E55E5E1EC275ECD" ^ "122142C9126DE5E9411F06805071983F") ~output3:("CCA815558FFE08873C9AF373FAA546B2" ^ "FB3EA3059EFD02CB778D01962E87EFA8" ^ "5F24BC5BEFD4ED02C986C0229D70ABA0" ^ "D4E97328780FBD0ECB367A8C085414E9") let salsa20_20_256bit_ecrypt_set2_vector189_test = test_salsa20_20 ~key:"BDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBD" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("DED8C79CC623162C2074FC7B4876F754" ^ "1B959209AC6573E6D25D1F1E649CC241" ^ "31A2F1B1B9E9E0FA639F8AF373CCAB88" ^ "3C659001BD120449997871E6A1D5AD8E") ~output1:("1E946CF03C4C89D19DDB9C48EACFE7FA" ^ "A48235899DF49232CE2A586130BAD63D" ^ "52540151FBC02E3BFEF082A63A900C42" ^ "0D6D7A11E289C34387A6155ABB71816A") ~output2:("3CCAA2AEA81296ED9171B608FD8DEAEA" ^ "3EA5B8A87B17B10751A01713EDE6A156" ^ "652783C26C0247E347860C06AD633AAE" ^ "2C0AFB239291A6E7729F8838A4D97533") ~output3:("065DCB330DDC528BD42DC6A0F85179A3" ^ "531CF900DC5F7D3B5455DC49D451161F" ^ "9AFD79A619DD951C854019412532D33C" ^ "9DE6F9AE44394208653CF12D316F4A70") let salsa20_20_256bit_ecrypt_set2_vector198_test = test_salsa20_20 ~key:"C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("36AFBAFFF746195D8784CB72A16D12AA" ^ "604CDBF567955F15FB55DD42FAE8DDC4" ^ "E6CEA63B6F8E2815F3094005E403FEA3" ^ "0EEDD68B5F2573EFD03A4E2BC41AEC32") ~output1:("4F7E1CE5E727D83989222ACF56776F0A" ^ "FD1B00E9A5734408E1513313E0CA347C" ^ "C37D8DE7AF4F6C5C7EF311BDA97BD8F4" ^ "52F89B4D44411D63105BECADC661D558") ~output2:("2677C65207F10008A28E0D3D2C7D43A6" ^ "71A96CB9A98ED1ECDEBA8F5AFAF4DDF3" ^ "F7B078346EB1DAEB1047D2E656EFB331" ^ "F3A71302E6FB547568D6A8A2871EB5B2") ~output3:("C39BC4103ED0D8FE8C7D5FC072C94080" ^ "DF9DAB70F627D8BD68719A721836554F" ^ "3A2CFD08616170F4E3C3B0420BB41FBE" ^ "9A84C43D405B9EE32285BB5051CD5E83") let salsa20_20_256bit_ecrypt_set2_vector207_test = test_salsa20_20 ~key:"CFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCF" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("AA68F6EB41DB62A2C5E4E9AAF21D7D43" ^ "1C29A66303854A68EF737872CBF7C505" ^ "918B87CE4DB6B3D84BC039906AC0561D" ^ "F79F0A57CFA762B8B9C2991F1DC98032") ~output1:("7BC0564BAF3C88CF14FCD2020433CEDF" ^ "65EE68DF4AFAB7E040DFC396A856617F" ^ "677217529B839EB9DF47AFD6758CAACD" ^ "75E734FCC653ED5AC25C8A7B1AEBAA49") ~output2:("AD21BBE24EA84C0859B2EF3E09070493" ^ "6A6D2A97DF912207D3F50D63FCD56676" ^ "61A47AD0DF1FA8DDE08EAD7201AF15FA" ^ "85BCBA0962D7921397E35E60149BB4EB") ~output3:("8914307989CD704120A6DAC52789B845" ^ "7260A2939CA0E02A4C41C46ECE890305" ^ "9F58A2B0F3D93B45160D08A13737D51E" ^ "984B97CD4A28DC2D92155FCADA3F8033") let salsa20_20_256bit_ecrypt_set2_vector216_test = test_salsa20_20 ~key:"D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("596EA70BBA1A4DE2F8ED2AF37A0CE6D1" ^ "2443354659CD0C41203EB345E160CF05" ^ "6F8D71314AA7221D86F868304F34D5B3" ^ "ED4D51072FE7B12568B859077B6F920D") ~output1:("26716254A9C7067808EDC0D31D54D289" ^ "88A3F655C10931E217B3C9A8A4B557D2" ^ "8AD6C701612A8D848FED1589CCFBBE7B" ^ "566496F4662B1D98FCFC70C1716E5347") ~output2:("B33C15E9488DE8A97AFE67FBFAF47FFE" ^ "5C3934B05B5E2EA061A41A2BF0D81FB6" ^ "054C824B492775E3E8300DAD609BCEA5" ^ "837392668C0B54FECE2F2945F18160D3") ~output3:("A1F72ECB02649F01D4396574EA80BBCB" ^ "8934FCF989CF1D7CF7410B0A93E08C10" ^ "0A229C952DA999789662E1666CA71C65" ^ "4DBEB2C5BBC20BB67DF67CD39B51B4CB") let salsa20_20_256bit_ecrypt_set2_vector225_test = test_salsa20_20 ~key:"E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("6D221A5561813E4B6BF1A3821F0BC95B" ^ "3D51004ED29EAECD26016E5B7F628BA0" ^ "6B2BA4D650D685C3BA9FB51E305EEB36" ^ "A11CA08C431E0740D59D521FBDDBF716") ~output1:("9C9EEBCA7428A88562FAD4EC9800EB7D" ^ "E4EBE571855B40D3F1D9770236EF0131" ^ "70A6BF8CF9C1880A1BC3C58193777098" ^ "89384D19F4F9D6E8098E8E326B9AC4B7") ~output2:("86ECBB7CA8E1526F538805A692C354B8" ^ "E335BAC919CB4355C15B40D721328BE9" ^ "81105395FD27BB6F0515A427469DF557" ^ "DC92EB010C49C332BFEB1A98154BF0AA") ~output3:("0503DAA102F9CDFBFF854D6015BF484A" ^ "201F69E6E789A757B8DAB005D5859027" ^ "849ECA4E951AE28126FB6C63BB65EF61" ^ "94C9661F9E40CAAB817CBE89595096EC") let salsa20_20_256bit_ecrypt_set2_vector234_test = test_salsa20_20 ~key:"EAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEA" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("304665A82B0838D4EA0A7737855CEAB0" ^ "44583FBF2F8E68D7B3B191600ADAEB33" ^ "538942A71998F68DA9A0D4BAC36A5052" ^ "CBEAEFFCABC6B506E5F805F8105D5E79") ~output1:("96B62FE40229E2CEBEAE44431F01A0A4" ^ "3FA080D685215BEA4705B6B78187751B" ^ "E1DFA0DCC1C8D6A2040C0716F524CF40" ^ "42889F743A3EDC01EBDFD3A6FF3E92DD") ~output2:("D1667A839D7725E602FD36A69117D039" ^ "AE92EC7032432323A61AFB1602F17E4F" ^ "B66F0BB5A5F4C54329F7217497B3546F" ^ "FF9938966B05789E0CA65CBF34DB1B2D") ~output3:("3557FC69A9D44C66FB022ED8D4D349C1" ^ "D82A41DA40E3687B197DFC070000B69C" ^ "2FD9B1F9F99C63BF3ED82F2CCBD2A6ED" ^ "20A14ABA05F6855078DF5C73A4D50493") let salsa20_20_256bit_ecrypt_set2_vector243_test = test_salsa20_20 ~key:"F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("BF9634C2D81B6400C2ADACFCC0C353CE" ^ "3AC45A2EB636AE9D2D6B8DB6107511C9" ^ "399FB22CA2DF6406307EADEED423E72B" ^ "72411E11530B1814AB196A74DFD4FA61") ~output1:("50F32FC8C94BEFCE5E51F3E774134ACA" ^ "D60BF3DE49BFE1F17DDD88395C4880AC" ^ "926528971A3D74796303A4064F67733B" ^ "A2AB545344B97F555525C0A5611151DE") ~output2:("A6E426963373DCDCE54C1827F683859D" ^ "F11857D7BEB1EEA10FF137CF6B395635" ^ "53C79E92295B1FA385C59BC201612C70" ^ "39341B55D49139B88A16544AEDBDA967") ~output3:("EB50C1AFCDFBF83EDA42011C141B67CD" ^ "041598209605800EAFF2EE6A99A6C958" ^ "9621B778FA4DB6D2FC4980030B86F3C8" ^ "670B46BED56A511B9A18E60B1FED27D5") let salsa20_20_256bit_ecrypt_set2_vector252_test = test_salsa20_20 ~key:"FCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFC" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("356DD71DBC2B216B7A439E07BCC1348F" ^ "769F7EF482486C92E8FD8EB050224838" ^ "AB1F4DFCD2FB196AFD4C4FFBF51B9124" ^ "6BF45AE8131B8D5CAFA29FC3025A3597") ~output1:("C09481306DB9FF12F1798A21A3031921" ^ "B237E1B54A73F724CC0378379DB2FD86" ^ "8DF08983A3D26C32379E3B132A6F1766" ^ "646A963AA56C8F5D45B35F79B24D27C0") ~output2:("6C198E30BBAD2E329A7A3ED5C383340F" ^ "90EADD9F44AB7F339E6BE9217366188C" ^ "4C8D721BD6DC5D5D192A8E854013EBE2" ^ "66633893015AFBED28EA42F928B27F60") ~output3:("FF9B8ED2074ABD83B51AA93A65E5E303" ^ "774CD6874D344236B1EFD39A3605984E" ^ "DFEBCFB5B41AC09AAD500F71AF6D77A0" ^ "7CE81A5E0E1E29C857609143B5BE0BA6") let salsa20_20_256bit_ecrypt_set3_vector0_test = test_salsa20_20 ~key:"000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("B580F7671C76E5F7441AF87C146D6B51" ^ "3910DC8B4146EF1B3211CF12AF4A4B49" ^ "E5C874B3EF4F85E7D7ED539FFEBA73EB" ^ "73E0CCA74FBD306D8AA716C7783E89AF") ~output1:("9B5B5406977968E7F472DE2924EFFD0E" ^ "8EA74C954D23FCC21E4ED87BBA9E0F79" ^ "D1477D1810368F02259F7F53966F91CE" ^ "B50ECD3DA10363E7F08EEAB83A0EF71A") ~output2:("68E43AA40C5D5718E636D8E3B0AB3830" ^ "D61698A12EB15BD9C923FF40A23E80BE" ^ "026B7E1349265AD9C20A6C8A60256F4A" ^ "CD1D7AD0DCBE1DFF3058ACD9E1B4C537") ~output3:("343ED5D011373AF376308D0B0DAB7806" ^ "A4B4D3BF9B898181D546EFCF83D7464C" ^ "FC56AE76F03F3711174DC67AC9363E69" ^ "84F5A447BD25642A00754F1133BFD953") let salsa20_20_256bit_ecrypt_set3_vector9_test = test_salsa20_20 ~key:"090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("0DD83B7F93629BA8E489E30FE4B6EE54" ^ "9BAFB44CB794AAEF2EF07116649FD4C4" ^ "4DAC52560EFB34FF1A2E56FC0DD86F2D" ^ "56C2C5C97089FC4C35C6788F36E6F142") ~output1:("19A8C09135CBB83C6140BBEB60099BDB" ^ "469178F58B6DC87AD2B33CAE53A83B46" ^ "A3BCE1289A68528D5A32A8867587FCC7" ^ "F4DFE8EEA78BB2A9C40B9F6D8797BFE3") ~output2:("2E4E97BAAE813AD2C14848ABAB7C51A7" ^ "4BF3153C63101F4E6E4EEA56B470F0A6" ^ "78FAC3AA6CC300A51A7A345356D3FE1E" ^ "3A56242086CA61A1E8E43F6703CDF6DE") ~output3:("306FBEFC44132B66D527F5E75D171868" ^ "EE8CBC6DAEFD6FC5B3730541CEA82CF6" ^ "7D41B8783D75117D266B924502D5AA5F" ^ "28FF44A13AA2179DD8F0F4AD4B29024F") let salsa20_20_256bit_ecrypt_set3_vector18_test = test_salsa20_20 ~key:"12131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F3031" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("4B094A8031FEA02C5CBDC1E2A64B13A9" ^ "A0976897FCBD92A15738330CD1F85448" ^ "EBD8B7E61A76855C64BE1BE78034ADEB" ^ "FFDEDFCF064AB92744760DFBF59F0A9D") ~output1:("F807DF0420C6D87DAD3A1811A96B5E4D" ^ "2B2F284CD9130F51D307521BD2CABE72" ^ "1F1BAC0EF6219B7ACF8923C026C7F9AD" ^ "8762CC9A9F8847750511D3697E165689") ~output2:("AFB3798B54C003AA6C05C7893C5DB290" ^ "AC7FAFE8C25D3E66AC699BBA3A880330" ^ "70D17C0314DAEAF51DBDA0C9DF36B713" ^ "A913BD397B41DA7FF410A593568AB2BE") ~output3:("67AFD443E67F5FF76A247EFCF3D54649" ^ "0649CDE396FE3AA34549C3ABC8F7447D" ^ "DB7A666C0402AFA25ADC47E95B8924B4" ^ "B1C955C11A746FD4C0DA15432C1B83B7") let salsa20_20_256bit_ecrypt_set3_vector27_test = test_salsa20_20 ~key:"1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("AE39508EAC9AECE7BF97BB20B9DEE41F" ^ "87D947F828913598DB72CC232948565E" ^ "837E0BF37D5D387B2D7102B43BB5D823" ^ "B04ADF3CECB6D93B9BA752BEC5D45059") ~output1:("CF7F36734A7AD1EF4D9A4AA518A91C14" ^ "64184688F31E5E775E879E01E82FB42E" ^ "AEE8F382AA0701D54AF5DB788858CCDF" ^ "801DED1E18BA4195019AA3111BA111AC") ~output2:("AB84E643D214E8DE9274720A1557A1E0" ^ "471F00394934A83A324D4270949BD448" ^ "A7BB6B5D5FA40E9831AE5B4EA7D8D34E" ^ "071EB56EFD84F127C8E34DA9BF633B46") ~output3:("E757CA957797D6416E17F852AFFBF191" ^ "AF98EB8CF73DCBBA0BCE8EFA29B958E3" ^ "9C0085F0076E0B4E31289A4F2DF35855" ^ "ADD6BBEC725FC2860D4F49AB4EEA6C87") let salsa20_20_256bit_ecrypt_set3_vector36_test = test_salsa20_20 ~key:"2425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F40414243" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("5DDE22EEE0ED12CF83F433441A3799B3" ^ "A4415A2018A60BDE0A0F8E08993820C8" ^ "20998D420F346D8B808CBED40FC7CBD0" ^ "CC43949B0A16F0EF2577CECAD03DCAD6") ~output1:("5C86A6AB19AD083676D609D2C094FFC2" ^ "921CD8D4580815522BA72AA20FEC59D5" ^ "64F1EDF2E2AE4810C69701BCD515A939" ^ "D9C156254F28DE5C90C6CA2B0A385D53") ~output2:("956A71BB6344DDF03A8B828A03FEA914" ^ "8585BB8D21E52134F1FA9541A57519F4" ^ "4C2D56C8746E9FB40EB1FCF3551A5F95" ^ "38B90606924F3D082987B77C127D1DB7") ~output3:("2160DB576116DD75880E4DE9A7505308" ^ "05EBD00F48B6BFB62679F93EDBD42766" ^ "A51AD3052C64174B5B027F6D5DD02059" ^ "2F5BBC369D48708295259F4B9519B19B") let salsa20_20_256bit_ecrypt_set3_vector45_test = test_salsa20_20 ~key:"2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("BDF4E0BB6B36D01A31EE2E76F2379D33" ^ "286ABFA82F6872677955777DEE0B1662" ^ "A65D85EBC56A7995A6F6CF995154C444" ^ "C27CEF3EABC85B8985C7FA94C8ECB065") ~output1:("8835BF6D66FD567BCDA956673D9DA182" ^ "701921B79AAAB6039D65ABE1C7178923" ^ "BC39C8A56FDEC8FEAAC4C29707914F68" ^ "CA6CBEDE4DBE9FEAAF84DA2DFEC56E96") ~output2:("A2751597632CF806C8246F7F9D9C4A72" ^ "DE85C8C0C36A769F32A062DFCD45635B" ^ "0C7131BFB38CE253886D4918CC4B7DBA" ^ "780CAE5FA0F22479F445C0AD1285F35D") ~output3:("1130339E16298874524D18F68266246C" ^ "A0B2060607B60689D025BD30BC6DE7FF" ^ "5DDB90249319C9EA13195200ACADB595" ^ "14D56FC358D7A0D3BAEA374E34EA2E9D") let salsa20_20_256bit_ecrypt_set3_vector54_test = test_salsa20_20 ~key:"363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("51B180F1C9C31388F8B3DE8734F3918F" ^ "F6DEC759689E6A54D0EAF8734DECAB2C" ^ "A2ACA4DFAA260AB781769B83CF94C2A0" ^ "166F2643585CAB42220D200F92074363") ~output1:("147CE4098C9884493CF00DD28B6439A5" ^ "B794F871CCC4FFE349CABF3963C6BACE" ^ "D799AAB7F778B59473EDE8CB475056A1" ^ "E7F5D0BE68DE84C535A8FB67724E0C6D") ~output2:("7F0BCA1B790CD5C8F8CFD047AFE1C5BF" ^ "DDA8C8E0BBAF0567D4AE6B63C9E32770" ^ "51D1200ED8740D60FBBADC20CAC825A0" ^ "819CB66398FF7CFA38F3CE5CF23BAC37") ~output3:("74C2B38820E2614D4AC42477185346D7" ^ "5EC3BB41DC9810610C5B745A1B423A3C" ^ "BF14A7E45C08C5E7C1CAE65B8839F030" ^ "A8E52500776B45EA65885322FC1B3A57") let salsa20_20_256bit_ecrypt_set3_vector63_test = test_salsa20_20 ~key:"3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("AADBA970B29F5BB8522C3817E849E5D0" ^ "417863554D16D6FC42405CA5A826A82A" ^ "7F0ADD295D02DF3EB565E10CA1902E7E" ^ "E84CC977614F325AA0BCA298F64871C4") ~output1:("23453B14E9067B2733C88A3137650D83" ^ "BF2EDEA3BD78D336765151C9DC15A534" ^ "5394C7B0E1B0DD3BEF7C7BBBB84AB0B5" ^ "7992446F8DD102F90B0D72728686EC17") ~output2:("0291E9B6188CB3E43F98B576C9C114B4" ^ "E1165A39B33E32E7260D6767058C45B0" ^ "93717E09868B400557E750557417E7C7" ^ "F0DA6A8AB0179630023EEE17B0362575") ~output3:("D98E6AF3B8A4BE5EE6CD4F067FDDE869" ^ "FA2569648498460C0B2E4A3A4652FB71" ^ "77D02D632BFEF2C3511F1D374AAADDE1" ^ "4542AC660114716E5CAF854AA5C2CF1A") let salsa20_20_256bit_ecrypt_set3_vector72_test = test_salsa20_20 ~key:"48494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F6061626364656667" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("53AD3698A011F779AD71030F3EFBEBA0" ^ "A7EE3C55789681B1591EF33A7BE521ED" ^ "68FC36E58F53FFD6E1369B00E390E973" ^ "F656ACB097E0D603BE59A0B8F7975B98") ~output1:("A04698274C6AC6EC03F66ED3F94C08B7" ^ "9FFDBF2A1610E6F5814905E73AD6D0D2" ^ "8164EEB8450D8ED0BB4B644761B43512" ^ "52DD5DDF00C31E3DABA0BC17691CCFDC") ~output2:("B826C7F071E796D34E3BFFB3C96E76A1" ^ "209388392806947C7F19B86D379FA3AE" ^ "DFCD19EBF49803DACC6E577E5B97B0F6" ^ "D2036B6624D8196C96FCF02C865D30C1") ~output3:("B505D41E2C207FA1C0A0E93413DDCFFC" ^ "9BECA8030AFFAC2466E56482DA0EF428" ^ "E63880B5021D3051F18679505A2B9D4F" ^ "9B2C5A2D271D276DE3F51DBEBA934436") let salsa20_20_256bit_ecrypt_set3_vector81_test = test_salsa20_20 ~key:"5152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("B2995CDC9255E4E6177398EECE05F338" ^ "BE14825E8025598C1B4B0B80013E5D4B" ^ "C195802ACF47326F309C58809E044CA0" ^ "2027CCE97D80F7AEBA6D0376C96BFD7A") ~output1:("0B89114F6F4111D2C7C33B0CC3DE682F" ^ "932E9B060BD3D1E17801ADBF7F034819" ^ "2D1F77F99104BE2FE62AA14CAF17D0C2" ^ "35243B76D298C9CB51F7E5E02914027D") ~output2:("A93BEF16E18FB3D34FD342AEAC4EC93F" ^ "474910948F5E25F20C3C6AF50FBFFD14" ^ "8B8272DF4AAE7400843AE11502D06196" ^ "59F3F2484D5D5659BC340039CAC03B20") ~output3:("031AB90E5D0C95ED116B7D03EFDD3543" ^ "ACDA91FE89071680C1B025F305538F7E" ^ "7154BDF131351E68F0F0ADDD40FB5183" ^ "0DD7761114BB4BA9692BD72500E7B2A3") let salsa20_20_256bit_ecrypt_set3_vector90_test = test_salsa20_20 ~key:"5A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576777879" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("447D16E09F139ADBFDBC742D248EC354" ^ "67F165D42937FBA97B816016613DE365" ^ "B0C23E4145CA71A3680B382CFF6D615C" ^ "E7B2B02AEE1B6CAE692E4D09B2B47CE4") ~output1:("49DEBE1A89CE85C6BC52DCE9E80422D0" ^ "523FA99D29132F3B292B695EC641C0E3" ^ "C3C339414349F83BAAF6E534E426DA98" ^ "2BB80981B58401128A158AEB75FD48E7") ~output2:("E661F70FC1DCB4437D4DE0C4F6540EFC" ^ "14D319CF67906DDBF41BA8FA8FD1B17E" ^ "A8452CCB67F4078A8CEB2953218F97C7" ^ "73850D1CB882656A6486C0D12F9324EE") ~output3:("7916FA50772F5BCD5DBF87F6733466B7" ^ "E0DC28687A5AFDEE5BDFCA4A197E7B6D" ^ "82072AC49F2C7944519999FCE9438AF9" ^ "80EC5576BEF6454C43AEC151A488A405") let salsa20_20_256bit_ecrypt_set3_vector99_test = test_salsa20_20 ~key:"636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("D356187B3A555932420B005EEA1703CB" ^ "6C568987D54316540561425C078A0BC1" ^ "6011BD3A1E88C62039608DDB65C35453" ^ "8E6E6BE417066D824B4CC3F4842D1B7D") ~output1:("FC9DB2F6F1A10BB4690291F108119B07" ^ "C7D908E2A3C35BDEDF1F0B79041C04B9" ^ "1D63CE0D20459F3A99BF37AB195D907D" ^ "3EBF1C75C5B7272D29ED83C0ECAE915F") ~output2:("2193BE6883F2B56B74312E46F422441C" ^ "C1A54EF08360C87F70AF598751E24F28" ^ "5E7A0C2F886147DFEC52B34466F3A598" ^ "8DDAF657AF45A452495F852233F3E312") ~output3:("42822BF1D4BFD3122C2C842CE59BD9AD" ^ "4616D916AADBBADB1A7F710EED2F7211" ^ "653055D94569FA2BE4C2BA8B758E2956" ^ "2C7A3354074705A28891B5E66EB8A7D7") let salsa20_20_256bit_ecrypt_set3_vector108_test = test_salsa20_20 ~key:"6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("4C2EB1D4A9A84064F43082EAC25C741F" ^ "A49F2579FCB069A2B072B4D7EB704B38" ^ "E00DB35E0D9C2077E58B9403D73904B9" ^ "BDAF16A1C79A0A25B0B9BC06E49D2659") ~output1:("DBB77843D3F626E1F577ED0AB0D90348" ^ "66237611BC25FEA9713D5D001D2FE59F" ^ "51A5C201D1EE6F7844BF231C34BB489A" ^ "CB3EA4434226248FDA91597AC400C8D2") ~output2:("3AC1C77E12C7B3CD306743B805738AAA" ^ "8269B47132D1902ECEAD7EC403E2CE6F" ^ "D3EA6DFF1FE350995BAC330874EB0777" ^ "EA659488C3991432A1FF9CDE7ABB9D34") ~output3:("FFC9E408A4521EFDA22B2D4C30F22781" ^ "D17CB1C709C4ECB2FD03ABEF56B4DD98" ^ "6379C068662A5CBC01053A0A7B3D1A0E" ^ "9B9AB81EEB8F57EDED3BE1EE75ED340B") let salsa20_20_256bit_ecrypt_set3_vector117_test = test_salsa20_20 ~key:"75767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F9091929394" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("B36D9BB49A62689A751CF5C971A15F70" ^ "439E56DC516F15F958369E3DA2500EC4" ^ "D51CE469B050037570D03B0948D9FF82" ^ "F2AD1B1D65FA5D782CAE515E03BA6A60") ~output1:("0A4DE80091F11609F0AE9BE3AA9BE969" ^ "9AA1C0BDEE5C1DE5C00C36C642D7FF87" ^ "2195871708F2A2325DE93F81462E7305" ^ "4CECEFA7C1906CDAE88F874135D5B95D") ~output2:("F69916317394BF360EB6E726751B7050" ^ "96C5BF1317554006E4E832123D7E43CE" ^ "74A06499BF685BB0AAC8E19C41C75B1C" ^ "840FD9375F656AD2B1377B5A0B26289A") ~output3:("5A49B471376394B09890CA0A5A72410A" ^ "B34ED9B829B127FB5677026E1BFC75B4" ^ "AFE9DBF53B5C1B4D8BEB5CEDB678D697" ^ "FE56DACBA9D6DEA9C57CD8243153755A") let salsa20_20_256bit_ecrypt_set3_vector126_test = test_salsa20_20 ~key:"7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("4E7DB2320A4A7717959C27182A53072B" ^ "9D18874644B42B319963B5512340AA4D" ^ "C7088FE4803EE59CC25E77AC29D13E72" ^ "20654487F4A3BF2D39C073C7D231DB17") ~output1:("58A4B8F161BE5C1AC1573FB95C216AAE" ^ "ADBF17205072225CD2236439A574B40A" ^ "2AD76749E37AAEC60B52D79F5DA5459F" ^ "094244FDE783122FACE929D94E914A87") ~output2:("BE41A549607DA00691D0C3734D1F9CF7" ^ "1A0D21056E50BC89F29135989432FDB5" ^ "C2340BFF6D181946BACD49D4B28A5104" ^ "97990B241CE021280159DFAAC44DA45C") ~output3:("E7CEFE15DADB07044C730CE7650E4124" ^ "687B7781C85C472EF6D3DD6C7150B050" ^ "001904552B59778F2BAEA8C0CA29900F" ^ "0470F14CCED15E2D83FB1A06A0C57C7E") let salsa20_20_256bit_ecrypt_set3_vector135_test = test_salsa20_20 ~key:"8788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("EE17A6C5E4275B77E5CE6B0549B556A6" ^ "C3B98B508CC370E5FA9C4EA928F7B516" ^ "D8C481B89E3B6BE41F964EE23F226A97" ^ "E13F0B1D7F3C3FBBFF2E49A9A9B2A87F") ~output1:("1246C91147270CA53D2CEACA1D11D00B" ^ "F83BB8F1C893E6F10118807D71021972" ^ "586592F9935827B03EA663B7CF032AA7" ^ "ED9F1F9EE15409B18E08D12F4880E162") ~output2:("6B6AC56A7E4C7636D6589886D8D27462" ^ "41BACAF2A1C102C5D0DE1603E4C7A92B" ^ "42F609BCB73BC5BFC0927EF075C72656" ^ "7018B47870365138EE821345C958F917") ~output3:("DA438732BA03CBB9AFFF4B796A0B4482" ^ "EA5880D7C3B02E2BE135B81D63DF351E" ^ "EECEFA571731184CD5CB7EEA0A1D1626" ^ "83BA706373017EE078B8068B14953FBF") let salsa20_20_256bit_ecrypt_set3_vector144_test = test_salsa20_20 ~key:"909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAF" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("14530F67317B09CB008EA4FD08813F80" ^ "4AC63D6B1D595D21E244E11AA4F153E1" ^ "256DF77976F713B4F7DD1DF64E7016BB" ^ "F9460A1A7CC7F3E9D28D8D19A69EB0B4") ~output1:("6C025A7A0A9F32AE768D35C56231AFFF" ^ "5E9A283260E54F442D1F3263A837545C" ^ "234F7701D1A5B568DDA76A5D596F532C" ^ "4F950425A2F79CD74203CCBB27293020") ~output2:("CA585389DDA8D79B73CA2C64B476C776" ^ "0DC029271B359EB10D09B90FEF816E96" ^ "432CCEDFB51322F7AEA6DEB896E048FA" ^ "2AAD234F89C45FC25967DF99955B1234") ~output3:("7DECE5C4BA2E08A2A61A37D9DD56BC89" ^ "2E141874A572AE4342067CBD4E080933" ^ "1851640E5D6EF48F73A4A638C74471C1" ^ "85E731136BAC231B0803A66A4CDB6A4C") let salsa20_20_256bit_ecrypt_set3_vector153_test = test_salsa20_20 ~key:"999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("9B05907B8F2EE3E831D9A0BE6203DBED" ^ "012C381B7E3225B52282B9D0BA5A5A6A" ^ "A367F7C553177557B87FFAA73C59E123" ^ "B8B2F069B6C0F6DF25CC0A340CD2550D") ~output1:("4274D6C7996E9E605D378A52CB5AECCC" ^ "E6EF862FC0F40091C79FDC93DE2B7CF8" ^ "4B484FC874687BE243965F92080444D2" ^ "206123C6815E9A497610283D79EB8FA9") ~output2:("B9EBAF94F5CD2CCDAA2F8804E586DE09" ^ "98A5E2E79D9C2E9F6267A16B314C3748" ^ "07E7DD80A3115D2F64F1A7B6AF174AD6" ^ "8EA04962D48C7F0BCA72D9CDA9945FB1") ~output3:("A08547DA215E1372CED1AC1192431AF3" ^ "52B670CE9FF5F1F3A598CB17961D7780" ^ "F1D08A6C69BF2EF73BB54DAC8308D320" ^ "66CB8132DE497FDD9BB54739A54A57AC") let salsa20_20_256bit_ecrypt_set3_vector162_test = test_salsa20_20 ~key:"A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("7D0FF0DCB7CAAC90E548E24BEEA22D10" ^ "1C927E0A9BD559BC32BA70B346659F41" ^ "8FD9E36202D3AF35CB836F1BD15087DE" ^ "0D01FFF0BD42BC24B01A65CAD6F38E2C") ~output1:("12E246BA025A6174789C631646D092A8" ^ "865094571FF71BC28A38BEACEB08A822" ^ "72441DE97C1F273A9AE185B1F05B2953" ^ "EC37C940EE4C3AB5C901FF563563CCC9") ~output2:("2B48A7B5979BD5D27E841D2A6ED203D7" ^ "9126471DB9201444D07FCEA31A66D22F" ^ "DC65636F451B8D51365639CE2F5090B8" ^ "D08E14FE955580CB3692F4A35410D9BA") ~output3:("A94E650CCC1ADEE62D2BAC9AA8969BA1" ^ "911429B6B9287E2E8A553752EDDF6F82" ^ "132FA5620E1F4F671EDF9C2EF1B76DB1" ^ "CE63A8A61EDF905A8D5D195D8EE7A116") let salsa20_20_256bit_ecrypt_set3_vector171_test = test_salsa20_20 ~key:"ABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CA" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("F943B21C04A85C22ED1FC5BFBACAAF93" ^ "2CB889EF7CD4472089B16B6DDA5C72E9" ^ "A8F11B66CFC7677D72FB8908018B2A32" ^ "F6B37A2AC811665D8266841199C066AE") ~output1:("E877CA4C8570A4A0CF06FECCCF0430BB" ^ "C63077B80518C4BFEC10BA18ABB08C0B" ^ "3FD72D94EED86F1A9A38385AD4395A96" ^ "7ABB10B245D71680E50C2918CB5AE210") ~output2:("89B67848C1661AFE6D54D7B7A92EB3FF" ^ "AB5D4E1438B6BEB9E51DE6733F08A71F" ^ "F16B676851ADD55712C5EE91B3F89381" ^ "0352A3C0DC7093FCC6D11810C475F472") ~output3:("14ABC36FB047EB4137390D3AA3486407" ^ "7400CDF9AC001025BA6F45BEDD460ECD" ^ "2FD4C16064F5579C50ACC64361EE9470" ^ "468B39F5CABCF366E0AE7DEA4EB1FEB1") let salsa20_20_256bit_ecrypt_set3_vector180_test = test_salsa20_20 ~key:"B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("5F76E49A712A9B36D646FDB1355FA862" ^ "DE02BDC06E9AA4DF8DC0749102ADB071" ^ "D575101D0CA6E36034EE3A039CF5239B" ^ "817466A88DE350081D91090D79842DF5") ~output1:("48AEECB9BA29A1B52B2A5F58597980CF" ^ "2B5A31CD6DB97B98A4DB560500705ED7" ^ "0BF7D9946DF6B2D26C77E2BC3152F23C" ^ "2302F08ADE124F97E9E45F2894832434") ~output2:("BD9BFA707093FD92BE49E0B0FD0A9E89" ^ "0AFD92AC6A50375173CE0C966C9D9A87" ^ "E2B538445E697EA193BD33D60DC9F107" ^ "1784CDA56C8AAD2BC67E17C9F5BDBAF8") ~output3:("1477E6B19CA394B91496C5C1E1EFE3D4" ^ "68D157B035C87A4667F6559F56C84ABF" ^ "3CE27D85D85784C40081EA064835904D" ^ "AE34A9277900B6F2F0B67F44B6B41776") let salsa20_20_256bit_ecrypt_set3_vector189_test = test_salsa20_20 ~key:"BDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDC" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("1D8D3CB0B17972779FBD8339BDBC5D0C" ^ "4178C943381AFA6FA974FF792C78B4BB" ^ "5E0D8A2D2F9988C01F0FF7CE8AD310B6" ^ "6FA3B8D8CB507E507C4516BC9E7603B6") ~output1:("F32D0691B1832478889516518C441ADB" ^ "8F0FE2165B15043756BB37928EBCA33F" ^ "9C166A5907F7F85CCF45CE6BFB68E725" ^ "748FA39528149A0E96B0B6C656854F88") ~output2:("66A7226EA4CF4DB203592F0C678BA8D2" ^ "99F26E212F2874681E29426A579469B2" ^ "CA747B8620E7E48A7E77D50E5C45FF62" ^ "A733D6052B2FB4AAB4AC782539193A76") ~output3:("25CCCD9E6FF25D8D6525E621BC376F6A" ^ "F73C749E80213260F1418B0C191B1F24" ^ "C1922DAD397EFA6062BBE9E3612D35D5" ^ "30F49C5D9D4F11E4CB2B3A4E66731FA8") let salsa20_20_256bit_ecrypt_set3_vector198_test = test_salsa20_20 ~key:"C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("9D2EB0E9A93A0EF9F8ABCE0916C06EEB" ^ "E9C8EBB52A8112CD352A8E2E4EE84DFD" ^ "44B7C8251D0D1A36EA69CEB8C595D527" ^ "DA0EF26A2C5A5F443DC3040C6BF2DA49") ~output1:("A86842C08DA057352B70FB63EBD1516F" ^ "D56E7BB389BBBB22F8EDE940DC7036CF" ^ "E10104AB81A51F23CFE35CCCC07BF50D" ^ "40A2438F3B3AEAB62953406A9E7D7BF3") ~output2:("9EE5EE22FFEDB13C11A81B0E5EC82DB6" ^ "303F22A62F0FD0574CE7007AF1EA2FCC" ^ "23D9C4196EBE897AB0D00371429F518E" ^ "C150063EAE314EE72EFADB1AA7714AC6") ~output3:("125ACD159548C79FCC93BFEC7B832C5D" ^ "387AFD85A0537BB6A49A8C3F4673306B" ^ "D76E17AC601629E00AB5AFF62B269491" ^ "AD996A624C6B1888BF13785AD63DEC7C") let salsa20_20_256bit_ecrypt_set3_vector207_test = test_salsa20_20 ~key:"CFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEE" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("1D99BD420A9EBE17CF6144EEBE46A4B5" ^ "D8CE913F571DCEDEE6C6E3CFA27572F5" ^ "9983D4B2CADC292A956983AF7250CA81" ^ "A23A9EDA42417CC150597891045FF321") ~output1:("D53AB2E60871F42D10E6747FE358E562" ^ "14D7CE3E7BA38E51354C801B72E5D515" ^ "DD805F8FDBA9F1BC81C5926DBE8CDBD2" ^ "3B006714CC8D550671036F6FD2991825") ~output2:("FD97553220FB51132C33EBDA78606A24" ^ "5C5E3578A69754BF4FC11D6242605160" ^ "B4085DFDFC3D11505F72DC15CC16C683" ^ "37798E0DABD37C67B2E8912E498EA940") ~output3:("A2D9199683D73F01DDD77BD46CD5BCEF" ^ "37CD9D4ECBA40B6C51446DCC68BCAD18" ^ "9FBEFEFC3D82131ECF98263299DC0CA9" ^ "1DD349E4DD348A88B2E3D7AA2D20CC13") let salsa20_20_256bit_ecrypt_set3_vector216_test = test_salsa20_20 ~key:"D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("B9751AF24FCF14907948F7AD36E2649A" ^ "9A07B637F84D34E961EE82B7C33A9CC3" ^ "7B96DA6A956AFF4A629546C422802767" ^ "AD9F24BB2E79F09FCD43775FAC965123") ~output1:("6C4CB6AD15DDCE11F1BF68FFF1376E0F" ^ "4CE35ABCE777F4AB1D6906D09184689D" ^ "B697D1CFFAF46C5B85AD9F21CFF0D756" ^ "3DF67CF86D4199FA055F4BE18AFA34C2") ~output2:("35F4A1BBB9DA8476A82367A5607C72A0" ^ "C273A8D1F94DC4D62FDB2FA303858678" ^ "FABCD6C6EBA64849640BFB6FE4ADB340" ^ "28FAE26F802EA0ECE37D2AC2F2560CE8") ~output3:("3D208E3CFAF58AF11BCC527F948A3B75" ^ "E1751A28A76CBFE94204783820AD7FEE" ^ "7C98B318EDA2DC87111D18978CEE0C0C" ^ "E39F1469E7CB3EEEDBD6BF30DA68DF34") let salsa20_20_256bit_ecrypt_set3_vector225_test = test_salsa20_20 ~key:"E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF00" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("EA444200CDE137A48DD3728CFC0FE82A" ^ "1CD6F0F412C0343639052B6471F8321C" ^ "3C9A38986A5F882A26ABCFB342D3FF50" ^ "4E2EBF01D8CDA2408AE1A9023F4D64CA") ~output1:("5C20B3CECA032C29E7B8118BB8B946F9" ^ "90A9DD8895D9D7FE620727087DB8C6E9" ^ "6973741552A24E8C3B9EC81FA2B06E5F" ^ "F4283201639C83CC0C6AF8AA20FBDDD9") ~output2:("4DB2FF5167737BB90AD337FE16C10BD9" ^ "E4D2B8D6FBD172F5448D099D24FEAEA9" ^ "B30224AB670781C667292D04C76EFEC2" ^ "476B2D33ADA7A7132677E4B8270C68CD") ~output3:("5AB9F03158EA17B1D845CDC688C3BB0F" ^ "F1AC5CEAA2F16DB3178223D1471D0191" ^ "0E9D5BB3C6D0C9CC652C0ACF527B4F44" ^ "94B0DE521164493800E132B272A42A22") let salsa20_20_256bit_ecrypt_set3_vector234_test = test_salsa20_20 ~key:"EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF00010203040506070809" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("99A8CCEC6C5B2A0B6E336CB20652241C" ^ "32B24D34ACC0457EF679178EDE7CF805" ^ "805A9305C7C49909683BD1A803327817" ^ "627CA46FE8B929B6DF0012BD864183BE") ~output1:("2D226C11F47B3C0CCD0959B61F59D5CC" ^ "30FCEF6DBB8CBB3DCC1CC25204FCD449" ^ "8C37426A63BEA3282B1A8A0D60E13EB2" ^ "FE59241A9F6AF426689866EDC769E1E6") ~output2:("482FE1C128A15C1123B5655ED546DF01" ^ "4CE0C455DBF5D3A13D9CD4F0E2D1DAB9" ^ "F12FB68C544261D7F88EAC1C6CBF993F" ^ "BBB8E0AA8510BFF8E73835A1E86EADBB") ~output3:("0597188A1C19255769BE1C210399AD17" ^ "2EB46C52F92FD541DF2EAD71B1FF8EA7" ^ "ADD380EC71A5FD7ADB5181EADD1825EC" ^ "02779A4509BE5832708CA2836C1693A5") let salsa20_20_256bit_ecrypt_set3_vector243_test = test_salsa20_20 ~key:"F3F4F5F6F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E0F101112" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("B4C0AFA503BE7FC29A62058166D56F8F" ^ "5D27DC246F75B9AD8760C8C39DFD8749" ^ "2D3B76D5D9637F009EADA14458A52DFB" ^ "09815337E72672681DDDC24633750D83") ~output1:("DBBA0683DF48C335A9802EEF02522563" ^ "54C9F763C3FDE19131A6BB7B85040624" ^ "B1D6CD4BF66D16F7482236C8602A6D58" ^ "505EEDCCA0B77AED574AB583115124B9") ~output2:("F0C5F98BAE05E019764EF6B65E0694A9" ^ "04CB9EC9C10C297B1AB1A6052365BB78" ^ "E55D3C6CB9F06184BA7D425A92E7E987" ^ "757FC5D9AFD7082418DD64125CA6F2B6") ~output3:("5A5FB5C8F0AFEA471F0318A4A2792F7A" ^ "A5C67B6D6E0F0DDB79961C34E3A564BA" ^ "2EECE78D9AFF45E510FEAB1030B102D3" ^ "9DFCECB77F5798F7D2793C0AB09C7A04") let salsa20_20_256bit_ecrypt_set3_vector252_test = test_salsa20_20 ~key:"FCFDFEFF000102030405060708090A0B0C0D0E0F101112131415161718191A1B" ~nonce:"0000000000000000" ~input:(String.make 1024 '0') ~output0:("2064790538ACDF1DE3852C465070D962" ^ "FE2993BDD20C96DED5B2E5FA33283374" ^ "2A6B03966D47F8874D39C501ECFE0045" ^ "725C463530967ED1499097906B9775C3") ~output1:("9F880124435347E31FDF6EF96981FAB3" ^ "1A912D0B70210CBED6DDC9813521CCE2" ^ "B5C2B80193A59DCD933026D262E8EC74" ^ "F5880028FBB06166E0A304453A3A54BB") ~output2:("8A3F922FCDE48CE6C2E324EAA639DECC" ^ "E7257A25C420A2435BBA98740DF6C92A" ^ "8FA18F1D4E67C5F75F314219BB769685" ^ "A0C028D115321D10D58B46E5D58ABB4E") ~output3:("905C86F2F2C1E0454963E21D7498E8F4" ^ "67ECF23F8B02671F57584322E9952223" ^ "58D4FD541714BF12EFB189ACEA624AFF" ^ "2D55B252974D39D8598E8A066536ACB2") let salsa20_20_256bit_ecrypt_set4_vector0_test = test_salsa20_20 ~key:"0053A6F94C9FF24598EB3E91E4378ADD3083D6297CCF2275C81B6EC11467BA0D" ~nonce:"0000000000000000" ~input:(String.make 262144 '0') ~output0:("F9D2DC274BB55AEFC2A0D9F8A982830F" ^ "6916122BC0A6870F991C6ED8D00D2F85" ^ "94E3151DE4C5A19A9A06FBC191C87BF0" ^ "39ADF971314BAF6D02337080F2DAE5CE") ~output1:("05BDA8EE240BA6DC53A42C14C17F620F" ^ "6FA799A6BC88775E04EEF427B4B9DE5A" ^ "5349327FCADA077F385BA321DB4B3939" ^ "C0F49EA99801790B0FD32986AFC41B85") ~output2:("FED5279620FBCBDD3C3980B11FCE4787" ^ "E6F9F97772BEAAD0EF215FDCD0B3A16F" ^ "BB56D72AFD5FD52E6A584BF840914168" ^ "D04A594FFDDA959A63EB4CF42694F03F") ~output3:("F161DCE8FA4CF80F8143DDB21FA1BFA3" ^ "1CA4DC0A412233EDE80EF72DAA1B8039" ^ "4BCE3875CA1E1E195D58BC3197F803A8" ^ "9C433A59A0718C1A009BCB4DA2AC1778") let salsa20_20_256bit_ecrypt_set4_vector1_test = test_salsa20_20 ~key:"0558ABFE51A4F74A9DF04396E93C8FE23588DB2E81D4277ACD2073C6196CBF12" ~nonce:"0000000000000000" ~input:(String.make 262144 '0') ~output0:("2F634849A4EDC206CE3E3F89949DF4E6" ^ "EA9A0E3EE87F0AB108C4D3B789ACE673" ^ "07AC8C54F07F30BAD9640B7F6EDEEC9D" ^ "B15E51599EB15E1CA94739FEA5F1E3D7") ~output1:("EB2B0FD63C7EEEAA5A4D712EEEFC0A7E" ^ "214BEB04D3FDA19C32250949868216D3" ^ "A659B312E13EC66C5832E970F9C91FF9" ^ "4F7463439A9827ECCA52248D3CC604CD") ~output2:("425E0DF93A3DE6B22E0871EB4E435691" ^ "D77B5C471228DE302A79001F89F7E77D" ^ "837C5CA0177B2206568EDC2EB0F169D5" ^ "6B414B9DCCDC928659B4BE1E0DEDFF73") ~output3:("6AA3D6938B6B54B4CB8D2885274A991B" ^ "4A0D5CCF35D981953EC64452FACC8640" ^ "B5ACFA39A372E38BE4E10EE68E7F1B50" ^ "5A5660CDFBAE8DCBFCC9A3847BBB6BA4") let salsa20_20_256bit_ecrypt_set4_vector2_test = test_salsa20_20 ~key:"0A5DB00356A9FC4FA2F5489BEE4194E73A8DE03386D92C7FD22578CB1E71C417" ~nonce:"0000000000000000" ~input:(String.make 262144 '0') ~output0:("0A8BBD088ABADC4D57D3389E32175878" ^ "125BD89DE7E9D05DBF29B753F5F0C2CB" ^ "F0EEF9333526E9308A114E06EB9564EB" ^ "35C28EA93C17BEF0466748079A355B9C") ~output1:("F47FDFF047F0303F6CCE2510FA2475F0" ^ "7784D5F0FBD63D1746BD8CE4BB02802C" ^ "3052A375D7DE75D439174E7B19CEBA3B" ^ "9546DB027F14FFDB9EF542D5768CE5A7") ~output2:("40FEC0EE1697D63CB04299A17C446DE0" ^ "6B3407D10C6DD2143DFA24EB7362D09A" ^ "6857C6AA83A191D65B05EBBBC8133D12" ^ "2BDE75900C86FCD8785EECE48659C3B0") ~output3:("7820087794D46993E984536E7B74C615" ^ "67AB34C6C0A90090DB080E6EB79532FB" ^ "414CD1145A781A2C55519A3E3AD19FA6" ^ "D78790313EBE19A86F61068E4C8E508D") let salsa20_20_256bit_ecrypt_set4_vector3_test = test_salsa20_20 ~key:"0F62B5085BAE0154A7FA4DA0F34699EC3F92E5388BDE3184D72A7DD02376C91C" ~nonce:"0000000000000000" ~input:(String.make 262144 '0') ~output0:("4A671A2AE75DB7555BEA5995DC53AF8D" ^ "C1E8776AF917A3AB2CA9827BCED53DA7" ^ "00B779820F17294751A2C37EF5CCCFE9" ^ "7BF7481E85AFC9ECAE431B7CF05F6153") ~output1:("15C415BE73C12230AC9505B92B2B1273" ^ "7F6FB2FAAF9C51F22ECCB8CBED36A27A" ^ "1E0738E1252D26E8E5E5651FE8AA02CC" ^ "9887D141A7CBAE80F01BE09B314005BB") ~output2:("1C48158413F5EC5E64D2FA4786D91D27" ^ "27DF6BECD614F6AE745CF2B6F35CD824" ^ "3E5F1C440BEDE01E6C8A1145F2AB77FA" ^ "24D634DE88F955D4F830D4A548A926D0") ~output3:("A9BE2FB00C8BD01054153F77EC0C633C" ^ "E8DF7F78E994907B9F387FF090CB3B95" ^ "4271FEADF50C9084106F4285FF4F534D" ^ "AEC130AAE287D47033179BBAEEB36CE6") let salsa20_20_256bit_ecrypt_set5_vector0_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000000000" ~nonce:"8000000000000000" ~input:(String.make 1024 '0') ~output0:("2ABA3DC45B4947007B14C851CD694456" ^ "B303AD59A465662803006705673D6C3E" ^ "29F1D3510DFC0405463C03414E0E07E3" ^ "59F1F1816C68B2434A19D3EEE0464873") ~output1:("EFF0C107DCA563B5C0048EB488B40341" ^ "ED34052790475CD204A947EB480F3D75" ^ "3EF5347CEBB0A21F25B6CC8DE6B48906" ^ "E604F554A6B01B23791F95C4A93A4717") ~output2:("E3393E1599863B52DE8C52CF26C752FB" ^ "473B74A34D6D9FE31E9CA8DD6292522F" ^ "13EB456C5BE9E5432C06E1BA3965D454" ^ "48936BC98376BF903969F049347EA05D") ~output3:("FC4B2EF3B6B3815C99A437F16BDB06C5" ^ "B948692786081D91C48CC7B072ABB901" ^ "C0491CC6900F2FEA217BFFC70C43EDD6" ^ "65E3E020B59AAA43868E9949FBB9AE22") let salsa20_20_256bit_ecrypt_set5_vector9_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000000000" ~nonce:"0040000000000000" ~input:(String.make 1024 '0') ~output0:("F28343BCF4C946FC95DCAAED9DA10B27" ^ "7E573FC8EBC8CEE246FDDC533D29C2EA" ^ "05451ED9A821C4161EE0AFA32EC0FCA0" ^ "DAD124B702DA9248B3D2AA64489C9D26") ~output1:("C65F799168D6B229D0281309526B746C" ^ "490D3EDC0F6408A04339275FCE04BDF4" ^ "656AB5868495C32D238FDB97869A9332" ^ "E09CB7BE8031D38B8F565FB5469C8459") ~output2:("03E48FD41282FCD62C7217ED64153E55" ^ "B558F82A613245C3D8A885542346AA39" ^ "27DE9734C0581338C3DE5DB443EC4227" ^ "E3F82677D259D2D42601D187C79BF87A") ~output3:("551F95AD9751E4F4BACE7FD48B6A3C67" ^ "E86C4B1E5B747BA60377B07FE8365E09" ^ "F8973085F8A6086FC56BD88168D8C561" ^ "8B01B159EF29F658C85FD117925D46E0") let salsa20_20_256bit_ecrypt_set5_vector18_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000000000" ~nonce:"0000200000000000" ~input:(String.make 1024 '0') ~output0:("621F3014E0ADC8022868C3D9070BC49E" ^ "48BC6B504AFF11CB17957F0EBFB7612F" ^ "7FCB67C60A2FBD7A4BD7C312E8F50AF3" ^ "CA7520821D73DB47189DAD557C436DDC") ~output1:("42C8DFE869C90018825E2037BB5E2EBB" ^ "C4A4A42660AFEA8A2E385AFBBC63EF30" ^ "98D052FF4A52ED12107EE71C1AEC271E" ^ "6870538FCEAA1191B4224A6FFDCE5327") ~output2:("4214DA4FAF0DF7FC2955D81403C9D49E" ^ "E87116B1975C5823E28D9A08C5B1189D" ^ "C52BCBEF065B637F1870980CB778B75A" ^ "DDA41613F5F4728AD8D8D189FBF0E76D") ~output3:("4CA854257ECE95E67383FC8665C3A823" ^ "8B87255F815CA4DEC2D57DB72924C60C" ^ "B20A7EE40C559406AAAB25BE5F47184D" ^ "D187ED7EA191133F3000CB88DCBAC433") let salsa20_20_256bit_ecrypt_set5_vector27_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000000000" ~nonce:"0000001000000000" ~input:(String.make 1024 '0') ~output0:("D2DB1A5CF1C1ACDBE81A7A4340EF5343" ^ "5E7F4B1A50523F8D283DCF851D696E60" ^ "F2DE7456181B8410D462BA6050F061F2" ^ "1C787FC12434AF58BF2C59CA9077F3B0") ~output1:("6CE020B3E83765A11F9AE157AD2D07D1" ^ "EA4E9FBBF386C83FEF54319746E5F997" ^ "D35BE9F73B99772DA97054FF07301314" ^ "3FF9E5B47C61966D8525F17265F48D08") ~output2:("FFEAB16EEA5C43BFD08D2591F9A40293" ^ "24CDDC83A840B2C136B7CE99AF3A66CB" ^ "3084E4E2CA6F44AC5CEAF7A1157BE267" ^ "3DF688B43BD51B9A8444CE194E3CA7F2") ~output3:("0D3873FD47A7B3400115C40574469D21" ^ "5BCE0679ED5CF9E374E473B4427DE498" ^ "5804DD75151D72EE367A3F066E641B7F" ^ "5CF28A67215B74DD80EB3FC02E12A308") let salsa20_20_256bit_ecrypt_set5_vector36_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000000000" ~nonce:"0000000008000000" ~input:(String.make 1024 '0') ~output0:("22E129373F7589D9EAFFF18DEA63432E" ^ "38D0245BAE221D3635BEE176760552B8" ^ "9B6BC49CFEB7D9A5B358963C488ED8FA" ^ "D01F1C72307CADEEF9C20273FB5D6775") ~output1:("6E6FFCB8B324EE4FF55E64449B2A356B" ^ "D53D8AB7747DFFC0B3D044E0BE1A736B" ^ "4AB2109624600FE8CA7E6949A4DF82AC" ^ "A5C96D039F78B67767A1B66FAB0EF24B") ~output2:("C3DF823DBA0F84D70E425D0C2C88DCE3" ^ "CAEC3ACCA435B5A2832BE2E0F0AA46AD" ^ "3F288AFE49BE5C345DC65445D26993F5" ^ "1E3F46E0C1B02B5AEDF73D68336AA04F") ~output3:("443B0FDC4F8365AB93A07682EBCA7B92" ^ "42259A26DAB3574B2E562CCABDB25633" ^ "96F331146347C26D5DB49C87054642F8" ^ "60FC1A0B87468ED0B5CB9C30D72EA8F7") let salsa20_20_256bit_ecrypt_set5_vector45_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000000000" ~nonce:"0000000000040000" ~input:(String.make 1024 '0') ~output0:("DC302570A4D1C44F31D9FA55C7712B11" ^ "AE770BFAA3F8631DFF924BCF00A09C90" ^ "6571B024CE5264215E516D73416BF3E3" ^ "CE373CAE669DB1A057EFD7EB184243B6") ~output1:("A52427068F8048FC5E3E6E94A1A616CD" ^ "11F5A9ED4F8899F780F67836EEC4FADB" ^ "B19C183C6946541F182F224104DF9444" ^ "66D96A6CE7F2EFE723807A8738950AD9") ~output2:("D1410A14DFA3DA5C9BDF18A34476F7C0" ^ "D7A8373331741ED62682C555EA8B62A8" ^ "1EDB10DB9479BAF2CD532CFB18357A92" ^ "FF90897315F69CEE526DE31329CFA06B") ~output3:("9CA44AF188E42090F9969FB5F771C987" ^ "557912B83261760EE80A809F7E398A66" ^ "D56049FFDFFBD3E16633537B84AFB38E" ^ "564B717A0C26EBFEE907B8EF7FDA31F0") let salsa20_20_256bit_ecrypt_set5_vector54_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000000000" ~nonce:"0000000000000200" ~input:(String.make 1024 '0') ~output0:("98951956F4BD5E2E9DC624CCD2D79E60" ^ "6D24A4DB51D413FDAF9A9741A6F079B4" ^ "21400FDA0B4D8785578BB318BDAD4ABC" ^ "A8C2D1BA3BA4E18C2F5572499F345BC1") ~output1:("C3A267F0EB87ED714E09CABC2780FEF6" ^ "E5F665BBBBB44C8448D8EB42D88275CD" ^ "62AD759AAC9F4080F73993DE50FF94E8" ^ "34E2CF7B74A91E68B38EACE9C12922C2") ~output2:("78BD0BB32A69E62362EE7E31F1DD9E96" ^ "CA6E196844EFD9459F270D612119DFA4" ^ "5DD1522967629143CECD585CFE62B7FD" ^ "9D1503A62A238C35A66595C49DD71575") ~output3:("C17F946C14A492392A1C554993F406B2" ^ "EA806E4186D97FCB420C21FB4245A3DB" ^ "4EBA2BCB59D2C33CE2CD5044A79A96F9" ^ "5182112D9724E16AD9E965047DA71F05") let salsa20_20_256bit_ecrypt_set5_vector63_test = test_salsa20_20 ~key:"0000000000000000000000000000000000000000000000000000000000000000" ~nonce:"0000000000000001" ~input:(String.make 1024 '0') ~output0:("B47F96AA96786135297A3C4EC56A613D" ^ "0B80095324FF43239D684C57FFE42E1C" ^ "44F3CC011613DB6CDC880999A1E65AED" ^ "1287FCB11C839C37120765AFA73E5075") ~output1:("97128BD699DDC1B4B135D94811B5D2D6" ^ "B2ADCBDC1ED8D3CF86ECF65A1750DE66" ^ "CA5F1C2ED350DC2F497396E029DBD4A0" ^ "6FDDA6238BE7D120DD41E9F19E6DEEA2") ~output2:("FF8065AD901A2DFC5C01642A840F7593" ^ "AE032946058E54EA67300FBF7B928C20" ^ "3244EF546762BA640032B6A2514122DE" ^ "0CA969283F70CE21F981A5D668274F0D") ~output3:("1309268BE548EFEC38D79DF4334CA949" ^ "AB15A2A1003E2B97969FE0CD74A16A06" ^ "5FE8691F03CBD0ECFCF6312F2EE0697F" ^ "44BD3BF3E60320B289CBF21B428C8922") let salsa20_20_256bit_ecrypt_set6_vector0_test = test_salsa20_20 ~key:"0053A6F94C9FF24598EB3E91E4378ADD3083D6297CCF2275C81B6EC11467BA0D" ~nonce:"0D74DB42A91077DE" ~input:(String.make 262144 '0') ~output0:("F5FAD53F79F9DF58C4AEA0D0ED9A9601" ^ "F278112CA7180D565B420A48019670EA" ^ "F24CE493A86263F677B46ACE1924773D" ^ "2BB25571E1AA8593758FC382B1280B71") ~output1:("B70C50139C63332EF6E77AC54338A407" ^ "9B82BEC9F9A403DFEA821B83F7860791" ^ "650EF1B2489D0590B1DE772EEDA4E3BC" ^ "D60FA7CE9CD623D9D2FD5758B8653E70") ~output2:("81582C65D7562B80AEC2F1A673A9D01C" ^ "9F892A23D4919F6AB47B9154E08E699B" ^ "4117D7C666477B60F8391481682F5D95" ^ "D96623DBC489D88DAA6956B9F0646B6E") ~output3:("A13FFA1208F8BF50900886FAAB40FD10" ^ "E8CAA306E63DF39536A1564FB760B242" ^ "A9D6A4628CDC878762834E27A541DA2A" ^ "5E3B3445989C76F611E0FEC6D91ACACC") let salsa20_20_256bit_ecrypt_set6_vector1_test = test_salsa20_20 ~key:"0558ABFE51A4F74A9DF04396E93C8FE23588DB2E81D4277ACD2073C6196CBF12" ~nonce:"167DE44BB21980E7" ~input:(String.make 262144 '0') ~output0:("3944F6DC9F85B128083879FDF190F7DE" ^ "E4053A07BC09896D51D0690BD4DA4AC1" ^ "062F1E47D3D0716F80A9B4D85E6D6085" ^ "EE06947601C85F1A27A2F76E45A6AA87") ~output1:("36E03B4B54B0B2E04D069E690082C8C5" ^ "92DF56E633F5D8C7682A02A65ECD1371" ^ "8CA4352AACCB0DA20ED6BBBA62E177F2" ^ "10E3560E63BB822C4158CAA806A88C82") ~output2:("1B779E7A917C8C26039FFB23CF0EF8E0" ^ "8A1A13B43ACDD9402CF5DF38501098DF" ^ "C945A6CC69A6A17367BC03431A86B3ED" ^ "04B0245B56379BF997E25800AD837D7D") ~output3:("7EC6DAE81A105E67172A0B8C4BBE7D06" ^ "A7A8759F914FBEB1AF62C8A552EF4A4F" ^ "56967EA29C7471F46F3B07F7A3746E95" ^ "3D315821B85B6E8CB40122B96635313C") let salsa20_20_256bit_ecrypt_set6_vector2_test = test_salsa20_20 ~key:"0A5DB00356A9FC4FA2F5489BEE4194E73A8DE03386D92C7FD22578CB1E71C417" ~nonce:"1F86ED54BB2289F0" ~input:(String.make 262144 '0') ~output0:("3FE85D5BB1960A82480B5E6F4E965A44" ^ "60D7A54501664F7D60B54B06100A37FF" ^ "DCF6BDE5CE3F4886BA77DD5B44E95644" ^ "E40A8AC65801155DB90F02522B644023") ~output1:("C8D6E54C29CA204018A830E266CEEE0D" ^ "037DC47E921947302ACE40D1B996A6D8" ^ "0B598677F3352F1DAA6D9888F891AD95" ^ "A1C32FFEB71BB861E8B07058515171C9") ~output2:("B79FD776542B4620EFCB88449599F234" ^ "03E74A6E91CACC50A05A8F8F3C0DEA8B" ^ "00E1A5E6081F5526AE975B3BC0450F1A" ^ "0C8B66F808F1904B971361137C93156F") ~output3:("7998204FED70CE8E0D027B206635C08C" ^ "8BC443622608970E40E3AEDF3CE790AE" ^ "EDF89F922671B45378E2CD03F6F62356" ^ "529C4158B7FF41EE854B1235373988C8") let salsa20_20_256bit_ecrypt_set6_vector3_test = test_salsa20_20 ~key:"0F62B5085BAE0154A7FA4DA0F34699EC3F92E5388BDE3184D72A7DD02376C91C" ~nonce:"288FF65DC42B92F9" ~input:(String.make 262144 '0') ~output0:("5E5E71F90199340304ABB22A37B6625B" ^ "F883FB89CE3B21F54A10B81066EF87DA" ^ "30B77699AA7379DA595C77DD59542DA2" ^ "08E5954F89E40EB7AA80A84A6176663F") ~output1:("2DA2174BD150A1DFEC1796E921E9D6E2" ^ "4ECF0209BCBEA4F98370FCE629056F64" ^ "917283436E2D3F45556225307D5CC5A5" ^ "65325D8993B37F1654195C240BF75B16") ~output2:("ABF39A210EEE89598B7133377056C2FE" ^ "F42DA731327563FB67C7BEDB27F38C7C" ^ "5A3FC2183A4C6B277F901152472C6B2A" ^ "BCF5E34CBE315E81FD3D180B5D66CB6C") ~output3:("1BA89DBD3F98839728F56791D5B7CE23" ^ "5036DE843CCCAB0390B8B5862F1E4596" ^ "AE8A16FB23DA997F371F4E0AACC26DB8" ^ "EB314ED470B1AF6B9F8D69DD79A9D750") let salsa20_20_tests = [ "128 bit, Set 1, vector# 0", `Quick, salsa20_20_128bit_ecrypt_set1_vector0_test; "128 bit, Set 1, vector# 9", `Quick, salsa20_20_128bit_ecrypt_set1_vector9_test; "128 bit, Set 1, vector# 18", `Quick, salsa20_20_128bit_ecrypt_set1_vector18_test; "128 bit, Set 1, vector# 27", `Quick, salsa20_20_128bit_ecrypt_set1_vector27_test; "128 bit, Set 1, vector# 36", `Quick, salsa20_20_128bit_ecrypt_set1_vector36_test; "128 bit, Set 1, vector# 45", `Quick, salsa20_20_128bit_ecrypt_set1_vector45_test; "128 bit, Set 1, vector# 54", `Quick, salsa20_20_128bit_ecrypt_set1_vector54_test; "128 bit, Set 1, vector# 63", `Quick, salsa20_20_128bit_ecrypt_set1_vector63_test; "128 bit, Set 1, vector# 72", `Quick, salsa20_20_128bit_ecrypt_set1_vector72_test; "128 bit, Set 1, vector# 81", `Quick, salsa20_20_128bit_ecrypt_set1_vector81_test; "128 bit, Set 1, vector# 90", `Quick, salsa20_20_128bit_ecrypt_set1_vector90_test; "128 bit, Set 1, vector# 99", `Quick, salsa20_20_128bit_ecrypt_set1_vector99_test; "128 bit, Set 1, vector# 108", `Quick, salsa20_20_128bit_ecrypt_set1_vector108_test; "128 bit, Set 1, vector# 117", `Quick, salsa20_20_128bit_ecrypt_set1_vector117_test; "128 bit, Set 1, vector# 126", `Quick, salsa20_20_128bit_ecrypt_set1_vector126_test; "128 bit, Set 2, vector# 0", `Quick, salsa20_20_128bit_ecrypt_set2_vector0_test; "128 bit, Set 2, vector# 9", `Quick, salsa20_20_128bit_ecrypt_set2_vector9_test; "128 bit, Set 2, vector# 18", `Quick, salsa20_20_128bit_ecrypt_set2_vector18_test; "128 bit, Set 2, vector# 27", `Quick, salsa20_20_128bit_ecrypt_set2_vector27_test; "128 bit, Set 2, vector# 36", `Quick, salsa20_20_128bit_ecrypt_set2_vector36_test; "128 bit, Set 2, vector# 45", `Quick, salsa20_20_128bit_ecrypt_set2_vector45_test; "128 bit, Set 2, vector# 54", `Quick, salsa20_20_128bit_ecrypt_set2_vector54_test; "128 bit, Set 2, vector# 63", `Quick, salsa20_20_128bit_ecrypt_set2_vector63_test; "128 bit, Set 2, vector# 72", `Quick, salsa20_20_128bit_ecrypt_set2_vector72_test; "128 bit, Set 2, vector# 81", `Quick, salsa20_20_128bit_ecrypt_set2_vector81_test; "128 bit, Set 2, vector# 90", `Quick, salsa20_20_128bit_ecrypt_set2_vector90_test; "128 bit, Set 2, vector# 99", `Quick, salsa20_20_128bit_ecrypt_set2_vector99_test; "128 bit, Set 2, vector# 108", `Quick, salsa20_20_128bit_ecrypt_set2_vector108_test; "128 bit, Set 2, vector# 117", `Quick, salsa20_20_128bit_ecrypt_set2_vector117_test; "128 bit, Set 2, vector# 126", `Quick, salsa20_20_128bit_ecrypt_set2_vector126_test; "128 bit, Set 2, vector# 135", `Quick, salsa20_20_128bit_ecrypt_set2_vector135_test; "128 bit, Set 2, vector# 144", `Quick, salsa20_20_128bit_ecrypt_set2_vector144_test; "128 bit, Set 2, vector# 153", `Quick, salsa20_20_128bit_ecrypt_set2_vector153_test; "128 bit, Set 2, vector# 162", `Quick, salsa20_20_128bit_ecrypt_set2_vector162_test; "128 bit, Set 2, vector# 171", `Quick, salsa20_20_128bit_ecrypt_set2_vector171_test; "128 bit, Set 2, vector# 180", `Quick, salsa20_20_128bit_ecrypt_set2_vector180_test; "128 bit, Set 2, vector# 189", `Quick, salsa20_20_128bit_ecrypt_set2_vector189_test; "128 bit, Set 2, vector# 198", `Quick, salsa20_20_128bit_ecrypt_set2_vector198_test; "128 bit, Set 2, vector# 207", `Quick, salsa20_20_128bit_ecrypt_set2_vector207_test; "128 bit, Set 2, vector# 216", `Quick, salsa20_20_128bit_ecrypt_set2_vector216_test; "128 bit, Set 2, vector# 225", `Quick, salsa20_20_128bit_ecrypt_set2_vector225_test; "128 bit, Set 2, vector# 234", `Quick, salsa20_20_128bit_ecrypt_set2_vector234_test; "128 bit, Set 2, vector# 243", `Quick, salsa20_20_128bit_ecrypt_set2_vector243_test; "128 bit, Set 2, vector# 252", `Quick, salsa20_20_128bit_ecrypt_set2_vector252_test; "128 bit, Set 3, vector# 0", `Quick, salsa20_20_128bit_ecrypt_set3_vector0_test; "128 bit, Set 3, vector# 9", `Quick, salsa20_20_128bit_ecrypt_set3_vector9_test; "128 bit, Set 3, vector# 18", `Quick, salsa20_20_128bit_ecrypt_set3_vector18_test; "128 bit, Set 3, vector# 27", `Quick, salsa20_20_128bit_ecrypt_set3_vector27_test; "128 bit, Set 3, vector# 36", `Quick, salsa20_20_128bit_ecrypt_set3_vector36_test; "128 bit, Set 3, vector# 45", `Quick, salsa20_20_128bit_ecrypt_set3_vector45_test; "128 bit, Set 3, vector# 54", `Quick, salsa20_20_128bit_ecrypt_set3_vector54_test; "128 bit, Set 3, vector# 63", `Quick, salsa20_20_128bit_ecrypt_set3_vector63_test; "128 bit, Set 3, vector# 72", `Quick, salsa20_20_128bit_ecrypt_set3_vector72_test; "128 bit, Set 3, vector# 81", `Quick, salsa20_20_128bit_ecrypt_set3_vector81_test; "128 bit, Set 3, vector# 90", `Quick, salsa20_20_128bit_ecrypt_set3_vector90_test; "128 bit, Set 3, vector# 99", `Quick, salsa20_20_128bit_ecrypt_set3_vector99_test; "128 bit, Set 3, vector# 108", `Quick, salsa20_20_128bit_ecrypt_set3_vector108_test; "128 bit, Set 3, vector# 117", `Quick, salsa20_20_128bit_ecrypt_set3_vector117_test; "128 bit, Set 3, vector# 126", `Quick, salsa20_20_128bit_ecrypt_set3_vector126_test; "128 bit, Set 3, vector# 135", `Quick, salsa20_20_128bit_ecrypt_set3_vector135_test; "128 bit, Set 3, vector# 144", `Quick, salsa20_20_128bit_ecrypt_set3_vector144_test; "128 bit, Set 3, vector# 153", `Quick, salsa20_20_128bit_ecrypt_set3_vector153_test; "128 bit, Set 3, vector# 162", `Quick, salsa20_20_128bit_ecrypt_set3_vector162_test; "128 bit, Set 3, vector# 171", `Quick, salsa20_20_128bit_ecrypt_set3_vector171_test; "128 bit, Set 3, vector# 180", `Quick, salsa20_20_128bit_ecrypt_set3_vector180_test; "128 bit, Set 3, vector# 189", `Quick, salsa20_20_128bit_ecrypt_set3_vector189_test; "128 bit, Set 3, vector# 198", `Quick, salsa20_20_128bit_ecrypt_set3_vector198_test; "128 bit, Set 3, vector# 207", `Quick, salsa20_20_128bit_ecrypt_set3_vector207_test; "128 bit, Set 3, vector# 216", `Quick, salsa20_20_128bit_ecrypt_set3_vector216_test; "128 bit, Set 3, vector# 225", `Quick, salsa20_20_128bit_ecrypt_set3_vector225_test; "128 bit, Set 3, vector# 234", `Quick, salsa20_20_128bit_ecrypt_set3_vector234_test; "128 bit, Set 3, vector# 243", `Quick, salsa20_20_128bit_ecrypt_set3_vector243_test; "128 bit, Set 3, vector# 252", `Quick, salsa20_20_128bit_ecrypt_set3_vector252_test; "128 bit, Set 4, vector# 0", `Quick, salsa20_20_128bit_ecrypt_set4_vector0_test; "128 bit, Set 4, vector# 1", `Quick, salsa20_20_128bit_ecrypt_set4_vector1_test; "128 bit, Set 4, vector# 2", `Quick, salsa20_20_128bit_ecrypt_set4_vector2_test; "128 bit, Set 4, vector# 3", `Quick, salsa20_20_128bit_ecrypt_set4_vector3_test; "128 bit, Set 5, vector# 0", `Quick, salsa20_20_128bit_ecrypt_set5_vector0_test; "128 bit, Set 5, vector# 9", `Quick, salsa20_20_128bit_ecrypt_set5_vector9_test; "128 bit, Set 5, vector# 18", `Quick, salsa20_20_128bit_ecrypt_set5_vector18_test; "128 bit, Set 5, vector# 27", `Quick, salsa20_20_128bit_ecrypt_set5_vector27_test; "128 bit, Set 5, vector# 36", `Quick, salsa20_20_128bit_ecrypt_set5_vector36_test; "128 bit, Set 5, vector# 45", `Quick, salsa20_20_128bit_ecrypt_set5_vector45_test; "128 bit, Set 5, vector# 54", `Quick, salsa20_20_128bit_ecrypt_set5_vector54_test; "128 bit, Set 5, vector# 63", `Quick, salsa20_20_128bit_ecrypt_set5_vector63_test; "128 bit, Set 6, vector# 0", `Quick, salsa20_20_128bit_ecrypt_set6_vector0_test; "128 bit, Set 6, vector# 1", `Quick, salsa20_20_128bit_ecrypt_set6_vector1_test; "128 bit, Set 6, vector# 2", `Quick, salsa20_20_128bit_ecrypt_set6_vector2_test; "128 bit, Set 6, vector# 3", `Quick, salsa20_20_128bit_ecrypt_set6_vector3_test; "256 bit, Set 1, vector# 0", `Quick, salsa20_20_256bit_ecrypt_set1_vector0_test; "256 bit, Set 1, vector# 9", `Quick, salsa20_20_256bit_ecrypt_set1_vector9_test; "256 bit, Set 1, vector# 18", `Quick, salsa20_20_256bit_ecrypt_set1_vector18_test; "256 bit, Set 1, vector# 27", `Quick, salsa20_20_256bit_ecrypt_set1_vector27_test; "256 bit, Set 1, vector# 36", `Quick, salsa20_20_256bit_ecrypt_set1_vector36_test; "256 bit, Set 1, vector# 45", `Quick, salsa20_20_256bit_ecrypt_set1_vector45_test; "256 bit, Set 1, vector# 54", `Quick, salsa20_20_256bit_ecrypt_set1_vector54_test; "256 bit, Set 1, vector# 63", `Quick, salsa20_20_256bit_ecrypt_set1_vector63_test; "256 bit, Set 1, vector# 72", `Quick, salsa20_20_256bit_ecrypt_set1_vector72_test; "256 bit, Set 1, vector# 81", `Quick, salsa20_20_256bit_ecrypt_set1_vector81_test; "256 bit, Set 1, vector# 90", `Quick, salsa20_20_256bit_ecrypt_set1_vector90_test; "256 bit, Set 1, vector# 99", `Quick, salsa20_20_256bit_ecrypt_set1_vector99_test; "256 bit, Set 1, vector# 108", `Quick, salsa20_20_256bit_ecrypt_set1_vector108_test; "256 bit, Set 1, vector# 117", `Quick, salsa20_20_256bit_ecrypt_set1_vector117_test; "256 bit, Set 1, vector# 126", `Quick, salsa20_20_256bit_ecrypt_set1_vector126_test; "256 bit, Set 1, vector# 135", `Quick, salsa20_20_256bit_ecrypt_set1_vector135_test; "256 bit, Set 1, vector# 144", `Quick, salsa20_20_256bit_ecrypt_set1_vector144_test; "256 bit, Set 1, vector# 153", `Quick, salsa20_20_256bit_ecrypt_set1_vector153_test; "256 bit, Set 1, vector# 162", `Quick, salsa20_20_256bit_ecrypt_set1_vector162_test; "256 bit, Set 1, vector# 171", `Quick, salsa20_20_256bit_ecrypt_set1_vector171_test; "256 bit, Set 1, vector# 180", `Quick, salsa20_20_256bit_ecrypt_set1_vector180_test; "256 bit, Set 1, vector# 189", `Quick, salsa20_20_256bit_ecrypt_set1_vector189_test; "256 bit, Set 1, vector# 198", `Quick, salsa20_20_256bit_ecrypt_set1_vector198_test; "256 bit, Set 1, vector# 207", `Quick, salsa20_20_256bit_ecrypt_set1_vector207_test; "256 bit, Set 1, vector# 216", `Quick, salsa20_20_256bit_ecrypt_set1_vector216_test; "256 bit, Set 1, vector# 225", `Quick, salsa20_20_256bit_ecrypt_set1_vector225_test; "256 bit, Set 1, vector# 234", `Quick, salsa20_20_256bit_ecrypt_set1_vector234_test; "256 bit, Set 1, vector# 243", `Quick, salsa20_20_256bit_ecrypt_set1_vector243_test; "256 bit, Set 1, vector# 252", `Quick, salsa20_20_256bit_ecrypt_set1_vector252_test; "256 bit, Set 2, vector# 0", `Quick, salsa20_20_256bit_ecrypt_set2_vector0_test; "256 bit, Set 2, vector# 9", `Quick, salsa20_20_256bit_ecrypt_set2_vector9_test; "256 bit, Set 2, vector# 18", `Quick, salsa20_20_256bit_ecrypt_set2_vector18_test; "256 bit, Set 2, vector# 27", `Quick, salsa20_20_256bit_ecrypt_set2_vector27_test; "256 bit, Set 2, vector# 36", `Quick, salsa20_20_256bit_ecrypt_set2_vector36_test; "256 bit, Set 2, vector# 45", `Quick, salsa20_20_256bit_ecrypt_set2_vector45_test; "256 bit, Set 2, vector# 54", `Quick, salsa20_20_256bit_ecrypt_set2_vector54_test; "256 bit, Set 2, vector# 63", `Quick, salsa20_20_256bit_ecrypt_set2_vector63_test; "256 bit, Set 2, vector# 72", `Quick, salsa20_20_256bit_ecrypt_set2_vector72_test; "256 bit, Set 2, vector# 81", `Quick, salsa20_20_256bit_ecrypt_set2_vector81_test; "256 bit, Set 2, vector# 90", `Quick, salsa20_20_256bit_ecrypt_set2_vector90_test; "256 bit, Set 2, vector# 99", `Quick, salsa20_20_256bit_ecrypt_set2_vector99_test; "256 bit, Set 2, vector# 108", `Quick, salsa20_20_256bit_ecrypt_set2_vector108_test; "256 bit, Set 2, vector# 117", `Quick, salsa20_20_256bit_ecrypt_set2_vector117_test; "256 bit, Set 2, vector# 126", `Quick, salsa20_20_256bit_ecrypt_set2_vector126_test; "256 bit, Set 2, vector# 135", `Quick, salsa20_20_256bit_ecrypt_set2_vector135_test; "256 bit, Set 2, vector# 144", `Quick, salsa20_20_256bit_ecrypt_set2_vector144_test; "256 bit, Set 2, vector# 153", `Quick, salsa20_20_256bit_ecrypt_set2_vector153_test; "256 bit, Set 2, vector# 162", `Quick, salsa20_20_256bit_ecrypt_set2_vector162_test; "256 bit, Set 2, vector# 171", `Quick, salsa20_20_256bit_ecrypt_set2_vector171_test; "256 bit, Set 2, vector# 180", `Quick, salsa20_20_256bit_ecrypt_set2_vector180_test; "256 bit, Set 2, vector# 189", `Quick, salsa20_20_256bit_ecrypt_set2_vector189_test; "256 bit, Set 2, vector# 198", `Quick, salsa20_20_256bit_ecrypt_set2_vector198_test; "256 bit, Set 2, vector# 207", `Quick, salsa20_20_256bit_ecrypt_set2_vector207_test; "256 bit, Set 2, vector# 216", `Quick, salsa20_20_256bit_ecrypt_set2_vector216_test; "256 bit, Set 2, vector# 225", `Quick, salsa20_20_256bit_ecrypt_set2_vector225_test; "256 bit, Set 2, vector# 234", `Quick, salsa20_20_256bit_ecrypt_set2_vector234_test; "256 bit, Set 2, vector# 243", `Quick, salsa20_20_256bit_ecrypt_set2_vector243_test; "256 bit, Set 2, vector# 252", `Quick, salsa20_20_256bit_ecrypt_set2_vector252_test; "256 bit, Set 3, vector# 0", `Quick, salsa20_20_256bit_ecrypt_set3_vector0_test; "256 bit, Set 3, vector# 9", `Quick, salsa20_20_256bit_ecrypt_set3_vector9_test; "256 bit, Set 3, vector# 18", `Quick, salsa20_20_256bit_ecrypt_set3_vector18_test; "256 bit, Set 3, vector# 27", `Quick, salsa20_20_256bit_ecrypt_set3_vector27_test; "256 bit, Set 3, vector# 36", `Quick, salsa20_20_256bit_ecrypt_set3_vector36_test; "256 bit, Set 3, vector# 45", `Quick, salsa20_20_256bit_ecrypt_set3_vector45_test; "256 bit, Set 3, vector# 54", `Quick, salsa20_20_256bit_ecrypt_set3_vector54_test; "256 bit, Set 3, vector# 63", `Quick, salsa20_20_256bit_ecrypt_set3_vector63_test; "256 bit, Set 3, vector# 72", `Quick, salsa20_20_256bit_ecrypt_set3_vector72_test; "256 bit, Set 3, vector# 81", `Quick, salsa20_20_256bit_ecrypt_set3_vector81_test; "256 bit, Set 3, vector# 90", `Quick, salsa20_20_256bit_ecrypt_set3_vector90_test; "256 bit, Set 3, vector# 99", `Quick, salsa20_20_256bit_ecrypt_set3_vector99_test; "256 bit, Set 3, vector# 108", `Quick, salsa20_20_256bit_ecrypt_set3_vector108_test; "256 bit, Set 3, vector# 117", `Quick, salsa20_20_256bit_ecrypt_set3_vector117_test; "256 bit, Set 3, vector# 126", `Quick, salsa20_20_256bit_ecrypt_set3_vector126_test; "256 bit, Set 3, vector# 135", `Quick, salsa20_20_256bit_ecrypt_set3_vector135_test; "256 bit, Set 3, vector# 144", `Quick, salsa20_20_256bit_ecrypt_set3_vector144_test; "256 bit, Set 3, vector# 153", `Quick, salsa20_20_256bit_ecrypt_set3_vector153_test; "256 bit, Set 3, vector# 162", `Quick, salsa20_20_256bit_ecrypt_set3_vector162_test; "256 bit, Set 3, vector# 171", `Quick, salsa20_20_256bit_ecrypt_set3_vector171_test; "256 bit, Set 3, vector# 180", `Quick, salsa20_20_256bit_ecrypt_set3_vector180_test; "256 bit, Set 3, vector# 189", `Quick, salsa20_20_256bit_ecrypt_set3_vector189_test; "256 bit, Set 3, vector# 198", `Quick, salsa20_20_256bit_ecrypt_set3_vector198_test; "256 bit, Set 3, vector# 207", `Quick, salsa20_20_256bit_ecrypt_set3_vector207_test; "256 bit, Set 3, vector# 216", `Quick, salsa20_20_256bit_ecrypt_set3_vector216_test; "256 bit, Set 3, vector# 225", `Quick, salsa20_20_256bit_ecrypt_set3_vector225_test; "256 bit, Set 3, vector# 234", `Quick, salsa20_20_256bit_ecrypt_set3_vector234_test; "256 bit, Set 3, vector# 243", `Quick, salsa20_20_256bit_ecrypt_set3_vector243_test; "256 bit, Set 3, vector# 252", `Quick, salsa20_20_256bit_ecrypt_set3_vector252_test; "256 bit, Set 4, vector# 0", `Quick, salsa20_20_256bit_ecrypt_set4_vector0_test; "256 bit, Set 4, vector# 1", `Quick, salsa20_20_256bit_ecrypt_set4_vector1_test; "256 bit, Set 4, vector# 2", `Quick, salsa20_20_256bit_ecrypt_set4_vector2_test; "256 bit, Set 4, vector# 3", `Quick, salsa20_20_256bit_ecrypt_set4_vector3_test; "256 bit, Set 5, vector# 0", `Quick, salsa20_20_256bit_ecrypt_set5_vector0_test; "256 bit, Set 5, vector# 9", `Quick, salsa20_20_256bit_ecrypt_set5_vector9_test; "256 bit, Set 5, vector# 18", `Quick, salsa20_20_256bit_ecrypt_set5_vector18_test; "256 bit, Set 5, vector# 27", `Quick, salsa20_20_256bit_ecrypt_set5_vector27_test; "256 bit, Set 5, vector# 36", `Quick, salsa20_20_256bit_ecrypt_set5_vector36_test; "256 bit, Set 5, vector# 45", `Quick, salsa20_20_256bit_ecrypt_set5_vector45_test; "256 bit, Set 5, vector# 54", `Quick, salsa20_20_256bit_ecrypt_set5_vector54_test; "256 bit, Set 5, vector# 63", `Quick, salsa20_20_256bit_ecrypt_set5_vector63_test; "256 bit, Set 6, vector# 0", `Quick, salsa20_20_256bit_ecrypt_set6_vector0_test; "256 bit, Set 6, vector# 1", `Quick, salsa20_20_256bit_ecrypt_set6_vector1_test; "256 bit, Set 6, vector# 2", `Quick, salsa20_20_256bit_ecrypt_set6_vector2_test; "256 bit, Set 6, vector# 3", `Quick, salsa20_20_256bit_ecrypt_set6_vector3_test; ] let () = Alcotest.run "Salsa20 Tests" [ "Salsa20 8 tests", salsa20_8_tests; "Salsa20 12 tests", salsa20_12_tests; "Salsa20 20 tests", salsa20_20_tests; ]
Archive.h
//===- Archive.h - ar archive file format -----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file declares the ar archive file format class. // //===----------------------------------------------------------------------===// #ifndef LLVM_OBJECT_ARCHIVE_H #define LLVM_OBJECT_ARCHIVE_H #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/fallible_iterator.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Object/Binary.h" #include "llvm/Support/Chrono.h" #include "llvm/Support/Error.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include <algorithm> #include <cassert> #include <cstdint> #include <memory> #include <string> #include <vector> namespace llvm { namespace object { class Archive; class ArchiveMemberHeader { public: friend class Archive; ArchiveMemberHeader(Archive const *Parent, const char *RawHeaderPtr, uint64_t Size, Error *Err); // ArchiveMemberHeader() = default; /// Get the name without looking up long names. Expected<StringRef> getRawName() const; /// Get the name looking up long names. Expected<StringRef> getName(uint64_t Size) const; Expected<uint64_t> getSize() const; Expected<sys::fs::perms> getAccessMode() const; Expected<sys::TimePoint<std::chrono::seconds>> getLastModified() const; StringRef getRawLastModified() const { return StringRef(ArMemHdr->LastModified, sizeof(ArMemHdr->LastModified)).rtrim(' '); } Expected<unsigned> getUID() const; Expected<unsigned> getGID() const; // This returns the size of the private struct ArMemHdrType uint64_t getSizeOf() const { return sizeof(ArMemHdrType); } private: struct ArMemHdrType { char Name[16]; char LastModified[12]; char UID[6]; char GID[6]; char AccessMode[8]; char Size[10]; ///< Size of data, not including header or padding. char Terminator[2]; }; Archive const *Parent; ArMemHdrType const *ArMemHdr; }; class Archive : public Binary { virtual void anchor(); public: class Child { friend Archive; friend ArchiveMemberHeader; const Archive *Parent; ArchiveMemberHeader Header; /// Includes header but not padding byte. StringRef Data; /// Offset from Data to the start of the file. uint16_t StartOfFile; Expected<bool> isThinMember() const; public: Child(const Archive *Parent, const char *Start, Error *Err); Child(const Archive *Parent, StringRef Data, uint16_t StartOfFile); bool operator ==(const Child &other) const { assert(!Parent || !other.Parent || Parent == other.Parent); return Data.begin() == other.Data.begin(); } const Archive *getParent() const { return Parent; } Expected<Child> getNext() const; Expected<StringRef> getName() const; Expected<std::string> getFullName() const; Expected<StringRef> getRawName() const { return Header.getRawName(); } Expected<sys::TimePoint<std::chrono::seconds>> getLastModified() const { return Header.getLastModified(); } StringRef getRawLastModified() const { return Header.getRawLastModified(); } Expected<unsigned> getUID() const { return Header.getUID(); } Expected<unsigned> getGID() const { return Header.getGID(); } Expected<sys::fs::perms> getAccessMode() const { return Header.getAccessMode(); } /// \return the size of the archive member without the header or padding. Expected<uint64_t> getSize() const; /// \return the size in the archive header for this member. Expected<uint64_t> getRawSize() const; Expected<StringRef> getBuffer() const; uint64_t getChildOffset() const; uint64_t getDataOffset() const { return getChildOffset() + StartOfFile; } Expected<MemoryBufferRef> getMemoryBufferRef() const; Expected<std::unique_ptr<Binary>> getAsBinary(LLVMContext *Context = nullptr) const; }; class ChildFallibleIterator { Child C; public: ChildFallibleIterator() : C(Child(nullptr, nullptr, nullptr)) {} ChildFallibleIterator(const Child &C) : C(C) {} const Child *operator->() const { return &C; } const Child &operator*() const { return C; } bool operator==(const ChildFallibleIterator &other) const { // Ignore errors here: If an error occurred during increment then getNext // will have been set to child_end(), and the following comparison should // do the right thing. return C == other.C; } bool operator!=(const ChildFallibleIterator &other) const { return !(*this == other); } Error inc() { auto NextChild = C.getNext(); if (!NextChild) return NextChild.takeError(); C = std::move(*NextChild); return Error::success(); } }; using child_iterator = fallible_iterator<ChildFallibleIterator>; class Symbol { const Archive *Parent; uint32_t SymbolIndex; uint32_t StringIndex; // Extra index to the string. public: Symbol(const Archive *p, uint32_t symi, uint32_t stri) : Parent(p) , SymbolIndex(symi) , StringIndex(stri) {} bool operator ==(const Symbol &other) const { return (Parent == other.Parent) && (SymbolIndex == other.SymbolIndex); } StringRef getName() const; Expected<Child> getMember() const; Symbol getNext() const; }; class symbol_iterator { Symbol symbol; public: symbol_iterator(const Symbol &s) : symbol(s) {} const Symbol *operator->() const { return &symbol; } const Symbol &operator*() const { return symbol; } bool operator==(const symbol_iterator &other) const { return symbol == other.symbol; } bool operator!=(const symbol_iterator &other) const { return !(*this == other); } symbol_iterator& operator++() { // Preincrement symbol = symbol.getNext(); return *this; } }; Archive(MemoryBufferRef Source, Error &Err); static Expected<std::unique_ptr<Archive>> create(MemoryBufferRef Source); /// Size field is 10 decimal digits long static const uint64_t MaxMemberSize = 9999999999; enum Kind { K_GNU, K_GNU64, K_BSD, K_DARWIN, K_DARWIN64, K_COFF }; Kind kind() const { return (Kind)Format; } bool isThin() const { return IsThin; } child_iterator child_begin(Error &Err, bool SkipInternal = true) const; child_iterator child_end() const; iterator_range<child_iterator> children(Error &Err, bool SkipInternal = true) const { return make_range(child_begin(Err, SkipInternal), child_end()); } symbol_iterator symbol_begin() const; symbol_iterator symbol_end() const; iterator_range<symbol_iterator> symbols() const { return make_range(symbol_begin(), symbol_end()); } // Cast methods. static bool classof(Binary const *v) { return v->isArchive(); } // check if a symbol is in the archive Expected<Optional<Child>> findSym(StringRef name) const; bool isEmpty() const; bool hasSymbolTable() const; StringRef getSymbolTable() const { return SymbolTable; } StringRef getStringTable() const { return StringTable; } uint32_t getNumberOfSymbols() const; std::vector<std::unique_ptr<MemoryBuffer>> takeThinBuffers() { return std::move(ThinBuffers); } private: StringRef SymbolTable; StringRef StringTable; StringRef FirstRegularData; uint16_t FirstRegularStartOfFile = -1; void setFirstRegular(const Child &C); unsigned Format : 3; unsigned IsThin : 1; mutable std::vector<std::unique_ptr<MemoryBuffer>> ThinBuffers; }; } // end namespace object } // end namespace llvm #endif // LLVM_OBJECT_ARCHIVE_H
test_tez_repr.ml
(** Testing ------- Component: Tez_repr Invocation: dune exec ./src/proto_alpha/lib_protocol/test/unit/main.exe -- test Tez_repr Dependencies: -- Subject: To test the modules (including the top-level) in tez_repr.ml as individual units, particularly failure cases. Superficial goal: increase coverage percentage. *) open Protocol open Tztest module Test_tez_repr = struct (** Testing predefined units: zero, one_mutez etc *) let test_predefined_values () = let zero_int64 = Tez_repr.to_mutez Tez_repr.zero in Assert.equal_int64 ~loc:__LOC__ zero_int64 0L >>=? fun () -> let one_mutez_int64 = Tez_repr.to_mutez Tez_repr.one_mutez in Assert.equal_int64 ~loc:__LOC__ one_mutez_int64 1L >>=? fun () -> let one_cent_int64 = Tez_repr.to_mutez Tez_repr.one_cent in Assert.equal_int64 ~loc:__LOC__ one_cent_int64 10000L >>=? fun () -> let fifty_cents_int64 = Tez_repr.to_mutez Tez_repr.fifty_cents in Assert.equal_int64 ~loc:__LOC__ fifty_cents_int64 500000L >>=? fun () -> let one_int64 = Tez_repr.to_mutez Tez_repr.one in Assert.equal_int64 ~loc:__LOC__ one_int64 1000000L let test_subtract () = (Lwt.return @@ Tez_repr.(one -? zero)) >|= Environment.wrap_tzresult >>=? fun res -> Assert.equal_int64 ~loc:__LOC__ (Tez_repr.to_mutez res) 1000000L let test_substract_underflow () = (Lwt.return @@ Tez_repr.(zero -? one)) >|= Environment.wrap_tzresult >>= function | Ok _ -> failwith "Expected to underflow" | Error _ -> return_unit let test_addition () = (Lwt.return @@ Tez_repr.(one +? zero)) >|= Environment.wrap_tzresult >>=? fun res -> Assert.equal_int64 ~loc:__LOC__ (Tez_repr.to_mutez res) 1000000L let test_addition_overflow () = (Lwt.return @@ Tez_repr.(of_mutez_exn 0x7fffffffffffffffL +? one)) >|= Environment.wrap_tzresult >>= function | Ok _ -> failwith "Expected to overflow" | Error _ -> return_unit let test_mul () = (Lwt.return @@ Tez_repr.(zero *? 1L)) >|= Environment.wrap_tzresult >>=? fun res -> Assert.equal_int64 ~loc:__LOC__ (Tez_repr.to_mutez res) 0L let test_mul_overflow () = (Lwt.return @@ Tez_repr.(of_mutez_exn 0x7fffffffffffffffL *? 2L)) >|= Environment.wrap_tzresult >>= function | Ok _ -> failwith "Expected to overflow" | Error _ -> return_unit let test_div () = (Lwt.return @@ Tez_repr.(one *? 1L)) >|= Environment.wrap_tzresult >>=? fun res -> Assert.equal_int64 ~loc:__LOC__ (Tez_repr.to_mutez res) 1000000L let test_div_by_zero () = (Lwt.return @@ Tez_repr.(one /? 0L)) >|= Environment.wrap_tzresult >>= function | Ok _ -> failwith "Expected to overflow" | Error _ -> return_unit let test_to_mutez () = let int64v = Tez_repr.(to_mutez one) in Assert.equal_int64 ~loc:__LOC__ int64v 1000000L let test_of_mutez_non_negative () = match Tez_repr.of_mutez 1000000L with | Some tz -> Assert.equal_int64 ~loc:__LOC__ (Tez_repr.to_mutez tz) Tez_repr.(to_mutez one) | None -> failwith "should have successfully converted 1000000L to tez" let test_of_mutez_negative () = match Tez_repr.of_mutez (-1000000L) with | Some _ -> failwith "should have failed to converted -1000000L to tez" | None -> return_unit let test_of_mutez_exn () = try let tz = Tez_repr.of_mutez_exn 1000000L in Assert.equal_int64 ~loc:__LOC__ (Tez_repr.to_mutez tz) Tez_repr.(to_mutez one) with e -> let msg = Printexc.to_string e and stack = Printexc.get_backtrace () in failwith "Unexpected exception: %s %s" msg stack let test_of_mutez_exn_negative () = try let _ = Tez_repr.of_mutez_exn (-1000000L) in failwith "should have failed to converted -1000000L to tez" with | Invalid_argument _ -> return_unit | e -> let msg = Printexc.to_string e and stack = Printexc.get_backtrace () in failwith "Unexpected exception: %s %s" msg stack (* NOTE: Avoid assertions against too many functions from Tez_repr. Convert them to int64 and compare instead of using [Tez_repr]'s compare *) (** Testing [encoding], int64 underneath, by applying it with Data_encoding *) let test_data_encoding () = let encoding = Tez_repr.encoding in let bytes = Data_encoding.Binary.to_bytes_exn Data_encoding.n (Z.of_int 1000000) in (Data_encoding.Binary.of_bytes encoding bytes |> function | Ok x -> Lwt.return (Ok x) | Error e -> failwith "Data_encoding.Binary.read shouldn't have failed with \ Tez_repr.encoding: %a" Data_encoding.Binary.pp_read_error e) >>=? fun v -> Assert.equal_int64 ~loc:__LOC__ (Tez_repr.to_mutez v) 1000000L end let tests = [ tztest "Check if predefined values hold expected values" `Quick Test_tez_repr.test_predefined_values; tztest "Tez.substract: basic behaviour" `Quick Test_tez_repr.test_subtract; tztest "Tez.substract: underflow case" `Quick Test_tez_repr.test_substract_underflow; tztest "Tez.add: basic behaviour (one + zero)" `Quick Test_tez_repr.test_addition; tztest "Tez.add: overflow" `Quick Test_tez_repr.test_addition_overflow; tztest "Tez.mul: basic case" `Quick Test_tez_repr.test_mul; tztest "Tez.mul: overflow case" `Quick Test_tez_repr.test_mul_overflow; tztest "Tez.div: basic case" `Quick Test_tez_repr.test_div; tztest "Tez.div: division by zero" `Quick Test_tez_repr.test_div_by_zero; tztest "Tez.to_mutez: basic assertion" `Quick Test_tez_repr.test_to_mutez; tztest "Tez.of_mutez: of non-negative ints" `Quick Test_tez_repr.test_of_mutez_non_negative; tztest "Tez.of_mutez: of non-negative ints" `Quick Test_tez_repr.test_of_mutez_non_negative; tztest "Tez.of_mutez: of negative ints" `Quick Test_tez_repr.test_of_mutez_negative; tztest "Tez.of_mutez_exn: of non-negative ints" `Quick Test_tez_repr.test_of_mutez_non_negative; tztest "Tez.of_mutez_exn: of negative ints" `Quick Test_tez_repr.test_of_mutez_negative; tztest "Tez.data_encoding: must encode tezzies correctly" `Quick Test_tez_repr.test_data_encoding; ]
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2021 Marigold <contact@marigold.dev> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
dune
(test (name chacha_tests) (modules chacha_tests) (libraries cstruct chacha alcotest))
ml_stubs_Gio.c
#include <caml/mlvalues.h> #include <caml/alloc.h> #define Val_double(val) caml_copy_double(val) #define Val_string_new(val) caml_copy_string(val) #define Val_int32(val) caml_copy_int32(val) #define Val_int32_new(val) caml_copy_int32(val) /*TODO: conversion for record 'GAllocator' */ /*TODO: conversion for record 'GArray' */ /*TODO: conversion for record 'GAsyncQueue' */ /*TODO: conversion for record 'GBookmarkFile' */ /*TODO: conversion for record 'GByteArray' */ /*TODO: conversion for record 'GCache' */ /*TODO: conversion for record 'GChecksum' */ /*TODO: conversion for record 'GCompletion' */ /*TODO: conversion for record 'GCond' */ /*TODO: conversion for record 'GData' */ /*TODO: conversion for record 'GDate' */ /*TODO: conversion for record 'GDateTime' */ /*TODO: conversion for record 'GDebugKey' */ /*TODO: conversion for record 'GDir' */ /*TODO: conversion for record 'GError' */ /*TODO: conversion for record 'GHashTable' */ /*TODO: conversion for record 'GHashTableIter' */ /*TODO: conversion for record 'GHook' */ /*TODO: conversion for record 'GHookList' */ /*TODO: conversion for record 'GIConv' */ /*TODO: conversion for record 'GIOChannel' */ /*TODO: conversion for record 'GIOFuncs' */ /*TODO: conversion for record 'GKeyFile' */ /*TODO: conversion for record 'GList' */ /*TODO: conversion for record 'GMainContext' */ /*TODO: conversion for record 'GMainLoop' */ /*TODO: conversion for record 'GMappedFile' */ /*TODO: conversion for record 'GMarkupParseContext' */ /*TODO: conversion for record 'GMarkupParser' */ /*TODO: conversion for record 'GMatchInfo' */ /*TODO: conversion for record 'GMemChunk' */ /*TODO: conversion for record 'GMemVTable' */ /*TODO: conversion for record 'GMutex' */ /*TODO: conversion for record 'GNode' */ /*TODO: conversion for record 'GOnce' */ /*TODO: conversion for record 'GOptionContext' */ /*TODO: conversion for record 'GOptionEntry' */ /*TODO: conversion for record 'GOptionGroup' */ /*TODO: conversion for record 'GPatternSpec' */ /*TODO: conversion for record 'GPollFD' */ /*TODO: conversion for record 'GPrivate' */ /*TODO: conversion for record 'GPtrArray' */ /*TODO: conversion for record 'GQueue' */ /*TODO: conversion for record 'GRand' */ /*TODO: conversion for record 'GRegex' */ /*TODO: conversion for record 'GRelation' */ /*TODO: conversion for record 'GSList' */ /*TODO: conversion for record 'GScanner' */ /*TODO: conversion for record 'GScannerConfig' */ /*TODO: conversion for record 'GSequence' */ /*TODO: conversion for record 'GSequenceIter' */ /*TODO: conversion for record 'GSource' */ /*TODO: conversion for record 'GSourceCallbackFuncs' */ /*TODO: conversion for record 'GSourceFuncs' */ /*TODO: conversion for record 'GSourcePrivate' */ /*TODO: conversion for record 'GStatBuf' */ /*TODO: conversion for record 'GStaticMutex' */ /*TODO: conversion for record 'GStaticPrivate' */ /*TODO: conversion for record 'GStaticRWLock' */ /*TODO: conversion for record 'GStaticRecMutex' */ /*TODO: conversion for record 'GString' */ /*TODO: conversion for record 'GStringChunk' */ /*TODO: conversion for record 'GTestCase' */ /*TODO: conversion for record 'GTestConfig' */ /*TODO: conversion for record 'GTestLogBuffer' */ /*TODO: conversion for record 'GTestLogMsg' */ /*TODO: conversion for record 'GTestSuite' */ /*TODO: conversion for record 'GThread' */ /*TODO: conversion for record 'GThreadFunctions' */ /*TODO: conversion for record 'GThreadPool' */ /*TODO: conversion for record 'GTimeVal' */ /*TODO: conversion for record 'GTimeZone' */ /*TODO: conversion for record 'GTimer' */ /*TODO: conversion for record 'GTrashStack' */ /*TODO: conversion for record 'GTree' */ /*TODO: conversion for record 'GTuples' */ /*TODO: conversion for record 'GVariant' */ /*TODO: conversion for record 'GVariantBuilder' */ /*TODO: conversion for record 'GVariantIter' */ /*TODO: conversion for record 'GVariantType' */ #define GBinding_val(val) check_cast(G_BINDING,val) #define Val_GBinding(val) Val_GObject((GObject*)val) #define Val_GBinding_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GCClosure' */ /*TODO: conversion for record 'GClosure' */ /*TODO: conversion for record 'GClosureNotifyData' */ /*TODO: conversion for record 'GEnumClass' */ /*TODO: conversion for record 'GEnumValue' */ /*TODO: conversion for record 'GFlagsClass' */ /*TODO: conversion for record 'GFlagsValue' */ /*TODO: conversion for record 'GInitiallyUnownedClass' */ /*TODO: conversion for record 'GInterfaceInfo' */ /*TODO: conversion for record 'GObjectClass' */ /*TODO: conversion for record 'GObjectConstructParam' */ /*TODO: conversion for record 'GParamSpec' */ /*TODO: conversion for record 'GParamSpecBoolean' */ /*TODO: conversion for record 'GParamSpecBoxed' */ /*TODO: conversion for record 'GParamSpecChar' */ /*TODO: conversion for record 'GParamSpecClass' */ /*TODO: conversion for record 'GParamSpecDouble' */ /*TODO: conversion for record 'GParamSpecEnum' */ /*TODO: conversion for record 'GParamSpecFlags' */ /*TODO: conversion for record 'GParamSpecFloat' */ /*TODO: conversion for record 'GParamSpecGType' */ /*TODO: conversion for record 'GParamSpecInt' */ /*TODO: conversion for record 'GParamSpecInt64' */ /*TODO: conversion for record 'GParamSpecLong' */ /*TODO: conversion for record 'GParamSpecObject' */ /*TODO: conversion for record 'GParamSpecOverride' */ /*TODO: conversion for record 'GParamSpecParam' */ /*TODO: conversion for record 'GParamSpecPointer' */ /*TODO: conversion for record 'GParamSpecPool' */ /*TODO: conversion for record 'GParamSpecString' */ /*TODO: conversion for record 'GParamSpecTypeInfo' */ /*TODO: conversion for record 'GParamSpecUChar' */ /*TODO: conversion for record 'GParamSpecUInt' */ /*TODO: conversion for record 'GParamSpecUInt64' */ /*TODO: conversion for record 'GParamSpecULong' */ /*TODO: conversion for record 'GParamSpecUnichar' */ /*TODO: conversion for record 'GParamSpecValueArray' */ /*TODO: conversion for record 'GParamSpecVariant' */ /*TODO: conversion for record 'GParameter' */ /*TODO: conversion for record 'GSignalInvocationHint' */ /*TODO: conversion for record 'GSignalQuery' */ /*TODO: conversion for record 'GTypeClass' */ /*TODO: conversion for record 'GTypeFundamentalInfo' */ /*TODO: conversion for record 'GTypeInfo' */ /*TODO: conversion for record 'GTypeInstance' */ /*TODO: conversion for record 'GTypeInterface' */ #define GTypeModule_val(val) check_cast(G_TYPE_MODULE,val) #define Val_GTypeModule(val) Val_GObject((GObject*)val) #define Val_GTypeModule_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GTypeModuleClass' */ /*TODO: conversion for record 'GTypePluginClass' */ /*TODO: conversion for record 'GTypeQuery' */ /*TODO: conversion for record 'GTypeValueTable' */ /*TODO: conversion for record 'GValue' */ /*TODO: conversion for record 'GValueArray' */ /*TODO: conversion for record 'AtkActionIface' */ /*TODO: conversion for record 'AtkAttribute' */ /*TODO: conversion for record 'AtkComponentIface' */ /*TODO: conversion for record 'AtkDocumentIface' */ /*TODO: conversion for record 'AtkEditableTextIface' */ #define AtkGObjectAccessible_val(val) check_cast(ATK_G_OBJECT_ACCESSIBLE,val) #define Val_AtkGObjectAccessible(val) Val_GObject((GObject*)val) #define Val_AtkGObjectAccessible_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkGObjectAccessibleClass' */ #define AtkHyperlink_val(val) check_cast(ATK_HYPERLINK,val) #define Val_AtkHyperlink(val) Val_GObject((GObject*)val) #define Val_AtkHyperlink_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkHyperlinkClass' */ /*TODO: conversion for record 'AtkHyperlinkImplIface' */ /*TODO: conversion for record 'AtkHypertextIface' */ /*TODO: conversion for record 'AtkImageIface' */ /*TODO: conversion for record 'AtkImplementor' */ /*TODO: conversion for record 'AtkKeyEventStruct' */ #define AtkMisc_val(val) check_cast(ATK_MISC,val) #define Val_AtkMisc(val) Val_GObject((GObject*)val) #define Val_AtkMisc_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkMiscClass' */ #define AtkNoOpObject_val(val) check_cast(ATK_NO_OP_OBJECT,val) #define Val_AtkNoOpObject(val) Val_GObject((GObject*)val) #define Val_AtkNoOpObject_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkNoOpObjectClass' */ #define AtkNoOpObjectFactory_val(val) check_cast(ATK_NO_OP_OBJECT_FACTORY,val) #define Val_AtkNoOpObjectFactory(val) Val_GObject((GObject*)val) #define Val_AtkNoOpObjectFactory_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkNoOpObjectFactoryClass' */ #define AtkObject_val(val) check_cast(ATK_OBJECT,val) #define Val_AtkObject(val) Val_GObject((GObject*)val) #define Val_AtkObject_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkObjectClass' */ #define AtkObjectFactory_val(val) check_cast(ATK_OBJECT_FACTORY,val) #define Val_AtkObjectFactory(val) Val_GObject((GObject*)val) #define Val_AtkObjectFactory_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkObjectFactoryClass' */ #define AtkPlug_val(val) check_cast(ATK_PLUG,val) #define Val_AtkPlug(val) Val_GObject((GObject*)val) #define Val_AtkPlug_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkPlugClass' */ /*TODO: conversion for record 'AtkRectangle' */ #define AtkRelation_val(val) check_cast(ATK_RELATION,val) #define Val_AtkRelation(val) Val_GObject((GObject*)val) #define Val_AtkRelation_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkRelationClass' */ #define AtkRelationSet_val(val) check_cast(ATK_RELATION_SET,val) #define Val_AtkRelationSet(val) Val_GObject((GObject*)val) #define Val_AtkRelationSet_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkRelationSetClass' */ /*TODO: conversion for record 'AtkSelectionIface' */ #define AtkSocket_val(val) check_cast(ATK_SOCKET,val) #define Val_AtkSocket(val) Val_GObject((GObject*)val) #define Val_AtkSocket_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkSocketClass' */ #define AtkStateSet_val(val) check_cast(ATK_STATE_SET,val) #define Val_AtkStateSet(val) Val_GObject((GObject*)val) #define Val_AtkStateSet_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkStateSetClass' */ /*TODO: conversion for record 'AtkStreamableContentIface' */ /*TODO: conversion for record 'AtkTableIface' */ /*TODO: conversion for record 'AtkTextIface' */ /*TODO: conversion for record 'AtkTextRange' */ /*TODO: conversion for record 'AtkTextRectangle' */ #define AtkUtil_val(val) check_cast(ATK_UTIL,val) #define Val_AtkUtil(val) Val_GObject((GObject*)val) #define Val_AtkUtil_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'AtkUtilClass' */ /*TODO: conversion for record 'AtkValueIface' */ /*TODO: conversion for record '_AtkPropertyValues' */ /*TODO: conversion for record '_AtkRegistry' */ /*TODO: conversion for record '_AtkRegistryClass' */ /*TODO: conversion for record 'GModule' */ /*TODO: conversion for record 'GActionGroupInterface' */ /*TODO: conversion for record 'GActionInterface' */ /*TODO: conversion for record 'GAppInfoIface' */ #define GAppLaunchContext_val(val) check_cast(G_APP_LAUNCH_CONTEXT,val) #define Val_GAppLaunchContext(val) Val_GObject((GObject*)val) #define Val_GAppLaunchContext_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GAppLaunchContextClass' */ /*TODO: conversion for record 'GAppLaunchContextPrivate' */ #define GApplication_val(val) check_cast(G_APPLICATION,val) #define Val_GApplication(val) Val_GObject((GObject*)val) #define Val_GApplication_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GApplicationClass' */ #define GApplicationCommandLine_val(val) check_cast(G_APPLICATION_COMMAND_LINE,val) #define Val_GApplicationCommandLine(val) Val_GObject((GObject*)val) #define Val_GApplicationCommandLine_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GApplicationCommandLineClass' */ /*TODO: conversion for record 'GApplicationCommandLinePrivate' */ /*TODO: conversion for record 'GApplicationPrivate' */ /*TODO: conversion for record 'GAsyncInitableIface' */ /*TODO: conversion for record 'GAsyncResultIface' */ #define GBufferedInputStream_val(val) check_cast(G_BUFFERED_INPUT_STREAM,val) #define Val_GBufferedInputStream(val) Val_GObject((GObject*)val) #define Val_GBufferedInputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GBufferedInputStreamClass' */ /*TODO: conversion for record 'GBufferedInputStreamPrivate' */ #define GBufferedOutputStream_val(val) check_cast(G_BUFFERED_OUTPUT_STREAM,val) #define Val_GBufferedOutputStream(val) Val_GObject((GObject*)val) #define Val_GBufferedOutputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GBufferedOutputStreamClass' */ /*TODO: conversion for record 'GBufferedOutputStreamPrivate' */ #define GCancellable_val(val) check_cast(G_CANCELLABLE,val) #define Val_GCancellable(val) Val_GObject((GObject*)val) #define Val_GCancellable_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GCancellableClass' */ /*TODO: conversion for record 'GCancellablePrivate' */ #define GCharsetConverter_val(val) check_cast(G_CHARSET_CONVERTER,val) #define Val_GCharsetConverter(val) Val_GObject((GObject*)val) #define Val_GCharsetConverter_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GCharsetConverterClass' */ /*TODO: conversion for record 'GConverterIface' */ #define GConverterInputStream_val(val) check_cast(G_CONVERTER_INPUT_STREAM,val) #define Val_GConverterInputStream(val) Val_GObject((GObject*)val) #define Val_GConverterInputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GConverterInputStreamClass' */ /*TODO: conversion for record 'GConverterInputStreamPrivate' */ #define GConverterOutputStream_val(val) check_cast(G_CONVERTER_OUTPUT_STREAM,val) #define Val_GConverterOutputStream(val) Val_GObject((GObject*)val) #define Val_GConverterOutputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GConverterOutputStreamClass' */ /*TODO: conversion for record 'GConverterOutputStreamPrivate' */ #define GCredentials_val(val) check_cast(G_CREDENTIALS,val) #define Val_GCredentials(val) Val_GObject((GObject*)val) #define Val_GCredentials_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GCredentialsClass' */ /*TODO: conversion for record 'GDBusAnnotationInfo' */ /*TODO: conversion for record 'GDBusArgInfo' */ #define GDBusAuthObserver_val(val) check_cast(G_D_BUS_AUTH_OBSERVER,val) #define Val_GDBusAuthObserver(val) Val_GObject((GObject*)val) #define Val_GDBusAuthObserver_new(val) Val_GObject_new((GObject*)val) #define GDBusConnection_val(val) check_cast(G_D_BUS_CONNECTION,val) #define Val_GDBusConnection(val) Val_GObject((GObject*)val) #define Val_GDBusConnection_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GDBusErrorEntry' */ /*TODO: conversion for record 'GDBusInterfaceInfo' */ /*TODO: conversion for record 'GDBusInterfaceVTable' */ #define GDBusMessage_val(val) check_cast(G_D_BUS_MESSAGE,val) #define Val_GDBusMessage(val) Val_GObject((GObject*)val) #define Val_GDBusMessage_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GDBusMethodInfo' */ #define GDBusMethodInvocation_val(val) check_cast(G_D_BUS_METHOD_INVOCATION,val) #define Val_GDBusMethodInvocation(val) Val_GObject((GObject*)val) #define Val_GDBusMethodInvocation_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GDBusNodeInfo' */ /*TODO: conversion for record 'GDBusPropertyInfo' */ #define GDBusProxy_val(val) check_cast(G_D_BUS_PROXY,val) #define Val_GDBusProxy(val) Val_GObject((GObject*)val) #define Val_GDBusProxy_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GDBusProxyClass' */ /*TODO: conversion for record 'GDBusProxyPrivate' */ #define GDBusServer_val(val) check_cast(G_D_BUS_SERVER,val) #define Val_GDBusServer(val) Val_GObject((GObject*)val) #define Val_GDBusServer_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GDBusSignalInfo' */ /*TODO: conversion for record 'GDBusSubtreeVTable' */ #define GDataInputStream_val(val) check_cast(G_DATA_INPUT_STREAM,val) #define Val_GDataInputStream(val) Val_GObject((GObject*)val) #define Val_GDataInputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GDataInputStreamClass' */ /*TODO: conversion for record 'GDataInputStreamPrivate' */ #define GDataOutputStream_val(val) check_cast(G_DATA_OUTPUT_STREAM,val) #define Val_GDataOutputStream(val) Val_GObject((GObject*)val) #define Val_GDataOutputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GDataOutputStreamClass' */ /*TODO: conversion for record 'GDataOutputStreamPrivate' */ #define GDesktopAppInfo_val(val) check_cast(G_DESKTOP_APP_INFO,val) #define Val_GDesktopAppInfo(val) Val_GObject((GObject*)val) #define Val_GDesktopAppInfo_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GDesktopAppInfoClass' */ /*TODO: conversion for record 'GDesktopAppInfoLaunchHandlerIface' */ /*TODO: conversion for record 'GDesktopAppInfoLookupIface' */ /*TODO: conversion for record 'GDriveIface' */ #define GEmblem_val(val) check_cast(G_EMBLEM,val) #define Val_GEmblem(val) Val_GObject((GObject*)val) #define Val_GEmblem_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GEmblemClass' */ #define GEmblemedIcon_val(val) check_cast(G_EMBLEMED_ICON,val) #define Val_GEmblemedIcon(val) Val_GObject((GObject*)val) #define Val_GEmblemedIcon_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GEmblemedIconClass' */ /*TODO: conversion for record 'GEmblemedIconPrivate' */ /*TODO: conversion for record 'GFileAttributeInfo' */ /*TODO: conversion for record 'GFileAttributeInfoList' */ /*TODO: conversion for record 'GFileAttributeMatcher' */ /*TODO: conversion for record 'GFileDescriptorBasedIface' */ #define GFileEnumerator_val(val) check_cast(G_FILE_ENUMERATOR,val) #define Val_GFileEnumerator(val) Val_GObject((GObject*)val) #define Val_GFileEnumerator_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GFileEnumeratorClass' */ /*TODO: conversion for record 'GFileEnumeratorPrivate' */ #define GFileIOStream_val(val) check_cast(G_FILE_I_O_STREAM,val) #define Val_GFileIOStream(val) Val_GObject((GObject*)val) #define Val_GFileIOStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GFileIOStreamClass' */ /*TODO: conversion for record 'GFileIOStreamPrivate' */ #define GFileIcon_val(val) check_cast(G_FILE_ICON,val) #define Val_GFileIcon(val) Val_GObject((GObject*)val) #define Val_GFileIcon_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GFileIconClass' */ /*TODO: conversion for record 'GFileIface' */ #define GFileInfo_val(val) check_cast(G_FILE_INFO,val) #define Val_GFileInfo(val) Val_GObject((GObject*)val) #define Val_GFileInfo_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GFileInfoClass' */ #define GFileInputStream_val(val) check_cast(G_FILE_INPUT_STREAM,val) #define Val_GFileInputStream(val) Val_GObject((GObject*)val) #define Val_GFileInputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GFileInputStreamClass' */ /*TODO: conversion for record 'GFileInputStreamPrivate' */ #define GFileMonitor_val(val) check_cast(G_FILE_MONITOR,val) #define Val_GFileMonitor(val) Val_GObject((GObject*)val) #define Val_GFileMonitor_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GFileMonitorClass' */ /*TODO: conversion for record 'GFileMonitorPrivate' */ #define GFileOutputStream_val(val) check_cast(G_FILE_OUTPUT_STREAM,val) #define Val_GFileOutputStream(val) Val_GObject((GObject*)val) #define Val_GFileOutputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GFileOutputStreamClass' */ /*TODO: conversion for record 'GFileOutputStreamPrivate' */ #define GFilenameCompleter_val(val) check_cast(G_FILENAME_COMPLETER,val) #define Val_GFilenameCompleter(val) Val_GObject((GObject*)val) #define Val_GFilenameCompleter_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GFilenameCompleterClass' */ #define GFilterInputStream_val(val) check_cast(G_FILTER_INPUT_STREAM,val) #define Val_GFilterInputStream(val) Val_GObject((GObject*)val) #define Val_GFilterInputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GFilterInputStreamClass' */ #define GFilterOutputStream_val(val) check_cast(G_FILTER_OUTPUT_STREAM,val) #define Val_GFilterOutputStream(val) Val_GObject((GObject*)val) #define Val_GFilterOutputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GFilterOutputStreamClass' */ /*TODO: conversion for record 'GIOExtension' */ /*TODO: conversion for record 'GIOExtensionPoint' */ #define GIOModule_val(val) check_cast(G_I_O_MODULE,val) #define Val_GIOModule(val) Val_GObject((GObject*)val) #define Val_GIOModule_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GIOModuleClass' */ /*TODO: conversion for record 'GIOSchedulerJob' */ #define GIOStream_val(val) check_cast(G_I_O_STREAM,val) #define Val_GIOStream(val) Val_GObject((GObject*)val) #define Val_GIOStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GIOStreamAdapter' */ /*TODO: conversion for record 'GIOStreamClass' */ /*TODO: conversion for record 'GIOStreamPrivate' */ /*TODO: conversion for record 'GIconIface' */ #define GInetAddress_val(val) check_cast(G_INET_ADDRESS,val) #define Val_GInetAddress(val) Val_GObject((GObject*)val) #define Val_GInetAddress_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GInetAddressClass' */ /*TODO: conversion for record 'GInetAddressPrivate' */ #define GInetSocketAddress_val(val) check_cast(G_INET_SOCKET_ADDRESS,val) #define Val_GInetSocketAddress(val) Val_GObject((GObject*)val) #define Val_GInetSocketAddress_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GInetSocketAddressClass' */ /*TODO: conversion for record 'GInetSocketAddressPrivate' */ /*TODO: conversion for record 'GInitableIface' */ #define GInputStream_val(val) check_cast(G_INPUT_STREAM,val) #define Val_GInputStream(val) Val_GObject((GObject*)val) #define Val_GInputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GInputStreamClass' */ /*TODO: conversion for record 'GInputStreamPrivate' */ /*TODO: conversion for record 'GInputVector' */ /*TODO: conversion for record 'GLoadableIconIface' */ #define GMemoryInputStream_val(val) check_cast(G_MEMORY_INPUT_STREAM,val) #define Val_GMemoryInputStream(val) Val_GObject((GObject*)val) #define Val_GMemoryInputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GMemoryInputStreamClass' */ /*TODO: conversion for record 'GMemoryInputStreamPrivate' */ #define GMemoryOutputStream_val(val) check_cast(G_MEMORY_OUTPUT_STREAM,val) #define Val_GMemoryOutputStream(val) Val_GObject((GObject*)val) #define Val_GMemoryOutputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GMemoryOutputStreamClass' */ /*TODO: conversion for record 'GMemoryOutputStreamPrivate' */ /*TODO: conversion for record 'GMountIface' */ #define GMountOperation_val(val) check_cast(G_MOUNT_OPERATION,val) #define Val_GMountOperation(val) Val_GObject((GObject*)val) #define Val_GMountOperation_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GMountOperationClass' */ /*TODO: conversion for record 'GMountOperationPrivate' */ #define GNativeVolumeMonitor_val(val) check_cast(G_NATIVE_VOLUME_MONITOR,val) #define Val_GNativeVolumeMonitor(val) Val_GObject((GObject*)val) #define Val_GNativeVolumeMonitor_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GNativeVolumeMonitorClass' */ #define GNetworkAddress_val(val) check_cast(G_NETWORK_ADDRESS,val) #define Val_GNetworkAddress(val) Val_GObject((GObject*)val) #define Val_GNetworkAddress_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GNetworkAddressClass' */ /*TODO: conversion for record 'GNetworkAddressPrivate' */ #define GNetworkService_val(val) check_cast(G_NETWORK_SERVICE,val) #define Val_GNetworkService(val) Val_GObject((GObject*)val) #define Val_GNetworkService_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GNetworkServiceClass' */ /*TODO: conversion for record 'GNetworkServicePrivate' */ #define GOutputStream_val(val) check_cast(G_OUTPUT_STREAM,val) #define Val_GOutputStream(val) Val_GObject((GObject*)val) #define Val_GOutputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GOutputStreamClass' */ /*TODO: conversion for record 'GOutputStreamPrivate' */ /*TODO: conversion for record 'GOutputVector' */ #define GPermission_val(val) check_cast(G_PERMISSION,val) #define Val_GPermission(val) Val_GObject((GObject*)val) #define Val_GPermission_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GPermissionClass' */ /*TODO: conversion for record 'GPermissionPrivate' */ /*TODO: conversion for record 'GPollableInputStreamInterface' */ /*TODO: conversion for record 'GPollableOutputStreamInterface' */ #define GProxyAddress_val(val) check_cast(G_PROXY_ADDRESS,val) #define Val_GProxyAddress(val) Val_GObject((GObject*)val) #define Val_GProxyAddress_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GProxyAddressClass' */ #define GProxyAddressEnumerator_val(val) check_cast(G_PROXY_ADDRESS_ENUMERATOR,val) #define Val_GProxyAddressEnumerator(val) Val_GObject((GObject*)val) #define Val_GProxyAddressEnumerator_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GProxyAddressEnumeratorClass' */ /*TODO: conversion for record 'GProxyAddressEnumeratorPrivate' */ /*TODO: conversion for record 'GProxyAddressPrivate' */ /*TODO: conversion for record 'GProxyInterface' */ /*TODO: conversion for record 'GProxyResolverInterface' */ #define GResolver_val(val) check_cast(G_RESOLVER,val) #define Val_GResolver(val) Val_GObject((GObject*)val) #define Val_GResolver_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GResolverClass' */ /*TODO: conversion for record 'GResolverPrivate' */ /*TODO: conversion for record 'GSeekableIface' */ #define GSettings_val(val) check_cast(G_SETTINGS,val) #define Val_GSettings(val) Val_GObject((GObject*)val) #define Val_GSettings_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GSettingsBackend' */ /*TODO: conversion for record 'GSettingsClass' */ /*TODO: conversion for record 'GSettingsPrivate' */ #define GSimpleAction_val(val) check_cast(G_SIMPLE_ACTION,val) #define Val_GSimpleAction(val) Val_GObject((GObject*)val) #define Val_GSimpleAction_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GSimpleActionClass' */ #define GSimpleActionGroup_val(val) check_cast(G_SIMPLE_ACTION_GROUP,val) #define Val_GSimpleActionGroup(val) Val_GObject((GObject*)val) #define Val_GSimpleActionGroup_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GSimpleActionGroupClass' */ /*TODO: conversion for record 'GSimpleActionGroupPrivate' */ /*TODO: conversion for record 'GSimpleActionPrivate' */ #define GSimpleAsyncResult_val(val) check_cast(G_SIMPLE_ASYNC_RESULT,val) #define Val_GSimpleAsyncResult(val) Val_GObject((GObject*)val) #define Val_GSimpleAsyncResult_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GSimpleAsyncResultClass' */ #define GSimplePermission_val(val) check_cast(G_SIMPLE_PERMISSION,val) #define Val_GSimplePermission(val) Val_GObject((GObject*)val) #define Val_GSimplePermission_new(val) Val_GObject_new((GObject*)val) #define GSocket_val(val) check_cast(G_SOCKET,val) #define Val_GSocket(val) Val_GObject((GObject*)val) #define Val_GSocket_new(val) Val_GObject_new((GObject*)val) #define GSocketAddress_val(val) check_cast(G_SOCKET_ADDRESS,val) #define Val_GSocketAddress(val) Val_GObject((GObject*)val) #define Val_GSocketAddress_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GSocketAddressClass' */ #define GSocketAddressEnumerator_val(val) check_cast(G_SOCKET_ADDRESS_ENUMERATOR,val) #define Val_GSocketAddressEnumerator(val) Val_GObject((GObject*)val) #define Val_GSocketAddressEnumerator_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GSocketAddressEnumeratorClass' */ /*TODO: conversion for record 'GSocketClass' */ #define GSocketClient_val(val) check_cast(G_SOCKET_CLIENT,val) #define Val_GSocketClient(val) Val_GObject((GObject*)val) #define Val_GSocketClient_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GSocketClientClass' */ /*TODO: conversion for record 'GSocketClientPrivate' */ /*TODO: conversion for record 'GSocketConnectableIface' */ #define GSocketConnection_val(val) check_cast(G_SOCKET_CONNECTION,val) #define Val_GSocketConnection(val) Val_GObject((GObject*)val) #define Val_GSocketConnection_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GSocketConnectionClass' */ /*TODO: conversion for record 'GSocketConnectionPrivate' */ #define GSocketControlMessage_val(val) check_cast(G_SOCKET_CONTROL_MESSAGE,val) #define Val_GSocketControlMessage(val) Val_GObject((GObject*)val) #define Val_GSocketControlMessage_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GSocketControlMessageClass' */ /*TODO: conversion for record 'GSocketControlMessagePrivate' */ #define GSocketListener_val(val) check_cast(G_SOCKET_LISTENER,val) #define Val_GSocketListener(val) Val_GObject((GObject*)val) #define Val_GSocketListener_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GSocketListenerClass' */ /*TODO: conversion for record 'GSocketListenerPrivate' */ /*TODO: conversion for record 'GSocketPrivate' */ #define GSocketService_val(val) check_cast(G_SOCKET_SERVICE,val) #define Val_GSocketService(val) Val_GObject((GObject*)val) #define Val_GSocketService_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GSocketServiceClass' */ /*TODO: conversion for record 'GSocketServicePrivate' */ /*TODO: conversion for record 'GSrvTarget' */ #define GTcpConnection_val(val) check_cast(G_TCP_CONNECTION,val) #define Val_GTcpConnection(val) Val_GObject((GObject*)val) #define Val_GTcpConnection_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GTcpConnectionClass' */ /*TODO: conversion for record 'GTcpConnectionPrivate' */ #define GTcpWrapperConnection_val(val) check_cast(G_TCP_WRAPPER_CONNECTION,val) #define Val_GTcpWrapperConnection(val) Val_GObject((GObject*)val) #define Val_GTcpWrapperConnection_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GTcpWrapperConnectionClass' */ /*TODO: conversion for record 'GTcpWrapperConnectionPrivate' */ #define GThemedIcon_val(val) check_cast(G_THEMED_ICON,val) #define Val_GThemedIcon(val) Val_GObject((GObject*)val) #define Val_GThemedIcon_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GThemedIconClass' */ #define GThreadedSocketService_val(val) check_cast(G_THREADED_SOCKET_SERVICE,val) #define Val_GThreadedSocketService(val) Val_GObject((GObject*)val) #define Val_GThreadedSocketService_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GThreadedSocketServiceClass' */ /*TODO: conversion for record 'GThreadedSocketServicePrivate' */ /*TODO: conversion for record 'GTlsBackendInterface' */ #define GTlsCertificate_val(val) check_cast(G_TLS_CERTIFICATE,val) #define Val_GTlsCertificate(val) Val_GObject((GObject*)val) #define Val_GTlsCertificate_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GTlsCertificateClass' */ /*TODO: conversion for record 'GTlsCertificatePrivate' */ /*TODO: conversion for record 'GTlsClientConnectionInterface' */ /*TODO: conversion for record 'GTlsClientContext' */ #define GTlsConnection_val(val) check_cast(G_TLS_CONNECTION,val) #define Val_GTlsConnection(val) Val_GObject((GObject*)val) #define Val_GTlsConnection_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GTlsConnectionClass' */ /*TODO: conversion for record 'GTlsConnectionPrivate' */ /*TODO: conversion for record 'GTlsContext' */ /*TODO: conversion for record 'GTlsServerConnectionInterface' */ /*TODO: conversion for record 'GTlsServerContext' */ #define GUnixConnection_val(val) check_cast(G_UNIX_CONNECTION,val) #define Val_GUnixConnection(val) Val_GObject((GObject*)val) #define Val_GUnixConnection_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GUnixConnectionClass' */ /*TODO: conversion for record 'GUnixConnectionPrivate' */ #define GUnixCredentialsMessage_val(val) check_cast(G_UNIX_CREDENTIALS_MESSAGE,val) #define Val_GUnixCredentialsMessage(val) Val_GObject((GObject*)val) #define Val_GUnixCredentialsMessage_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GUnixCredentialsMessageClass' */ /*TODO: conversion for record 'GUnixCredentialsMessagePrivate' */ #define GUnixFDList_val(val) check_cast(G_UNIX_F_D_LIST,val) #define Val_GUnixFDList(val) Val_GObject((GObject*)val) #define Val_GUnixFDList_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GUnixFDListClass' */ /*TODO: conversion for record 'GUnixFDListPrivate' */ #define GUnixFDMessage_val(val) check_cast(G_UNIX_F_D_MESSAGE,val) #define Val_GUnixFDMessage(val) Val_GObject((GObject*)val) #define Val_GUnixFDMessage_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GUnixFDMessageClass' */ /*TODO: conversion for record 'GUnixFDMessagePrivate' */ #define GUnixInputStream_val(val) check_cast(G_UNIX_INPUT_STREAM,val) #define Val_GUnixInputStream(val) Val_GObject((GObject*)val) #define Val_GUnixInputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GUnixInputStreamClass' */ /*TODO: conversion for record 'GUnixInputStreamPrivate' */ /*TODO: conversion for record 'GUnixMountEntry' */ #define GUnixMountMonitor_val(val) check_cast(G_UNIX_MOUNT_MONITOR,val) #define Val_GUnixMountMonitor(val) Val_GObject((GObject*)val) #define Val_GUnixMountMonitor_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GUnixMountMonitorClass' */ /*TODO: conversion for record 'GUnixMountPoint' */ #define GUnixOutputStream_val(val) check_cast(G_UNIX_OUTPUT_STREAM,val) #define Val_GUnixOutputStream(val) Val_GObject((GObject*)val) #define Val_GUnixOutputStream_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GUnixOutputStreamClass' */ /*TODO: conversion for record 'GUnixOutputStreamPrivate' */ #define GUnixSocketAddress_val(val) check_cast(G_UNIX_SOCKET_ADDRESS,val) #define Val_GUnixSocketAddress(val) Val_GObject((GObject*)val) #define Val_GUnixSocketAddress_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GUnixSocketAddressClass' */ /*TODO: conversion for record 'GUnixSocketAddressPrivate' */ #define GVfs_val(val) check_cast(G_VFS,val) #define Val_GVfs(val) Val_GObject((GObject*)val) #define Val_GVfs_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GVfsClass' */ /*TODO: conversion for record 'GVolumeIface' */ #define GVolumeMonitor_val(val) check_cast(G_VOLUME_MONITOR,val) #define Val_GVolumeMonitor(val) Val_GObject((GObject*)val) #define Val_GVolumeMonitor_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GVolumeMonitorClass' */ #define GZlibCompressor_val(val) check_cast(G_ZLIB_COMPRESSOR,val) #define Val_GZlibCompressor(val) Val_GObject((GObject*)val) #define Val_GZlibCompressor_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GZlibCompressorClass' */ #define GZlibDecompressor_val(val) check_cast(G_ZLIB_DECOMPRESSOR,val) #define Val_GZlibDecompressor(val) Val_GObject((GObject*)val) #define Val_GZlibDecompressor_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GZlibDecompressorClass' */ #define GdkPixbuf_val(val) check_cast(GDK_PIXBUF,val) #define Val_GdkPixbuf(val) Val_GObject((GObject*)val) #define Val_GdkPixbuf_new(val) Val_GObject_new((GObject*)val) #define GdkPixbufAnimation_val(val) check_cast(GDK_PIXBUF_ANIMATION,val) #define Val_GdkPixbufAnimation(val) Val_GObject((GObject*)val) #define Val_GdkPixbufAnimation_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GdkPixbufAnimationClass' */ #define GdkPixbufAnimationIter_val(val) check_cast(GDK_PIXBUF_ANIMATION_ITER,val) #define Val_GdkPixbufAnimationIter(val) Val_GObject((GObject*)val) #define Val_GdkPixbufAnimationIter_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GdkPixbufAnimationIterClass' */ /*TODO: conversion for record 'GdkPixbufFormat' */ #define GdkPixbufLoader_val(val) check_cast(GDK_PIXBUF_LOADER,val) #define Val_GdkPixbufLoader(val) Val_GObject((GObject*)val) #define Val_GdkPixbufLoader_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GdkPixbufLoaderClass' */ /*TODO: conversion for record 'GdkPixbufModule' */ /*TODO: conversion for record 'GdkPixbufModulePattern' */ #define GdkPixbufSimpleAnim_val(val) check_cast(GDK_PIXBUF_SIMPLE_ANIM,val) #define Val_GdkPixbufSimpleAnim(val) Val_GObject((GObject*)val) #define Val_GdkPixbufSimpleAnim_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GdkPixbufSimpleAnimClass' */ /*TODO: conversion for record 'GdkPixdata' */ /*TODO: conversion for record 'cairo_t' */ /*TODO: conversion for record 'cairo_surface_t' */ /*TODO: conversion for record 'cairo_matrix_t' */ /*TODO: conversion for record 'cairo_pattern_t' */ /*TODO: conversion for record 'cairo_region_t' */ /*TODO: conversion for record 'cairo_font_options_t' */ /*TODO: conversion for record 'cairo_font_type_t' */ /*TODO: conversion for record 'cairo_font_face_t' */ /*TODO: conversion for record 'cairo_scaled_font_t' */ /*TODO: conversion for record 'cairo_path_t' */ /*TODO: conversion for record 'cairo_rectangle_int_t' */ /*TODO: conversion for record 'PangoAnalysis' */ /*TODO: conversion for record 'PangoAttrClass' */ /*TODO: conversion for record 'PangoAttrColor' */ /*TODO: conversion for record 'PangoAttrFloat' */ /*TODO: conversion for record 'PangoAttrFontDesc' */ /*TODO: conversion for record 'PangoAttrInt' */ /*TODO: conversion for record 'PangoAttrIterator' */ /*TODO: conversion for record 'PangoAttrLanguage' */ /*TODO: conversion for record 'PangoAttrList' */ /*TODO: conversion for record 'PangoAttrShape' */ /*TODO: conversion for record 'PangoAttrSize' */ /*TODO: conversion for record 'PangoAttrString' */ /*TODO: conversion for record 'PangoAttribute' */ /*TODO: conversion for record 'PangoColor' */ #define PangoContext_val(val) check_cast(PANGO_CONTEXT,val) #define Val_PangoContext(val) Val_GObject((GObject*)val) #define Val_PangoContext_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'PangoContextClass' */ /*TODO: conversion for record 'PangoCoverage' */ /*TODO: conversion for record 'PangoEngineLang' */ /*TODO: conversion for record 'PangoEngineShape' */ #define PangoFont_val(val) check_cast(PANGO_FONT,val) #define Val_PangoFont(val) Val_GObject((GObject*)val) #define Val_PangoFont_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'PangoFontDescription' */ #define PangoFontFace_val(val) check_cast(PANGO_FONT_FACE,val) #define Val_PangoFontFace(val) Val_GObject((GObject*)val) #define Val_PangoFontFace_new(val) Val_GObject_new((GObject*)val) #define PangoFontFamily_val(val) check_cast(PANGO_FONT_FAMILY,val) #define Val_PangoFontFamily(val) Val_GObject((GObject*)val) #define Val_PangoFontFamily_new(val) Val_GObject_new((GObject*)val) #define PangoFontMap_val(val) check_cast(PANGO_FONT_MAP,val) #define Val_PangoFontMap(val) Val_GObject((GObject*)val) #define Val_PangoFontMap_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'PangoFontMetrics' */ #define PangoFontset_val(val) check_cast(PANGO_FONTSET,val) #define Val_PangoFontset(val) Val_GObject((GObject*)val) #define Val_PangoFontset_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'PangoGlyphGeometry' */ /*TODO: conversion for record 'PangoGlyphInfo' */ /*TODO: conversion for record 'PangoGlyphItem' */ /*TODO: conversion for record 'PangoGlyphItemIter' */ /*TODO: conversion for record 'PangoGlyphString' */ /*TODO: conversion for record 'PangoGlyphVisAttr' */ /*TODO: conversion for record 'PangoItem' */ /*TODO: conversion for record 'PangoLanguage' */ #define PangoLayout_val(val) check_cast(PANGO_LAYOUT,val) #define Val_PangoLayout(val) Val_GObject((GObject*)val) #define Val_PangoLayout_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'PangoLayoutClass' */ /*TODO: conversion for record 'PangoLayoutIter' */ /*TODO: conversion for record 'PangoLayoutLine' */ /*TODO: conversion for record 'PangoLogAttr' */ /*TODO: conversion for record 'PangoMatrix' */ /*TODO: conversion for record 'PangoRectangle' */ #define PangoRenderer_val(val) check_cast(PANGO_RENDERER,val) #define Val_PangoRenderer(val) Val_GObject((GObject*)val) #define Val_PangoRenderer_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'PangoRendererClass' */ /*TODO: conversion for record 'PangoRendererPrivate' */ /*TODO: conversion for record 'PangoScriptIter' */ /*TODO: conversion for record 'PangoTabArray' */ /*TODO: conversion for record '_PangoScriptForLang' */ #define GdkAppLaunchContext_val(val) check_cast(GDK_APP_LAUNCH_CONTEXT,val) #define Val_GdkAppLaunchContext(val) Val_GObject((GObject*)val) #define Val_GdkAppLaunchContext_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GdkAtom' */ /*TODO: conversion for record 'GdkColor' */ #define GdkCursor_val(val) check_cast(GDK_CURSOR,val) #define Val_GdkCursor(val) Val_GObject((GObject*)val) #define Val_GdkCursor_new(val) Val_GObject_new((GObject*)val) #define GdkDevice_val(val) check_cast(GDK_DEVICE,val) #define Val_GdkDevice(val) Val_GObject((GObject*)val) #define Val_GdkDevice_new(val) Val_GObject_new((GObject*)val) #define GdkDeviceManager_val(val) check_cast(GDK_DEVICE_MANAGER,val) #define Val_GdkDeviceManager(val) Val_GObject((GObject*)val) #define Val_GdkDeviceManager_new(val) Val_GObject_new((GObject*)val) #define GdkDisplay_val(val) check_cast(GDK_DISPLAY_OBJECT,val) #define Val_GdkDisplay(val) Val_GObject((GObject*)val) #define Val_GdkDisplay_new(val) Val_GObject_new((GObject*)val) #define GdkDisplayManager_val(val) check_cast(GDK_DISPLAY_MANAGER,val) #define Val_GdkDisplayManager(val) Val_GObject((GObject*)val) #define Val_GdkDisplayManager_new(val) Val_GObject_new((GObject*)val) #define GdkDragContext_val(val) check_cast(GDK_DRAG_CONTEXT,val) #define Val_GdkDragContext(val) Val_GObject((GObject*)val) #define Val_GdkDragContext_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GdkEventAny' */ /*TODO: conversion for record 'GdkEventButton' */ /*TODO: conversion for record 'GdkEventConfigure' */ /*TODO: conversion for record 'GdkEventCrossing' */ /*TODO: conversion for record 'GdkEventDND' */ /*TODO: conversion for record 'GdkEventExpose' */ /*TODO: conversion for record 'GdkEventFocus' */ /*TODO: conversion for record 'GdkEventGrabBroken' */ /*TODO: conversion for record 'GdkEventKey' */ /*TODO: conversion for record 'GdkEventMotion' */ /*TODO: conversion for record 'GdkEventOwnerChange' */ /*TODO: conversion for record 'GdkEventProperty' */ /*TODO: conversion for record 'GdkEventProximity' */ /*TODO: conversion for record 'GdkEventScroll' */ /*TODO: conversion for record 'GdkEventSelection' */ /*TODO: conversion for record 'GdkEventSetting' */ /*TODO: conversion for record 'GdkEventVisibility' */ /*TODO: conversion for record 'GdkEventWindowState' */ /*TODO: conversion for record 'GdkGeometry' */ #define GdkKeymap_val(val) check_cast(GDK_KEYMAP,val) #define Val_GdkKeymap(val) Val_GObject((GObject*)val) #define Val_GdkKeymap_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GdkKeymapKey' */ /*TODO: conversion for record 'GdkPoint' */ /*TODO: conversion for record 'GdkRGBA' */ #define GdkScreen_val(val) check_cast(GDK_SCREEN,val) #define Val_GdkScreen(val) Val_GObject((GObject*)val) #define Val_GdkScreen_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GdkTimeCoord' */ #define GdkVisual_val(val) check_cast(GDK_VISUAL,val) #define Val_GdkVisual(val) Val_GObject((GObject*)val) #define Val_GdkVisual_new(val) Val_GObject_new((GObject*)val) #define GdkWindow_val(val) check_cast(GDK_WINDOW,val) #define Val_GdkWindow(val) Val_GObject((GObject*)val) #define Val_GdkWindow_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GdkWindowAttr' */ /*TODO: conversion for record 'GdkWindowClass' */ /*TODO: conversion for record 'GdkWindowRedirect' */ #define GtkAboutDialog_val(val) check_cast(GTK_ABOUT_DIALOG,val) #define Val_GtkAboutDialog(val) Val_GObject((GObject*)val) #define Val_GtkAboutDialog_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAboutDialogClass' */ /*TODO: conversion for record 'GtkAboutDialogPrivate' */ #define GtkAccelGroup_val(val) check_cast(GTK_ACCEL_GROUP,val) #define Val_GtkAccelGroup(val) Val_GObject((GObject*)val) #define Val_GtkAccelGroup_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAccelGroupClass' */ /*TODO: conversion for record 'GtkAccelGroupEntry' */ /*TODO: conversion for record 'GtkAccelGroupPrivate' */ /*TODO: conversion for record 'GtkAccelKey' */ #define GtkAccelLabel_val(val) check_cast(GTK_ACCEL_LABEL,val) #define Val_GtkAccelLabel(val) Val_GObject((GObject*)val) #define Val_GtkAccelLabel_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAccelLabelClass' */ /*TODO: conversion for record 'GtkAccelLabelPrivate' */ #define GtkAccelMap_val(val) check_cast(GTK_ACCEL_MAP,val) #define Val_GtkAccelMap(val) Val_GObject((GObject*)val) #define Val_GtkAccelMap_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAccelMapClass' */ #define GtkAccessible_val(val) check_cast(GTK_ACCESSIBLE,val) #define Val_GtkAccessible(val) Val_GObject((GObject*)val) #define Val_GtkAccessible_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAccessibleClass' */ /*TODO: conversion for record 'GtkAccessiblePrivate' */ #define GtkAction_val(val) check_cast(GTK_ACTION,val) #define Val_GtkAction(val) Val_GObject((GObject*)val) #define Val_GtkAction_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkActionClass' */ /*TODO: conversion for record 'GtkActionEntry' */ #define GtkActionGroup_val(val) check_cast(GTK_ACTION_GROUP,val) #define Val_GtkActionGroup(val) Val_GObject((GObject*)val) #define Val_GtkActionGroup_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkActionGroupClass' */ /*TODO: conversion for record 'GtkActionGroupPrivate' */ /*TODO: conversion for record 'GtkActionPrivate' */ /*TODO: conversion for record 'GtkActivatableIface' */ #define GtkAdjustment_val(val) check_cast(GTK_ADJUSTMENT,val) #define Val_GtkAdjustment(val) Val_GObject((GObject*)val) #define Val_GtkAdjustment_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAdjustmentClass' */ /*TODO: conversion for record 'GtkAdjustmentPrivate' */ #define GtkAlignment_val(val) check_cast(GTK_ALIGNMENT,val) #define Val_GtkAlignment(val) Val_GObject((GObject*)val) #define Val_GtkAlignment_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAlignmentClass' */ /*TODO: conversion for record 'GtkAlignmentPrivate' */ #define GtkAppChooserButton_val(val) check_cast(GTK_APP_CHOOSER_BUTTON,val) #define Val_GtkAppChooserButton(val) Val_GObject((GObject*)val) #define Val_GtkAppChooserButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAppChooserButtonClass' */ /*TODO: conversion for record 'GtkAppChooserButtonPrivate' */ #define GtkAppChooserDialog_val(val) check_cast(GTK_APP_CHOOSER_DIALOG,val) #define Val_GtkAppChooserDialog(val) Val_GObject((GObject*)val) #define Val_GtkAppChooserDialog_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAppChooserDialogClass' */ /*TODO: conversion for record 'GtkAppChooserDialogPrivate' */ #define GtkAppChooserWidget_val(val) check_cast(GTK_APP_CHOOSER_WIDGET,val) #define Val_GtkAppChooserWidget(val) Val_GObject((GObject*)val) #define Val_GtkAppChooserWidget_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAppChooserWidgetClass' */ /*TODO: conversion for record 'GtkAppChooserWidgetPrivate' */ #define GtkApplication_val(val) check_cast(GTK_APPLICATION,val) #define Val_GtkApplication(val) Val_GObject((GObject*)val) #define Val_GtkApplication_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkApplicationClass' */ /*TODO: conversion for record 'GtkApplicationPrivate' */ #define GtkArrow_val(val) check_cast(GTK_ARROW,val) #define Val_GtkArrow(val) Val_GObject((GObject*)val) #define Val_GtkArrow_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkArrowClass' */ /*TODO: conversion for record 'GtkArrowPrivate' */ #define GtkAspectFrame_val(val) check_cast(GTK_ASPECT_FRAME,val) #define Val_GtkAspectFrame(val) Val_GObject((GObject*)val) #define Val_GtkAspectFrame_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAspectFrameClass' */ /*TODO: conversion for record 'GtkAspectFramePrivate' */ #define GtkAssistant_val(val) check_cast(GTK_ASSISTANT,val) #define Val_GtkAssistant(val) Val_GObject((GObject*)val) #define Val_GtkAssistant_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkAssistantClass' */ /*TODO: conversion for record 'GtkAssistantPrivate' */ #define GtkBin_val(val) check_cast(GTK_BIN,val) #define Val_GtkBin(val) Val_GObject((GObject*)val) #define Val_GtkBin_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkBinClass' */ /*TODO: conversion for record 'GtkBinPrivate' */ /*TODO: conversion for record 'GtkBindingArg' */ /*TODO: conversion for record 'GtkBindingEntry' */ /*TODO: conversion for record 'GtkBindingSet' */ /*TODO: conversion for record 'GtkBindingSignal' */ /*TODO: conversion for record 'GtkBorder' */ #define GtkBox_val(val) check_cast(GTK_BOX,val) #define Val_GtkBox(val) Val_GObject((GObject*)val) #define Val_GtkBox_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkBoxClass' */ /*TODO: conversion for record 'GtkBoxPrivate' */ /*TODO: conversion for record 'GtkBuildableIface' */ #define GtkBuilder_val(val) check_cast(GTK_BUILDER,val) #define Val_GtkBuilder(val) Val_GObject((GObject*)val) #define Val_GtkBuilder_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkBuilderClass' */ /*TODO: conversion for record 'GtkBuilderPrivate' */ #define GtkButton_val(val) check_cast(GTK_BUTTON,val) #define Val_GtkButton(val) Val_GObject((GObject*)val) #define Val_GtkButton_new(val) Val_GObject_new((GObject*)val) #define GtkButtonBox_val(val) check_cast(GTK_BUTTON_BOX,val) #define Val_GtkButtonBox(val) Val_GObject((GObject*)val) #define Val_GtkButtonBox_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkButtonBoxClass' */ /*TODO: conversion for record 'GtkButtonBoxPrivate' */ /*TODO: conversion for record 'GtkButtonClass' */ /*TODO: conversion for record 'GtkButtonPrivate' */ #define GtkCalendar_val(val) check_cast(GTK_CALENDAR,val) #define Val_GtkCalendar(val) Val_GObject((GObject*)val) #define Val_GtkCalendar_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCalendarClass' */ /*TODO: conversion for record 'GtkCalendarPrivate' */ #define GtkCellArea_val(val) check_cast(GTK_CELL_AREA,val) #define Val_GtkCellArea(val) Val_GObject((GObject*)val) #define Val_GtkCellArea_new(val) Val_GObject_new((GObject*)val) #define GtkCellAreaBox_val(val) check_cast(GTK_CELL_AREA_BOX,val) #define Val_GtkCellAreaBox(val) Val_GObject((GObject*)val) #define Val_GtkCellAreaBox_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCellAreaBoxClass' */ /*TODO: conversion for record 'GtkCellAreaBoxPrivate' */ /*TODO: conversion for record 'GtkCellAreaClass' */ #define GtkCellAreaContext_val(val) check_cast(GTK_CELL_AREA_CONTEXT,val) #define Val_GtkCellAreaContext(val) Val_GObject((GObject*)val) #define Val_GtkCellAreaContext_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCellAreaContextClass' */ /*TODO: conversion for record 'GtkCellAreaContextPrivate' */ /*TODO: conversion for record 'GtkCellAreaPrivate' */ /*TODO: conversion for record 'GtkCellEditableIface' */ /*TODO: conversion for record 'GtkCellLayoutIface' */ #define GtkCellRenderer_val(val) check_cast(GTK_CELL_RENDERER,val) #define Val_GtkCellRenderer(val) Val_GObject((GObject*)val) #define Val_GtkCellRenderer_new(val) Val_GObject_new((GObject*)val) #define GtkCellRendererAccel_val(val) check_cast(GTK_CELL_RENDERER_ACCEL,val) #define Val_GtkCellRendererAccel(val) Val_GObject((GObject*)val) #define Val_GtkCellRendererAccel_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCellRendererAccelClass' */ /*TODO: conversion for record 'GtkCellRendererAccelPrivate' */ /*TODO: conversion for record 'GtkCellRendererClass' */ #define GtkCellRendererCombo_val(val) check_cast(GTK_CELL_RENDERER_COMBO,val) #define Val_GtkCellRendererCombo(val) Val_GObject((GObject*)val) #define Val_GtkCellRendererCombo_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCellRendererComboClass' */ /*TODO: conversion for record 'GtkCellRendererComboPrivate' */ #define GtkCellRendererPixbuf_val(val) check_cast(GTK_CELL_RENDERER_PIXBUF,val) #define Val_GtkCellRendererPixbuf(val) Val_GObject((GObject*)val) #define Val_GtkCellRendererPixbuf_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCellRendererPixbufClass' */ /*TODO: conversion for record 'GtkCellRendererPixbufPrivate' */ /*TODO: conversion for record 'GtkCellRendererPrivate' */ #define GtkCellRendererProgress_val(val) check_cast(GTK_CELL_RENDERER_PROGRESS,val) #define Val_GtkCellRendererProgress(val) Val_GObject((GObject*)val) #define Val_GtkCellRendererProgress_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCellRendererProgressClass' */ /*TODO: conversion for record 'GtkCellRendererProgressPrivate' */ #define GtkCellRendererSpin_val(val) check_cast(GTK_CELL_RENDERER_SPIN,val) #define Val_GtkCellRendererSpin(val) Val_GObject((GObject*)val) #define Val_GtkCellRendererSpin_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCellRendererSpinClass' */ /*TODO: conversion for record 'GtkCellRendererSpinPrivate' */ #define GtkCellRendererSpinner_val(val) check_cast(GTK_CELL_RENDERER_SPINNER,val) #define Val_GtkCellRendererSpinner(val) Val_GObject((GObject*)val) #define Val_GtkCellRendererSpinner_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCellRendererSpinnerClass' */ /*TODO: conversion for record 'GtkCellRendererSpinnerPrivate' */ #define GtkCellRendererText_val(val) check_cast(GTK_CELL_RENDERER_TEXT,val) #define Val_GtkCellRendererText(val) Val_GObject((GObject*)val) #define Val_GtkCellRendererText_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCellRendererTextClass' */ /*TODO: conversion for record 'GtkCellRendererTextPrivate' */ #define GtkCellRendererToggle_val(val) check_cast(GTK_CELL_RENDERER_TOGGLE,val) #define Val_GtkCellRendererToggle(val) Val_GObject((GObject*)val) #define Val_GtkCellRendererToggle_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCellRendererToggleClass' */ /*TODO: conversion for record 'GtkCellRendererTogglePrivate' */ #define GtkCellView_val(val) check_cast(GTK_CELL_VIEW,val) #define Val_GtkCellView(val) Val_GObject((GObject*)val) #define Val_GtkCellView_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCellViewClass' */ /*TODO: conversion for record 'GtkCellViewPrivate' */ #define GtkCheckButton_val(val) check_cast(GTK_CHECK_BUTTON,val) #define Val_GtkCheckButton(val) Val_GObject((GObject*)val) #define Val_GtkCheckButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCheckButtonClass' */ #define GtkCheckMenuItem_val(val) check_cast(GTK_CHECK_MENU_ITEM,val) #define Val_GtkCheckMenuItem(val) Val_GObject((GObject*)val) #define Val_GtkCheckMenuItem_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCheckMenuItemClass' */ /*TODO: conversion for record 'GtkCheckMenuItemPrivate' */ #define GtkClipboard_val(val) check_cast(GTK_CLIPBOARD,val) #define Val_GtkClipboard(val) Val_GObject((GObject*)val) #define Val_GtkClipboard_new(val) Val_GObject_new((GObject*)val) #define GtkColorButton_val(val) check_cast(GTK_COLOR_BUTTON,val) #define Val_GtkColorButton(val) Val_GObject((GObject*)val) #define Val_GtkColorButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkColorButtonClass' */ /*TODO: conversion for record 'GtkColorButtonPrivate' */ #define GtkColorSelection_val(val) check_cast(GTK_COLOR_SELECTION,val) #define Val_GtkColorSelection(val) Val_GObject((GObject*)val) #define Val_GtkColorSelection_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkColorSelectionClass' */ #define GtkColorSelectionDialog_val(val) check_cast(GTK_COLOR_SELECTION_DIALOG,val) #define Val_GtkColorSelectionDialog(val) Val_GObject((GObject*)val) #define Val_GtkColorSelectionDialog_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkColorSelectionDialogClass' */ /*TODO: conversion for record 'GtkColorSelectionDialogPrivate' */ /*TODO: conversion for record 'GtkColorSelectionPrivate' */ #define GtkComboBox_val(val) check_cast(GTK_COMBO_BOX,val) #define Val_GtkComboBox(val) Val_GObject((GObject*)val) #define Val_GtkComboBox_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkComboBoxClass' */ /*TODO: conversion for record 'GtkComboBoxPrivate' */ #define GtkComboBoxText_val(val) check_cast(GTK_COMBO_BOX_TEXT,val) #define Val_GtkComboBoxText(val) Val_GObject((GObject*)val) #define Val_GtkComboBoxText_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkComboBoxTextClass' */ /*TODO: conversion for record 'GtkComboBoxTextPrivate' */ #define GtkContainer_val(val) check_cast(GTK_CONTAINER,val) #define Val_GtkContainer(val) Val_GObject((GObject*)val) #define Val_GtkContainer_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkContainerClass' */ /*TODO: conversion for record 'GtkContainerPrivate' */ #define GtkCssProvider_val(val) check_cast(GTK_CSS_PROVIDER,val) #define Val_GtkCssProvider(val) Val_GObject((GObject*)val) #define Val_GtkCssProvider_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkCssProviderClass' */ #define GtkDialog_val(val) check_cast(GTK_DIALOG,val) #define Val_GtkDialog(val) Val_GObject((GObject*)val) #define Val_GtkDialog_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkDialogClass' */ /*TODO: conversion for record 'GtkDialogPrivate' */ #define GtkDrawingArea_val(val) check_cast(GTK_DRAWING_AREA,val) #define Val_GtkDrawingArea(val) Val_GObject((GObject*)val) #define Val_GtkDrawingArea_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkDrawingAreaClass' */ /*TODO: conversion for record 'GtkEditableInterface' */ #define GtkEntry_val(val) check_cast(GTK_ENTRY,val) #define Val_GtkEntry(val) Val_GObject((GObject*)val) #define Val_GtkEntry_new(val) Val_GObject_new((GObject*)val) #define GtkEntryBuffer_val(val) check_cast(GTK_ENTRY_BUFFER,val) #define Val_GtkEntryBuffer(val) Val_GObject((GObject*)val) #define Val_GtkEntryBuffer_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkEntryBufferClass' */ /*TODO: conversion for record 'GtkEntryBufferPrivate' */ /*TODO: conversion for record 'GtkEntryClass' */ #define GtkEntryCompletion_val(val) check_cast(GTK_ENTRY_COMPLETION,val) #define Val_GtkEntryCompletion(val) Val_GObject((GObject*)val) #define Val_GtkEntryCompletion_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkEntryCompletionClass' */ /*TODO: conversion for record 'GtkEntryCompletionPrivate' */ /*TODO: conversion for record 'GtkEntryPrivate' */ #define GtkEventBox_val(val) check_cast(GTK_EVENT_BOX,val) #define Val_GtkEventBox(val) Val_GObject((GObject*)val) #define Val_GtkEventBox_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkEventBoxClass' */ /*TODO: conversion for record 'GtkEventBoxPrivate' */ #define GtkExpander_val(val) check_cast(GTK_EXPANDER,val) #define Val_GtkExpander(val) Val_GObject((GObject*)val) #define Val_GtkExpander_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkExpanderClass' */ /*TODO: conversion for record 'GtkExpanderPrivate' */ #define GtkFileChooserButton_val(val) check_cast(GTK_FILE_CHOOSER_BUTTON,val) #define Val_GtkFileChooserButton(val) Val_GObject((GObject*)val) #define Val_GtkFileChooserButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkFileChooserButtonClass' */ /*TODO: conversion for record 'GtkFileChooserButtonPrivate' */ #define GtkFileChooserDialog_val(val) check_cast(GTK_FILE_CHOOSER_DIALOG,val) #define Val_GtkFileChooserDialog(val) Val_GObject((GObject*)val) #define Val_GtkFileChooserDialog_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkFileChooserDialogClass' */ /*TODO: conversion for record 'GtkFileChooserDialogPrivate' */ #define GtkFileChooserWidget_val(val) check_cast(GTK_FILE_CHOOSER_WIDGET,val) #define Val_GtkFileChooserWidget(val) Val_GObject((GObject*)val) #define Val_GtkFileChooserWidget_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkFileChooserWidgetClass' */ /*TODO: conversion for record 'GtkFileChooserWidgetPrivate' */ #define GtkFileFilter_val(val) check_cast(GTK_FILE_FILTER,val) #define Val_GtkFileFilter(val) Val_GObject((GObject*)val) #define Val_GtkFileFilter_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkFileFilterInfo' */ #define GtkFixed_val(val) check_cast(GTK_FIXED,val) #define Val_GtkFixed(val) Val_GObject((GObject*)val) #define Val_GtkFixed_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkFixedChild' */ /*TODO: conversion for record 'GtkFixedClass' */ /*TODO: conversion for record 'GtkFixedPrivate' */ #define GtkFontButton_val(val) check_cast(GTK_FONT_BUTTON,val) #define Val_GtkFontButton(val) Val_GObject((GObject*)val) #define Val_GtkFontButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkFontButtonClass' */ /*TODO: conversion for record 'GtkFontButtonPrivate' */ #define GtkFontSelection_val(val) check_cast(GTK_FONT_SELECTION,val) #define Val_GtkFontSelection(val) Val_GObject((GObject*)val) #define Val_GtkFontSelection_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkFontSelectionClass' */ #define GtkFontSelectionDialog_val(val) check_cast(GTK_FONT_SELECTION_DIALOG,val) #define Val_GtkFontSelectionDialog(val) Val_GObject((GObject*)val) #define Val_GtkFontSelectionDialog_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkFontSelectionDialogClass' */ /*TODO: conversion for record 'GtkFontSelectionDialogPrivate' */ /*TODO: conversion for record 'GtkFontSelectionPrivate' */ #define GtkFrame_val(val) check_cast(GTK_FRAME,val) #define Val_GtkFrame(val) Val_GObject((GObject*)val) #define Val_GtkFrame_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkFrameClass' */ /*TODO: conversion for record 'GtkFramePrivate' */ /*TODO: conversion for record 'GtkGradient' */ #define GtkGrid_val(val) check_cast(GTK_GRID,val) #define Val_GtkGrid(val) Val_GObject((GObject*)val) #define Val_GtkGrid_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkGridClass' */ /*TODO: conversion for record 'GtkGridPrivate' */ #define GtkHBox_val(val) check_cast(GTK_H_BOX,val) #define Val_GtkHBox(val) Val_GObject((GObject*)val) #define Val_GtkHBox_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkHBoxClass' */ #define GtkHButtonBox_val(val) check_cast(GTK_H_BUTTON_BOX,val) #define Val_GtkHButtonBox(val) Val_GObject((GObject*)val) #define Val_GtkHButtonBox_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkHButtonBoxClass' */ #define GtkHPaned_val(val) check_cast(GTK_H_PANED,val) #define Val_GtkHPaned(val) Val_GObject((GObject*)val) #define Val_GtkHPaned_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkHPanedClass' */ #define GtkHSV_val(val) check_cast(GTK_HSV,val) #define Val_GtkHSV(val) Val_GObject((GObject*)val) #define Val_GtkHSV_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkHSVClass' */ /*TODO: conversion for record 'GtkHSVPrivate' */ #define GtkHScale_val(val) check_cast(GTK_H_SCALE,val) #define Val_GtkHScale(val) Val_GObject((GObject*)val) #define Val_GtkHScale_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkHScaleClass' */ #define GtkHScrollbar_val(val) check_cast(GTK_H_SCROLLBAR,val) #define Val_GtkHScrollbar(val) Val_GObject((GObject*)val) #define Val_GtkHScrollbar_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkHScrollbarClass' */ #define GtkHSeparator_val(val) check_cast(GTK_H_SEPARATOR,val) #define Val_GtkHSeparator(val) Val_GObject((GObject*)val) #define Val_GtkHSeparator_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkHSeparatorClass' */ #define GtkHandleBox_val(val) check_cast(GTK_HANDLE_BOX,val) #define Val_GtkHandleBox(val) Val_GObject((GObject*)val) #define Val_GtkHandleBox_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkHandleBoxClass' */ /*TODO: conversion for record 'GtkHandleBoxPrivate' */ #define GtkIMContext_val(val) check_cast(GTK_IM_CONTEXT,val) #define Val_GtkIMContext(val) Val_GObject((GObject*)val) #define Val_GtkIMContext_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkIMContextClass' */ /*TODO: conversion for record 'GtkIMContextInfo' */ #define GtkIMContextSimple_val(val) check_cast(GTK_I_M_CONTEXT_SIMPLE,val) #define Val_GtkIMContextSimple(val) Val_GObject((GObject*)val) #define Val_GtkIMContextSimple_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkIMContextSimpleClass' */ /*TODO: conversion for record 'GtkIMContextSimplePrivate' */ #define GtkIMMulticontext_val(val) check_cast(GTK_IM_MULTICONTEXT,val) #define Val_GtkIMMulticontext(val) Val_GObject((GObject*)val) #define Val_GtkIMMulticontext_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkIMMulticontextClass' */ /*TODO: conversion for record 'GtkIMMulticontextPrivate' */ #define GtkIconFactory_val(val) check_cast(GTK_ICON_FACTORY,val) #define Val_GtkIconFactory(val) Val_GObject((GObject*)val) #define Val_GtkIconFactory_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkIconFactoryClass' */ /*TODO: conversion for record 'GtkIconFactoryPrivate' */ /*TODO: conversion for record 'GtkIconInfo' */ /*TODO: conversion for record 'GtkIconSet' */ /*TODO: conversion for record 'GtkIconSource' */ #define GtkIconTheme_val(val) check_cast(GTK_ICON_THEME,val) #define Val_GtkIconTheme(val) Val_GObject((GObject*)val) #define Val_GtkIconTheme_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkIconThemeClass' */ /*TODO: conversion for record 'GtkIconThemePrivate' */ #define GtkIconView_val(val) check_cast(GTK_ICON_VIEW,val) #define Val_GtkIconView(val) Val_GObject((GObject*)val) #define Val_GtkIconView_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkIconViewClass' */ /*TODO: conversion for record 'GtkIconViewPrivate' */ #define GtkImage_val(val) check_cast(GTK_IMAGE,val) #define Val_GtkImage(val) Val_GObject((GObject*)val) #define Val_GtkImage_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkImageClass' */ #define GtkImageMenuItem_val(val) check_cast(GTK_IMAGE_MENU_ITEM,val) #define Val_GtkImageMenuItem(val) Val_GObject((GObject*)val) #define Val_GtkImageMenuItem_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkImageMenuItemClass' */ /*TODO: conversion for record 'GtkImageMenuItemPrivate' */ /*TODO: conversion for record 'GtkImagePrivate' */ #define GtkInfoBar_val(val) check_cast(GTK_INFO_BAR,val) #define Val_GtkInfoBar(val) Val_GObject((GObject*)val) #define Val_GtkInfoBar_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkInfoBarClass' */ /*TODO: conversion for record 'GtkInfoBarPrivate' */ #define GtkInvisible_val(val) check_cast(GTK_INVISIBLE,val) #define Val_GtkInvisible(val) Val_GObject((GObject*)val) #define Val_GtkInvisible_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkInvisibleClass' */ /*TODO: conversion for record 'GtkInvisiblePrivate' */ #define GtkLabel_val(val) check_cast(GTK_LABEL,val) #define Val_GtkLabel(val) Val_GObject((GObject*)val) #define Val_GtkLabel_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkLabelClass' */ /*TODO: conversion for record 'GtkLabelPrivate' */ /*TODO: conversion for record 'GtkLabelSelectionInfo' */ #define GtkLayout_val(val) check_cast(GTK_LAYOUT,val) #define Val_GtkLayout(val) Val_GObject((GObject*)val) #define Val_GtkLayout_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkLayoutClass' */ /*TODO: conversion for record 'GtkLayoutPrivate' */ #define GtkLinkButton_val(val) check_cast(GTK_LINK_BUTTON,val) #define Val_GtkLinkButton(val) Val_GObject((GObject*)val) #define Val_GtkLinkButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkLinkButtonClass' */ /*TODO: conversion for record 'GtkLinkButtonPrivate' */ #define GtkListStore_val(val) check_cast(GTK_LIST_STORE,val) #define Val_GtkListStore(val) Val_GObject((GObject*)val) #define Val_GtkListStore_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkListStoreClass' */ /*TODO: conversion for record 'GtkListStorePrivate' */ #define GtkMenu_val(val) check_cast(GTK_MENU,val) #define Val_GtkMenu(val) Val_GObject((GObject*)val) #define Val_GtkMenu_new(val) Val_GObject_new((GObject*)val) #define GtkMenuBar_val(val) check_cast(GTK_MENU_BAR,val) #define Val_GtkMenuBar(val) Val_GObject((GObject*)val) #define Val_GtkMenuBar_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkMenuBarClass' */ /*TODO: conversion for record 'GtkMenuBarPrivate' */ /*TODO: conversion for record 'GtkMenuClass' */ #define GtkMenuItem_val(val) check_cast(GTK_MENU_ITEM,val) #define Val_GtkMenuItem(val) Val_GObject((GObject*)val) #define Val_GtkMenuItem_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkMenuItemClass' */ /*TODO: conversion for record 'GtkMenuItemPrivate' */ /*TODO: conversion for record 'GtkMenuPrivate' */ #define GtkMenuShell_val(val) check_cast(GTK_MENU_SHELL,val) #define Val_GtkMenuShell(val) Val_GObject((GObject*)val) #define Val_GtkMenuShell_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkMenuShellClass' */ /*TODO: conversion for record 'GtkMenuShellPrivate' */ #define GtkMenuToolButton_val(val) check_cast(GTK_MENU_TOOL_BUTTON,val) #define Val_GtkMenuToolButton(val) Val_GObject((GObject*)val) #define Val_GtkMenuToolButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkMenuToolButtonClass' */ /*TODO: conversion for record 'GtkMenuToolButtonPrivate' */ #define GtkMessageDialog_val(val) check_cast(GTK_MESSAGE_DIALOG,val) #define Val_GtkMessageDialog(val) Val_GObject((GObject*)val) #define Val_GtkMessageDialog_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkMessageDialogClass' */ /*TODO: conversion for record 'GtkMessageDialogPrivate' */ #define GtkMisc_val(val) check_cast(GTK_MISC,val) #define Val_GtkMisc(val) Val_GObject((GObject*)val) #define Val_GtkMisc_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkMiscClass' */ /*TODO: conversion for record 'GtkMiscPrivate' */ #define GtkMountOperation_val(val) check_cast(GTK_MOUNT_OPERATION,val) #define Val_GtkMountOperation(val) Val_GObject((GObject*)val) #define Val_GtkMountOperation_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkMountOperationClass' */ /*TODO: conversion for record 'GtkMountOperationPrivate' */ #define GtkNotebook_val(val) check_cast(GTK_NOTEBOOK,val) #define Val_GtkNotebook(val) Val_GObject((GObject*)val) #define Val_GtkNotebook_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkNotebookClass' */ /*TODO: conversion for record 'GtkNotebookPrivate' */ #define GtkNumerableIcon_val(val) check_cast(GTK_NUMERABLE_ICON,val) #define Val_GtkNumerableIcon(val) Val_GObject((GObject*)val) #define Val_GtkNumerableIcon_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkNumerableIconClass' */ /*TODO: conversion for record 'GtkNumerableIconPrivate' */ #define GtkOffscreenWindow_val(val) check_cast(GTK_OFFSCREEN_WINDOW,val) #define Val_GtkOffscreenWindow(val) Val_GObject((GObject*)val) #define Val_GtkOffscreenWindow_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkOffscreenWindowClass' */ /*TODO: conversion for record 'GtkOrientableIface' */ /*TODO: conversion for record 'GtkPageRange' */ #define GtkPageSetup_val(val) check_cast(GTK_PAGE_SETUP,val) #define Val_GtkPageSetup(val) Val_GObject((GObject*)val) #define Val_GtkPageSetup_new(val) Val_GObject_new((GObject*)val) #define GtkPaned_val(val) check_cast(GTK_PANED,val) #define Val_GtkPaned(val) Val_GObject((GObject*)val) #define Val_GtkPaned_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkPanedClass' */ /*TODO: conversion for record 'GtkPanedPrivate' */ /*TODO: conversion for record 'GtkPaperSize' */ #define GtkPlug_val(val) check_cast(GTK_PLUG,val) #define Val_GtkPlug(val) Val_GObject((GObject*)val) #define Val_GtkPlug_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkPlugClass' */ /*TODO: conversion for record 'GtkPlugPrivate' */ #define GtkPrintContext_val(val) check_cast(GTK_PRINT_CONTEXT,val) #define Val_GtkPrintContext(val) Val_GObject((GObject*)val) #define Val_GtkPrintContext_new(val) Val_GObject_new((GObject*)val) #define GtkPrintOperation_val(val) check_cast(GTK_PRINT_OPERATION,val) #define Val_GtkPrintOperation(val) Val_GObject((GObject*)val) #define Val_GtkPrintOperation_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkPrintOperationClass' */ /*TODO: conversion for record 'GtkPrintOperationPreviewIface' */ /*TODO: conversion for record 'GtkPrintOperationPrivate' */ #define GtkPrintSettings_val(val) check_cast(GTK_PRINT_SETTINGS,val) #define Val_GtkPrintSettings(val) Val_GObject((GObject*)val) #define Val_GtkPrintSettings_new(val) Val_GObject_new((GObject*)val) #define GtkProgressBar_val(val) check_cast(GTK_PROGRESS_BAR,val) #define Val_GtkProgressBar(val) Val_GObject((GObject*)val) #define Val_GtkProgressBar_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkProgressBarClass' */ /*TODO: conversion for record 'GtkProgressBarPrivate' */ #define GtkRadioAction_val(val) check_cast(GTK_RADIO_ACTION,val) #define Val_GtkRadioAction(val) Val_GObject((GObject*)val) #define Val_GtkRadioAction_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRadioActionClass' */ /*TODO: conversion for record 'GtkRadioActionEntry' */ /*TODO: conversion for record 'GtkRadioActionPrivate' */ #define GtkRadioButton_val(val) check_cast(GTK_RADIO_BUTTON,val) #define Val_GtkRadioButton(val) Val_GObject((GObject*)val) #define Val_GtkRadioButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRadioButtonClass' */ /*TODO: conversion for record 'GtkRadioButtonPrivate' */ #define GtkRadioMenuItem_val(val) check_cast(GTK_RADIO_MENU_ITEM,val) #define Val_GtkRadioMenuItem(val) Val_GObject((GObject*)val) #define Val_GtkRadioMenuItem_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRadioMenuItemClass' */ /*TODO: conversion for record 'GtkRadioMenuItemPrivate' */ #define GtkRadioToolButton_val(val) check_cast(GTK_RADIO_TOOL_BUTTON,val) #define Val_GtkRadioToolButton(val) Val_GObject((GObject*)val) #define Val_GtkRadioToolButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRadioToolButtonClass' */ #define GtkRange_val(val) check_cast(GTK_RANGE,val) #define Val_GtkRange(val) Val_GObject((GObject*)val) #define Val_GtkRange_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRangeClass' */ /*TODO: conversion for record 'GtkRangePrivate' */ /*TODO: conversion for record 'GtkRcContext' */ /*TODO: conversion for record 'GtkRcProperty' */ #define GtkRcStyle_val(val) check_cast(GTK_RC_STYLE,val) #define Val_GtkRcStyle(val) Val_GObject((GObject*)val) #define Val_GtkRcStyle_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRcStyleClass' */ #define GtkRecentAction_val(val) check_cast(GTK_RECENT_ACTION,val) #define Val_GtkRecentAction(val) Val_GObject((GObject*)val) #define Val_GtkRecentAction_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRecentActionClass' */ /*TODO: conversion for record 'GtkRecentActionPrivate' */ #define GtkRecentChooserDialog_val(val) check_cast(GTK_RECENT_CHOOSER_DIALOG,val) #define Val_GtkRecentChooserDialog(val) Val_GObject((GObject*)val) #define Val_GtkRecentChooserDialog_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRecentChooserDialogClass' */ /*TODO: conversion for record 'GtkRecentChooserDialogPrivate' */ /*TODO: conversion for record 'GtkRecentChooserIface' */ #define GtkRecentChooserMenu_val(val) check_cast(GTK_RECENT_CHOOSER_MENU,val) #define Val_GtkRecentChooserMenu(val) Val_GObject((GObject*)val) #define Val_GtkRecentChooserMenu_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRecentChooserMenuClass' */ /*TODO: conversion for record 'GtkRecentChooserMenuPrivate' */ #define GtkRecentChooserWidget_val(val) check_cast(GTK_RECENT_CHOOSER_WIDGET,val) #define Val_GtkRecentChooserWidget(val) Val_GObject((GObject*)val) #define Val_GtkRecentChooserWidget_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRecentChooserWidgetClass' */ /*TODO: conversion for record 'GtkRecentChooserWidgetPrivate' */ /*TODO: conversion for record 'GtkRecentData' */ #define GtkRecentFilter_val(val) check_cast(GTK_RECENT_FILTER,val) #define Val_GtkRecentFilter(val) Val_GObject((GObject*)val) #define Val_GtkRecentFilter_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRecentFilterInfo' */ /*TODO: conversion for record 'GtkRecentInfo' */ #define GtkRecentManager_val(val) check_cast(GTK_RECENT_MANAGER,val) #define Val_GtkRecentManager(val) Val_GObject((GObject*)val) #define Val_GtkRecentManager_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkRecentManagerClass' */ /*TODO: conversion for record 'GtkRecentManagerPrivate' */ /*TODO: conversion for record 'GtkRequestedSize' */ /*TODO: conversion for record 'GtkRequisition' */ #define GtkScale_val(val) check_cast(GTK_SCALE,val) #define Val_GtkScale(val) Val_GObject((GObject*)val) #define Val_GtkScale_new(val) Val_GObject_new((GObject*)val) #define GtkScaleButton_val(val) check_cast(GTK_SCALE_BUTTON,val) #define Val_GtkScaleButton(val) Val_GObject((GObject*)val) #define Val_GtkScaleButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkScaleButtonClass' */ /*TODO: conversion for record 'GtkScaleButtonPrivate' */ /*TODO: conversion for record 'GtkScaleClass' */ /*TODO: conversion for record 'GtkScalePrivate' */ /*TODO: conversion for record 'GtkScrollableInterface' */ #define GtkScrollbar_val(val) check_cast(GTK_SCROLLBAR,val) #define Val_GtkScrollbar(val) Val_GObject((GObject*)val) #define Val_GtkScrollbar_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkScrollbarClass' */ #define GtkScrolledWindow_val(val) check_cast(GTK_SCROLLED_WINDOW,val) #define Val_GtkScrolledWindow(val) Val_GObject((GObject*)val) #define Val_GtkScrolledWindow_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkScrolledWindowClass' */ /*TODO: conversion for record 'GtkScrolledWindowPrivate' */ /*TODO: conversion for record 'GtkSelectionData' */ #define GtkSeparator_val(val) check_cast(GTK_SEPARATOR,val) #define Val_GtkSeparator(val) Val_GObject((GObject*)val) #define Val_GtkSeparator_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkSeparatorClass' */ #define GtkSeparatorMenuItem_val(val) check_cast(GTK_SEPARATOR_MENU_ITEM,val) #define Val_GtkSeparatorMenuItem(val) Val_GObject((GObject*)val) #define Val_GtkSeparatorMenuItem_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkSeparatorMenuItemClass' */ /*TODO: conversion for record 'GtkSeparatorPrivate' */ #define GtkSeparatorToolItem_val(val) check_cast(GTK_SEPARATOR_TOOL_ITEM,val) #define Val_GtkSeparatorToolItem(val) Val_GObject((GObject*)val) #define Val_GtkSeparatorToolItem_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkSeparatorToolItemClass' */ /*TODO: conversion for record 'GtkSeparatorToolItemPrivate' */ #define GtkSettings_val(val) check_cast(GTK_SETTINGS,val) #define Val_GtkSettings(val) Val_GObject((GObject*)val) #define Val_GtkSettings_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkSettingsClass' */ /*TODO: conversion for record 'GtkSettingsPrivate' */ /*TODO: conversion for record 'GtkSettingsValue' */ #define GtkSizeGroup_val(val) check_cast(GTK_SIZE_GROUP,val) #define Val_GtkSizeGroup(val) Val_GObject((GObject*)val) #define Val_GtkSizeGroup_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkSizeGroupClass' */ /*TODO: conversion for record 'GtkSizeGroupPrivate' */ #define GtkSocket_val(val) check_cast(GTK_SOCKET,val) #define Val_GtkSocket(val) Val_GObject((GObject*)val) #define Val_GtkSocket_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkSocketClass' */ /*TODO: conversion for record 'GtkSocketPrivate' */ #define GtkSpinButton_val(val) check_cast(GTK_SPIN_BUTTON,val) #define Val_GtkSpinButton(val) Val_GObject((GObject*)val) #define Val_GtkSpinButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkSpinButtonClass' */ /*TODO: conversion for record 'GtkSpinButtonPrivate' */ #define GtkSpinner_val(val) check_cast(GTK_SPINNER,val) #define Val_GtkSpinner(val) Val_GObject((GObject*)val) #define Val_GtkSpinner_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkSpinnerClass' */ /*TODO: conversion for record 'GtkSpinnerPrivate' */ #define GtkStatusIcon_val(val) check_cast(GTK_STATUS_ICON,val) #define Val_GtkStatusIcon(val) Val_GObject((GObject*)val) #define Val_GtkStatusIcon_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkStatusIconClass' */ /*TODO: conversion for record 'GtkStatusIconPrivate' */ #define GtkStatusbar_val(val) check_cast(GTK_STATUSBAR,val) #define Val_GtkStatusbar(val) Val_GObject((GObject*)val) #define Val_GtkStatusbar_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkStatusbarClass' */ /*TODO: conversion for record 'GtkStatusbarPrivate' */ /*TODO: conversion for record 'GtkStockItem' */ #define GtkStyle_val(val) check_cast(GTK_STYLE,val) #define Val_GtkStyle(val) Val_GObject((GObject*)val) #define Val_GtkStyle_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkStyleClass' */ #define GtkStyleContext_val(val) check_cast(GTK_STYLE_CONTEXT,val) #define Val_GtkStyleContext(val) Val_GObject((GObject*)val) #define Val_GtkStyleContext_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkStyleContextClass' */ #define GtkStyleProperties_val(val) check_cast(GTK_STYLE_PROPERTIES,val) #define Val_GtkStyleProperties(val) Val_GObject((GObject*)val) #define Val_GtkStyleProperties_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkStylePropertiesClass' */ /*TODO: conversion for record 'GtkStyleProviderIface' */ #define GtkSwitch_val(val) check_cast(GTK_SWITCH,val) #define Val_GtkSwitch(val) Val_GObject((GObject*)val) #define Val_GtkSwitch_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkSwitchClass' */ /*TODO: conversion for record 'GtkSwitchPrivate' */ /*TODO: conversion for record 'GtkSymbolicColor' */ #define GtkTable_val(val) check_cast(GTK_TABLE,val) #define Val_GtkTable(val) Val_GObject((GObject*)val) #define Val_GtkTable_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTableChild' */ /*TODO: conversion for record 'GtkTableClass' */ /*TODO: conversion for record 'GtkTablePrivate' */ /*TODO: conversion for record 'GtkTableRowCol' */ /*TODO: conversion for record 'GtkTargetEntry' */ /*TODO: conversion for record 'GtkTargetList' */ #define GtkTearoffMenuItem_val(val) check_cast(GTK_TEAROFF_MENU_ITEM,val) #define Val_GtkTearoffMenuItem(val) Val_GObject((GObject*)val) #define Val_GtkTearoffMenuItem_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTearoffMenuItemClass' */ /*TODO: conversion for record 'GtkTearoffMenuItemPrivate' */ /*TODO: conversion for record 'GtkTextAppearance' */ /*TODO: conversion for record 'GtkTextAttributes' */ /*TODO: conversion for record 'GtkTextBTree' */ #define GtkTextBuffer_val(val) check_cast(GTK_TEXT_BUFFER,val) #define Val_GtkTextBuffer(val) Val_GObject((GObject*)val) #define Val_GtkTextBuffer_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTextBufferClass' */ /*TODO: conversion for record 'GtkTextBufferPrivate' */ #define GtkTextChildAnchor_val(val) check_cast(GTK_TEXT_CHILD_ANCHOR,val) #define Val_GtkTextChildAnchor(val) Val_GObject((GObject*)val) #define Val_GtkTextChildAnchor_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTextChildAnchorClass' */ /*TODO: conversion for record 'GtkTextIter' */ #define GtkTextMark_val(val) check_cast(GTK_TEXT_MARK,val) #define Val_GtkTextMark(val) Val_GObject((GObject*)val) #define Val_GtkTextMark_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTextMarkClass' */ #define GtkTextTag_val(val) check_cast(GTK_TEXT_TAG,val) #define Val_GtkTextTag(val) Val_GObject((GObject*)val) #define Val_GtkTextTag_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTextTagClass' */ /*TODO: conversion for record 'GtkTextTagPrivate' */ #define GtkTextTagTable_val(val) check_cast(GTK_TEXT_TAG_TABLE,val) #define Val_GtkTextTagTable(val) Val_GObject((GObject*)val) #define Val_GtkTextTagTable_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTextTagTableClass' */ /*TODO: conversion for record 'GtkTextTagTablePrivate' */ #define GtkTextView_val(val) check_cast(GTK_TEXT_VIEW,val) #define Val_GtkTextView(val) Val_GObject((GObject*)val) #define Val_GtkTextView_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTextViewClass' */ /*TODO: conversion for record 'GtkTextViewPrivate' */ /*TODO: conversion for record 'GtkThemeEngine' */ #define GtkThemingEngine_val(val) check_cast(GTK_THEMING_ENGINE,val) #define Val_GtkThemingEngine(val) Val_GObject((GObject*)val) #define Val_GtkThemingEngine_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkThemingEngineClass' */ #define GtkToggleAction_val(val) check_cast(GTK_TOGGLE_ACTION,val) #define Val_GtkToggleAction(val) Val_GObject((GObject*)val) #define Val_GtkToggleAction_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkToggleActionClass' */ /*TODO: conversion for record 'GtkToggleActionEntry' */ /*TODO: conversion for record 'GtkToggleActionPrivate' */ #define GtkToggleButton_val(val) check_cast(GTK_TOGGLE_BUTTON,val) #define Val_GtkToggleButton(val) Val_GObject((GObject*)val) #define Val_GtkToggleButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkToggleButtonClass' */ /*TODO: conversion for record 'GtkToggleButtonPrivate' */ #define GtkToggleToolButton_val(val) check_cast(GTK_TOGGLE_TOOL_BUTTON,val) #define Val_GtkToggleToolButton(val) Val_GObject((GObject*)val) #define Val_GtkToggleToolButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkToggleToolButtonClass' */ /*TODO: conversion for record 'GtkToggleToolButtonPrivate' */ #define GtkToolButton_val(val) check_cast(GTK_TOOL_BUTTON,val) #define Val_GtkToolButton(val) Val_GObject((GObject*)val) #define Val_GtkToolButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkToolButtonClass' */ /*TODO: conversion for record 'GtkToolButtonPrivate' */ #define GtkToolItem_val(val) check_cast(GTK_TOOL_ITEM,val) #define Val_GtkToolItem(val) Val_GObject((GObject*)val) #define Val_GtkToolItem_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkToolItemClass' */ #define GtkToolItemGroup_val(val) check_cast(GTK_TOOL_ITEM_GROUP,val) #define Val_GtkToolItemGroup(val) Val_GObject((GObject*)val) #define Val_GtkToolItemGroup_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkToolItemGroupClass' */ /*TODO: conversion for record 'GtkToolItemGroupPrivate' */ /*TODO: conversion for record 'GtkToolItemPrivate' */ #define GtkToolPalette_val(val) check_cast(GTK_TOOL_PALETTE,val) #define Val_GtkToolPalette(val) Val_GObject((GObject*)val) #define Val_GtkToolPalette_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkToolPaletteClass' */ /*TODO: conversion for record 'GtkToolPalettePrivate' */ /*TODO: conversion for record 'GtkToolShellIface' */ #define GtkToolbar_val(val) check_cast(GTK_TOOLBAR,val) #define Val_GtkToolbar(val) Val_GObject((GObject*)val) #define Val_GtkToolbar_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkToolbarClass' */ /*TODO: conversion for record 'GtkToolbarPrivate' */ #define GtkTooltip_val(val) check_cast(GTK_TOOLTIP,val) #define Val_GtkTooltip(val) Val_GObject((GObject*)val) #define Val_GtkTooltip_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTreeDragDestIface' */ /*TODO: conversion for record 'GtkTreeDragSourceIface' */ /*TODO: conversion for record 'GtkTreeIter' */ #define GtkTreeModelFilter_val(val) check_cast(GTK_TREE_MODEL_FILTER,val) #define Val_GtkTreeModelFilter(val) Val_GObject((GObject*)val) #define Val_GtkTreeModelFilter_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTreeModelFilterClass' */ /*TODO: conversion for record 'GtkTreeModelFilterPrivate' */ /*TODO: conversion for record 'GtkTreeModelIface' */ #define GtkTreeModelSort_val(val) check_cast(GTK_TREE_MODEL_SORT,val) #define Val_GtkTreeModelSort(val) Val_GObject((GObject*)val) #define Val_GtkTreeModelSort_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTreeModelSortClass' */ /*TODO: conversion for record 'GtkTreeModelSortPrivate' */ /*TODO: conversion for record 'GtkTreePath' */ /*TODO: conversion for record 'GtkTreeRowReference' */ #define GtkTreeSelection_val(val) check_cast(GTK_TREE_SELECTION,val) #define Val_GtkTreeSelection(val) Val_GObject((GObject*)val) #define Val_GtkTreeSelection_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTreeSelectionClass' */ /*TODO: conversion for record 'GtkTreeSelectionPrivate' */ /*TODO: conversion for record 'GtkTreeSortableIface' */ #define GtkTreeStore_val(val) check_cast(GTK_TREE_STORE,val) #define Val_GtkTreeStore(val) Val_GObject((GObject*)val) #define Val_GtkTreeStore_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTreeStoreClass' */ /*TODO: conversion for record 'GtkTreeStorePrivate' */ #define GtkTreeView_val(val) check_cast(GTK_TREE_VIEW,val) #define Val_GtkTreeView(val) Val_GObject((GObject*)val) #define Val_GtkTreeView_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTreeViewClass' */ #define GtkTreeViewColumn_val(val) check_cast(GTK_TREE_VIEW_COLUMN,val) #define Val_GtkTreeViewColumn(val) Val_GObject((GObject*)val) #define Val_GtkTreeViewColumn_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkTreeViewColumnClass' */ /*TODO: conversion for record 'GtkTreeViewColumnPrivate' */ /*TODO: conversion for record 'GtkTreeViewPrivate' */ #define GtkUIManager_val(val) check_cast(GTK_UI_MANAGER,val) #define Val_GtkUIManager(val) Val_GObject((GObject*)val) #define Val_GtkUIManager_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkUIManagerClass' */ /*TODO: conversion for record 'GtkUIManagerPrivate' */ #define GtkVBox_val(val) check_cast(GTK_V_BOX,val) #define Val_GtkVBox(val) Val_GObject((GObject*)val) #define Val_GtkVBox_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkVBoxClass' */ #define GtkVButtonBox_val(val) check_cast(GTK_V_BUTTON_BOX,val) #define Val_GtkVButtonBox(val) Val_GObject((GObject*)val) #define Val_GtkVButtonBox_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkVButtonBoxClass' */ #define GtkVPaned_val(val) check_cast(GTK_V_PANED,val) #define Val_GtkVPaned(val) Val_GObject((GObject*)val) #define Val_GtkVPaned_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkVPanedClass' */ #define GtkVScale_val(val) check_cast(GTK_V_SCALE,val) #define Val_GtkVScale(val) Val_GObject((GObject*)val) #define Val_GtkVScale_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkVScaleClass' */ #define GtkVScrollbar_val(val) check_cast(GTK_V_SCROLLBAR,val) #define Val_GtkVScrollbar(val) Val_GObject((GObject*)val) #define Val_GtkVScrollbar_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkVScrollbarClass' */ #define GtkVSeparator_val(val) check_cast(GTK_V_SEPARATOR,val) #define Val_GtkVSeparator(val) Val_GObject((GObject*)val) #define Val_GtkVSeparator_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkVSeparatorClass' */ #define GtkViewport_val(val) check_cast(GTK_VIEWPORT,val) #define Val_GtkViewport(val) Val_GObject((GObject*)val) #define Val_GtkViewport_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkViewportClass' */ /*TODO: conversion for record 'GtkViewportPrivate' */ #define GtkVolumeButton_val(val) check_cast(GTK_VOLUME_BUTTON,val) #define Val_GtkVolumeButton(val) Val_GObject((GObject*)val) #define Val_GtkVolumeButton_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkVolumeButtonClass' */ #define GtkWidget_val(val) check_cast(GTK_WIDGET,val) #define Val_GtkWidget(val) Val_GObject((GObject*)val) #define Val_GtkWidget_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkWidgetAuxInfo' */ /*TODO: conversion for record 'GtkWidgetClass' */ /*TODO: conversion for record 'GtkWidgetPath' */ /*TODO: conversion for record 'GtkWidgetPrivate' */ #define GtkWindow_val(val) check_cast(GTK_WINDOW,val) #define Val_GtkWindow(val) Val_GObject((GObject*)val) #define Val_GtkWindow_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkWindowClass' */ /*TODO: conversion for record 'GtkWindowGeometryInfo' */ #define GtkWindowGroup_val(val) check_cast(GTK_WINDOW_GROUP,val) #define Val_GtkWindowGroup(val) Val_GObject((GObject*)val) #define Val_GtkWindowGroup_new(val) Val_GObject_new((GObject*)val) /*TODO: conversion for record 'GtkWindowGroupClass' */ /*TODO: conversion for record 'GtkWindowGroupPrivate' */ /*TODO: conversion for record 'GtkWindowPrivate' */ #include <gio/gio.h> #include "../wrappers.h" #include "../ml_gobject.h" /* Module ZlibDecompressorClass */ /* end of ZlibDecompressorClass */ /* Module ZlibDecompressor */ ML_1(g_zlib_decompressor_get_file_info,GZlibDecompressor_val, Val_GFileInfo) /* end of ZlibDecompressor */ /* Module ZlibCompressorClass */ /* end of ZlibCompressorClass */ /* Module ZlibCompressor */ ML_2(g_zlib_compressor_set_file_info,GZlibCompressor_val, Option_val(arg2,GFileInfo_val,NULL) Ignore, Unit) ML_1(g_zlib_compressor_get_file_info,GZlibCompressor_val, Val_GFileInfo) /* end of ZlibCompressor */ /* Module VolumeMonitorClass */ /* end of VolumeMonitorClass */ /* Module VolumeMonitor */ ML_1(g_volume_monitor_get_volumes,GVolumeMonitor_val, Val_GList_new) ML_1(g_volume_monitor_get_mounts,GVolumeMonitor_val, Val_GList_new) ML_1(g_volume_monitor_get_connected_drives,GVolumeMonitor_val, Val_GList_new) ML_0(g_volume_monitor_get,Val_GVolumeMonitor_new) /* end of VolumeMonitor */ /* Module VolumeIface */ /* end of VolumeIface */ /* Module VfsClass */ /* end of VfsClass */ /* Module Vfs */ ML_1(g_vfs_is_active,GVfs_val, Val_bool) ML_0(g_vfs_get_local,Val_GVfs) ML_0(g_vfs_get_default,Val_GVfs) /* end of Vfs */ /* Module UnixSocketAddressPrivate */ /* end of UnixSocketAddressPrivate */ /* Module UnixSocketAddressClass */ /* end of UnixSocketAddressClass */ /* Module UnixSocketAddress */ ML_1(g_unix_socket_address_get_path_len,GUnixSocketAddress_val, Val_int) ML_1(g_unix_socket_address_get_path,GUnixSocketAddress_val, Val_string) ML_1(g_unix_socket_address_get_is_abstract,GUnixSocketAddress_val, Val_bool) ML_0(g_unix_socket_address_abstract_names_supported,Val_bool) /* end of UnixSocketAddress */ /* Module UnixOutputStreamPrivate */ /* end of UnixOutputStreamPrivate */ /* Module UnixOutputStreamClass */ /* end of UnixOutputStreamClass */ /* Module UnixOutputStream */ ML_2(g_unix_output_stream_set_close_fd,GUnixOutputStream_val, Bool_val, Unit) ML_1(g_unix_output_stream_get_fd,GUnixOutputStream_val, Val_int) ML_1(g_unix_output_stream_get_close_fd,GUnixOutputStream_val, Val_bool) /* end of UnixOutputStream */ /* Module UnixMountPoint */ ML_1(g_unix_mount_point_is_user_mountable,GUnixMountPoint_val, Val_bool) ML_1(g_unix_mount_point_is_readonly,GUnixMountPoint_val, Val_bool) ML_1(g_unix_mount_point_is_loopback,GUnixMountPoint_val, Val_bool) ML_1(g_unix_mount_point_guess_name,GUnixMountPoint_val, Val_string_new) ML_1(g_unix_mount_point_guess_can_eject,GUnixMountPoint_val, Val_bool) ML_1(g_unix_mount_point_get_mount_path,GUnixMountPoint_val, Val_string) ML_1(g_unix_mount_point_get_fs_type,GUnixMountPoint_val, Val_string) ML_1(g_unix_mount_point_get_device_path,GUnixMountPoint_val, Val_string) ML_1(g_unix_mount_point_free,GUnixMountPoint_val, Unit) ML_2(g_unix_mount_point_compare,GUnixMountPoint_val, GUnixMountPoint_val, Val_int) /* end of UnixMountPoint */ /* Module UnixMountMonitorClass */ /* end of UnixMountMonitorClass */ /* Module UnixMountMonitor */ ML_2(g_unix_mount_monitor_set_rate_limit,GUnixMountMonitor_val, Int_val, Unit) /* end of UnixMountMonitor */ /* Module UnixMountEntry */ /* end of UnixMountEntry */ /* Module UnixInputStreamPrivate */ /* end of UnixInputStreamPrivate */ /* Module UnixInputStreamClass */ /* end of UnixInputStreamClass */ /* Module UnixInputStream */ ML_2(g_unix_input_stream_set_close_fd,GUnixInputStream_val, Bool_val, Unit) ML_1(g_unix_input_stream_get_fd,GUnixInputStream_val, Val_int) ML_1(g_unix_input_stream_get_close_fd,GUnixInputStream_val, Val_bool) /* end of UnixInputStream */ /* Module UnixFDMessagePrivate */ /* end of UnixFDMessagePrivate */ /* Module UnixFDMessageClass */ /* end of UnixFDMessageClass */ /* Module UnixFDMessage */ ML_1(g_unix_fd_message_get_fd_list,GUnixFDMessage_val, Val_GUnixFDList) /* end of UnixFDMessage */ /* Module UnixFDListPrivate */ /* end of UnixFDListPrivate */ /* Module UnixFDListClass */ /* end of UnixFDListClass */ /* Module UnixFDList */ ML_1(g_unix_fd_list_get_length,GUnixFDList_val, Val_int) /* end of UnixFDList */ /* Module UnixCredentialsMessagePrivate */ /* end of UnixCredentialsMessagePrivate */ /* Module UnixCredentialsMessageClass */ /* end of UnixCredentialsMessageClass */ /* Module UnixCredentialsMessage */ ML_1(g_unix_credentials_message_get_credentials,GUnixCredentialsMessage_val, Val_GCredentials) ML_0(g_unix_credentials_message_is_supported,Val_bool) /* end of UnixCredentialsMessage */ /* Module UnixConnectionPrivate */ /* end of UnixConnectionPrivate */ /* Module UnixConnectionClass */ /* end of UnixConnectionClass */ /* Module UnixConnection */ /* end of UnixConnection */ /* Module TlsServerContext */ /* end of TlsServerContext */ /* Module TlsServerConnectionInterface */ /* end of TlsServerConnectionInterface */ /* Module TlsContext */ /* end of TlsContext */ /* Module TlsConnectionPrivate */ /* end of TlsConnectionPrivate */ /* Module TlsConnectionClass */ /* end of TlsConnectionClass */ /* Module TlsConnection */ ML_2(g_tls_connection_set_use_system_certdb,GTlsConnection_val, Bool_val, Unit) ML_2(g_tls_connection_set_require_close_notify,GTlsConnection_val, Bool_val, Unit) ML_2(g_tls_connection_set_certificate,GTlsConnection_val, GTlsCertificate_val, Unit) ML_1(g_tls_connection_get_use_system_certdb,GTlsConnection_val, Val_bool) ML_1(g_tls_connection_get_require_close_notify,GTlsConnection_val, Val_bool) ML_1(g_tls_connection_get_peer_certificate,GTlsConnection_val, Val_GTlsCertificate) ML_1(g_tls_connection_get_certificate,GTlsConnection_val, Val_GTlsCertificate) /* end of TlsConnection */ /* Module TlsClientContext */ /* end of TlsClientContext */ /* Module TlsClientConnectionInterface */ /* end of TlsClientConnectionInterface */ /* Module TlsCertificatePrivate */ /* end of TlsCertificatePrivate */ /* Module TlsCertificateClass */ /* end of TlsCertificateClass */ /* Module TlsCertificate */ ML_1(g_tls_certificate_get_issuer,GTlsCertificate_val, Val_GTlsCertificate) /* end of TlsCertificate */ /* Module TlsBackendInterface */ /* end of TlsBackendInterface */ /* Module ThreadedSocketServicePrivate */ /* end of ThreadedSocketServicePrivate */ /* Module ThreadedSocketServiceClass */ /* end of ThreadedSocketServiceClass */ /* Module ThreadedSocketService */ /* end of ThreadedSocketService */ /* Module ThemedIconClass */ /* end of ThemedIconClass */ /* Module ThemedIcon */ ML_2(g_themed_icon_prepend_name,GThemedIcon_val, String_val, Unit) ML_2(g_themed_icon_append_name,GThemedIcon_val, String_val, Unit) /* end of ThemedIcon */ /* Module TcpWrapperConnectionPrivate */ /* end of TcpWrapperConnectionPrivate */ /* Module TcpWrapperConnectionClass */ /* end of TcpWrapperConnectionClass */ /* Module TcpWrapperConnection */ ML_1(g_tcp_wrapper_connection_get_base_io_stream,GTcpWrapperConnection_val, Val_GIOStream) /* end of TcpWrapperConnection */ /* Module TcpConnectionPrivate */ /* end of TcpConnectionPrivate */ /* Module TcpConnectionClass */ /* end of TcpConnectionClass */ /* Module TcpConnection */ ML_2(g_tcp_connection_set_graceful_disconnect,GTcpConnection_val, Bool_val, Unit) ML_1(g_tcp_connection_get_graceful_disconnect,GTcpConnection_val, Val_bool) /* end of TcpConnection */ /* Module SrvTarget */ ML_1(g_srv_target_get_weight,GSrvTarget_val, Val_int) ML_1(g_srv_target_get_priority,GSrvTarget_val, Val_int) ML_1(g_srv_target_get_port,GSrvTarget_val, Val_int) ML_1(g_srv_target_get_hostname,GSrvTarget_val, Val_string) ML_1(g_srv_target_free,GSrvTarget_val, Unit) ML_1(g_srv_target_copy,GSrvTarget_val, Val_GSrvTarget_new) /* end of SrvTarget */ /* Module SocketServicePrivate */ /* end of SocketServicePrivate */ /* Module SocketServiceClass */ /* end of SocketServiceClass */ /* Module SocketService */ ML_1(g_socket_service_stop,GSocketService_val, Unit) ML_1(g_socket_service_start,GSocketService_val, Unit) ML_1(g_socket_service_is_active,GSocketService_val, Val_bool) /* end of SocketService */ /* Module SocketPrivate */ /* end of SocketPrivate */ /* Module SocketListenerPrivate */ /* end of SocketListenerPrivate */ /* Module SocketListenerClass */ /* end of SocketListenerClass */ /* Module SocketListener */ ML_2(g_socket_listener_set_backlog,GSocketListener_val, Int_val, Unit) ML_1(g_socket_listener_close,GSocketListener_val, Unit) /* end of SocketListener */ /* Module SocketControlMessagePrivate */ /* end of SocketControlMessagePrivate */ /* Module SocketControlMessageClass */ /* end of SocketControlMessageClass */ /* Module SocketControlMessage */ ML_1(g_socket_control_message_get_size,GSocketControlMessage_val, Val_int) ML_1(g_socket_control_message_get_msg_type,GSocketControlMessage_val, Val_int) ML_1(g_socket_control_message_get_level,GSocketControlMessage_val, Val_int) /* end of SocketControlMessage */ /* Module SocketConnectionPrivate */ /* end of SocketConnectionPrivate */ /* Module SocketConnectionClass */ /* end of SocketConnectionClass */ /* Module SocketConnection */ ML_1(g_socket_connection_get_socket,GSocketConnection_val, Val_GSocket) /* end of SocketConnection */ /* Module SocketConnectableIface */ /* end of SocketConnectableIface */ /* Module SocketClientPrivate */ /* end of SocketClientPrivate */ /* Module SocketClientClass */ /* end of SocketClientClass */ /* Module SocketClient */ ML_2(g_socket_client_set_tls,GSocketClient_val, Bool_val, Unit) ML_2(g_socket_client_set_timeout,GSocketClient_val, Int_val, Unit) ML_2(g_socket_client_set_local_address,GSocketClient_val, GSocketAddress_val, Unit) ML_2(g_socket_client_set_enable_proxy,GSocketClient_val, Bool_val, Unit) ML_1(g_socket_client_get_tls,GSocketClient_val, Val_bool) ML_1(g_socket_client_get_timeout,GSocketClient_val, Val_int) ML_1(g_socket_client_get_local_address,GSocketClient_val, Val_GSocketAddress) ML_1(g_socket_client_get_enable_proxy,GSocketClient_val, Val_bool) ML_2(g_socket_client_add_application_proxy,GSocketClient_val, String_val, Unit) /* end of SocketClient */ /* Module SocketClass */ /* end of SocketClass */ /* Module SocketAddressEnumeratorClass */ /* end of SocketAddressEnumeratorClass */ /* Module SocketAddressEnumerator */ /* end of SocketAddressEnumerator */ /* Module SocketAddressClass */ /* end of SocketAddressClass */ /* Module SocketAddress */ ML_1(g_socket_address_get_native_size,GSocketAddress_val, Val_int) /* end of SocketAddress */ /* Module Socket */ ML_1(g_socket_speaks_ipv4,GSocket_val, Val_bool) ML_2(g_socket_set_timeout,GSocket_val, Int_val, Unit) ML_2(g_socket_set_listen_backlog,GSocket_val, Int_val, Unit) ML_2(g_socket_set_keepalive,GSocket_val, Bool_val, Unit) ML_2(g_socket_set_blocking,GSocket_val, Bool_val, Unit) ML_1(g_socket_is_connected,GSocket_val, Val_bool) ML_1(g_socket_is_closed,GSocket_val, Val_bool) ML_1(g_socket_get_timeout,GSocket_val, Val_int) ML_1(g_socket_get_listen_backlog,GSocket_val, Val_int) ML_1(g_socket_get_keepalive,GSocket_val, Val_bool) ML_1(g_socket_get_fd,GSocket_val, Val_int) ML_1(g_socket_get_blocking,GSocket_val, Val_bool) ML_1(g_socket_connection_factory_create_connection,GSocket_val, Val_GSocketConnection_new) /* end of Socket */ /* Module SimplePermission */ /* end of SimplePermission */ /* Module SimpleAsyncResultClass */ /* end of SimpleAsyncResultClass */ /* Module SimpleAsyncResult */ ML_2(g_simple_async_result_take_error,GSimpleAsyncResult_val, GError_val, Unit) ML_2(g_simple_async_result_set_op_res_gssize,GSimpleAsyncResult_val, Int_val, Unit) ML_2(g_simple_async_result_set_op_res_gboolean,GSimpleAsyncResult_val, Bool_val, Unit) ML_2(g_simple_async_result_set_handle_cancellation,GSimpleAsyncResult_val, Bool_val, Unit) ML_2(g_simple_async_result_set_from_error,GSimpleAsyncResult_val, GError_val, Unit) ML_1(g_simple_async_result_get_op_res_gssize,GSimpleAsyncResult_val, Val_int) ML_1(g_simple_async_result_get_op_res_gboolean,GSimpleAsyncResult_val, Val_bool) ML_1(g_simple_async_result_complete_in_idle,GSimpleAsyncResult_val, Unit) ML_1(g_simple_async_result_complete,GSimpleAsyncResult_val, Unit) /* end of SimpleAsyncResult */ /* Module SimpleActionPrivate */ /* end of SimpleActionPrivate */ /* Module SimpleActionGroupPrivate */ /* end of SimpleActionGroupPrivate */ /* Module SimpleActionGroupClass */ /* end of SimpleActionGroupClass */ /* Module SimpleActionGroup */ ML_2(g_simple_action_group_remove,GSimpleActionGroup_val, String_val, Unit) /* end of SimpleActionGroup */ /* Module SimpleActionClass */ /* end of SimpleActionClass */ /* Module SimpleAction */ ML_2(g_simple_action_set_enabled,GSimpleAction_val, Bool_val, Unit) /* end of SimpleAction */ /* Module SettingsPrivate */ /* end of SettingsPrivate */ /* Module SettingsClass */ /* end of SettingsClass */ /* Module SettingsBackend */ /* end of SettingsBackend */ /* Module Settings */ ML_3(g_settings_set_value,GSettings_val, String_val, GVariant_val, Val_bool) ML_3(g_settings_set_string,GSettings_val, String_val, String_val, Val_bool) ML_3(g_settings_set_int,GSettings_val, String_val, Int_val, Val_bool) ML_3(g_settings_set_flags,GSettings_val, String_val, Int_val, Val_bool) ML_3(g_settings_set_enum,GSettings_val, String_val, Int_val, Val_bool) ML_3(g_settings_set_double,GSettings_val, String_val, Double_val, Val_bool) ML_3(g_settings_set_boolean,GSettings_val, String_val, Bool_val, Val_bool) ML_1(g_settings_revert,GSettings_val, Unit) ML_2(g_settings_reset,GSettings_val, String_val, Unit) ML_3(g_settings_range_check,GSettings_val, String_val, GVariant_val, Val_bool) ML_2(g_settings_is_writable,GSettings_val, String_val, Val_bool) ML_2(g_settings_get_value,GSettings_val, String_val, Val_GVariant_new) ML_2(g_settings_get_string,GSettings_val, String_val, Val_string_new) ML_2(g_settings_get_range,GSettings_val, String_val, Val_GVariant_new) ML_2(g_settings_get_int,GSettings_val, String_val, Val_int) ML_1(g_settings_get_has_unapplied,GSettings_val, Val_bool) ML_2(g_settings_get_flags,GSettings_val, String_val, Val_int) ML_2(g_settings_get_enum,GSettings_val, String_val, Val_int) ML_2(g_settings_get_double,GSettings_val, String_val, Val_double) ML_2(g_settings_get_child,GSettings_val, String_val, Val_GSettings_new) ML_2(g_settings_get_boolean,GSettings_val, String_val, Val_bool) ML_1(g_settings_delay,GSettings_val, Unit) ML_1(g_settings_apply,GSettings_val, Unit) ML_0(g_settings_sync,Unit) /* end of Settings */ /* Module SeekableIface */ /* end of SeekableIface */ /* Module ResolverPrivate */ /* end of ResolverPrivate */ /* Module ResolverClass */ /* end of ResolverClass */ /* Module Resolver */ ML_1(g_resolver_set_default,GResolver_val, Unit) ML_0(g_resolver_get_default,Val_GResolver_new) ML_1(g_resolver_free_targets,GList_val, Unit) ML_1(g_resolver_free_addresses,GList_val, Unit) /* end of Resolver */ /* Module ProxyResolverInterface */ /* end of ProxyResolverInterface */ /* Module ProxyInterface */ /* end of ProxyInterface */ /* Module ProxyAddressPrivate */ /* end of ProxyAddressPrivate */ /* Module ProxyAddressEnumeratorPrivate */ /* end of ProxyAddressEnumeratorPrivate */ /* Module ProxyAddressEnumeratorClass */ /* end of ProxyAddressEnumeratorClass */ /* Module ProxyAddressEnumerator */ /* end of ProxyAddressEnumerator */ /* Module ProxyAddressClass */ /* end of ProxyAddressClass */ /* Module ProxyAddress */ ML_1(g_proxy_address_get_username,GProxyAddress_val, Val_string) ML_1(g_proxy_address_get_protocol,GProxyAddress_val, Val_string) ML_1(g_proxy_address_get_password,GProxyAddress_val, Val_string) ML_1(g_proxy_address_get_destination_port,GProxyAddress_val, Val_int) ML_1(g_proxy_address_get_destination_hostname,GProxyAddress_val, Val_string) /* end of ProxyAddress */ /* Module PollableOutputStreamInterface */ /* end of PollableOutputStreamInterface */ /* Module PollableInputStreamInterface */ /* end of PollableInputStreamInterface */ /* Module PermissionPrivate */ /* end of PermissionPrivate */ /* Module PermissionClass */ /* end of PermissionClass */ /* Module Permission */ ML_4(g_permission_impl_update,GPermission_val, Bool_val, Bool_val, Bool_val, Unit) ML_1(g_permission_get_can_release,GPermission_val, Val_bool) ML_1(g_permission_get_can_acquire,GPermission_val, Val_bool) ML_1(g_permission_get_allowed,GPermission_val, Val_bool) /* end of Permission */ /* Module OutputVector */ /* end of OutputVector */ /* Module OutputStreamPrivate */ /* end of OutputStreamPrivate */ /* Module OutputStreamClass */ /* end of OutputStreamClass */ /* Module OutputStream */ ML_1(g_output_stream_is_closing,GOutputStream_val, Val_bool) ML_1(g_output_stream_is_closed,GOutputStream_val, Val_bool) ML_1(g_output_stream_has_pending,GOutputStream_val, Val_bool) ML_1(g_output_stream_clear_pending,GOutputStream_val, Unit) /* end of OutputStream */ /* Module NetworkServicePrivate */ /* end of NetworkServicePrivate */ /* Module NetworkServiceClass */ /* end of NetworkServiceClass */ /* Module NetworkService */ ML_2(g_network_service_set_scheme,GNetworkService_val, String_val, Unit) ML_1(g_network_service_get_service,GNetworkService_val, Val_string) ML_1(g_network_service_get_scheme,GNetworkService_val, Val_string) ML_1(g_network_service_get_protocol,GNetworkService_val, Val_string) ML_1(g_network_service_get_domain,GNetworkService_val, Val_string) /* end of NetworkService */ /* Module NetworkAddressPrivate */ /* end of NetworkAddressPrivate */ /* Module NetworkAddressClass */ /* end of NetworkAddressClass */ /* Module NetworkAddress */ ML_1(g_network_address_get_scheme,GNetworkAddress_val, Val_string) ML_1(g_network_address_get_port,GNetworkAddress_val, Val_int) ML_1(g_network_address_get_hostname,GNetworkAddress_val, Val_string) /* end of NetworkAddress */ /* Module NativeVolumeMonitorClass */ /* end of NativeVolumeMonitorClass */ /* Module NativeVolumeMonitor */ /* end of NativeVolumeMonitor */ /* Module MountOperationPrivate */ /* end of MountOperationPrivate */ /* Module MountOperationClass */ /* end of MountOperationClass */ /* Module MountOperation */ ML_2(g_mount_operation_set_username,GMountOperation_val, String_val, Unit) ML_2(g_mount_operation_set_password,GMountOperation_val, String_val, Unit) ML_2(g_mount_operation_set_domain,GMountOperation_val, String_val, Unit) ML_2(g_mount_operation_set_choice,GMountOperation_val, Int_val, Unit) ML_2(g_mount_operation_set_anonymous,GMountOperation_val, Bool_val, Unit) ML_1(g_mount_operation_get_username,GMountOperation_val, Val_string) ML_1(g_mount_operation_get_password,GMountOperation_val, Val_string) ML_1(g_mount_operation_get_domain,GMountOperation_val, Val_string) ML_1(g_mount_operation_get_choice,GMountOperation_val, Val_int) ML_1(g_mount_operation_get_anonymous,GMountOperation_val, Val_bool) /* end of MountOperation */ /* Module MountIface */ /* end of MountIface */ /* Module MemoryOutputStreamPrivate */ /* end of MemoryOutputStreamPrivate */ /* Module MemoryOutputStreamClass */ /* end of MemoryOutputStreamClass */ /* Module MemoryOutputStream */ ML_1(g_memory_output_stream_get_size,GMemoryOutputStream_val, Val_int) ML_1(g_memory_output_stream_get_data_size,GMemoryOutputStream_val, Val_int) /* end of MemoryOutputStream */ /* Module MemoryInputStreamPrivate */ /* end of MemoryInputStreamPrivate */ /* Module MemoryInputStreamClass */ /* end of MemoryInputStreamClass */ /* Module MemoryInputStream */ /* end of MemoryInputStream */ /* Module LoadableIconIface */ /* end of LoadableIconIface */ /* Module InputVector */ /* end of InputVector */ /* Module InputStreamPrivate */ /* end of InputStreamPrivate */ /* Module InputStreamClass */ /* end of InputStreamClass */ /* Module InputStream */ ML_1(g_input_stream_is_closed,GInputStream_val, Val_bool) ML_1(g_input_stream_has_pending,GInputStream_val, Val_bool) ML_1(g_input_stream_clear_pending,GInputStream_val, Unit) /* end of InputStream */ /* Module InitableIface */ /* end of InitableIface */ /* Module InetSocketAddressPrivate */ /* end of InetSocketAddressPrivate */ /* Module InetSocketAddressClass */ /* end of InetSocketAddressClass */ /* Module InetSocketAddress */ ML_1(g_inet_socket_address_get_port,GInetSocketAddress_val, Val_int) ML_1(g_inet_socket_address_get_address,GInetSocketAddress_val, Val_GInetAddress) /* end of InetSocketAddress */ /* Module InetAddressPrivate */ /* end of InetAddressPrivate */ /* Module InetAddressClass */ /* end of InetAddressClass */ /* Module InetAddress */ ML_1(g_inet_address_to_string,GInetAddress_val, Val_string_new) ML_1(g_inet_address_get_native_size,GInetAddress_val, Val_int) ML_1(g_inet_address_get_is_site_local,GInetAddress_val, Val_bool) ML_1(g_inet_address_get_is_multicast,GInetAddress_val, Val_bool) ML_1(g_inet_address_get_is_mc_site_local,GInetAddress_val, Val_bool) ML_1(g_inet_address_get_is_mc_org_local,GInetAddress_val, Val_bool) ML_1(g_inet_address_get_is_mc_node_local,GInetAddress_val, Val_bool) ML_1(g_inet_address_get_is_mc_link_local,GInetAddress_val, Val_bool) ML_1(g_inet_address_get_is_mc_global,GInetAddress_val, Val_bool) ML_1(g_inet_address_get_is_loopback,GInetAddress_val, Val_bool) ML_1(g_inet_address_get_is_link_local,GInetAddress_val, Val_bool) ML_1(g_inet_address_get_is_any,GInetAddress_val, Val_bool) /* end of InetAddress */ /* Module IconIface */ /* end of IconIface */ /* Module IOStreamPrivate */ /* end of IOStreamPrivate */ /* Module IOStreamClass */ /* end of IOStreamClass */ /* Module IOStreamAdapter */ /* end of IOStreamAdapter */ /* Module IOStream */ ML_1(g_io_stream_is_closed,GIOStream_val, Val_bool) ML_1(g_io_stream_has_pending,GIOStream_val, Val_bool) ML_1(g_io_stream_get_output_stream,GIOStream_val, Val_GOutputStream) ML_1(g_io_stream_get_input_stream,GIOStream_val, Val_GInputStream) ML_1(g_io_stream_clear_pending,GIOStream_val, Unit) /* end of IOStream */ /* Module IOSchedulerJob */ /* end of IOSchedulerJob */ /* Module IOModuleClass */ /* end of IOModuleClass */ /* Module IOModule */ ML_1(g_io_module_unload,GIOModule_val, Unit) ML_1(g_io_module_load,GIOModule_val, Unit) /* end of IOModule */ /* Module IOExtensionPoint */ ML_2(g_io_extension_point_set_required_type,GIOExtensionPoint_val, Int_val, Unit) ML_1(g_io_extension_point_get_required_type,GIOExtensionPoint_val, Val_int) ML_1(g_io_extension_point_get_extensions,GIOExtensionPoint_val, Val_GList) ML_2(g_io_extension_point_get_extension_by_name,GIOExtensionPoint_val, String_val, Val_GIOExtension) /* end of IOExtensionPoint */ /* Module IOExtension */ ML_1(g_io_extension_ref_class,GIOExtension_val, Val_GTypeClass_new) ML_1(g_io_extension_get_priority,GIOExtension_val, Val_int) ML_1(g_io_extension_get_name,GIOExtension_val, Val_string) /* end of IOExtension */ /* Module FilterOutputStreamClass */ /* end of FilterOutputStreamClass */ /* Module FilterOutputStream */ ML_2(g_filter_output_stream_set_close_base_stream,GFilterOutputStream_val, Bool_val, Unit) ML_1(g_filter_output_stream_get_close_base_stream,GFilterOutputStream_val, Val_bool) ML_1(g_filter_output_stream_get_base_stream,GFilterOutputStream_val, Val_GOutputStream) /* end of FilterOutputStream */ /* Module FilterInputStreamClass */ /* end of FilterInputStreamClass */ /* Module FilterInputStream */ ML_2(g_filter_input_stream_set_close_base_stream,GFilterInputStream_val, Bool_val, Unit) ML_1(g_filter_input_stream_get_close_base_stream,GFilterInputStream_val, Val_bool) ML_1(g_filter_input_stream_get_base_stream,GFilterInputStream_val, Val_GInputStream) /* end of FilterInputStream */ /* Module FilenameCompleterClass */ /* end of FilenameCompleterClass */ /* Module FilenameCompleter */ ML_2(g_filename_completer_set_dirs_only,GFilenameCompleter_val, Bool_val, Unit) ML_2(g_filename_completer_get_completion_suffix,GFilenameCompleter_val, String_val, Val_string_new) /* end of FilenameCompleter */ /* Module FileOutputStreamPrivate */ /* end of FileOutputStreamPrivate */ /* Module FileOutputStreamClass */ /* end of FileOutputStreamClass */ /* Module FileOutputStream */ ML_1(g_file_output_stream_get_etag,GFileOutputStream_val, Val_string_new) /* end of FileOutputStream */ /* Module FileMonitorPrivate */ /* end of FileMonitorPrivate */ /* Module FileMonitorClass */ /* end of FileMonitorClass */ /* Module FileMonitor */ ML_2(g_file_monitor_set_rate_limit,GFileMonitor_val, Int_val, Unit) ML_1(g_file_monitor_is_cancelled,GFileMonitor_val, Val_bool) ML_1(g_file_monitor_cancel,GFileMonitor_val, Val_bool) /* end of FileMonitor */ /* Module FileInputStreamPrivate */ /* end of FileInputStreamPrivate */ /* Module FileInputStreamClass */ /* end of FileInputStreamClass */ /* Module FileInputStream */ /* end of FileInputStream */ /* Module FileInfoClass */ /* end of FileInfoClass */ /* Module FileInfo */ ML_1(g_file_info_unset_attribute_mask,GFileInfo_val, Unit) ML_2(g_file_info_set_symlink_target,GFileInfo_val, String_val, Unit) ML_2(g_file_info_set_sort_order,GFileInfo_val, Int32_val, Unit) ML_2(g_file_info_set_name,GFileInfo_val, String_val, Unit) ML_2(g_file_info_set_modification_time,GFileInfo_val, GTimeVal_val, Unit) ML_2(g_file_info_set_is_symlink,GFileInfo_val, Bool_val, Unit) ML_2(g_file_info_set_is_hidden,GFileInfo_val, Bool_val, Unit) ML_2(g_file_info_set_edit_name,GFileInfo_val, String_val, Unit) ML_2(g_file_info_set_display_name,GFileInfo_val, String_val, Unit) ML_2(g_file_info_set_content_type,GFileInfo_val, String_val, Unit) ML_3(g_file_info_set_attribute_uint64,GFileInfo_val, String_val, Int64_val, Unit) ML_3(g_file_info_set_attribute_uint32,GFileInfo_val, String_val, Int32_val, Unit) ML_3(g_file_info_set_attribute_string,GFileInfo_val, String_val, String_val, Unit) ML_2(g_file_info_set_attribute_mask,GFileInfo_val, GFileAttributeMatcher_val, Unit) ML_3(g_file_info_set_attribute_int64,GFileInfo_val, String_val, Int64_val, Unit) ML_3(g_file_info_set_attribute_int32,GFileInfo_val, String_val, Int32_val, Unit) ML_3(g_file_info_set_attribute_byte_string,GFileInfo_val, String_val, String_val, Unit) ML_3(g_file_info_set_attribute_boolean,GFileInfo_val, String_val, Bool_val, Unit) ML_2(g_file_info_remove_attribute,GFileInfo_val, String_val, Unit) ML_2(g_file_info_has_namespace,GFileInfo_val, String_val, Val_bool) ML_2(g_file_info_has_attribute,GFileInfo_val, String_val, Val_bool) ML_1(g_file_info_get_symlink_target,GFileInfo_val, Val_string) ML_1(g_file_info_get_sort_order,GFileInfo_val, Val_int32) ML_1(g_file_info_get_name,GFileInfo_val, Val_string) ML_2(g_file_info_get_modification_time,GFileInfo_val, GTimeVal_val, Unit) ML_1(g_file_info_get_is_symlink,GFileInfo_val, Val_bool) ML_1(g_file_info_get_is_hidden,GFileInfo_val, Val_bool) ML_1(g_file_info_get_is_backup,GFileInfo_val, Val_bool) ML_1(g_file_info_get_etag,GFileInfo_val, Val_string) ML_1(g_file_info_get_edit_name,GFileInfo_val, Val_string) ML_1(g_file_info_get_display_name,GFileInfo_val, Val_string) ML_1(g_file_info_get_content_type,GFileInfo_val, Val_string) ML_2(g_file_info_get_attribute_uint64,GFileInfo_val, String_val, Val_int64) ML_2(g_file_info_get_attribute_uint32,GFileInfo_val, String_val, Val_int32) ML_2(g_file_info_get_attribute_string,GFileInfo_val, String_val, Val_string) ML_2(g_file_info_get_attribute_int64,GFileInfo_val, String_val, Val_int64) ML_2(g_file_info_get_attribute_int32,GFileInfo_val, String_val, Val_int32) ML_2(g_file_info_get_attribute_byte_string,GFileInfo_val, String_val, Val_string) ML_2(g_file_info_get_attribute_boolean,GFileInfo_val, String_val, Val_bool) ML_2(g_file_info_get_attribute_as_string,GFileInfo_val, String_val, Val_string_new) ML_1(g_file_info_dup,GFileInfo_val, Val_GFileInfo_new) ML_2(g_file_info_copy_into,GFileInfo_val, GFileInfo_val, Unit) ML_1(g_file_info_clear_status,GFileInfo_val, Unit) /* end of FileInfo */ /* Module FileIface */ /* end of FileIface */ /* Module FileIconClass */ /* end of FileIconClass */ /* Module FileIcon */ /* end of FileIcon */ /* Module FileIOStreamPrivate */ /* end of FileIOStreamPrivate */ /* Module FileIOStreamClass */ /* end of FileIOStreamClass */ /* Module FileIOStream */ ML_1(g_file_io_stream_get_etag,GFileIOStream_val, Val_string_new) /* end of FileIOStream */ /* Module FileEnumeratorPrivate */ /* end of FileEnumeratorPrivate */ /* Module FileEnumeratorClass */ /* end of FileEnumeratorClass */ /* Module FileEnumerator */ ML_2(g_file_enumerator_set_pending,GFileEnumerator_val, Bool_val, Unit) ML_1(g_file_enumerator_is_closed,GFileEnumerator_val, Val_bool) ML_1(g_file_enumerator_has_pending,GFileEnumerator_val, Val_bool) /* end of FileEnumerator */ /* Module FileDescriptorBasedIface */ /* end of FileDescriptorBasedIface */ /* Module FileAttributeMatcher */ ML_1(g_file_attribute_matcher_unref,GFileAttributeMatcher_val, Unit) ML_1(g_file_attribute_matcher_ref,GFileAttributeMatcher_val, Val_GFileAttributeMatcher_new) ML_2(g_file_attribute_matcher_matches_only,GFileAttributeMatcher_val, String_val, Val_bool) ML_2(g_file_attribute_matcher_matches,GFileAttributeMatcher_val, String_val, Val_bool) ML_1(g_file_attribute_matcher_enumerate_next,GFileAttributeMatcher_val, Val_string) ML_2(g_file_attribute_matcher_enumerate_namespace,GFileAttributeMatcher_val, String_val, Val_bool) /* end of FileAttributeMatcher */ /* Module FileAttributeInfoList */ ML_1(g_file_attribute_info_list_unref,GFileAttributeInfoList_val, Unit) ML_1(g_file_attribute_info_list_ref,GFileAttributeInfoList_val, Val_GFileAttributeInfoList_new) ML_2(g_file_attribute_info_list_lookup,GFileAttributeInfoList_val, String_val, Val_GFileAttributeInfo) ML_1(g_file_attribute_info_list_dup,GFileAttributeInfoList_val, Val_GFileAttributeInfoList_new) /* end of FileAttributeInfoList */ /* Module FileAttributeInfo */ /* end of FileAttributeInfo */ /* Module EmblemedIconPrivate */ /* end of EmblemedIconPrivate */ /* Module EmblemedIconClass */ /* end of EmblemedIconClass */ /* Module EmblemedIcon */ ML_1(g_emblemed_icon_get_emblems,GEmblemedIcon_val, Val_GList) ML_1(g_emblemed_icon_clear_emblems,GEmblemedIcon_val, Unit) ML_2(g_emblemed_icon_add_emblem,GEmblemedIcon_val, GEmblem_val, Unit) /* end of EmblemedIcon */ /* Module EmblemClass */ /* end of EmblemClass */ /* Module Emblem */ /* end of Emblem */ /* Module DriveIface */ /* end of DriveIface */ /* Module DesktopAppInfoLookupIface */ /* end of DesktopAppInfoLookupIface */ /* Module DesktopAppInfoLaunchHandlerIface */ /* end of DesktopAppInfoLaunchHandlerIface */ /* Module DesktopAppInfoClass */ /* end of DesktopAppInfoClass */ /* Module DesktopAppInfo */ ML_1(g_desktop_app_info_get_is_hidden,GDesktopAppInfo_val, Val_bool) ML_1(g_desktop_app_info_get_filename,GDesktopAppInfo_val, Val_string) ML_1(g_desktop_app_info_set_desktop_env,String_val, Unit) /* end of DesktopAppInfo */ /* Module DataOutputStreamPrivate */ /* end of DataOutputStreamPrivate */ /* Module DataOutputStreamClass */ /* end of DataOutputStreamClass */ /* Module DataOutputStream */ /* end of DataOutputStream */ /* Module DataInputStreamPrivate */ /* end of DataInputStreamPrivate */ /* Module DataInputStreamClass */ /* end of DataInputStreamClass */ /* Module DataInputStream */ /* end of DataInputStream */ /* Module DBusSubtreeVTable */ /* end of DBusSubtreeVTable */ /* Module DBusSignalInfo */ ML_1(g_dbus_signal_info_unref,GDBusSignalInfo_val, Unit) ML_1(g_dbus_signal_info_ref,GDBusSignalInfo_val, Val_GDBusSignalInfo_new) /* end of DBusSignalInfo */ /* Module DBusServer */ ML_1(g_dbus_server_stop,GDBusServer_val, Unit) ML_1(g_dbus_server_start,GDBusServer_val, Unit) ML_1(g_dbus_server_is_active,GDBusServer_val, Val_bool) ML_1(g_dbus_server_get_guid,GDBusServer_val, Val_string) ML_1(g_dbus_server_get_client_address,GDBusServer_val, Val_string) /* end of DBusServer */ /* Module DBusProxyPrivate */ /* end of DBusProxyPrivate */ /* Module DBusProxyClass */ /* end of DBusProxyClass */ /* Module DBusProxy */ ML_2(g_dbus_proxy_set_interface_info,GDBusProxy_val, GDBusInterfaceInfo_val, Unit) ML_2(g_dbus_proxy_set_default_timeout,GDBusProxy_val, Int_val, Unit) ML_3(g_dbus_proxy_set_cached_property,GDBusProxy_val, String_val, GVariant_val, Unit) ML_1(g_dbus_proxy_get_object_path,GDBusProxy_val, Val_string) ML_1(g_dbus_proxy_get_name_owner,GDBusProxy_val, Val_string_new) ML_1(g_dbus_proxy_get_name,GDBusProxy_val, Val_string) ML_1(g_dbus_proxy_get_interface_name,GDBusProxy_val, Val_string) ML_1(g_dbus_proxy_get_interface_info,GDBusProxy_val, Val_GDBusInterfaceInfo_new) ML_1(g_dbus_proxy_get_default_timeout,GDBusProxy_val, Val_int) ML_1(g_dbus_proxy_get_connection,GDBusProxy_val, Val_GDBusConnection) ML_2(g_dbus_proxy_get_cached_property,GDBusProxy_val, String_val, Val_GVariant_new) /* end of DBusProxy */ /* Module DBusPropertyInfo */ ML_1(g_dbus_property_info_unref,GDBusPropertyInfo_val, Unit) ML_1(g_dbus_property_info_ref,GDBusPropertyInfo_val, Val_GDBusPropertyInfo_new) /* end of DBusPropertyInfo */ /* Module DBusNodeInfo */ ML_1(g_dbus_node_info_unref,GDBusNodeInfo_val, Unit) ML_1(g_dbus_node_info_ref,GDBusNodeInfo_val, Val_GDBusNodeInfo_new) ML_2(g_dbus_node_info_lookup_interface,GDBusNodeInfo_val, String_val, Val_GDBusInterfaceInfo_new) ML_3(g_dbus_node_info_generate_xml,GDBusNodeInfo_val, Int_val, GString_val, Unit) /* end of DBusNodeInfo */ /* Module DBusMethodInvocation */ ML_2(g_dbus_method_invocation_return_value,GDBusMethodInvocation_val, GVariant_val, Unit) ML_2(g_dbus_method_invocation_return_gerror,GDBusMethodInvocation_val, GError_val, Unit) ML_4(g_dbus_method_invocation_return_error_literal,GDBusMethodInvocation_val, Int32_val, Int_val, String_val, Unit) ML_3(g_dbus_method_invocation_return_dbus_error,GDBusMethodInvocation_val, String_val, String_val, Unit) ML_1(g_dbus_method_invocation_get_sender,GDBusMethodInvocation_val, Val_string) ML_1(g_dbus_method_invocation_get_parameters,GDBusMethodInvocation_val, Val_GVariant_new) ML_1(g_dbus_method_invocation_get_object_path,GDBusMethodInvocation_val, Val_string) ML_1(g_dbus_method_invocation_get_method_name,GDBusMethodInvocation_val, Val_string) ML_1(g_dbus_method_invocation_get_method_info,GDBusMethodInvocation_val, Val_GDBusMethodInfo) ML_1(g_dbus_method_invocation_get_message,GDBusMethodInvocation_val, Val_GDBusMessage) ML_1(g_dbus_method_invocation_get_interface_name,GDBusMethodInvocation_val, Val_string) ML_1(g_dbus_method_invocation_get_connection,GDBusMethodInvocation_val, Val_GDBusConnection) /* end of DBusMethodInvocation */ /* Module DBusMethodInfo */ ML_1(g_dbus_method_info_unref,GDBusMethodInfo_val, Unit) ML_1(g_dbus_method_info_ref,GDBusMethodInfo_val, Val_GDBusMethodInfo_new) /* end of DBusMethodInfo */ /* Module DBusMessage */ ML_2(g_dbus_message_set_unix_fd_list,GDBusMessage_val, Option_val(arg2,GUnixFDList_val,NULL) Ignore, Unit) ML_2(g_dbus_message_set_signature,GDBusMessage_val, String_val, Unit) ML_2(g_dbus_message_set_serial,GDBusMessage_val, Int32_val, Unit) ML_2(g_dbus_message_set_sender,GDBusMessage_val, String_val, Unit) ML_2(g_dbus_message_set_reply_serial,GDBusMessage_val, Int32_val, Unit) ML_2(g_dbus_message_set_path,GDBusMessage_val, String_val, Unit) ML_2(g_dbus_message_set_num_unix_fds,GDBusMessage_val, Int32_val, Unit) ML_2(g_dbus_message_set_member,GDBusMessage_val, String_val, Unit) ML_2(g_dbus_message_set_interface,GDBusMessage_val, String_val, Unit) ML_2(g_dbus_message_set_error_name,GDBusMessage_val, String_val, Unit) ML_2(g_dbus_message_set_destination,GDBusMessage_val, String_val, Unit) ML_2(g_dbus_message_set_body,GDBusMessage_val, GVariant_val, Unit) ML_2(g_dbus_message_print,GDBusMessage_val, Int_val, Val_string_new) ML_1(g_dbus_message_new_method_reply,GDBusMessage_val, Val_GDBusMessage_new) ML_3(g_dbus_message_new_method_error_literal,GDBusMessage_val, String_val, String_val, Val_GDBusMessage_new) ML_1(g_dbus_message_lock,GDBusMessage_val, Unit) ML_1(g_dbus_message_get_unix_fd_list,GDBusMessage_val, Val_GUnixFDList) ML_1(g_dbus_message_get_signature,GDBusMessage_val, Val_string) ML_1(g_dbus_message_get_serial,GDBusMessage_val, Val_int32) ML_1(g_dbus_message_get_sender,GDBusMessage_val, Val_string) ML_1(g_dbus_message_get_reply_serial,GDBusMessage_val, Val_int32) ML_1(g_dbus_message_get_path,GDBusMessage_val, Val_string) ML_1(g_dbus_message_get_num_unix_fds,GDBusMessage_val, Val_int32) ML_1(g_dbus_message_get_member,GDBusMessage_val, Val_string) ML_1(g_dbus_message_get_locked,GDBusMessage_val, Val_bool) ML_1(g_dbus_message_get_interface,GDBusMessage_val, Val_string) ML_1(g_dbus_message_get_header_fields,GDBusMessage_val, Val_string) ML_1(g_dbus_message_get_error_name,GDBusMessage_val, Val_string) ML_1(g_dbus_message_get_destination,GDBusMessage_val, Val_string) ML_1(g_dbus_message_get_body,GDBusMessage_val, Val_GVariant_new) ML_1(g_dbus_message_get_arg0,GDBusMessage_val, Val_string) /* end of DBusMessage */ /* Module DBusInterfaceVTable */ /* end of DBusInterfaceVTable */ /* Module DBusInterfaceInfo */ ML_1(g_dbus_interface_info_unref,GDBusInterfaceInfo_val, Unit) ML_1(g_dbus_interface_info_ref,GDBusInterfaceInfo_val, Val_GDBusInterfaceInfo_new) ML_2(g_dbus_interface_info_lookup_signal,GDBusInterfaceInfo_val, String_val, Val_GDBusSignalInfo_new) ML_2(g_dbus_interface_info_lookup_property,GDBusInterfaceInfo_val, String_val, Val_GDBusPropertyInfo_new) ML_2(g_dbus_interface_info_lookup_method,GDBusInterfaceInfo_val, String_val, Val_GDBusMethodInfo_new) ML_3(g_dbus_interface_info_generate_xml,GDBusInterfaceInfo_val, Int_val, GString_val, Unit) /* end of DBusInterfaceInfo */ /* Module DBusErrorEntry */ /* end of DBusErrorEntry */ /* Module DBusConnection */ ML_2(g_dbus_connection_unregister_subtree,GDBusConnection_val, Int_val, Val_bool) ML_2(g_dbus_connection_unregister_object,GDBusConnection_val, Int_val, Val_bool) ML_1(g_dbus_connection_start_message_processing,GDBusConnection_val, Unit) ML_2(g_dbus_connection_signal_unsubscribe,GDBusConnection_val, Int_val, Unit) ML_2(g_dbus_connection_set_exit_on_close,GDBusConnection_val, Bool_val, Unit) ML_2(g_dbus_connection_remove_filter,GDBusConnection_val, Int_val, Unit) ML_1(g_dbus_connection_is_closed,GDBusConnection_val, Val_bool) ML_1(g_dbus_connection_get_unique_name,GDBusConnection_val, Val_string) ML_1(g_dbus_connection_get_stream,GDBusConnection_val, Val_GIOStream) ML_1(g_dbus_connection_get_peer_credentials,GDBusConnection_val, Val_GCredentials) ML_1(g_dbus_connection_get_guid,GDBusConnection_val, Val_string) ML_1(g_dbus_connection_get_exit_on_close,GDBusConnection_val, Val_bool) /* end of DBusConnection */ /* Module DBusAuthObserver */ ML_3(g_dbus_auth_observer_authorize_authenticated_peer,GDBusAuthObserver_val, GIOStream_val, GCredentials_val, Val_bool) /* end of DBusAuthObserver */ /* Module DBusArgInfo */ ML_1(g_dbus_arg_info_unref,GDBusArgInfo_val, Unit) ML_1(g_dbus_arg_info_ref,GDBusArgInfo_val, Val_GDBusArgInfo_new) /* end of DBusArgInfo */ /* Module DBusAnnotationInfo */ ML_1(g_dbus_annotation_info_unref,GDBusAnnotationInfo_val, Unit) ML_1(g_dbus_annotation_info_ref,GDBusAnnotationInfo_val, Val_GDBusAnnotationInfo_new) /* end of DBusAnnotationInfo */ /* Module CredentialsClass */ /* end of CredentialsClass */ /* Module Credentials */ ML_1(g_credentials_to_string,GCredentials_val, Val_string_new) /* end of Credentials */ /* Module ConverterOutputStreamPrivate */ /* end of ConverterOutputStreamPrivate */ /* Module ConverterOutputStreamClass */ /* end of ConverterOutputStreamClass */ /* Module ConverterOutputStream */ /* end of ConverterOutputStream */ /* Module ConverterInputStreamPrivate */ /* end of ConverterInputStreamPrivate */ /* Module ConverterInputStreamClass */ /* end of ConverterInputStreamClass */ /* Module ConverterInputStream */ /* end of ConverterInputStream */ /* Module ConverterIface */ /* end of ConverterIface */ /* Module CharsetConverterClass */ /* end of CharsetConverterClass */ /* Module CharsetConverter */ ML_2(g_charset_converter_set_use_fallback,GCharsetConverter_val, Bool_val, Unit) ML_1(g_charset_converter_get_use_fallback,GCharsetConverter_val, Val_bool) ML_1(g_charset_converter_get_num_fallbacks,GCharsetConverter_val, Val_int) /* end of CharsetConverter */ /* Module CancellablePrivate */ /* end of CancellablePrivate */ /* Module CancellableClass */ /* end of CancellableClass */ /* Module Cancellable */ ML_1(g_cancellable_source_new,GCancellable_val, Val_GSource_new) ML_1(g_cancellable_reset,GCancellable_val, Unit) ML_1(g_cancellable_release_fd,GCancellable_val, Unit) ML_1(g_cancellable_push_current,GCancellable_val, Unit) ML_1(g_cancellable_pop_current,GCancellable_val, Unit) ML_2(g_cancellable_make_pollfd,GCancellable_val, GPollFD_val, Val_bool) ML_1(g_cancellable_is_cancelled,GCancellable_val, Val_bool) ML_1(g_cancellable_get_fd,GCancellable_val, Val_int) ML_2(g_cancellable_disconnect,GCancellable_val, Double_val, Unit) ML_1(g_cancellable_cancel,GCancellable_val, Unit) ML_0(g_cancellable_get_current,Val_GCancellable) /* end of Cancellable */ /* Module BufferedOutputStreamPrivate */ /* end of BufferedOutputStreamPrivate */ /* Module BufferedOutputStreamClass */ /* end of BufferedOutputStreamClass */ /* Module BufferedOutputStream */ ML_2(g_buffered_output_stream_set_buffer_size,GBufferedOutputStream_val, Int_val, Unit) ML_2(g_buffered_output_stream_set_auto_grow,GBufferedOutputStream_val, Bool_val, Unit) ML_1(g_buffered_output_stream_get_buffer_size,GBufferedOutputStream_val, Val_int) ML_1(g_buffered_output_stream_get_auto_grow,GBufferedOutputStream_val, Val_bool) /* end of BufferedOutputStream */ /* Module BufferedInputStreamPrivate */ /* end of BufferedInputStreamPrivate */ /* Module BufferedInputStreamClass */ /* end of BufferedInputStreamClass */ /* Module BufferedInputStream */ ML_2(g_buffered_input_stream_set_buffer_size,GBufferedInputStream_val, Int_val, Unit) ML_1(g_buffered_input_stream_get_buffer_size,GBufferedInputStream_val, Val_int) ML_1(g_buffered_input_stream_get_available,GBufferedInputStream_val, Val_int) /* end of BufferedInputStream */ /* Module AsyncResultIface */ /* end of AsyncResultIface */ /* Module AsyncInitableIface */ /* end of AsyncInitableIface */ /* Module ApplicationPrivate */ /* end of ApplicationPrivate */ /* Module ApplicationCommandLinePrivate */ /* end of ApplicationCommandLinePrivate */ /* Module ApplicationCommandLineClass */ /* end of ApplicationCommandLineClass */ /* Module ApplicationCommandLine */ ML_2(g_application_command_line_set_exit_status,GApplicationCommandLine_val, Int_val, Unit) ML_2(g_application_command_line_getenv,GApplicationCommandLine_val, String_val, Val_string) ML_1(g_application_command_line_get_platform_data,GApplicationCommandLine_val, Val_GVariant_new) ML_1(g_application_command_line_get_is_remote,GApplicationCommandLine_val, Val_bool) ML_1(g_application_command_line_get_exit_status,GApplicationCommandLine_val, Val_int) ML_1(g_application_command_line_get_cwd,GApplicationCommandLine_val, Val_string) /* end of ApplicationCommandLine */ /* Module ApplicationClass */ /* end of ApplicationClass */ /* Module Application */ ML_2(g_application_set_inactivity_timeout,GApplication_val, Int_val, Unit) ML_2(g_application_set_application_id,GApplication_val, String_val, Unit) ML_1(g_application_release,GApplication_val, Unit) ML_1(g_application_hold,GApplication_val, Unit) ML_1(g_application_get_is_remote,GApplication_val, Val_bool) ML_1(g_application_get_is_registered,GApplication_val, Val_bool) ML_1(g_application_get_inactivity_timeout,GApplication_val, Val_int) ML_1(g_application_get_application_id,GApplication_val, Val_string) ML_1(g_application_activate,GApplication_val, Unit) ML_1(g_application_id_is_valid,String_val, Val_bool) /* end of Application */ /* Module AppLaunchContextPrivate */ /* end of AppLaunchContextPrivate */ /* Module AppLaunchContextClass */ /* end of AppLaunchContextClass */ /* Module AppLaunchContext */ ML_2(g_app_launch_context_launch_failed,GAppLaunchContext_val, String_val, Unit) /* end of AppLaunchContext */ /* Module AppInfoIface */ /* end of AppInfoIface */ /* Module ActionInterface */ /* end of ActionInterface */ /* Module ActionGroupInterface */ /* end of ActionGroupInterface */ /* Global functions */ ML_1(g_unix_mounts_changed_since,Int64_val, Val_bool) ML_1(g_unix_mount_points_changed_since,Int64_val, Val_bool) ML_1(g_unix_mount_is_system_internal,GUnixMountEntry_val, Val_bool) ML_1(g_unix_mount_is_readonly,GUnixMountEntry_val, Val_bool) ML_1(g_unix_mount_guess_should_display,GUnixMountEntry_val, Val_bool) ML_1(g_unix_mount_guess_name,GUnixMountEntry_val, Val_string_new) ML_1(g_unix_mount_guess_can_eject,GUnixMountEntry_val, Val_bool) ML_1(g_unix_mount_get_mount_path,GUnixMountEntry_val, Val_string) ML_1(g_unix_mount_get_fs_type,GUnixMountEntry_val, Val_string) ML_1(g_unix_mount_get_device_path,GUnixMountEntry_val, Val_string) ML_1(g_unix_mount_free,GUnixMountEntry_val, Unit) ML_2(g_unix_mount_compare,GUnixMountEntry_val, GUnixMountEntry_val, Val_int) ML_1(g_unix_is_mount_path_system_internal,String_val, Val_bool) ML_0(g_tls_error_quark,Val_int32) ML_1(g_srv_target_list_sort,GList_val, Val_GList_new) ML_0(g_resolver_error_quark,Val_int32) ML_0(g_io_scheduler_cancel_all_jobs,Unit) ML_1(g_io_modules_scan_all_in_directory,String_val, Unit) ML_1(g_io_modules_load_all_in_directory,String_val, Val_GList_new) ML_1(g_io_extension_point_register,String_val, Val_GIOExtensionPoint) ML_1(g_io_extension_point_lookup,String_val, Val_GIOExtensionPoint) ML_4(g_io_extension_point_implement,String_val, Int_val, String_val, Int_val, Val_GIOExtension) ML_1(g_io_extension_get_type,GIOExtension_val, Val_int) ML_0(g_io_error_quark,Val_int32) ML_1(g_dbus_is_unique_name,String_val, Val_bool) ML_1(g_dbus_is_name,String_val, Val_bool) ML_1(g_dbus_is_member_name,String_val, Val_bool) ML_1(g_dbus_is_interface_name,String_val, Val_bool) ML_1(g_dbus_is_guid,String_val, Val_bool) ML_1(g_dbus_is_address,String_val, Val_bool) ML_0(g_dbus_generate_guid,Val_string_new) ML_3(g_dbus_error_unregister_error,Int32_val, Int_val, String_val, Val_bool) ML_1(g_dbus_error_strip_remote_error,GError_val, Val_bool) ML_3(g_dbus_error_register_error,Int32_val, Int_val, String_val, Val_bool) ML_0(g_dbus_error_quark,Val_int32) ML_2(g_dbus_error_new_for_dbus_error,String_val, String_val, Val_GError) ML_1(g_dbus_error_is_remote_error,GError_val, Val_bool) ML_1(g_dbus_error_get_remote_error,GError_val, Val_string_new) ML_1(g_dbus_error_encode_gerror,GError_val, Val_string_new) ML_0(g_content_types_get_registered,Val_GList_new) ML_1(g_content_type_is_unknown,String_val, Val_bool) ML_2(g_content_type_is_a,String_val, String_val, Val_bool) ML_1(g_content_type_get_mime_type,String_val, Val_string_new) ML_1(g_content_type_get_description,String_val, Val_string_new) ML_1(g_content_type_from_mime_type,String_val, Val_string_new) ML_2(g_content_type_equals,String_val, String_val, Val_bool) ML_1(g_content_type_can_be_executable,String_val, Val_bool) ML_1(g_bus_unwatch_name,Int_val, Unit) ML_1(g_bus_unown_name,Int_val, Unit) ML_1(g_app_info_reset_type_associations,String_val, Unit) ML_1(g_app_info_get_recommended_for_type,String_val, Val_GList_new) ML_1(g_app_info_get_fallback_for_type,String_val, Val_GList_new) ML_1(g_app_info_get_all_for_type,String_val, Val_GList_new) ML_0(g_app_info_get_all,Val_GList_new) /* End of global functions */
ground.mli
open Colibri2_popop_lib open Nodes module All : sig type ty = { app : Expr.Ty.Const.t; args : ty list } type term = { app : Expr.Term.Const.t; tyargs : ty list; args : Node.t IArray.t; ty : ty; } end module Subst : sig type ty = All.ty Expr.Ty.Var.M.t [@@deriving show, hash, ord, eq] type t = { term : Node.t Expr.Term.Var.M.t; ty : ty } include Colibri2_popop_lib.Popop_stdlib.Datatype with type t := t val empty : t val distinct_union : t -> t -> t val map_repr : _ Egraph.t -> t -> t end module Ty : sig type t = All.ty = { app : Expr.Ty.Const.t; args : t list } include Colibri2_popop_lib.Popop_stdlib.Datatype with type t := t val convert : Subst.ty -> Expr.Ty.t -> t val prop : t (** The type of propositions *) val bool : t (** Alias for {!prop}. *) val unit : t (** The unit type. *) val base : t (** An arbitrary type. *) val int : t (** The type of integers *) val rat : t (** The type of rationals *) val real : t (** The type of reals. *) val array : t -> t -> t (** The type of strings *) val string : t (** The type of strings *) val string_reg_lang : t (** The type of regular language over strings. *) val definition : Expr.Ty.Const.t -> Expr.Ty.def end module Term : sig type t = All.term = { app : Expr.Term.Const.t; tyargs : Ty.t list; args : Node.t IArray.t; ty : Ty.t; } include Colibri2_popop_lib.Popop_stdlib.Datatype with type t := t end type s = All.term = { app : Expr.Term.Const.t; tyargs : Ty.t list; args : Node.t IArray.t; ty : Ty.t; } include RegisteredThTerm with type s := Term.t val convert : ?subst:Subst.t -> _ Egraph.t -> Expr.Term.t -> Node.t val apply : _ Egraph.t -> Expr.Term.Const.t -> Ty.t list -> Node.t IArray.t -> Term.t val init : Egraph.wt -> unit val register_converter : Egraph.wt -> (Egraph.wt -> t -> unit) -> unit (** register callback called for each new ground term registered *) val tys : _ Egraph.t -> Node.t -> Ty.S.t val add_ty : Egraph.wt -> Node.t -> Ty.t -> unit module Defs : sig val add : Egraph.wt -> Dolmen_std.Expr.Term.Const.t -> Dolmen_std.Expr.Ty.Var.t list -> Dolmen_std.Expr.Term.Var.t list -> Expr.Term.t -> unit (** [add d sym tys vars def] add the definition [def] for the symbol [sym] *) val add_handler : Egraph.wt -> (Egraph.wt -> Dolmen_std.Expr.Term.Const.t -> Dolmen_std.Expr.Ty.Var.t list -> Dolmen_std.Expr.Term.Var.t list -> Expr.Term.t -> unit) -> unit (** Called every time a definition is registered *) end module ClosedQuantifier : sig type binder = Forall | Exists type s = { binder : binder; subst : Subst.t; ty_vars : Expr.Ty.Var.t list; term_vars : Expr.Term.Var.t list; body : Expr.Term.t; } include RegisteredThTerm with type s := s end module NotTotallyApplied : sig type s = | Lambda of { subst : Subst.t; ty_vars : Expr.Ty.Var.t list; term_vars : Expr.Term.Var.t list; body : Expr.Term.t; ty : Ty.t; } | Cst of Expr.Term.Const.t | App of { app : Node.t; tyargs : Ty.t list; args : Node.t IArray.t; ty : Ty.t; } include RegisteredThTerm with type s := s end val convert_and_iter : ('a -> t -> unit) -> ('a -> ClosedQuantifier.t -> unit) -> ('a -> NotTotallyApplied.t -> unit) -> 'a -> Subst.t -> Expr.Term.t -> Node.t (** Iter on the new ground terms when converting, bottom_up *) val convert_one_app : Subst.t -> 'a Egraph.t -> Expr.Term.t -> Expr.Ty.t list -> Node.t IArray.t -> Expr.Ty.t -> Node.t val convert_one_cst : Subst.t -> 'a Egraph.t -> Dolmen_std.Expr.Term.Const.t -> Node.t val convert_one_binder : Subst.t -> 'a Egraph.t -> Expr.binder -> Expr.Term.t -> Expr.Ty.t -> Node.t val convert_one_app_and_iter : 'a -> Expr.term -> Expr.ty list -> Node.t Colibri2_popop_lib.IArray.t -> Expr.ty -> Subst.t -> ('a -> t -> unit) -> ('a -> ClosedQuantifier.t -> unit) -> ('a -> NotTotallyApplied.t -> unit) -> Node.t val convert_one_cst_and_iter : 'a -> Dolmen_std.Expr.term_cst -> Subst.t -> ('a -> t -> unit) -> ('a -> NotTotallyApplied.t -> unit) -> Node.t val convert_one_binder_and_iter : 'a -> Expr.binder -> Expr.term -> Expr.ty -> Subst.t -> ('a -> ClosedQuantifier.t -> unit) -> ('a -> NotTotallyApplied.t -> unit) -> Node.t val convert_let_seq : Subst.t -> 'a -> (Dolmen_std.Expr.Term.Var.t * Expr.Term.t) list -> Expr.Term.t -> ('a -> Subst.t -> Expr.Term.t -> Node.t) -> Node.t val convert_let_par : Subst.t -> 'a -> (Dolmen_std.Expr.Term.Var.t * Expr.Term.t) list -> Expr.Term.t -> ('a -> Subst.t -> Expr.Term.t -> Node.t) -> Node.t
(*************************************************************************) (* This file is part of Colibri2. *) (* *) (* Copyright (C) 2014-2021 *) (* CEA (Commissariat à l'énergie atomique et aux énergies *) (* alternatives) *) (* *) (* you can redistribute it and/or modify it under the terms of the GNU *) (* Lesser General Public License as published by the Free Software *) (* Foundation, version 2.1. *) (* *) (* It 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 *) (* GNU Lesser General Public License for more details. *) (* *) (* See the GNU Lesser General Public License version 2.1 *) (* for more details (enclosed in the file licenses/LGPLv2.1). *) (*************************************************************************)
level_storage.ml
open Level_repr let from_raw c ?offset l = let l = match offset with | None -> l | Some o -> Raw_level_repr.(of_int32_exn (Int32.add (to_int32 l) o)) in let constants = Raw_context.constants c in let first_level = Raw_context.first_level c in Level_repr.from_raw ~first_level ~blocks_per_cycle:constants.Constants_repr.blocks_per_cycle ~blocks_per_voting_period:constants.Constants_repr.blocks_per_voting_period ~blocks_per_commitment:constants.Constants_repr.blocks_per_commitment l let root c = Level_repr.root (Raw_context.first_level c) let succ c l = from_raw c (Raw_level_repr.succ l.level) let pred c l = match Raw_level_repr.pred l.Level_repr.level with | None -> None | Some l -> Some (from_raw c l) let current ctxt = Raw_context.current_level ctxt let previous ctxt = let l = current ctxt in match pred ctxt l with | None -> assert false (* We never validate the Genesis... *) | Some p -> p let first_level_in_cycle ctxt c = let constants = Raw_context.constants ctxt in let first_level = Raw_context.first_level ctxt in from_raw ctxt (Raw_level_repr.of_int32_exn (Int32.add (Raw_level_repr.to_int32 first_level) (Int32.mul constants.Constants_repr.blocks_per_cycle (Cycle_repr.to_int32 c)))) let last_level_in_cycle ctxt c = match pred ctxt (first_level_in_cycle ctxt (Cycle_repr.succ c)) with | None -> assert false | Some x -> x let levels_in_cycle ctxt cycle = let first = first_level_in_cycle ctxt cycle in let rec loop n acc = if Cycle_repr.(n.cycle = first.cycle) then loop (succ ctxt n) (n :: acc) else acc in loop first [] let levels_in_current_cycle ctxt ?(offset = 0l) () = let current_cycle = Cycle_repr.to_int32 (current ctxt).cycle in let cycle = Int32.add current_cycle offset in if Compare.Int32.(cycle < 0l) then [] else let cycle = Cycle_repr.of_int32_exn cycle in levels_in_cycle ctxt cycle let levels_with_commitments_in_cycle ctxt c = let first = first_level_in_cycle ctxt c in let rec loop n acc = if Cycle_repr.(n.cycle = first.cycle) then if n.expected_commitment then loop (succ ctxt n) (n :: acc) else loop (succ ctxt n) acc else acc in loop first [] let last_allowed_fork_level c = let level = Raw_context.current_level c in let preserved_cycles = Constants_storage.preserved_cycles c in match Cycle_repr.sub level.cycle preserved_cycles with | None -> Raw_level_repr.root | Some cycle -> (first_level_in_cycle c cycle).level
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
script_string.ml
(** Strings of printable characters *) type repr = string (* Invariant: contains only printable characters *) type t = String_tag of repr [@@ocaml.unboxed] type error += Non_printable_character of (int * string) let () = let open Data_encoding in register_error_kind `Permanent ~id:"michelson_v1.non_printable_character" ~title:"Non printable character in a Michelson string" ~description: "Michelson strings are only allowed to contain printable characters \ (either the newline character or characters in the [32, 126] ASCII \ range)." ~pp:(fun ppf (pos, s) -> Format.fprintf ppf "In Michelson string \"%s\", character at position %d has ASCII code \ %d. Expected: either a newline character (ASCII code 10) or a \ printable character (ASCII code between 32 and 126)." s pos (Char.code s.[pos])) (obj2 (req "position" int31) (req "string" string)) (function Non_printable_character (pos, s) -> Some (pos, s) | _ -> None) (fun (pos, s) -> Non_printable_character (pos, s)) let empty = String_tag "" let of_string v = let rec check_printable_ascii i = if Compare.Int.(i < 0) then ok (String_tag v) else match v.[i] with | '\n' | '\x20' .. '\x7E' -> check_printable_ascii (i - 1) | _ -> error @@ Non_printable_character (i, v) in check_printable_ascii (String.length v - 1) let to_string (String_tag s) = s let compare (String_tag x) (String_tag y) = Compare.String.compare x y let length (String_tag s) = String.length s let concat_pair (String_tag x) (String_tag y) = String_tag (x ^ y) let concat l = let l = List.map (fun (String_tag s) -> s) l in String_tag (String.concat "" l) let sub (String_tag s) offset length = String_tag (String.sub s offset length)
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2021-2022 Nomadic Labs <contact@nomadic-labs.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
opamGit.ml
open OpamFilename.Op open OpamProcess.Job.Op (* let log fmt = OpamConsole.log "GIT" fmt *) module VCS : OpamVCS.VCS = struct let name = `git let exists repo_root = OpamFilename.exists_dir (repo_root / ".git") || OpamFilename.exists (repo_root // ".git") let cygpath = OpamSystem.get_cygpath_function ~command:"git" let git repo_root = let dir = OpamFilename.Dir.to_string repo_root in (* If the ?env arg is restored here, then the caching for the Cygwin-ness of git will need to change, as altering PATH could select a different Git *) fun ?verbose ?stdout args -> OpamSystem.make_command ~dir ?verbose ?stdout "git" args let init repo_root repo_url = OpamFilename.mkdir repo_root; OpamProcess.Job.of_list [ git repo_root [ "init" ]; (* Enforce this option, it can break our use of git if set *) git repo_root [ "config" ; "--local" ; "fetch.prune"; "false"]; (* We reset diff.noprefix to ensure we get a `-p1` patch and avoid <https://github.com/ocaml/opam/issues/3627>. *) git repo_root [ "config" ; "--local" ; "diff.noprefix"; "false"]; (* Disable automatic line-ending conversion and switch core.eol to Unix. THIS DOES NOT MEAN ALL FILES GET LF-ONLY LINE-ENDINGS! This combination of settings means that files will be checked out exactly as they appear in the repository, so if files are checked in with CRLF line-endings (either by not having .gitattributes with core.autocrlf = false, or having an explicit eol=crlf in .gitattributes), then they will still be checked out with CRLF endings. *) git repo_root [ "config" ; "--local" ; "core.autocrlf"; "false"]; git repo_root [ "config" ; "--local" ; "core.eol"; "lf"]; (* Document the remote for user-friendliness (we don't use it) *) git repo_root [ "remote"; "add"; "origin"; OpamUrl.base_url repo_url ]; ] @@+ function | None -> Done () | Some (_,err) -> OpamSystem.process_error err let remote_ref url = match url.OpamUrl.hash with | Some h -> "refs/remotes/opam-ref-"^h | None -> "refs/remotes/opam-ref" let fetch ?cache_dir ?subpath repo_root repo_url = (match subpath with | Some sp -> git repo_root [ "config"; "--local"; "core.sparseCheckout"; "true" ] @@> fun r -> OpamSystem.raise_on_process_error r; OpamFilename.write (repo_root / ".git" / "info" // "sparse-checkout") sp; Done() | None -> Done()) @@+ fun _ -> (match cache_dir with | Some c when OpamUrl.local_dir repo_url = None -> let dir = c / "git" in if not (OpamFilename.exists_dir dir) then (OpamFilename.mkdir dir; git dir [ "init"; "--bare" ] @@> fun r -> OpamSystem.raise_on_process_error r; Done (Some dir)) else Done (Some dir) | _ -> Done None) @@+ fun global_cache -> let repo_url = OpamUrl.map_file_url (Lazy.force cygpath) repo_url in let origin = OpamUrl.base_url repo_url in let branch = OpamStd.Option.default "HEAD" repo_url.OpamUrl.hash in let opam_ref = remote_ref repo_url in let refspec = Printf.sprintf "+%s:%s" branch opam_ref in git repo_root [ "remote" ; "set-url"; "origin"; origin ] @@> fun _ -> OpamStd.Option.iter (fun cache -> let alternates = repo_root / ".git" / "objects" / "info" // "alternates" in if not (OpamFilename.exists alternates) then OpamFilename.write alternates (OpamFilename.Dir.to_string (cache / "objects"))) global_cache; git repo_root [ "fetch" ; "-q"; origin; "--update-shallow"; refspec ] @@> fun r -> if OpamProcess.check_success_and_cleanup r then let refspec = Printf.sprintf "+%s:refs/remotes/%s" opam_ref (Digest.to_hex (Digest.string (OpamUrl.to_string repo_url))) in match global_cache with | Some cache -> git repo_root [ "push" ; OpamFilename.Dir.to_string cache ; refspec ] @@> fun _ -> Done () | None -> Done () else (* fallback to fetching all first (workaround, git 2.1 fails silently on 'fetch HASH' when HASH isn't available locally already). Also, remove the [--update-shallow] option in case git is so old that it didn't exist yet, as that is not needed in the general case *) git repo_root [ "fetch" ; "-q" ] @@> fun r -> OpamSystem.raise_on_process_error r; (* retry to fetch the specific branch *) git repo_root [ "fetch" ; "-q"; origin; refspec ] @@> fun r -> if OpamProcess.check_success_and_cleanup r then Done () else if OpamStd.String.fold_left (fun acc c -> match acc, c with | true, ('0'..'9' | 'a'..'f' | 'A'..'F') -> true | _ -> false) true branch then (* the above might still fail on raw, untracked hashes: try to bind to the direct refspec, if found *) (git repo_root [ "update-ref" ; opam_ref; branch ] @@> fun r -> if OpamProcess.check_success_and_cleanup r then Done() else (* check if the commit exists *) (git repo_root [ "fetch"; "-q" ] @@> fun r -> OpamSystem.raise_on_process_error r; git repo_root [ "show"; "-s"; "--format=%H"; branch ] @@> fun r -> if OpamProcess.check_success_and_cleanup r then failwith "Commit found, but unreachable: enable uploadpack.allowReachableSHA1InWant on server" else failwith "Commit not found on repository")) else let error = r in git repo_root ["ls-files"] @@> function | { OpamProcess.r_code = 0; OpamProcess.r_stdout = []; _ } -> git repo_root ["show"] @@> fun r -> if OpamProcess.is_failure r then failwith "Git repository seems just initialized, \ try again after your first commit" else OpamSystem.process_error error | _ -> OpamSystem.process_error error let revision repo_root = git repo_root ~verbose:false [ "rev-parse"; "HEAD" ] @@> fun r -> if r.OpamProcess.r_code = 128 then (OpamProcess.cleanup ~force:true r; Done None) else (OpamSystem.raise_on_process_error r; match r.OpamProcess.r_stdout with | [] -> Done None | full::_ -> if String.length full > 8 then Done (Some (String.sub full 0 8)) else Done (Some full)) let clean repo_root = git repo_root [ "clean"; "-fdx" ] @@> fun r -> OpamSystem.raise_on_process_error r; Done () let reset_tree repo_root repo_url = let rref = remote_ref repo_url in git repo_root [ "reset" ; "--hard"; rref; "--" ] @@> fun r -> if OpamProcess.is_failure r then OpamSystem.internal_error "Git error: %s not found." rref else clean repo_root @@+ fun () -> if OpamFilename.exists (repo_root // ".gitmodules") then git repo_root [ "submodule"; "update"; "--init"; "--recursive" ] @@> fun r -> if OpamProcess.is_failure r then OpamConsole.warning "Git submodule update failed in %s" (OpamFilename.Dir.to_string repo_root); Done () else Done () let patch_applied _ _ = (* This might be a good place to do 'git reset --soft' and check for unstaged changes. See <https://github.com/ocaml/opam/pull/3283>. *) Done () let diff repo_root repo_url = let rref = remote_ref repo_url in let patch_file = OpamSystem.temp_file ~auto_clean: false "git-diff" in let finalise () = OpamSystem.remove_file patch_file in OpamProcess.Job.catch (fun e -> finalise (); raise e) @@ fun () -> git repo_root [ "add"; "." ] @@> fun r -> (* Git diff is to the working dir, but doesn't work properly for unregistered directories. *) OpamSystem.raise_on_process_error r; (* We also reset diff.noprefix here to handle already existing repo. *) git repo_root ~stdout:patch_file [ "-c" ; "diff.noprefix=false" ; "diff" ; "--text" ; "--no-ext-diff" ; "-R" ; "-p" ; rref; "--" ] @@> fun r -> if not (OpamProcess.check_success_and_cleanup r) then (finalise (); OpamSystem.internal_error "Git error: %s not found." rref) else if OpamSystem.file_is_empty patch_file then (finalise (); Done None) else Done (Some (OpamFilename.of_string patch_file)) let is_up_to_date repo_root repo_url = let rref = remote_ref repo_url in git repo_root [ "diff" ; "--no-ext-diff" ; "--quiet" ; rref; "--" ] @@> function | { OpamProcess.r_code = 0; _ } -> Done true | { OpamProcess.r_code = 1; _ } as r -> OpamProcess.cleanup ~force:true r; Done false | r -> OpamSystem.process_error r let versioned_files repo_root = git repo_root ~verbose:false [ "ls-files" ] @@> fun r -> OpamSystem.raise_on_process_error r; Done r.OpamProcess.r_stdout let vc_dir repo_root = OpamFilename.Op.(repo_root / ".git") let current_branch dir = git dir [ "symbolic-ref"; "--quiet"; "--short"; "HEAD" ] @@> function | { OpamProcess.r_code = 0; OpamProcess.r_stdout = [s]; _ } -> Done (Some s) | _ -> Done (Some "HEAD") let is_dirty ?subpath dir = let subpath = match subpath with | None -> [] | Some dir -> ["--" ; dir] in git dir ([ "diff"; "--no-ext-diff"; "--quiet" ; "HEAD" ] @ subpath) @@> function | { OpamProcess.r_code = 0; _ } -> (git dir ["ls-files"; "--others"; "--exclude-standard"] @@> function | { OpamProcess.r_code = 0; OpamProcess.r_stdout = []; _ } -> Done false | { OpamProcess.r_code = 0; _ } | { OpamProcess.r_code = 1; _ } as r -> OpamProcess.cleanup ~force:true r; Done true | r -> OpamSystem.process_error r ) | { OpamProcess.r_code = 1; _ } as r -> OpamProcess.cleanup ~force:true r; Done true | r -> OpamSystem.process_error r let modified_files repo_root = git repo_root ~verbose:false [ "status" ; "--short" ] @@> fun r -> OpamSystem.raise_on_process_error r; let files = OpamStd.List.filter_map (fun line -> match OpamStd.String.split line ' ' with | ("A" | "M" | "AM")::file::[] | ("R"|"RM"|"C"|"CM")::_::"->"::file::[] -> Some file | _ -> None) r.OpamProcess.r_stdout in Done files let origin = "origin" (** check if a hash or branch is present in remote origin and returns *) let check_remote repo_root hash_or_b = let is_hex str = OpamStd.String.fold_left (fun hex ch -> hex && match ch with | '0'..'9' | 'A'..'F' | 'a'..'f' -> true | _ -> false ) true str in (* get the hash of the branch *) let hash = git repo_root ["branch"] @@> fun r -> if OpamProcess.is_success r then let is_branch = List.exists (OpamStd.String.contains ~sub:hash_or_b) r.r_stdout in if is_branch then git repo_root [ "rev-list"; hash_or_b; "-1" ] @@> fun r -> if OpamProcess.is_success r then (match List.filter is_hex r.r_stdout with | [hash] -> Done (Some hash) | _ -> Done None) else Done None else if is_hex hash_or_b then Done (Some hash_or_b) else Done None else Done None in hash @@+ function | Some hash -> (* check if hash / branch is present in remote *) (git repo_root ["branch"; "-r"; "--contains"; hash] @@> function | { OpamProcess.r_code = 0; _ } as r -> if r.r_stdout <> [] && (List.exists (OpamStd.String.contains ~sub:origin) r.r_stdout) then Done (Some hash_or_b) else Done None | { OpamProcess.r_code = 1; _ } -> Done None | r -> OpamSystem.process_error r) | None -> Done None let get_remote_url ?hash repo_root = git repo_root ["remote"; "get-url"; origin] @@> function | { OpamProcess.r_code = 0; OpamProcess.r_stdout = [url]; _ } -> (let u = OpamUrl.parse ~backend:`git url in if OpamUrl.local_dir u <> None then Done None else let hash_in_remote = match hash with | None -> (current_branch repo_root @@+ function | None | Some "HEAD" -> Done None | Some hash -> check_remote repo_root hash) | Some hash -> check_remote repo_root hash in hash_in_remote @@+ function | Some _ as hash -> Done (Some { u with OpamUrl.hash = hash }) | None -> Done (Some { u with OpamUrl.hash = None }) ) | { OpamProcess.r_code = 0; _ } | { OpamProcess.r_code = 1; _ } -> Done None | r -> OpamSystem.process_error r end module B = OpamVCS.Make(VCS)
(**************************************************************************) (* *) (* Copyright 2012-2019 OCamlPro *) (* Copyright 2012 INRIA *) (* *) (* All rights reserved. This file is distributed under the terms of the *) (* GNU Lesser General Public License version 2.1, with the special *) (* exception on linking described in the file LICENSE. *) (* *) (**************************************************************************)
sapling_validator.ml
(* Check that each nullifier is not already present in the state and add it. Important to avoid spending the same input twice in a transaction. *) let rec check_and_update_nullifiers ctxt state inputs = match inputs with | [] -> return (ctxt, Some state) | input :: inputs -> ( Sapling_storage.nullifiers_mem ctxt state Sapling.UTXO.(input.nf) >>=? function | (ctxt, true) -> return (ctxt, None) | (ctxt, false) -> let state = Sapling_storage.nullifiers_add state Sapling.UTXO.(input.nf) in check_and_update_nullifiers ctxt state inputs ) let verify_update : Raw_context.t -> Sapling_storage.state -> Sapling_repr.transaction -> string -> (Raw_context.t * (Int64.t * Sapling_storage.state) option) tzresult Lwt.t = fun ctxt state transaction key -> (* Check the transaction *) (* To avoid overflowing the balance, the number of inputs and outputs must be bounded. Ciphertexts' memo_size must match the state's memo_size. These constraints are already enforced at the encoding level. *) assert (Compare.Int.(List.compare_length_with transaction.inputs 5208 <= 0)) ; assert (Compare.Int.(List.compare_length_with transaction.outputs 2019 <= 0)) ; let pass = List.for_all (fun output -> Compare.Int.( Sapling.Ciphertext.get_memo_size Sapling.UTXO.(output.ciphertext) = state.memo_size)) transaction.outputs in if not pass then return (ctxt, None) else (* Check the root is a recent state *) Sapling_storage.root_mem ctxt state transaction.root >>=? fun pass -> if not pass then return (ctxt, None) else check_and_update_nullifiers ctxt state transaction.inputs >|=? function | (ctxt, None) -> (ctxt, None) | (ctxt, Some state) -> Sapling.Verification.with_verification_ctx (fun vctx -> let pass = (* Check all the output ZK proofs *) List.for_all (fun output -> Sapling.Verification.check_output vctx output) transaction.outputs in if not pass then (ctxt, None) else let pass = (* Check all the input Zk proofs and signatures *) List.for_all (fun input -> Sapling.Verification.check_spend vctx input transaction.root key) transaction.inputs in if not pass then (ctxt, None) else let pass = (* Check the signature and balance of the whole transaction *) Sapling.Verification.final_check vctx transaction key in if not pass then (ctxt, None) else (* update tree *) let list_to_add = List.map (fun output -> Sapling.UTXO.(output.cm, output.ciphertext)) transaction.outputs in let state = Sapling_storage.add state list_to_add in (ctxt, Some (transaction.balance, state)))
(* The MIT License (MIT) * * Copyright (c) 2019-2020 Nomadic Labs <contact@nomadic-labs.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. *)
sys.mli
val argv : string array val executable_name : string external file_exists : string -> bool = "caml_sys_file_exists" external remove : string -> unit = "caml_sys_remove" external rename : string -> string -> unit = "caml_sys_rename" external getenv : string -> string = "caml_sys_getenv" external command : string -> int = "caml_sys_system_command" external time : unit -> float = "caml_sys_time" external chdir : string -> unit = "caml_sys_chdir" external getcwd : unit -> string = "caml_sys_getcwd" external readdir : string -> string array = "caml_sys_read_directory" val interactive : bool ref val os_type : string val word_size : int val max_string_length : int val max_array_length : int type signal_behavior = | Signal_default | Signal_ignore | Signal_handle of (int -> unit) external signal : int -> signal_behavior -> signal_behavior = "caml_install_signal_handler" val set_signal : int -> signal_behavior -> unit val sigabrt : int val sigalrm : int val sigfpe : int val sighup : int val sigill : int val sigint : int val sigkill : int val sigpipe : int val sigquit : int val sigsegv : int val sigterm : int val sigusr1 : int val sigusr2 : int val sigchld : int val sigcont : int val sigstop : int val sigtstp : int val sigttin : int val sigttou : int val sigvtalrm : int val sigprof : int exception Break val catch_break : bool -> unit val ocaml_version : string
ocaml_filetypes.ml
(* Types of files involved in an OCaml project and related functions *) type backend_specific = Object | Library | Program type t = | Implementation | Interface | C | C_minus_minus | Lexer | Grammar | Binary_interface | Obj | Backend_specific of Ocaml_backends.t * backend_specific | Text (* used by ocamldoc for text only documentation *) let string_of_backend_specific = function | Object -> "object" | Library -> "library" | Program -> "program" let string_of_filetype = function | Implementation -> "implementation" | Interface -> "interface" | C -> "C source file" | C_minus_minus -> "C minus minus source file" | Lexer -> "lexer" | Grammar -> "grammar" | Binary_interface -> "binary interface" | Obj -> "object" | Backend_specific (backend, filetype) -> ((Ocaml_backends.string_of_backend backend) ^ " " ^ (string_of_backend_specific filetype)) | Text -> "text" let extension_of_filetype = function | Implementation -> "ml" | Interface -> "mli" | C -> "c" | C_minus_minus -> "cmm" | Lexer -> "mll" | Grammar -> "mly" | Binary_interface -> "cmi" | Obj -> Ocamltest_config.objext | Backend_specific (backend, filetype) -> begin match (backend, filetype) with | (Ocaml_backends.Native, Object) -> "cmx" | (Ocaml_backends.Native, Library) -> "cmxa" | (Ocaml_backends.Native, Program) -> "opt" | (Ocaml_backends.Bytecode, Object) -> "cmo" | (Ocaml_backends.Bytecode, Library) -> "cma" | (Ocaml_backends.Bytecode, Program) -> "byte" end | Text -> "txt" let filetype_of_extension = function | "ml" -> Implementation | "mli" -> Interface | "c" -> C | "cmm" -> C_minus_minus | "mll" -> Lexer | "mly" -> Grammar | "cmi" -> Binary_interface | "o" -> Obj | "obj" -> Obj | "cmx" -> Backend_specific (Ocaml_backends.Native, Object) | "cmxa" -> Backend_specific (Ocaml_backends.Native, Library) | "opt" -> Backend_specific (Ocaml_backends.Native, Program) | "cmo" -> Backend_specific (Ocaml_backends.Bytecode, Object) | "cma" -> Backend_specific (Ocaml_backends.Bytecode, Library) | "byte" -> Backend_specific (Ocaml_backends.Bytecode, Program) | "txt" -> Text | _ as e -> Printf.eprintf "Unknown file extension %s\n%!" e; exit 2 let split_filename name = let l = String.length name in let is_dir_sep name i = name.[i] = Filename.dir_sep.[0] in let rec search_dot i = if i < 0 || is_dir_sep name i then (name, "") else if name.[i] = '.' then let basename = String.sub name 0 i in let extension = String.sub name (i+1) (l-i-1) in (basename, extension) else search_dot (i - 1) in search_dot (l - 1) let filetype filename = let (basename, extension) = split_filename filename in (basename, filetype_of_extension extension) let make_filename (basename, filetype) = let extension = extension_of_filetype filetype in basename ^ "." ^ extension let action_of_filetype = function | Implementation -> "Compiling implementation" | Interface -> "Compiling interface" | C -> "Compiling C source file" | C_minus_minus -> "Processing C-- file" | Lexer -> "Generating lexer" | Grammar -> "Generating parser" | filetype -> ("nothing to do for " ^ (string_of_filetype filetype))
(**************************************************************************) (* *) (* OCaml *) (* *) (* Sebastien Hinderer, projet Gallium, INRIA Paris *) (* *) (* Copyright 2016 Institut National de Recherche en Informatique et *) (* en Automatique. *) (* *) (* All rights reserved. This file is distributed under the terms of *) (* the GNU Lesser General Public License version 2.1, with the *) (* special exception on linking described in the file LICENSE. *) (* *) (**************************************************************************)
roll_repr.mli
type t = private int32 type roll = t val encoding: roll Data_encoding.t val rpc_arg: roll RPC_arg.t val random: Seed_repr.sequence -> bound:roll -> roll * Seed_repr.sequence val first: roll val succ: roll -> roll val to_int32: roll -> Int32.t val (=): roll -> roll -> bool module Index : Storage_description.INDEX with type t = roll
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
dune
(include v0.dune.inc) (library (name tezos_protocol_environment_sigs) (public_name tezos-protocol-environment-sigs) (flags (:standard -nopervasives )) (modules ("V0")))
average_block.mli
(** Description of the average block in terms of the total counts for various transaction types. *) type t = { regular : int; (** The total number of regular transactions (from and to normal contracts). *) origination : int; (** The number of originations. *) contract : (string * int) list; (** List of contract names paired with the number of calls that had that contract as their destination. *) } (** Encoding of the average block. *) val encoding : t Data_encoding.t (** Load a description of the average block from a file. If [None] is passed, the default average block is returned. *) val load : string option -> t Lwt.t (** Verify that all smart contracts in the description of the average block are known to us. *) val check_for_unknown_smart_contracts : t -> unit Lwt.t
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2021 Nomadic Labs, <contact@nomadic-labs.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
context.mli
(** The modules defined below represent a {e local context} as defined by Chapter 4 in the Reference Manual: A {e local context} is an ordered list of of {e local declarations} of names that we call {e variables}. A {e local declaration} of some variable can be either: - a {e local assumption}, or - a {e local definition}. {e Local assumptions} are denoted in the Reference Manual as [(name : typ)] and {e local definitions} are there denoted as [(name := value : typ)]. *) open Names type 'a binder_annot = { binder_name : 'a; binder_relevance : Sorts.relevance } val eq_annot : ('a -> 'a -> bool) -> 'a binder_annot -> 'a binder_annot -> bool val hash_annot : ('a -> int) -> 'a binder_annot -> int val map_annot : ('a -> 'b) -> 'a binder_annot -> 'b binder_annot val make_annot : 'a -> Sorts.relevance -> 'a binder_annot val binder_name : 'a binder_annot -> 'a val binder_relevance : 'a binder_annot -> Sorts.relevance val annotR : 'a -> 'a binder_annot (** Always Relevant *) val nameR : Id.t -> Name.t binder_annot (** Relevant + Name *) val anonR : Name.t binder_annot (** Relevant + Anonymous *) (** Representation of contexts that can capture anonymous as well as non-anonymous variables. Individual declarations are then designated by de Bruijn indexes. *) module Rel : sig module Declaration : sig (* local declaration *) type ('constr, 'types) pt = | LocalAssum of Name.t binder_annot * 'types (** name, type *) | LocalDef of Name.t binder_annot * 'constr * 'types (** name, value, type *) val get_annot : _ pt -> Name.t binder_annot (** Return the name bound by a given declaration. *) val get_name : ('c, 't) pt -> Name.t (** Return [Some value] for local-declarations and [None] for local-assumptions. *) val get_value : ('c, 't) pt -> 'c option (** Return the type of the name bound by a given declaration. *) val get_type : ('c, 't) pt -> 't val get_relevance : ('c, 't) pt -> Sorts.relevance (** Set the name that is bound by a given declaration. *) val set_name : Name.t -> ('c, 't) pt -> ('c, 't) pt (** Set the type of the bound variable in a given declaration. *) val set_type : 't -> ('c, 't) pt -> ('c, 't) pt (** Return [true] iff a given declaration is a local assumption. *) val is_local_assum : ('c, 't) pt -> bool (** Return [true] iff a given declaration is a local definition. *) val is_local_def : ('c, 't) pt -> bool (** Check whether any term in a given declaration satisfies a given predicate. *) val exists : ('c -> bool) -> ('c, 'c) pt -> bool (** Check whether all terms in a given declaration satisfy a given predicate. *) val for_all : ('c -> bool) -> ('c, 'c) pt -> bool (** Check whether the two given declarations are equal. *) val equal : ('c -> 'c -> bool) -> ('c, 'c) pt -> ('c, 'c) pt -> bool (** Map the name bound by a given declaration. *) val map_name : (Name.t -> Name.t) -> ('c, 't) pt -> ('c, 't) pt (** For local assumptions, this function returns the original local assumptions. For local definitions, this function maps the value in the local definition. *) val map_value : ('c -> 'c) -> ('c, 't) pt -> ('c, 't) pt (** Map the type of the name bound by a given declaration. *) val map_type : ('t -> 't) -> ('c, 't) pt -> ('c, 't) pt (** Map all terms in a given declaration. *) val map_constr : ('c -> 'c) -> ('c, 'c) pt -> ('c, 'c) pt (** Map all terms, with an heterogeneous function. *) val map_constr_het : ('a -> 'b) -> ('a, 'a) pt -> ('b, 'b) pt (** Perform a given action on all terms in a given declaration. *) val iter_constr : ('c -> unit) -> ('c, 'c) pt -> unit (** Reduce all terms in a given declaration to a single value. *) val fold_constr : ('c -> 'a -> 'a) -> ('c, 'c) pt -> 'a -> 'a val to_tuple : ('c, 't) pt -> Name.t binder_annot * 'c option * 't (** Turn [LocalDef] into [LocalAssum], identity otherwise. *) val drop_body : ('c, 't) pt -> ('c, 't) pt end (** Rel-context is represented as a list of declarations. Inner-most declarations are at the beginning of the list. Outer-most declarations are at the end of the list. *) type ('constr, 'types) pt = ('constr, 'types) Declaration.pt list (** empty rel-context *) val empty : ('c, 't) pt (** Return a new rel-context enriched by with a given inner-most declaration. *) val add : ('c, 't) Declaration.pt -> ('c, 't) pt -> ('c, 't) pt (** Return the number of {e local declarations} in a given rel-context. *) val length : ('c, 't) pt -> int (** Check whether given two rel-contexts are equal. *) val equal : ('c -> 'c -> bool) -> ('c, 'c) pt -> ('c, 'c) pt -> bool (** Return the number of {e local assumptions} in a given rel-context. *) val nhyps : ('c, 't) pt -> int (** Return a declaration designated by a given de Bruijn index. @raise Not_found if the designated de Bruijn index outside the range. *) val lookup : int -> ('c, 't) pt -> ('c, 't) Declaration.pt (** Map all terms in a given rel-context. *) val map : ('c -> 'c) -> ('c, 'c) pt -> ('c, 'c) pt (** Map all terms in a given rel-context taking into account the position of the binder in the context starting at 1. *) val map_with_binders : (int -> 'c -> 'c) -> ('c, 'c) pt -> ('c, 'c) pt (** Perform a given action on every declaration in a given rel-context. *) val iter : ('c -> unit) -> ('c, 'c) pt -> unit (** Reduce all terms in a given rel-context to a single value. Innermost declarations are processed first. *) val fold_inside : ('a -> ('c, 't) Declaration.pt -> 'a) -> init:'a -> ('c, 't) pt -> 'a (** Reduce all terms in a given rel-context to a single value. Outermost declarations are processed first. *) val fold_outside : (('c, 't) Declaration.pt -> 'a -> 'a) -> ('c, 't) pt -> init:'a -> 'a (** Return the set of all named variables bound in a given rel-context. *) val to_vars : ('c, 't) pt -> Id.Set.t (** Map a given rel-context to a list where each {e local assumption} is mapped to [true] and each {e local definition} is mapped to [false]. The resulting list is in reverse order compared to the order of declarations in the context. *) val to_tags : ('c, 't) pt -> bool list (** Turn all [LocalDef] into [LocalAssum], leave [LocalAssum] unchanged. *) val drop_bodies : ('c, 't) pt -> ('c, 't) pt (** [chop_nhyps n Γ] returns [Γ'',Γ'] such that [Γ]=[Γ'Γ''], [Γ''] has [n] hypotheses (i.e. [LocalAssum]), excluding local definitions (i.e. [LocalDef]), and [Γ''], if [n] non zero, starts with an hypothesis (i.e., [Γ''] has the form [x:A;Γ'''], i.e., local definitions at the junction of the [n] hypotheses are put in [Γ'] rather than in [Γ''] *) val chop_nhyps : int -> ('c, 't) pt -> ('c, 't) pt * ('c, 't) pt (** [instance mk n Γ] builds an instance [args] such that [Γ,Δ ⊢ args:Γ] with n = |Δ| and with the {e local definitions} of [Γ] skipped in [args] where [mk] is used to build the corresponding variables. Example: for [x:T, y:=c, z:U] and [n]=2, it gives [mk 5, mk 3]. *) val instance : (int -> 'r) -> int -> ('c, 't) pt -> 'r array (** [instance_list] is like [instance] but returning a list. *) val instance_list : (int -> 'r) -> int -> ('c, 't) pt -> 'r list val to_extended_vect : (int -> 'r) -> int -> ('c, 't) pt -> 'r array [@@ocaml.deprecated "Use synonymous [Context.Rel.instance]"] val to_extended_list : (int -> 'r) -> int -> ('c, 't) pt -> 'r list [@@ocaml.deprecated "Use synonymous [Context.Rel.instance_list]"] end (** This module represents contexts that can capture non-anonymous variables. Individual declarations are then designated by the identifiers they bind. *) module Named : sig (** Representation of {e local declarations}. *) module Declaration : sig type ('constr, 'types) pt = | LocalAssum of Id.t binder_annot * 'types (** identifier, type *) | LocalDef of Id.t binder_annot * 'constr * 'types (** identifier, value, type *) val get_annot : _ pt -> Id.t binder_annot (** Return the identifier bound by a given declaration. *) val get_id : ('c, 't) pt -> Id.t (** Return [Some value] for local-declarations and [None] for local-assumptions. *) val get_value : ('c, 't) pt -> 'c option (** Return the type of the name bound by a given declaration. *) val get_type : ('c, 't) pt -> 't val get_relevance : ('c, 't) pt -> Sorts.relevance (** Set the identifier that is bound by a given declaration. *) val set_id : Id.t -> ('c, 't) pt -> ('c, 't) pt (** Set the type of the bound variable in a given declaration. *) val set_type : 't -> ('c, 't) pt -> ('c, 't) pt (** Return [true] iff a given declaration is a local assumption. *) val is_local_assum : ('c, 't) pt -> bool (** Return [true] iff a given declaration is a local definition. *) val is_local_def : ('c, 't) pt -> bool (** Check whether any term in a given declaration satisfies a given predicate. *) val exists : ('c -> bool) -> ('c, 'c) pt -> bool (** Check whether all terms in a given declaration satisfy a given predicate. *) val for_all : ('c -> bool) -> ('c, 'c) pt -> bool (** Check whether the two given declarations are equal. *) val equal : ('c -> 'c -> bool) -> ('c, 'c) pt -> ('c, 'c) pt -> bool (** Map the identifier bound by a given declaration. *) val map_id : (Id.t -> Id.t) -> ('c, 't) pt -> ('c, 't) pt (** For local assumptions, this function returns the original local assumptions. For local definitions, this function maps the value in the local definition. *) val map_value : ('c -> 'c) -> ('c, 't) pt -> ('c, 't) pt (** Map the type of the name bound by a given declaration. *) val map_type : ('t -> 't) -> ('c, 't) pt -> ('c, 't) pt (** Map all terms in a given declaration. *) val map_constr : ('c -> 'c) -> ('c, 'c) pt -> ('c, 'c) pt (** Map all terms, with an heterogeneous function. *) val map_constr_het : ('a -> 'b) -> ('a, 'a) pt -> ('b, 'b) pt (** Perform a given action on all terms in a given declaration. *) val iter_constr : ('c -> unit) -> ('c, 'c) pt -> unit (** Reduce all terms in a given declaration to a single value. *) val fold_constr : ('c -> 'a -> 'a) -> ('c, 'c) pt -> 'a -> 'a val to_tuple : ('c, 't) pt -> Id.t binder_annot * 'c option * 't val of_tuple : Id.t binder_annot * 'c option * 't -> ('c, 't) pt (** Turn [LocalDef] into [LocalAssum], identity otherwise. *) val drop_body : ('c, 't) pt -> ('c, 't) pt (** Convert [Rel.Declaration.t] value to the corresponding [Named.Declaration.t] value. The function provided as the first parameter determines how to translate "names" to "ids". *) val of_rel_decl : (Name.t -> Id.t) -> ('c, 't) Rel.Declaration.pt -> ('c, 't) pt (** Convert [Named.Declaration.t] value to the corresponding [Rel.Declaration.t] value. *) (* TODO: Move this function to [Rel.Declaration] module and rename it to [of_named]. *) val to_rel_decl : ('c, 't) pt -> ('c, 't) Rel.Declaration.pt end (** Named-context is represented as a list of declarations. Inner-most declarations are at the beginning of the list. Outer-most declarations are at the end of the list. *) type ('constr, 'types) pt = ('constr, 'types) Declaration.pt list (** empty named-context *) val empty : ('c, 't) pt (** Return a new named-context enriched by with a given inner-most declaration. *) val add : ('c, 't) Declaration.pt -> ('c, 't) pt -> ('c, 't) pt (** Return the number of {e local declarations} in a given named-context. *) val length : ('c, 't) pt -> int (** Return a declaration designated by an identifier of the variable bound in that declaration. @raise Not_found if the designated identifier is not bound in a given named-context. *) val lookup : Id.t -> ('c, 't) pt -> ('c, 't) Declaration.pt (** Check whether given two named-contexts are equal. *) val equal : ('c -> 'c -> bool) -> ('c, 'c) pt -> ('c, 'c) pt -> bool (** Map all terms in a given named-context. *) val map : ('c -> 'c) -> ('c, 'c) pt -> ('c, 'c) pt (** Perform a given action on every declaration in a given named-context. *) val iter : ('c -> unit) -> ('c, 'c) pt -> unit (** Reduce all terms in a given named-context to a single value. Innermost declarations are processed first. *) val fold_inside : ('a -> ('c, 't) Declaration.pt -> 'a) -> init:'a -> ('c, 't) pt -> 'a (** Reduce all terms in a given named-context to a single value. Outermost declarations are processed first. *) val fold_outside : (('c, 't) Declaration.pt -> 'a -> 'a) -> ('c, 't) pt -> init:'a -> 'a (** Return the set of all identifiers bound in a given named-context. *) val to_vars : ('c, 't) pt -> Id.Set.t (** Turn all [LocalDef] into [LocalAssum], leave [LocalAssum] unchanged. *) val drop_bodies : ('c, 't) pt -> ('c, 't) pt (** [to_instance Ω] builds an instance [args] in reverse order such that [Ω ⊢ args:Ω] where [Ω] is a named-context and with the local definitions of [Ω] skipped. Example: for [id1:T,id2:=c,id3:U], it gives [Var id1, Var id3]. All [idj] are supposed distinct. *) val to_instance : (Id.t -> 'r) -> ('c, 't) pt -> 'r list [@@ocaml.deprecated "[to_instance] was missing a [List.rev] to comply to its specification; rely on [instance] for the correct specification or use [List.rev (instance ...)] for strict compatibility"] (** [instance Ω] builds an instance [args] such that [Ω ⊢ args:Ω] where [Ω] is a named-context and with the local definitions of [Ω] skipped. Example: for the context [id1:T,id2:=c,id3:U] (which is internally represented by a list with [id3] at the head), it gives [Var id1, Var id3]. All [idj] are supposed distinct. *) val instance : (Id.t -> 'r) -> ('c, 't) pt -> 'r array (** [instance_list] is like [instance] but returning a list. *) val instance_list : (Id.t -> 'r) -> ('c, 't) pt -> 'r list end module Compacted : sig module Declaration : sig type ('constr, 'types) pt = | LocalAssum of Id.t binder_annot list * 'types | LocalDef of Id.t binder_annot list * 'constr * 'types val map_constr : ('c -> 'c) -> ('c, 'c) pt -> ('c, 'c) pt val of_named_decl : ('c, 't) Named.Declaration.pt -> ('c, 't) pt val to_named_context : ('c, 't) pt -> ('c, 't) Named.pt end type ('constr, 'types) pt = ('constr, 'types) Declaration.pt list val fold : (('c, 't) Declaration.pt -> 'a -> 'a) -> ('c, 't) pt -> init:'a -> 'a end
(************************************************************************) (* * The Coq Proof Assistant / The Coq Development Team *) (* v * Copyright INRIA, CNRS and contributors *) (* <O___,, * (see version control and CREDITS file for authors & dates) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************)
abstract.ml
type t = int let print i = Printf.printf "Abstract %i\n" i let x = 10
Logging_helpers.ml
(* Set up logging globally and for each module based on what we found on the command line or config files. TODO? could move setup in commons/Logging.ml *) let logger = Logging.get_logger [ __MODULE__ ] let setup ~debug ~log_config_file ~log_to_file = (* Logging: set global level to Info and then make exceptions for debugging specific modules. *) let log_config_file = if Sys.file_exists log_config_file then Some log_config_file else None in let want_logging = debug || log_config_file <> None || log_to_file <> None in (* Set log destination: none, stderr, or file *) (if want_logging then let handler = match log_to_file with | None -> Easy_logging.(Handlers.make (CliErr Debug)) | Some file -> Easy_logging.(Handlers.make (File (file, Debug))) in Logging.apply_to_all_loggers (fun logger -> logger#add_handler handler)); (* Set default level to Info rather than logging nothing (NoLevel). *) (if want_logging then Logging.(set_global_level Info)); (* Fine-tune log levels for each module, as instructed in the file 'log_config.json' or the file specified with '-log_config_file'. *) match log_config_file with | None -> () | Some file -> Logging.load_config_file file; logger#info "loaded %s" file
(* Set up logging globally and for each module based on what we found on the command line or config files. TODO? could move setup in commons/Logging.ml *)
struct.mli
(* $Id: struct.mli,v 1.7 2002-01-16 09:42:03 xleroy Exp $ *) (* Marshaling for structs *) open Idltypes val struct_ml_to_c : (out_channel -> bool -> Prefix.t -> idltype -> string -> string -> unit) -> out_channel -> bool -> Prefix.t -> struct_decl -> string -> string -> unit val struct_c_to_ml : (out_channel -> Prefix.t -> idltype -> string -> string -> unit) -> out_channel -> Prefix.t -> struct_decl -> string -> string -> unit val remove_dependent_fields: field list -> field list
(***********************************************************************) (* *) (* CamlIDL *) (* *) (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) (* *) (* Copyright 1999 Institut National de Recherche en Informatique et *) (* en Automatique. All rights reserved. This file is distributed *) (* under the terms of the GNU Lesser General Public License LGPL v2.1 *) (* *) (***********************************************************************)
t-eta_qexp.c
#include "flint.h" #include "fmpz.h" #include "fmpz_poly.h" int main(void) { int i; FLINT_TEST_INIT(state); flint_printf("eta_qexp...."); fflush(stdout); for (i = 0; i < 2000; i++) { fmpz_poly_t a, b; slong e, n; fmpz_poly_init(a); fmpz_poly_init(b); e = n_randint(state, 100) - 50; n = n_randint(state, 250); fmpz_poly_randtest(a, state, n_randint(state, 250), 1 + n_randint(state, 100)); fmpz_poly_eta_qexp(a, e, n); fmpz_poly_eta_qexp(b, 1, n + n_randint(state, 10)); if (n == 0) { fmpz_poly_zero(b); } else { if (e >= 0) { fmpz_poly_pow_trunc(b, b, e, n); } else { fmpz_poly_inv_series(b, b, n); fmpz_poly_pow_trunc(b, b, -e, n); } } if (!fmpz_poly_equal(a, b)) { flint_printf("FAIL (powering):\n"); flint_printf("e = %wd, n = %wd\n\n", e, n); fmpz_poly_print(a), flint_printf("\n\n"); fmpz_poly_print(b), flint_printf("\n\n"); fflush(stdout); flint_abort(); } fmpz_poly_clear(a); fmpz_poly_clear(b); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return EXIT_SUCCESS; }
/* Copyright (C) 2013 Fredrik Johansson This file is part of FLINT. FLINT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>. */
dune
(library (name lib) (wrapped false) (default_implementation lib.impl))
cache_repr.mli
(** Frequently used data should be kept in memory and persisted along a chain of blocks. The caching mechanism allows the economic protocol to declare such data and to rely on a Least Recently Used strategy to keep the cache size under a fixed limit. Take a look at {!Environment_cache} and {!Environment_context} for additional implementation details about the protocol cache. The protocol has two main kinds of interaction with the cache: 1. It is responsible for setting up the cache with appropriate parameter values and callbacks. It must also compute cache nonces to give the shell enough information to properly synchronize the in-memory cache with the block contexts and protocol upgrades. A typical place where this happens is {!Apply}. This aspect must be implemented using {!Cache.Admin}. 2. It can exploit the cache to retrieve, to insert, and to update cached values from the in-memory cache. The basic idea is to avoid recomputing values from scratch at each block when they are frequently used. {!Script_cache} is an example of such usage. This aspect must be implemented using {!Cache.Interface}. *) (** Size for subcaches and values of the cache. *) type size = int (** Index type to index caches. *) type index = int (** The following module acts on the whole cache, not on a specific sub-cache, unlike {!Interface}. It is used to administrate the protocol cache, e.g., to maintain the cache in a consistent state with respect to the chain. This module is typically used by low-level layers of the protocol and by the shell. *) module Admin : sig (** A key uniquely identifies a cached [value] in some subcache. *) type key (** Cached values. *) type value (** [pp fmt ctxt] is a pretty printter for the [cache] of [ctxt]. *) val pp : Format.formatter -> Raw_context.t -> unit (** [sync ctxt ~cache_nonce] updates the context with the domain of the cache computed so far. Such function is expected to be called at the end of the validation of a block, when there is no more accesses to the cache. [cache_nonce] identifies the block that introduced new cache entries. The nonce should identify uniquely the block which modifies this value. It cannot be the block hash for circularity reasons: The value of the nonce is stored onto the context and consequently influences the context hash of the very same block. Such nonce cannot be determined by the shell and its computation is delegated to the economic protocol. *) val sync : Raw_context.t -> cache_nonce:Bytes.t -> Raw_context.t Lwt.t (** {3 Cache helpers for RPCs} *) (** [future_cache_expectation ?blocks_before_activation ctxt ~time_in_blocks] returns [ctxt] except that the entries of the caches that are presumably too old to still be in the caches in [n_blocks] are removed. This function is based on a heuristic. The context maintains the median of the number of removed entries: this number is multipled by `n_blocks` to determine the entries that are likely to be removed in `n_blocks`. If [blocks_before_activation] is set to [Some n], then the cache is considered empty if [0 <= n <= time_in_blocks]. Otherwise, if [blocks_before_activation] is set to [None] and if the voting period is the adoption, the cache is considered empty if [blocks <= time_in_blocks remaining for adoption phase]. *) val future_cache_expectation : ?blocks_before_activation:int32 -> Raw_context.t -> time_in_blocks:int -> Raw_context.t tzresult Lwt.t (** [cache_size ctxt ~cache_index] returns an overapproximation of the size of the cache. Returns [None] if [cache_index] is greater than the number of subcaches declared by the cache layout. *) val cache_size : Raw_context.t -> cache_index:int -> size option (** [cache_size_limit ctxt ~cache_index] returns the maximal size of the cache indexed by [cache_index]. Returns [None] if [cache_index] is greater than the number of subcaches declared by the cache layout. *) val cache_size_limit : Raw_context.t -> cache_index:int -> size option (** [value_of_key ctxt k] interprets the functions introduced by [register] to construct a cacheable value for a key [k]. [value_of_key] is a maintenance operation: it is typically run when a node reboots. For this reason, this operation is not carbonated. *) val value_of_key : Raw_context.t -> Context.Cache.key -> Context.Cache.value tzresult Lwt.t end (** A client uses a unique namespace (represented as a string without '@') to avoid collision with the keys of other clients. *) type namespace = private string (** [create_namespace str] creates a valid namespace from [str] @raise Invalid_argument if [str] contains '@' *) val create_namespace : string -> namespace (** A key is fully determined by a namespace and an identifier. *) type identifier = string (** To use the cache, a client must implement the [CLIENT] interface. *) module type CLIENT = sig (** The type of value to be stored in the cache. *) type cached_value (** The client must declare the index of the subcache where its values shall live. [cache_index] must be between [0] and [List.length Constants_repr.cache_layout - 1]. *) val cache_index : index (** The client must declare a namespace. This namespace must be unique. Otherwise, the program stops. A namespace cannot contain '@'. *) val namespace : namespace (** [value_of_identifier id] builds the cached value identified by [id]. This function is called when the subcache is loaded into memory from the on-disk representation of its domain. An error during the execution of this function is fatal as witnessed by its type: an error embedded in a [tzresult] is not supposed to be caught by the protocol. *) val value_of_identifier : Raw_context.t -> identifier -> cached_value tzresult Lwt.t end (** An [INTERFACE] to the subcache where keys live in a given [namespace]. *) module type INTERFACE = sig (** The type of value to be stored in the cache. *) type cached_value (** [update ctxt i (Some (e, size))] returns a context where the value [e] of given [size] is associated to identifier [i] in the subcache. If [i] is already in the subcache, the cache entry is updated. [update ctxt i None] removes [i] from the subcache. *) val update : Raw_context.t -> identifier -> (cached_value * size) option -> Raw_context.t tzresult (** [find ctxt i = Some v] if [v] is the value associated to [i] in the subcache. Returns [None] if there is no such value in the subcache. This function is in the Lwt monad because if the value may have not been constructed (see the lazy loading mode in {!Environment_context}), it is constructed on the fly. *) val find : Raw_context.t -> identifier -> cached_value option tzresult Lwt.t (** [list_identifiers ctxt] returns the list of the identifiers of the cached values along with their respective size. The returned list is sorted in terms of their age in the cache, the oldest coming first. *) val list_identifiers : Raw_context.t -> (string * int) list (** [identifier_rank ctxt identifier] returns the number of cached values older than the one of [identifier]; or, [None] if the [identifier] has no associated value in the subcache. *) val identifier_rank : Raw_context.t -> string -> int option (** [size ctxt] returns an overapproximation of the subcache size. Note that the size unit is subcache specific. *) val size : Raw_context.t -> int (** [size_limit ctxt] returns the maximal size of the subcache. Note that the size unit is subcache specific. *) val size_limit : Raw_context.t -> int end (** [register_exn client] produces an [Interface] specific to a given [client]. This function can fail if [client] does not respect the invariant declared in the documentation of {!CLIENT}. *) val register_exn : (module CLIENT with type cached_value = 'a) -> (module INTERFACE with type cached_value = 'a)
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2021 Nomadic Labs <contact@nomadic-labs.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
storage_description.ml
module StringMap = Map.Make(String) type 'key t = 'key description ref and 'key description = | Empty : 'key description | Value : { get: 'key -> 'a option tzresult Lwt.t ; encoding: 'a Data_encoding.t } -> 'key description | NamedDir: 'key t StringMap.t -> 'key description | IndexedDir: { arg: 'a RPC_arg.t ; arg_encoding: 'a Data_encoding.t ; list: 'key -> 'a list tzresult Lwt.t ; subdir: ('key * 'a) t }-> 'key description let rec register_named_subcontext : type r. r t -> string list -> r t = fun dir names -> match !dir, names with | _, [] -> dir | Value _, _ -> invalid_arg "" | IndexedDir _, _ -> invalid_arg "" | Empty, name :: names -> let subdir = ref Empty in dir := NamedDir (StringMap.singleton name subdir) ; register_named_subcontext subdir names | NamedDir map, name :: names -> let subdir = match StringMap.find_opt name map with | Some subdir -> subdir | None -> let subdir = ref Empty in dir := NamedDir (StringMap.add name subdir map) ; subdir in register_named_subcontext subdir names type (_, _, _) args = | One : { rpc_arg: 'a RPC_arg.t ; encoding: 'a Data_encoding.t ; compare: 'a -> 'a -> int } -> ('key, 'a, 'key * 'a) args | Pair : ('key, 'a, 'inter_key) args * ('inter_key, 'b, 'sub_key) args -> ('key, 'a * 'b, 'sub_key) args let rec unpack : type a b c. (a, b, c) args -> c -> a * b = function | One _ -> (fun x -> x) | Pair (l, r) -> let unpack_l = unpack l in let unpack_r = unpack r in fun x -> let c, d = unpack_r x in let b, a = unpack_l c in (b, (a, d)) let rec pack : type a b c. (a, b, c) args -> a -> b -> c = function | One _ -> (fun b a -> (b, a)) | Pair (l, r) -> let pack_l = pack l in let pack_r = pack r in fun b (a, d) -> let c = pack_l b a in pack_r c d let rec compare : type a b c. (a, b, c) args -> b -> b -> int = function | One { compare ; _ } -> compare | Pair (l, r) -> let compare_l = compare l in let compare_r = compare r in fun (a1, b1) (a2, b2) -> match compare_l a1 a2 with | 0 -> compare_r b1 b2 | x -> x let destutter equal l = match l with | [] -> [] | (i, _) :: l -> let rec loop acc i = function | [] -> acc | (j, _) :: l -> if equal i j then loop acc i l else loop (j :: acc) j l in loop [i] i l let rec register_indexed_subcontext : type r a b. r t -> list:(r -> a list tzresult Lwt.t) -> (r, a, b) args -> b t = fun dir ~list path -> match path with | Pair (left, right) -> let compare_left = compare left in let equal_left x y = Compare.Int.(compare_left x y = 0) in let list_left r = list r >>=? fun l -> return (destutter equal_left l) in let list_right r = let a, k = unpack left r in list a >>=? fun l -> return (List.map snd (List.filter (fun (x, _) -> equal_left x k) l)) in register_indexed_subcontext (register_indexed_subcontext dir ~list:list_left left) ~list:list_right right | One { rpc_arg = arg ; encoding = arg_encoding ; _ } -> match !dir with | Value _ -> invalid_arg "" | NamedDir _ -> invalid_arg "" | Empty -> let subdir = ref Empty in dir := IndexedDir { arg ; arg_encoding ; list ; subdir }; subdir | IndexedDir { arg = inner_arg ; subdir ; _ } -> match RPC_arg.eq arg inner_arg with | None -> invalid_arg "" | Some RPC_arg.Eq -> subdir let register_value : type a b. a t -> get:(a -> b option tzresult Lwt.t) -> b Data_encoding.t -> unit = fun dir ~get encoding -> match !dir with | Empty -> dir := Value { get ; encoding } | _ -> invalid_arg "" let create () = ref Empty let rec pp : type a. Format.formatter -> a t -> unit = fun ppf dir -> match !dir with | Empty -> Format.fprintf ppf "EMPTY" | Value _e -> Format.fprintf ppf "Value" | NamedDir map -> Format.fprintf ppf "@[<v>%a@]" (Format.pp_print_list pp_item) (StringMap.bindings map) | IndexedDir { arg ; subdir ; _ } -> let name = Format.asprintf "<%s>" (RPC_arg.descr arg).name in pp_item ppf (name, subdir) and pp_item : type a. Format.formatter -> (string * a t) -> unit = fun ppf (name, dir) -> Format.fprintf ppf "@[<v 2>%s@ %a@]" name pp dir module type INDEX = sig type t val path_length: int val to_path: t -> string list -> string list val of_path: string list -> t option val rpc_arg: t RPC_arg.t val encoding: t Data_encoding.t val compare: t -> t -> int end type _ handler = Handler : { encoding: 'a Data_encoding.t ; get: 'key -> int -> 'a tzresult Lwt.t } -> 'key handler type _ opt_handler = Opt_handler : { encoding: 'a Data_encoding.t ; get: 'key -> int -> 'a option tzresult Lwt.t } -> 'key opt_handler let rec combine_object = function | [] -> Handler { encoding = Data_encoding.unit ; get = fun _ _ -> return_unit } | (name, Opt_handler handler) :: fields -> let Handler handlers = combine_object fields in Handler { encoding = Data_encoding.merge_objs Data_encoding.(obj1 (opt name (dynamic_size handler.encoding))) handlers.encoding ; get = fun k i -> handler.get k i >>=? fun v1 -> handlers.get k i >>=? fun v2 -> return (v1, v2) } type query = { depth: int ; } let depth_query = let open RPC_query in query (fun depth -> { depth }) |+ field "depth" RPC_arg.int 0 (fun t -> t.depth) |> seal let build_directory : type key. key t -> key RPC_directory.t = fun dir -> let rpc_dir = ref (RPC_directory.empty : key RPC_directory.t) in let register : type ikey. (key, ikey) RPC_path.t -> ikey opt_handler -> unit = fun path (Opt_handler { encoding ; get }) -> let service = RPC_service.get_service ~query: depth_query ~output: encoding path in rpc_dir := RPC_directory.register !rpc_dir service begin fun k q () -> get k (q.depth + 1) >>=? function | None -> raise Not_found | Some x -> return x end in let rec build_handler : type ikey. ikey t -> (key, ikey) RPC_path.t -> ikey opt_handler = fun dir path -> match !dir with | Empty -> Opt_handler { encoding = Data_encoding.unit ; get = fun _ _ -> return_none } | Value { get ; encoding } -> let handler = Opt_handler { encoding ; get = fun k i -> if Compare.Int.(i < 0) then return_none else get k } in register path handler ; handler | NamedDir map -> let fields = StringMap.bindings map in let fields = List.map (fun (name, dir) -> (name, build_handler dir RPC_path.(path / name))) fields in let Handler handler = combine_object fields in let handler = Opt_handler { encoding = handler.encoding ; get = fun k i -> if Compare.Int.(i < 0) then return_none else handler.get k (i-1) >>=? fun v -> return_some v } in register path handler ; handler | IndexedDir { arg ; arg_encoding ; list ; subdir } -> let Opt_handler handler = build_handler subdir RPC_path.(path /: arg) in let encoding = let open Data_encoding in union [ case (Tag 0) ~title:"Leaf" (dynamic_size arg_encoding) (function (key, None) -> Some key | _ -> None) (fun key -> (key, None)) ; case (Tag 1) ~title:"Dir" (tup2 (dynamic_size arg_encoding) (dynamic_size handler.encoding)) (function (key, Some value) -> Some (key, value) | _ -> None) (fun (key, value) -> (key, Some value)) ; ] in let get k i = if Compare.Int.(i < 0) then return_none else if Compare.Int.(i = 0) then return_some [] else list k >>=? fun keys -> map_s (fun key -> if Compare.Int.(i = 1) then return (key, None) else handler.get (k, key) (i-1) >>=? fun value -> return (key, value)) keys >>=? fun values -> return_some values in let handler = Opt_handler { encoding = Data_encoding.(list (dynamic_size encoding)) ; get ; } in register path handler ; handler in ignore (build_handler dir RPC_path.open_root : key opt_handler) ; !rpc_dir
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
optional_thunk.ml
type t = unit -> unit let none = Sys.opaque_identity (fun () -> ()) let some f = if f == none then failwith "Optional_thunk: this function is not representable as a some value"; f let is_none t = t == none let is_some t = not (is_none t) let call_if_some t = t () let unchecked_value t = t
resetFpgaImageAttribute.mli
open Types type input = ResetFpgaImageAttributeRequest.t type output = ResetFpgaImageAttributeResult.t type error = Errors_internal.t include Aws.Call with type input := input and type output := output and type error := error
dune
;; Extensions to `ppx_irmin` intended for Irmin developers only (library (kind ppx_rewriter) (name ppx_irmin_internal) (public_name ppx_irmin.internal) (modules ppx_irmin_internal) (ppx_runtime_libraries logs ppx_irmin.internal-lib) (preprocess (pps ppxlib.metaquot)) (libraries ppxlib ppx_irmin.internal-lib ;; Depending on [ppx_irmin.internal] implies a dependency on [ppx_irmin] ppx_irmin)) (library (name ppx_irmin_internal_lib) (public_name ppx_irmin.internal-lib) (modules ppx_irmin_internal_lib) (libraries logs))
fileutils.h
#ifndef Py_CPYTHON_FILEUTILS_H # error "this header file must not be included directly" #endif // Used by _testcapi which must not use the internal C API PyAPI_FUNC(FILE*) _Py_fopen_obj( PyObject *path, const char *mode);
proxy_events.ml
include Internal_event.Simple let section = ["proxy_rpc_ctxt"] let level = Internal_event.Debug let delegate_to_http = declare_3 ~section ~level ~name:"delegate_to_http" ~msg:"delegating to http: {method} {name} {path}" ("method", Data_encoding.string) ("name", Data_encoding.string) ("path", Data_encoding.string) let done_locally = declare_3 ~section ~level ~name:"done_locally" ~msg:"locally done: {method} {name} {path}" ("method", Data_encoding.string) ("name", Data_encoding.string) ("path", Data_encoding.string) let delegate_media_type_call_to_http = declare_2 ~section ~level ~name:"delegate_media_type_call_to_http" ~msg:"delegating to http generic media type call: {method} {uri}" ("method", Data_encoding.string) ("uri", Data_encoding.string) let done_media_type_call_locally = declare_2 ~section ~level ~name:"done_media_type_call_locally" ~msg:"locally done generic media type call: {method} {uri}" ("method", Data_encoding.string) ("uri", Data_encoding.string)
mutex.ml
open Stdune open Core open Core.O type t = { mutable locked : bool ; mutable waiters : unit k Queue.t } let lock t k = if t.locked then suspend (fun k -> Queue.push t.waiters k) k else ( t.locked <- true; k ()) let unlock t k = assert t.locked; match Queue.pop t.waiters with | None -> t.locked <- false; k () | Some next -> resume next () k let with_lock t ~f = let* () = lock t in finalize f ~finally:(fun () -> unlock t) let create () = { locked = false; waiters = Queue.create () }
bar.ml
(** The first special comment of the file is the comment associated with the whole module.*) let x = 1
(** The first special comment of the file is the comment associated with the whole module.*)
ml_gobject.h
/**************************************************************************/ /* Lablgtk */ /* */ /* This program is free software; you can redistribute it */ /* and/or modify it under the terms of the GNU Library General */ /* Public License as published by the Free Software Foundation */ /* version 2, with the exception described in file COPYING which */ /* comes with the library. */ /* */ /* This program 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 */ /* GNU Library General Public License for more details. */ /* */ /* You should have received a copy of the GNU Library General */ /* Public License along with this program; if not, write to the */ /* Free Software Foundation, Inc., 59 Temple Place, Suite 330, */ /* Boston, MA 02111-1307 USA */ /* */ /* */ /**************************************************************************/ /* $Id$ */ /* Defined in ml_gobject.h */ #define GObject_val(val) ((GObject*)Pointer_val(val)) CAMLexport value Val_GObject (GObject *); CAMLexport value Val_GObject_new (GObject *); CAMLexport value Val_GObject_sink (GInitiallyUnowned *); #define Val_GAnyObject(val) Val_GObject(G_OBJECT(val)) #define Val_GAnyObject_new(val) Val_GObject_new(G_OBJECT(val)) #define Val_GAnyObject_sink(val) Val_GObject_sink(G_INITIALLY_UNOWNED(val)) CAMLexport void ml_g_object_unref_later (GObject *); #define GType_val(t) ((GType)Addr_val(t)) #define Val_GType Val_addr #define GClosure_val(val) ((GClosure*)Pointer_val(val)) CAMLexport value Val_GClosure (GClosure *); #define GValueptr_val(val) ((GValue*)MLPointer_val(val)) CAMLexport GValue *GValue_val(value); /* check for NULL pointer */ CAMLexport value Val_GValue_copy(GValue *); /* copy from the stack */ #define Val_GValue_wrap Val_pointer /* just wrap a pointer */ CAMLexport value ml_g_value_new(void); CAMLexport value Val_gboxed(GType t, gpointer p); /* finalized gboxed */ CAMLexport value Val_gboxed_new(GType t, gpointer p); /* without copy */ /* Macro utilities for export */ /* used in ml_gtk.h for instance */ #ifdef G_DISABLE_CAST_CHECKS #define check_cast(f,v) f(Pointer_val(v)) #else #define check_cast(f,v) (Pointer_val(v) == NULL ? NULL : f(Pointer_val(v))) #endif
/**************************************************************************/ /* Lablgtk */ /* */ /* This program is free software; you can redistribute it */ /* and/or modify it under the terms of the GNU Library General */ /* Public License as published by the Free Software Foundation */ /* version 2, with the exception described in file COPYING which */ /* comes with the library. */ /* */ /* This program 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 */ /* GNU Library General Public License for more details. */ /* */ /* You should have received a copy of the GNU Library General */ /* Public License along with this program; if not, write to the */ /* Free Software Foundation, Inc., 59 Temple Place, Suite 330, */ /* Boston, MA 02111-1307 USA */ /* */ /* */ /**************************************************************************/
bitcoin_ocamlnet.ml
(********************************************************************************) (* Bitcoin_ocamlnet.ml Copyright (c) 2012-2015 Dario Teixeira <dario.teixeira@nleyten.com> *) (********************************************************************************) (** Offers an implementation of a {!Bitcoin.HTTPCLIENT} using Ocamlnet's [Http_client]. *) (********************************************************************************) (** {1 Public modules} *) (********************************************************************************) module Httpclient : Bitcoin.HTTPCLIENT with type 'a Monad.t = 'a = struct module Monad = struct type 'a t = 'a let return x = x let fail x = raise x let bind t f = f t let catch t f = try t () with | exc -> f exc end let post_string ~headers ~inet_addr ~host:_ ~port ~uri request = let dst = "http://" ^ Unix.string_of_inet_addr inet_addr ^ ":" ^ string_of_int port ^ uri in let pipeline = new Nethttp_client.pipeline in let request = new Nethttp_client.post_raw dst request in let () = List.iter (fun (k, v) -> request#set_req_header k v) headers in let () = pipeline#add request in let () = pipeline#run () in request#response_body#value end
(********************************************************************************) (* Bitcoin_ocamlnet.ml
legacy_api.ml
open! Core open! Import module type S = Module_types.Component_s type ('i, 'r) t = 'i Proc.Value.t -> 'r Proc.Computation.t module type Model = Model module type Action = Action let const x _ = Proc.const x let input = Proc.read let pure ~f i = Proc.read (Proc.Value.map i ~f) let compose a b i = Proc.Let_syntax.Let_syntax.sub (a i) ~f:b let map a ~f i = Proc.Let_syntax.Let_syntax.sub (a i) ~f:(fun x -> Proc.read (Proc.Value.map ~f x)) ;; let map_input a ~f i = a (Proc.Value.map i ~f) let of_module = Proc.of_module1 let state_machine model action here = Proc.state_machine1 here model action let both a b i = let open Proc.Let_syntax in let%sub a = a i in let%sub b = b i in return (Proc.Value.both a b) ;; let enum m ~which ~handle input = let match_ = Proc.Value.map input ~f:which in let with_ key = handle key input in Proc.enum m ~match_ ~with_ ;; let if_ choose ~then_ ~else_ input = let open Proc.Let_syntax in let cond = Proc.Value.map input ~f:choose in if%sub cond then then_ input else else_ input ;; module Map = struct let assoc_input comparator f input = Proc.assoc comparator input ~f:(fun _ -> f) let associ_input comparator f input = Proc.assoc comparator input ~f:(fun key data -> f (Proc.Value.both key data)) ;; let associ_input_with_extra comparator f input = let open Proc.Let_syntax in let%pattern_bind input, extra = input in Proc.assoc comparator input ~f:(fun key data -> f (Tuple3.create <$> key <*> data <*> extra)) ;; end include struct open Proc.Let_syntax let arr f = pure ~f let ( >>^ ) a f = map a ~f let ( ^>> ) a f = map_input a ~f let first f i = let%pattern_bind fst, snd = i in let%sub out = f fst in return (Proc.Value.both out snd) ;; let second f i = let%pattern_bind fst, snd = i in let%sub out = f snd in return (Proc.Value.both fst out) ;; let split f1 f2 i = let%pattern_bind fst, snd = i in let%sub out1 = f1 fst in let%sub out2 = f2 snd in return (Proc.Value.both out1 out2) ;; let extend_first f i = let%sub out = f i in return (Proc.Value.both out i) ;; let extend_second f i = let%sub out = f i in return (Proc.Value.both i out) ;; let fanout f1 f2 i = let%sub out1 = f1 i in let%sub out2 = f2 i in return (Proc.Value.both out1 out2) ;; let partial_compose_first f1 f2 i = let%sub out1 = f1 i in let%pattern_bind shared, out1 = out1 in let%sub out2 = f2 (Proc.Value.both i shared) in return (Proc.Value.both out1 out2) ;; let pipe f1 ~into ~via ~finalize i = let%sub r1 = f1 i in let intermediate = via <$> i <*> r1 in let%sub r2 = into intermediate in return (finalize <$> i <*> r1 <*> r2) ;; let ( *** ) = split let ( &&& ) = fanout end module With_incr = struct let of_incr i _ = Proc.read (Proc.Private.conceal_value (Value.of_incr i)) let of_module (type i m a r) (component : (i, m, a, r) component_s_incr) ~default_model input : r Proc.Computation.t = let input = Proc.Private.reveal_value input in let (module M) = component in let t = Computation.Leaf_incr { input ; dynamic_apply_action = M.apply_action ; compute = (fun _ -> M.compute) ; name = M.name } in Computation.T { t ; model = Meta.Model.of_module (module M.Model) ~name:M.name ~default:default_model ; dynamic_action = Meta.Action.of_module (module M.Action) ~name:M.name ; static_action = Meta.Action.nothing ; apply_static = Proc.unusable_static_apply_action } |> Proc.Private.conceal_computation ;; let pure (type i r) ~f = of_module (module struct module Input = struct type t = i end module Result = struct type t = r end module Model = Unit module Action = Nothing let name = "pure" let apply_action _ ~inject:_ = Incr.return (fun ~schedule_event:_ _ _ -> ()) let compute input _ ~inject:_ = f input end) ~default_model:() ;; let map a ~f = compose a (pure ~f) let model_cutoff f a = Proc.Incr.model_cutoff (f a) let value_cutoff ~cutoff = map input ~f:(fun input -> let input = Incr.map input ~f:Fn.id in Incr.set_cutoff input cutoff; input) ;; end module Infix = struct let ( >>> ) = compose let ( >>| ) a f = map a ~f let ( @>> ) f a = map_input a ~f end module Let_syntax = struct let return = const let map = map let both = both include Infix module Let_syntax = struct let return = const let both = both let map = map module Open_on_rhs = Infix end end
dune
(library (name l))
request.mli
(** HTTP/1.1 request handling *) include S.Request with type t = Http.Request.t (** This contains the metadata for a HTTP/1.1 request header, including the {!headers}, {!version}, {!meth} and {!uri}. The body is handled by the separate {!S} module type, as it is dependent on the IO implementation. The interface exposes a [fieldslib] interface which provides individual accessor functions for each of the records below. It also provides [sexp] serializers to convert to-and-from an {!Core.Std.Sexp.t}. *) val has_body : t -> [ `No | `Unknown | `Yes ] val pp_hum : Format.formatter -> t -> unit (** Human-readable output, used by the toplevel printer *) module Make (IO : S.IO) : S.Http_io with type t = t and module IO = IO [@@deprecated "This functor is not part of the public API."] module Private : sig module Make (IO : S.IO) : S.Http_io with type t = t and module IO = IO end
(*{{{ Copyright (c) 2012-2014 Anil Madhavapeddy <anil@recoil.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * }}}*)
encode.ml
open Util module type S = sig type value type 'a encoder = 'a -> value val string : string encoder val int : int encoder val float : float encoder val bool : bool encoder val null : value val nullable : 'a encoder -> 'a option encoder val option : 'a encoder -> 'a option encoder [@@ocaml.deprecated "Use nullable instead."] val list : 'a encoder -> 'a list encoder val array : 'a encoder -> 'a array encoder val obj : (string * value) list encoder val obj' : (value * value) list encoder val value : value encoder val of_to_string : ('a -> string) -> 'a encoder val encode_value : 'a encoder -> 'a -> value val encode_string : 'a encoder -> 'a -> string end module type Encodeable = sig type value val to_string : value -> string val of_string : string -> value val of_int : int -> value val of_float : float -> value val of_bool : bool -> value val null : value val of_list : value list -> value val of_key_value_pairs : (value * value) list -> value end module Make (E : Encodeable) : S with type value = E.value = struct type value = E.value type 'a encoder = 'a -> value let string x = E.of_string x let int x = E.of_int x let float x = E.of_float x let bool x = E.of_bool x let null = E.null let nullable encoder = function None -> E.null | Some x -> encoder x let option = nullable let list encoder xs = xs |> My_list.map (fun x -> encoder x) |> E.of_list let array encoder xs = xs |> Array.to_list |> My_list.map (fun x -> encoder x) |> E.of_list let obj' xs = E.of_key_value_pairs xs let obj xs = xs |> List.map (fun (k, v) -> (E.of_string k, v)) |> E.of_key_value_pairs let value x = x let of_to_string to_string x = string (to_string x) let encode_value encoder x = encoder x let encode_string encoder x = encoder x |> E.to_string end
raw_level_repr.mli
(** The shell's notion of a level: an integer indicating the number of blocks since genesis: genesis is 0, all other blocks have increasing levels from there. *) type t type raw_level = t val encoding: raw_level Data_encoding.t val rpc_arg: raw_level RPC_arg.arg val pp: Format.formatter -> raw_level -> unit include Compare.S with type t := raw_level val to_int32: raw_level -> int32 val of_int32_exn: int32 -> raw_level val of_int32: int32 -> raw_level tzresult val diff: raw_level -> raw_level -> int32 val root: raw_level val succ: raw_level -> raw_level val pred: raw_level -> raw_level option module Index : Storage_description.INDEX with type t = raw_level
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
test_blackbox.mli
(*_ This signature is deliberately empty. *)
(*_ This signature is deliberately empty. *)
token_helpers_js.mli
val is_eof : Parser_js.token -> bool val is_comment : Parser_js.token -> bool val token_kind_of_tok : Parser_js.token -> Parse_info.token_kind val info_of_tok : Parser_js.token -> Parse_info.t val visitor_info_of_tok : (Parse_info.t -> Parse_info.t) -> Parser_js.token -> Parser_js.token val line_of_tok : Parser_js.token -> int val col_of_tok : Parser_js.token -> int
main.mli
(** {!modules:External External.X Main Internal Internal.Y Z F Type_of Type_of_str With_type Alias C1 C2 Inline_include Starts_with_open Resolve_synopsis External.Resolve_synopsis} *) (** Doc for [Internal]. An other paragraph*) module Internal : sig module Y : sig end (** Doc for Internal.[X]. An other sentence. *) module C1 : sig end (** Doc for [C1]. @canonical Main.C1 *) module C2 : sig (* Doc for [C2]. *) end (** @canonical Main.C2 *) end module Z : sig (** Doc for [Z]. *) end module F () : sig (** Doc for [F ()]. *) end module Type_of : module type of F () (* Without the extra blank lines in sig/struct, OCaml<4.06 doesn't see the doc comments. *) module Type_of_str : module type of struct (** Doc of [Type_of_str]. *) end module type T = sig (** Doc for [T]. *) type t end module With_type : T with type t = int module Alias = External.X module C1 = Internal.C1 module C2 = Internal.C2 module Inline_include : sig include T (** @inline *) end module Resolve_synopsis : sig (** This should be resolved when included: {!Main.Resolve_synopsis.t}. These shouldn't: {!t} {!Resolve_synopsis.t} *) type t end
(** {!modules:External External.X Main Internal Internal.Y Z F Type_of Type_of_str With_type Alias C1 C2 Inline_include Starts_with_open Resolve_synopsis External.Resolve_synopsis} *)
storage_description.mli
(** This module is responsible for building the description of the current state of the storage, which is then used to build specification of the RPC endpoints for accessing the storage. It produces [resto] [RPC_directory.t] values, which can be used directly to construct the RPC endpoint tree. *) (** Typed description of the key-value context. *) type 'key t (** Trivial display of the key-value context layout. *) val pp : Format.formatter -> 'key t -> unit (** Export an RPC hierarchy for querying the context. There is one service by possible path in the context. Services for "directory" are able to aggregate in one JSON object the whole subtree. *) val build_directory : 'key t -> 'key RPC_directory.t (** Create a empty context description, keys will be registered by side effects. *) val create : unit -> 'key t (** Register a single key accessor at a given path. *) val register_value : 'key t -> get:('key -> 'a option tzresult Lwt.t) -> 'a Data_encoding.t -> unit (** Return a description for a prefixed fragment of the given context. All keys registered in the subcontext will be shared by the external context *) val register_named_subcontext : 'key t -> string list -> 'key t (** Description of an index as a sequence of `RPC_arg.t`. *) type (_, _, _) args = | One : { rpc_arg : 'a RPC_arg.t; encoding : 'a Data_encoding.t; compare : 'a -> 'a -> int; } -> ('key, 'a, 'key * 'a) args | Pair : ('key, 'a, 'inter_key) args * ('inter_key, 'b, 'sub_key) args -> ('key, 'a * 'b, 'sub_key) args (** Return a description for a indexed sub-context. All keys registered in the subcontext will be shared by the external context. One should provide a function to list all the registered index in the context. *) val register_indexed_subcontext : 'key t -> list:('key -> 'arg list tzresult Lwt.t) -> ('key, 'arg, 'sub_key) args -> 'sub_key t (** Helpers for manipulating and defining indexes. *) val pack : ('key, 'a, 'sub_key) args -> 'key -> 'a -> 'sub_key val unpack : ('key, 'a, 'sub_key) args -> 'sub_key -> 'key * 'a module type INDEX = sig type t include Path_encoding.S with type t := t val rpc_arg : t RPC_arg.t val encoding : t Data_encoding.t val compare : t -> t -> int end
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)
dune
(library (public_name dscheck) (libraries containers oseq))
Ci_CLI.ml
open Cmdliner (*****************************************************************************) (* Prelude *) (*****************************************************************************) (* 'semgrep ci' subcommand Translated from ci.py *) (*****************************************************************************) (* Types and constants *) (*****************************************************************************) (* 'semgrep ci' shares most of its flags with 'semgrep scan' *) type conf = Scan_CLI.conf (*************************************************************************) (* Command-line parsing: turn argv into conf *) (*************************************************************************) let doc = "the recommended way to run semgrep in CI" let man : Manpage.block list = [ `S Manpage.s_description; `P "In pull_request/merge_request (PR/MR) contexts, `semgrep ci` will only \ report findings that were introduced by the PR/MR."; `P "When logged in, `semgrep ci` runs rules configured on Semgrep App and \ sends findings to your findings dashboard."; `P "Only displays findings that were marked as blocking."; ] @ CLI_common.help_page_bottom let cmdline_info : Cmd.info = Cmd.info "semgrep ci" ~doc ~man (*****************************************************************************) (* Entry point *) (*****************************************************************************) let parse_argv (argv : string array) : conf = (* mostly a copy of Scan_CLI.parse_argv with different doc and man *) let cmd : conf Cmd.t = Cmd.v cmdline_info Scan_CLI.cmdline_term in CLI_common.eval_value ~argv cmd
lazy_backtrack.ml
type ('a,'b) t = ('a,'b) eval ref and ('a,'b) eval = | Done of 'b | Raise of exn | Thunk of 'a type undo = | Nil | Cons : ('a, 'b) t * 'a * undo -> undo type log = undo ref let force f x = match !x with | Done x -> x | Raise e -> raise e | Thunk e -> match f e with | y -> x := Done y; y | exception e -> x := Raise e; raise e let get_arg x = match !x with Thunk a -> Some a | _ -> None let get_contents x = match !x with | Thunk a -> Either.Left a | Done b -> Either.Right b | Raise e -> raise e let create x = ref (Thunk x) let create_forced y = ref (Done y) let create_failed e = ref (Raise e) let log () = ref Nil let force_logged log f x = match !x with | Done x -> x | Raise e -> raise e | Thunk e -> match f e with | (Error _ as err : _ result) -> x := Done err; log := Cons(x, e, !log); err | Ok _ as res -> x := Done res; res | exception e -> x := Raise e; raise e let backtrack log = let rec loop = function | Nil -> () | Cons(x, e, rest) -> x := Thunk e; loop rest in loop !log (* For compatibility with 4.02 and 4.03 *) let is_val t = match !t with | Done _ -> true | Raise _ | Thunk _ -> false let view t = !t (* For compatibility with 4.08 and 4.09 *) let force_logged_408 log f x = match !x with | Done x -> x | Raise e -> raise e | Thunk e -> match f e with | None -> x := Done None; log := Cons(x, e, !log); None | Some _ as y -> x := Done y; y | exception e -> x := Raise e; raise e
clb_os_wrapper.c
#include <unistd.h> #include <time.h> #include "clb_os_wrapper.h" /*---------------------------------------------------------------------*/ /* Global Variables */ /*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/ /* Forward Declarations */ /*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/ /* Internal Functions */ /*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/ /* Exported Functions */ /*---------------------------------------------------------------------*/ /*----------------------------------------------------------------------- // // Function: SetSoftRlimit() // // Set a soft limit to the given value (or as close as the hard // limit allows). Return result. If get- or setrlimit() fail, errno // will contain the corresponding cause. // // Global Variables: - // // Side Effects : Changes the limits // /----------------------------------------------------------------------*/ RLimResult SetSoftRlimit(int resource, rlim_t limit) { RLimResult retval = RLimSuccess; struct rlimit rlim; if(getrlimit(resource, &rlim)==-1) { TmpErrno = errno; return RLimFailed; } if(rlim.rlim_max < limit) { retval = RLimReduced; limit = rlim.rlim_max; } rlim.rlim_cur = limit; if(setrlimit(resource, &rlim)==-1) { TmpErrno = errno; retval = RLimFailed; } return retval; } /*----------------------------------------------------------------------- // // Function: SetSoftRlimitErr() // // Try to set a soft limit to the given value. Print a warning if it // has to be reduced, terminate with a proper system error if it // fails. If desc is provided, use it for messages. // // Global Variables: // // Side Effects : As described... // /----------------------------------------------------------------------*/ void SetSoftRlimitErr(int resource, rlim_t limit, char* desc) { char* ldesc =""; static char message[300]; RLimResult res; if(desc) { ldesc = desc; } res = SetSoftRlimit(resource, limit); switch(res) { case RLimFailed: snprintf(message, 300, "Could not set limit %s to %lld (%s)", ldesc, (long long)limit, strerror(TmpErrno)); Warning(message); break; case RLimReduced: snprintf(message, 300, "Had to reduce limit %s", ldesc); Warning(message); break; case RLimSuccess: /* Nothing to do */ break; default: assert(false && "Out of bounds return from SetSoftRlimit()"); break; } } /*----------------------------------------------------------------------- // // Function: SetMemoryLimit() // // Set memory limit to the given limit (if any), or the largest // possible. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ void SetMemoryLimit(rlim_t mem_limit) { if(!mem_limit) { return; } SetSoftRlimitErr(RLIMIT_DATA, mem_limit, "RLIMIT_DATA"); #ifdef RLIMIT_AS SetSoftRlimitErr(RLIMIT_DATA, mem_limit, "RLIMIT_AS"); #endif /* RLIMIT_AS */ } /*----------------------------------------------------------------------- // // Function: GetSoftRlimit() // // Return the soft limit for the given resource, or 0 on failure. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ rlim_t GetSoftRlimit(int resource) { struct rlimit rlim; if(getrlimit(resource, &rlim)==-1) { return 0; } return rlim.rlim_cur; } /*----------------------------------------------------------------------- // // Function: IncreaseMaxStackSize() // // Try to increase the maximum stack size, then reexec the process // to work under the new limit. At least on some UNIXES, maximum // stack size cannot increase after the process has started). // // Global Variables: - // // Side Effects : Well, all, but really none ;-) // /----------------------------------------------------------------------*/ /* void IncreaseMaxStackSize(char *argv[], rlim_t stacksize) */ /* { */ /* int i, argc; */ /* char* opt="Dummy"; */ /* printf("Hallo\n"); */ /* char **argv2; */ /* for(i=1; argv[i]; i++) */ /* { */ /* printf("Hallo %s\n", argv[i]); */ /* if(strcmp(argv[i], opt)==0) */ /* { */ /* return; */ /* } */ /* } */ /* argc = i; */ /* if(GetSoftRlimit(RLIMIT_STACK)>=stacksize*KILO) */ /* { */ /* return; */ /* } */ /* if(SetSoftRlimit(RLIMIT_STACK, stacksize*KILO)!=RLimSuccess) */ /* { */ /* TmpErrno = errno; */ /* Warning("Cannot set stack limit:"); */ /* Warning(strerror(TmpErrno)); */ /* Warning("Continuing with default stack limit"); */ /* return; */ /* } */ /* argv2 = malloc(sizeof(char*) * (argc+2)); */ /* for(i=0; argv[i]; i++) */ /* { */ /* argv2[i] = argv[i]; */ /* } */ /* argv2[i] = opt; */ /* argv2[i+1] = NULL; */ /* if(execvp(argv2[0], argv2)) */ /* { */ /* TmpErrno = errno; */ /* SysError("Cannot exec", SYS_ERROR); */ /* } */ /* free(argv2); */ /* } */ /*----------------------------------------------------------------------- // // Function: GetUSecTime() // // Return the time in microseconds since the epoch. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ long long GetUSecTime(void) { struct timeval tv; gettimeofday(&tv, NULL); return (long long)tv.tv_sec*1000000ll+tv.tv_usec; } /*----------------------------------------------------------------------- // // Function: GetUSecClock() // // Return the process cpu time in microseconds. // // Global Variables: - // // Side Effects : - // /----------------------------------------------------------------------*/ long long GetUSecClock(void) { long long res = (clock()*1000000ll)/CLOCKS_PER_SEC; return res; } /*----------------------------------------------------------------------- // // Function: SecureFOpen() // // As fopen(), but terminate with a useful error message on failure. // // Global Variables: // // Side Effects : // /----------------------------------------------------------------------*/ FILE* SecureFOpen(char* name, char* mode) { FILE* res; res = fopen(name, mode); if(!res) { TmpErrno = errno; SysError("Cannot open file %s",FILE_ERROR,name); } return res; } /*----------------------------------------------------------------------- // // Function: SecureFClose() // // As fclose(), but print a warning on error. // // Global Variables: // // Side Effects : // /----------------------------------------------------------------------*/ void SecureFClose(FILE* fp) { if(fclose(fp)) { TmpErrno = errno; SysWarning("Problem closing file"); } } /*---------------------------------------------------------------------*/ /* End of File */ /*---------------------------------------------------------------------*/
/*----------------------------------------------------------------------- File : clb_os_wrapper.c Author: Stephan Schulz (schulz@eprover.org) Contents Wrapper functions for certain OS functionality. Copyright 2007 by the author. This code is released under the GNU General Public Licence and the GNU Lesser General Public License. See the file COPYING in the main E directory for details.. Run "eprover -h" for contact information. Changes <1> Sun Jul 1 13:45:15 CEST 2007 New -----------------------------------------------------------------------*/
latex.mli
(** This modules weaves the source code and the legislative text together into a document that law professionals can understand. *) open Catala_utils (** {1 Helpers} *) val wrap_latex : string list -> Cli.backend_lang -> Format.formatter -> (Format.formatter -> unit) -> unit (** Usage: [wrap_latex source_files language fmt wrapped] Prints an LaTeX complete documùent structure around the [wrapped] content. *) (** {1 API} *) val ast_to_latex : Cli.backend_lang -> print_only_law:bool -> Format.formatter -> Surface.Ast.program -> unit
(* This file is part of the Catala compiler, a specification language for tax and social benefits computation rules. Copyright (C) 2020 Inria, contributor: Denis Merigoux <denis.merigoux@inria.fr> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *)
Test_parsing_scala.mli
(* Print the set of tokens in a .scala file *) val test_tokens : Common.filename -> unit val actions : unit -> Arg_helpers.cmdline_actions
(* Print the set of tokens in a .scala file *) val test_tokens : Common.filename -> unit
iterExtra.ml
type 'a iter = 'a Iter.iter type 'a next = 'a Iter.iter -> 'a Iter.iter let ( $$ ) = (Iter.( $$ ) : 'a iter -> ('a -> 'b) -> 'b iter ) let ( $? ) = (Iter.( $? ) : 'a iter -> ('a -> 'b option) -> 'b iter ) let ( $$+ ) = (Iter.( $$+ ) : 'a iter -> ('a -> 'b) -> 'b next ) let ( $! ) = (Iter.( $! ) : 'a iter -> ('b -> 'a -> 'b) -> 'b -> 'b ) let ( $!! ) = (Iter.( $!! ) : 'a iter -> ('a -> 'a -> 'a) -> 'a option ) let ( $+ ) = (Iter.( $+ ) : 'a iter -> 'a iter -> 'a iter ) let ( $@++ ) = (Iter.( $@++) : 'a iter -> ('a -> 'b next) -> 'b next ) let ( $@+ ) = (Iter.( $@+ ) : 'a iter -> ('a -> 'b iter) -> 'b next ) let ( $@ ) = (Iter.( $@ ) : 'a iter -> ('a -> 'b iter) -> 'b iter ) let ( $*+ ) = (Iter.( $*+ ) : 'a iter -> 'b iter -> ('a * 'b) next ) let ( $* ) = (Iter.( $* ) : 'a iter -> 'b iter -> ('a * 'b) iter ) let ( $:+ ) = (Iter.( $:+ ) : 'a iter -> 'a list iter -> 'a list next ) let ( $: ) = (Iter.( $: ) : 'a iter -> 'a list iter -> 'a list iter ) let ( $^+ ) = (Iter.( $^+ ) : 'a iter -> int -> 'a list next ) let ( $^ ) = (Iter.( $^ ) : 'a iter -> int -> 'a list iter ) let ( $<++ ) = (Iter.( $<++ ): int -> (int -> 'a next) -> 'a next ) let ( $<+ ) = (Iter.( $<+ ) : int -> (int -> 'a iter) -> 'a next ) let ( $< ) = (Iter.( $< ) : int -> (int -> 'a iter) -> 'a iter )
(* * LGPL-3.0 Linking Exception * * Copyright (c) 2020-2022 Joan Thibault (joan.thibault@irisa.fr) * * GuaCaml : Generic Unspecific Algorithmic in OCaml * * IterExtra : Extension of OCaml's Standard Short Notations for * for [Iter] module on iterators. *)
state.ml
let empty = Base.Map.empty (module Base.String) let create assignments = match Base.Map.of_alist (module Base.String) assignments with | `Ok result -> Some result | `Duplicate_key _ -> None let create_exn assignments = Base.Map.of_alist_exn (module Base.String) assignments let rec value_of state value = match value with | Type.Var variable_name -> (match Base.Map.find state variable_name with | Some value -> value_of state value | None -> Type.Var variable_name) | _ -> value let add_to_state state variable_name value = match Base.Map.add state ~key:variable_name ~data:value with | `Ok result -> Some result | `Duplicate -> None let unify state value_a value_b = let new_value_a = value_of state value_a in let new_value_b = value_of state value_b in match new_value_a, new_value_b with | a, b when (Type.compare a b) = 0 -> Some state | Type.Var variable_name, value -> add_to_state state variable_name value | value, Type.Var variable_name -> add_to_state state variable_name value | _, _ -> None let assignment_to_string ~key ~data acc = Base.List.cons ("(" ^ key ^ Value.to_string data ^ ")") acc let to_string state = let assignments_content = Base.Map.fold state ~init:[] ~f:assignment_to_string in if Base.List.length assignments_content <> 0 then let assignments = Base.List.concat [["(Assignments("]; assignments_content; ["))"]] in Base.String.concat ~sep:"" assignments else ""
Core.ml
open Logic IFDEF STATS THEN type stat = { mutable unification_count : int; mutable unification_time : Mtime.span; mutable conj_counter : int; mutable disj_counter : int; mutable delay_counter : int } let stat = { unification_count = 0; unification_time = Mtime.Span.zero; conj_counter = 0; disj_counter = 0; delay_counter = 0 } let unification_counter () = stat.unification_count let unification_time () = stat.unification_time let conj_counter () = stat.conj_counter let disj_counter () = stat.disj_counter let delay_counter () = stat.delay_counter let (unification_incr,unification_time_incr,conj_counter_incr,disj_counter_incr,delay_counter_incr) = match Sys.getenv_opt "OCANREN_BENCH_COUNTS" with | None -> let c = (fun _ -> ()) in (c,c,c,c,c) | Some _ -> let unification_incr () = stat.unification_count <- stat.unification_count + 1 in let unification_time_incr t = stat.unification_time <- Mtime.Span.add stat.unification_time (t ()) in let conj_counter_incr () = stat.conj_counter <- stat.conj_counter + 1 in let disj_counter_incr () = stat.disj_counter <- stat.disj_counter + 1 in let delay_counter_incr () = stat.delay_counter <- stat.delay_counter + 1 in (unification_incr,unification_time_incr,conj_counter_incr,disj_counter_incr,delay_counter_incr) END (* to avoid clash with Std.List (i.e. logic list) *) module List = Stdlib.List module Answer : sig (* [Answer.t] - a type that represents (untyped) answer to a query *) type t (* [make env t] creates the answer from the environment and term (with constrainted variables) *) val make : Env.t -> Term.t -> t (* [lift env a] lifts the answer into different environment, replacing all variables consistently *) val lift : Env.t -> t -> t (* [env a] returns an environment of the answer *) val env : t -> Env.t (* [unctr_term a] returns a term with unconstrained variables *) val unctr_term : t -> Term.t (* [ctr_term a] returns a term with constrained variables *) val ctr_term : t -> Term.t (* [disequality a] returns all disequality constraints on variables in term as a list of bindings *) val disequality : t -> Subst.Binding.t list (* [equal t t'] syntactic equivalence (not an alpha-equivalence) *) val equal : t -> t -> bool (* [hash t] hashing that is consistent with syntactic equivalence *) val hash : t -> int end = struct type t = Env.t * Term.t let make env t = (env, t) let env (env, _) = env let unctr_term (_, t) = Term.map t ~fval:(fun x -> Term.repr x) ~fvar:(fun v -> Term.repr {v with Term.Var.constraints = []}) let ctr_term (_, t) = t let disequality (env, t) = let rec helper acc x = Term.fold x ~init:acc ~fval:(fun acc _ -> acc) ~fvar:(fun acc var -> ListLabels.fold_left var.Term.Var.constraints ~init:acc ~f:(fun acc ctr_term -> let ctr_term = Term.repr ctr_term in let var = {var with Term.Var.constraints = []} in let term = unctr_term @@ (env, ctr_term) in let acc = Subst.(Binding.({var; term}))::acc in helper acc ctr_term ) ) in helper [] t let lift env' (env, t) = let vartbl = Term.VarTbl.create 31 in let rec helper x = Term.map x ~fval:(fun x -> Term.repr x) ~fvar:(fun v -> Term.repr @@ try Term.VarTbl.find vartbl v with Not_found -> let new_var = Env.fresh ~scope:Term.Var.non_local_scope env' in Term.VarTbl.add vartbl v new_var; {new_var with Term.Var.constraints = List.map (fun x -> helper x) v.Term.Var.constraints |> List.sort Term.compare } ) in (env', helper t) let check_envs_exn env env' = if Env.equal env env' then () else failwith "OCanren fatal (Answer.check_envs): answers from different environments" let equal (env, t) (env', t') = check_envs_exn env env'; Term.equal t t' let hash (env, t) = Term.hash t end module Prunes : sig type rez = Violated | NonViolated type ('a, 'b) reifier = ('a,'b) Reifier.t type 'b cond = 'b -> bool type t val empty : t (* Returns false when constraints are violated *) val recheck : t -> Env.t -> Subst.t -> rez val check_last : t -> Env.t -> Subst.t -> rez val extend : t -> Term.VarTbl.key -> ('a, 'b) reifier -> 'b cond -> t end = struct type rez = Violated | NonViolated type ('a, 'b) reifier = ('a,'b) Reifier.t type reifier_untyped = Obj.t type 'b cond = 'b -> bool type cond_untyped = Obj.t -> bool let make_untyped : ('a, 'b) reifier -> 'b cond -> reifier_untyped * cond_untyped = fun a b -> Obj.magic (a,b) type t = (Obj.t * (reifier_untyped * cond_untyped)) list let empty = [] exception Fail let check_last map env subst = try let (term, (reifier, checker)) = List.hd map in let reifier : (_,_) reifier = Obj.obj reifier in let reified = reifier env (Obj.magic @@ Subst.apply env subst term) in if not (checker reified) then raise Fail; NonViolated with Not_found -> NonViolated | Fail -> Violated let recheck (ps: t) env s = try ps |> List.iter (fun (k, (reifier, checker)) -> let reifier : (_,_) Reifier.t = Obj.obj reifier in let reified = reifier env (Obj.magic @@ Subst.apply env s k) in if not (checker reified) then raise Fail ); NonViolated with Fail -> Violated let extend map term rr cond = let new_item = make_untyped rr cond in (Obj.repr term, new_item) :: map end type prines_control = { mutable pc_do_skip : bool ; mutable pc_checks_skipped : int ; mutable pc_max_to_skip : int ; mutable pc_skipped_prunes_total : int } let prunes_control = { pc_checks_skipped = 10; pc_do_skip=false; pc_max_to_skip = 11 ; pc_skipped_prunes_total = 0 } module PrunesControl = struct let enable_skips ~on = (* Printf.printf "enabling skips: %b\n%!" on;*) prunes_control.pc_do_skip <- on let is_enabled () = prunes_control.pc_do_skip let reset_cur_counter () = prunes_control.pc_checks_skipped <- 0 let reset () = reset_cur_counter (); prunes_control.pc_skipped_prunes_total <- 0 let set_max_skips n = assert (n>0); prunes_control.pc_max_to_skip <- n; reset () let skipped_prunes () = prunes_control.pc_skipped_prunes_total let incr () = if is_enabled () then let () = prunes_control.pc_checks_skipped <- 1 + prunes_control.pc_checks_skipped in prunes_control.pc_skipped_prunes_total <- 1 + prunes_control.pc_skipped_prunes_total let is_exceeded () = (not (is_enabled())) || (let ans = (prunes_control.pc_checks_skipped >= prunes_control.pc_max_to_skip) in (* Printf.printf "is_exceeded = %b, cur_steps=%d, max_steps=%d\n%!" ans prunes_control.pc_checks_skipped prunes_control.pc_max_to_skip;*) ans ) end (* let do_skip_prunes = ref false let prunes_checks_skipped = ref 0 let max_prunes_skipped = ref 10 let set_skip_prunes_count n = assert (n>0); max_prunes_skipped := n *) module State = struct type t = { env : Env.t ; subst : Subst.t ; ctrs : Disequality.t ; prunes: Prunes.t ; scope : Term.Var.scope } type reified = Env.t * Term.t let empty () = { env = Env.empty () ; subst = Subst.empty ; ctrs = Disequality.empty ; prunes = Prunes.empty ; scope = Term.Var.new_scope () } let env {env} = env let subst {subst} = subst let constraints {ctrs} = ctrs let scope {scope} = scope let prunes {prunes} = prunes let fresh {env; scope} = Env.fresh ~scope env let new_scope st = {st with scope = Term.Var.new_scope ()} let unify x y ({env; subst; ctrs; scope} as st) = match Subst.unify ~scope env subst x y with | None -> None | Some (prefix, subst) -> match Disequality.recheck env subst ctrs prefix with | None -> None | Some ctrs -> let next_state = {st with subst; ctrs} in if PrunesControl.is_exceeded () then begin let () = PrunesControl.reset_cur_counter () in match Prunes.recheck (prunes next_state) env subst with | Prunes.Violated -> None | NonViolated -> Some next_state end else begin (* print_endline "check skipped";*) let () = PrunesControl.incr () in Some next_state end let diseq x y ({env; subst; ctrs; scope} as st) = match Disequality.add env subst ctrs x y with | None -> None | Some ctrs -> match Prunes.recheck (prunes st) env subst with | Prunes.Violated -> None | NonViolated -> Some {st with ctrs} (* returns always non-empty list *) let reify x {env; subst; ctrs} = let answ = Subst.reify env subst x in match Disequality.reify env subst ctrs x with | [] -> [Answer.make env answ] | diseqs -> ListLabels.map diseqs ~f:(fun diseq -> let rec helper forbidden t = Term.map t ~fval:(fun x -> Term.repr x) ~fvar:(fun v -> Term.repr @@ if List.mem v.Term.Var.index forbidden then v else {v with Term.Var.constraints = Disequality.Answer.extract diseq v |> List.filter (fun dt -> match Env.var env dt with | Some u -> not (List.mem u.Term.Var.index forbidden) | None -> true ) |> List.map (fun x -> helper (v.Term.Var.index::forbidden) x) (* TODO: represent [Var.constraints] as [Set]; * TODO: hide all manipulations on [Var.t] inside [Var] module; *) |> List.sort Term.compare } ) in Answer.make env (helper [] answ) ) end let (!!!) = Obj.magic type 'a goal' = State.t -> 'a type goal = State.t Stream.t goal' let success st = Stream.single st let failure _ = Stream.nil let only_head g st = let stream = g st in try Stream.single @@ Stream.hd stream with Failure _ -> Stream.nil let (===) x y st = let _t = IFDEF STATS THEN (let () = unification_incr () in Timer.make ()) ELSE () END in match State.unify x y st with | Some st -> let () = IFDEF STATS THEN unification_time_incr _t ELSE () END in success st | None -> let () = IFDEF STATS THEN unification_time_incr _t ELSE () END in failure st let unify = (===) let (=/=) x y st = match State.diseq x y st with | Some st -> let () = IFDEF STATS THEN delay_counter_incr () ELSE () END in success st | None -> failure st let diseq = (=/=) let delay g st = Stream.from_fun (fun () -> g () st) let conj f g st = let () = IFDEF STATS THEN conj_counter_incr () ELSE () END in Stream.bind (f st) g let debug_var v reifier call = fun st -> let xs = List.map (fun answ -> reifier (Obj.magic @@ Answer.ctr_term answ) (Answer.env answ) ) (State.reify v st) in call xs st let structural : 'a -> ('a , 'b) Reifier.t -> ('b -> bool) -> goal = fun term rr k st -> let new_constraints = Prunes.extend (State.prunes st) (Obj.magic term) rr k in match Prunes.check_last new_constraints (State.env st) (State.subst st) with | Prunes.Violated -> failure st | NonViolated -> success { st with State.prunes = new_constraints } (* include (struct @type cost = CFixed of GT.int | CAtLeast of GT.int with show let show_cost x = GT.show cost x let minimize cost reifier var goalish state = let old_cost = ref None in goalish var state |> Stream.filter (fun st0 -> let reified = let env = State.env st0 in let s = State.subst st0 in reifier env (Obj.magic @@ Subst.apply env s var) in let c = cost reified in match !old_cost with | None -> Format.printf "setting intial cost %s\n%!" (show_cost c); old_cost := Some c; true | Some old -> match (old,c) with | CFixed old,CFixed new_ when old < new_ -> false | CFixed old, CFixed new_ when old = new_ -> true | CFixed old, CFixed new_ -> Format.printf "setting cost %s\n%!" (show_cost c); old_cost := Some c; true | CAtLeast old, CFixed new_ when old < new_ -> false | CAtLeast old, CFixed new_ -> Format.printf "setting cost %s\n%!" (show_cost c); old_cost := Some c; true | CFixed old, CAtLeast new_ when old < new_ -> false | CFixed old, CAtLeast new_ -> true | CAtLeast old, CAtLeast new_ when old < new_ -> false | CAtLeast old, CAtLeast new_ -> Format.printf "setting cost %s\n%!" (show_cost c); old_cost := Some c; true ) end : sig type cost = CFixed of GT.int | CAtLeast of GT.int val minimize : ('b -> cost) -> (Env.t -> 'a ilogic -> 'a) -> ('a ilogic) -> ('logicvar -> goal) -> goal end) *) let (&&&) = conj (* This is a strightforward implementation but in Scheme it is implemented differently *) (* let (?&) gs = List.fold_right (&&&) gs success *) (* This is actual clone of Scheme implementation *) let (?&) gs st = match gs with | [h] -> h st | h::tl -> List.fold_left (fun acc x -> Stream.bind acc x) (h st) tl | [] -> assert false (* TODO: Maybe introduce a special multiconjunction without corner case?*) let disj_base f g st = Stream.mplus (f st) (Stream.from_fun (fun () -> g st)) let disj f g st = let () = IFDEF STATS THEN disj_counter_incr () ELSE () END in let st = State.new_scope st in disj_base f g |> (fun g -> Stream.from_fun (fun () -> g st)) let (|||) = disj let (?|) gs st = let st = State.new_scope st in let rec inner = function | [g] -> g | g::gs -> disj_base g (inner gs) | [] -> failwith "Wrong argument of (?!)" in inner gs |> (fun g -> Stream.from_fun (fun () -> g st)) let conde = (?|) let call_fresh f st = let x = State.fresh st in f x st module Fresh = struct let succ prev f = call_fresh (fun x -> prev (f x)) let zero f = f let one f = succ zero f let two f = succ one f (* N.B. Manual inlining of numerals will speed-up OCanren a bit (mainly because of less memory consumption) *) (* let two g = fun st -> let scope = State.scope st in let env = State.env st in let q = Env.fresh ~scope env in let r = Env.fresh ~scope env in g q r st *) let three f = succ two f let four f = succ three f let five f = succ four f let q = one let qr = two let qrs = three let qrst = four let pqrst = five end (* ******************************************************************************* *) (* ************************** Reification stuff ********************************** *) module ExtractDeepest = struct let ext2 x = x let succ prev (a, z) = let foo, base = prev z in ((a, foo), base) end module Curry = struct let one = (@@) let succ k f x = k (fun tup -> f (x, tup)) end module Uncurry = struct let one = (@@) let succ k f (x,y) = k (f x) y end module LogicAdder : sig val zero : goal -> goal val succ : ('a -> State.t -> 'd) -> ('e ilogic -> 'a) -> State.t -> 'e ilogic * 'd end = struct let zero f = f let succ prev f = call_fresh (fun logic st -> (logic, prev (f logic) st)) end module ReifyTuple = struct let one x env = make_rr env x let succ prev (x, xs) env = (make_rr env x, prev xs env) end module NUMERAL_TYPS = struct type ('a, 'c, 'e, 'f, 'g) one = unit -> (('a ilogic -> goal) -> State.t -> 'a ilogic * State.t Stream.t) * ('c ilogic -> Env.t -> 'c reified) * ('e -> 'e) * (('f -> 'g) -> 'f -> 'g) type ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j) two = unit -> (('a Logic.ilogic -> 'b Logic.ilogic -> goal) -> State.t -> 'a Logic.ilogic * ('b Logic.ilogic * State.t Stream.t)) * ('c Logic.ilogic * 'd Logic.ilogic -> Env.t -> 'c Logic.reified * 'd Logic.reified) * ('e * ('f * 'g) -> ('e * 'f) * 'g) * (('h -> 'i -> 'j) -> 'h * 'i -> 'j) type ('a,'c,'e,'g,'i,'k,'m,'n,'o,'p,'q,'r,'s,'t) three = unit -> (('a ilogic -> 'c ilogic -> 'e ilogic -> goal) -> State.t -> 'a ilogic * ('c ilogic * ('e ilogic * State.t Stream.t))) * ('g ilogic * ('i ilogic * 'k ilogic) -> Env.t -> 'g reified * ('i reified * 'k reified)) * ('m * ('n * ('o * 'p)) -> ('m * ('n * 'o)) * 'p) * (('q -> 'r -> 's -> 't) -> 'q * ('r * 's) -> 't) type ('a,'b,'c,'d,'e,'f,'g,'h,'i,'j,'k,'l,'m,'n,'o,'p,'q,'r) four = unit -> (('a ilogic -> 'b ilogic -> 'c ilogic -> 'd ilogic -> goal) -> State.t -> 'a ilogic * ('b ilogic * ('c ilogic * ('d ilogic * State.t Stream.t)))) * ('e ilogic * ('f ilogic * ('g ilogic * 'h ilogic)) -> Env.t -> 'e reified * ('f reified * ('g reified * 'h reified))) * ('i * ('j * ('k * ('l * 'm))) -> ('i * ('j * ('k * 'l))) * 'm) * (('n -> 'o -> 'p -> 'q -> 'r) -> 'n * ('o * ('p * 'q)) -> 'r) end let succ n () = let adder, app, ext, uncurr = n () in (LogicAdder.succ adder, ReifyTuple.succ app, ExtractDeepest.succ ext, Uncurry.succ uncurr) let one : (_,_,_,_,_) NUMERAL_TYPS.one = fun () -> (LogicAdder.(succ zero)), ReifyTuple.one, ExtractDeepest.ext2, Uncurry.one let two : (_,_,_,_,_,_,_,_,_,_) NUMERAL_TYPS.two = fun () -> succ one () let three () = succ two () let four () = succ three () let five () = succ four () let q = one let qr : (_,_,_,_,_,_,_,_,_,_) NUMERAL_TYPS.two = two let qrs = three let qrst = four let qrstu = five let run n g h = let adder, reifier, ext, uncurr = n () in let args, stream = ext @@ adder g @@ State.empty () in Stream.bind stream (fun st -> Stream.of_list @@ State.reify args st) |> Stream.map (fun answ -> uncurr h @@ reifier (Obj.magic @@ Answer.ctr_term answ) (Answer.env answ) ) (** ************************************************************************* *) (** Tabling primitives *) module Table : sig (* Type of table. * Table is a map from answer term to the set of answer terms, * i.e. Answer.t -> [Answer.t] *) type t val create : unit -> t val call : t -> ('a -> goal) -> 'a -> goal end = struct module H = Hashtbl.Make(Answer) module Cache : sig type t val create : unit -> t val add : t -> Answer.t -> unit val contains : t -> Answer.t -> bool val consume : t -> 'a -> goal end = struct (* Cache is a pair of queue-like list of answers plus hashtbl of answers; * Queue is used because new answers may arrive during the search, * we store this new answers to the end of the queue while read from the beginning. * Hashtbl is used for a quick check that new added answer is not already contained in the cache. *) type t = Answer.t list ref * unit H.t let create () = (ref [], H.create 11) let add (cache, tbl) answ = cache := List.cons answ !cache; H.add tbl answ () let contains (_, tbl) answ = try H.find tbl answ; true with Not_found -> false let consume (cache, _) args = let open State in fun {env; subst; scope} as st -> let st = State.new_scope st in (* [helper start curr seen] consumes answer terms from cache one by one * until [curr] (i.e. current pointer into cache list) is not equal to [seen] * (i.e. to the head of seen part of the cache list) *) let rec helper start curr seen = if curr == seen then (* update `seen` - pointer to already seen part of cache *) let seen = start in (* delayed check that current head of cache is not equal to head of seen part *) let is_ready () = seen != !cache in (* delayed thunk starts to consume unseen part of cache *) Stream.suspend ~is_ready @@ fun () -> helper !cache !cache seen else (* consume one answer term from cache and `lift` it to the current environment *) let answ, tail = (Answer.lift env @@ List.hd curr), List.tl curr in match State.unify (Obj.repr args) (Answer.unctr_term answ) st with | None -> helper start tail seen | Some ({subst=subst'; ctrs=ctrs'} as st') -> begin (* check `answ` disequalities against external substitution *) let ctrs = ListLabels.fold_left (Answer.disequality answ) ~init:Disequality.empty ~f:(let open Subst.Binding in fun acc {var; term} -> match Disequality.add env Subst.empty acc (Term.repr var) term with (* we should not violate disequalities *) | None -> assert false | Some acc -> acc ) in match Disequality.recheck env subst' ctrs (Subst.split subst') with | None -> helper start tail seen | Some ctrs -> let st' = {st' with ctrs = Disequality.merge_disjoint env subst' ctrs' ctrs} in Stream.(cons st' (from_fun @@ fun () -> helper start tail seen)) end in helper !cache !cache [] end type t = Cache.t H.t let make_answ args st = match State.reify args st with | [answ] -> let env = Env.create ~anchor:Term.Var.tabling_env in Answer.lift env answ | _ -> failwith "should not happen" let create () = H.create 1031 let call tbl g args = let open State in fun ({env; subst; ctrs} as st) -> (* we abstract away disequality constraints before lookup in the table *) let abs_st = {st with ctrs = Disequality.empty} in let key = make_answ args abs_st in try (* slave call *) Cache.consume (H.find tbl key) args st with Not_found -> (* master call *) let cache = Cache.create () in H.add tbl key cache; (* auxiliary goal for addition of new answer to the cache *) let hook ({env=env'; subst=subst'; ctrs=ctrs'} as st') = let answ = make_answ args st' in if not (Cache.contains cache answ) then begin Cache.add cache answ; (* TODO: we only need to check diff, i.e. [subst' \ subst] *) match Disequality.recheck env subst' ctrs (Subst.split subst') with | None -> failure () | Some ctrs -> success {st' with ctrs = Disequality.merge_disjoint env subst' ctrs ctrs'} end else failure () in ((g args) &&& hook) abs_st end module Tabling = struct let succ n () = let currier, uncurrier = n () in let sc = (Curry.succ : (('a -> 'b) -> 'c) -> ((((_) ilogic as 'k) * 'a -> 'b) -> 'k -> 'c)) in (sc currier, Uncurry.succ uncurrier) let one () = ((Curry.(one) : ((_) ilogic -> _) as 'x -> 'x), Uncurry.one) let two () = succ one () let three () = succ two () let four () = succ three () let five () = succ four () let tabled n g = let tbl = Table.create () in let currier, uncurrier = n () in currier (Table.call tbl @@ uncurrier g) let tabledrec n g_norec = let tbl = Table.create () in let currier, uncurrier = n () in let g = ref (fun _ -> assert false) in let g_rec args = uncurrier (g_norec !g) args in let g_tabled = Table.call tbl g_rec in g := currier g_tabled; !g end
(* * OCanren. * Copyright (C) 2015-2017 * Dmitri Boulytchev, Dmitry Kosarev, Alexey Syomin, Evgeny Moiseenko * St.Petersburg State University, JetBrains Research * * This software is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License version 2, as published by the Free Software Foundation. * * This software 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 GNU Library General Public License version 2 for more details * (enclosed in the file COPYING). *)
alpha_context.ml
type t = Raw_context.t type context = t module type BASIC_DATA = sig type t include Compare.S with type t := t val encoding: t Data_encoding.t val pp: Format.formatter -> t -> unit end module Tez = Tez_repr module Period = Period_repr module Timestamp = struct include Time_repr let current = Raw_context.current_timestamp end include Operation_repr module Operation = struct type 'kind t = 'kind operation = { shell: Operation.shell_header ; protocol_data: 'kind protocol_data ; } type packed = packed_operation let unsigned_encoding = unsigned_operation_encoding include Operation_repr end module Block_header = Block_header_repr module Vote = struct include Vote_repr include Vote_storage end module Raw_level = Raw_level_repr module Cycle = Cycle_repr module Script_int = Script_int_repr module Script_timestamp = struct include Script_timestamp_repr let now ctxt = Raw_context.current_timestamp ctxt |> Timestamp.to_seconds |> of_int64 end module Script = struct include Michelson_v1_primitives include Script_repr let force_decode ctxt lexpr = Lwt.return (Script_repr.force_decode lexpr >>? fun (v, cost) -> Raw_context.consume_gas ctxt cost >|? fun ctxt -> (v, ctxt)) let force_bytes ctxt lexpr = Lwt.return (Script_repr.force_bytes lexpr >>? fun (b, cost) -> Raw_context.consume_gas ctxt cost >|? fun ctxt -> (b, ctxt)) end module Fees = Fees_storage type public_key = Signature.Public_key.t type public_key_hash = Signature.Public_key_hash.t type signature = Signature.t module Constants = struct include Constants_repr include Constants_storage end module Voting_period = Voting_period_repr module Gas = struct include Gas_limit_repr type error += Gas_limit_too_high = Raw_context.Gas_limit_too_high let check_limit = Raw_context.check_gas_limit let set_limit = Raw_context.set_gas_limit let set_unlimited = Raw_context.set_gas_unlimited let consume = Raw_context.consume_gas let check_enough = Raw_context.check_enough_gas let level = Raw_context.gas_level let consumed = Raw_context.gas_consumed let block_level = Raw_context.block_gas_level end module Level = struct include Level_repr include Level_storage end module Contract = struct include Contract_repr include Contract_storage let originate c contract ~balance ~manager ?script ~delegate ~spendable ~delegatable = originate c contract ~balance ~manager ?script ~delegate ~spendable ~delegatable let init_origination_nonce = Raw_context.init_origination_nonce let unset_origination_nonce = Raw_context.unset_origination_nonce end module Delegate = Delegate_storage module Roll = struct include Roll_repr include Roll_storage end module Nonce = Nonce_storage module Seed = struct include Seed_repr include Seed_storage end module Fitness = struct include Fitness_repr include Fitness type fitness = t include Fitness_storage end module Bootstrap = Bootstrap_storage module Commitment = struct include Commitment_repr include Commitment_storage end module Global = struct let get_last_block_priority = Storage.Last_block_priority.get let set_last_block_priority = Storage.Last_block_priority.set end let prepare_first_block = Init_storage.prepare_first_block let prepare = Init_storage.prepare let finalize ?commit_message:message c = let fitness = Fitness.from_int64 (Fitness.current c) in let context = Raw_context.recover c in { Updater.context ; fitness ; message ; max_operations_ttl = 60 ; last_allowed_fork_level = Raw_level.to_int32 @@ Level.last_allowed_fork_level c; } let activate = Raw_context.activate let fork_test_chain = Raw_context.fork_test_chain let record_endorsement = Raw_context.record_endorsement let allowed_endorsements = Raw_context.allowed_endorsements let init_endorsements = Raw_context.init_endorsements let reset_internal_nonce = Raw_context.reset_internal_nonce let fresh_internal_nonce = Raw_context.fresh_internal_nonce let record_internal_nonce = Raw_context.record_internal_nonce let internal_nonce_already_recorded = Raw_context.internal_nonce_already_recorded let add_deposit = Raw_context.add_deposit let add_fees = Raw_context.add_fees let add_rewards = Raw_context.add_rewards let get_deposits = Raw_context.get_deposits let get_fees = Raw_context.get_fees let get_rewards = Raw_context.get_rewards let description = Raw_context.description
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************)