diff options
author | Stephane Glondu <steph@glondu.net> | 2020-01-24 15:01:07 +0100 |
---|---|---|
committer | Stéphane Glondu <steph@glondu.net> | 2020-01-24 15:01:07 +0100 |
commit | 9a98231aa31f51ad0a6b79fbe0c251116a22812b (patch) | |
tree | a3ea35057880527bb7b1420649c46c98629f7e08 | |
parent | 6918f6f32b91bee183435402d82ad4af50046bf7 (diff) |
New upstream version 3.1.1
-rw-r--r-- | bitstring.opam | 37 | ||||
-rw-r--r-- | dune | 3 | ||||
-rw-r--r-- | dune-project | 2 | ||||
-rw-r--r-- | examples/dune | 48 | ||||
-rw-r--r-- | examples/jbuild | 50 | ||||
-rw-r--r-- | ppx/dune | 7 | ||||
-rw-r--r-- | ppx/jbuild | 13 | ||||
-rw-r--r-- | ppx/ppx_bitstring.ml | 58 | ||||
-rw-r--r-- | src/bitstring.ml | 2 | ||||
-rw-r--r-- | src/dune | 6 | ||||
-rw-r--r-- | src/jbuild | 9 | ||||
-rw-r--r-- | tests/dune | 12 | ||||
-rw-r--r-- | tests/jbuild | 12 |
13 files changed, 127 insertions, 132 deletions
diff --git a/bitstring.opam b/bitstring.opam index 1cac698..23d995a 100644 --- a/bitstring.opam +++ b/bitstring.opam @@ -1,30 +1,35 @@ authors : [ "Richard W.M. Jones" "Xavier R. Guérin" ] bug-reports : "https://bitbucket.org/thanatonauts/bitstring/issues" -dev-repo : "https://bitbucket.org/thanatonauts/bitstring.git" +dev-repo : "git+https://bitbucket.org/thanatonauts/bitstring.git" doc : "https://bitstring.software" homepage : "https://bitstring.software" -license : "LGPLv2+ with exceptions and GPLv2+" +license : ["LGPL-2.0-or-later with exceptions" "GPL-2.0-or-later"] maintainer : "Xavier R. Guérin <ghub@applepine.org>" -opam-version : "1.2" -version : "3.1.0" +opam-version: "2.0" +version : "3.1.1" build: [ - ["jbuilder" "build" "-p" name "-j" jobs] + ["dune" "build" "-p" name "-j" jobs] + ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] - -build-test: [ - ["jbuilder" "runtest" "-p" name "-j" jobs] -] - depends: [ - "jbuilder" { build } - "ppx_tools_versioned" { build } - "ocaml-migrate-parsetree" { build & >= "1.0.5" } - "ounit" { test } + "ocaml" {>= "4.02.3"} + "dune" + "ppx_tools_versioned" {build} + "ocaml-migrate-parsetree" {>= "1.0.5"} + "stdlib-shims" + "ounit" {with-test} ] - conflicts: [ "ppx_bitstring" ] -available: ocaml-version >= "4.02.3" +synopsis: "bitstrings and bitstring matching for OCaml" +description: """ +The ocaml-bitstring project adds Erlang-style bitstrings and matching over bitstrings as a syntax extension and library for OCaml. +You can use this module to both parse and generate binary formats, files and protocols. +Bitstring handling is added as primitives to the language, making it exceptionally simple to use and very powerful.""" +url { + src: "https://bitbucket.org/thanatonauts/bitstring/get/v3.1.1.tar.gz" + checksum: "md5=7da1b8627c6ab7cb4825a0b4f415d251" +} @@ -0,0 +1,3 @@ +(env + (dev + (flags (:standard -w -27-32-33-35)))) diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..b900a19 --- /dev/null +++ b/dune-project @@ -0,0 +1,2 @@ +(lang dune 1.0) +(name bitstring) diff --git a/examples/dune b/examples/dune new file mode 100644 index 0000000..e4eaec7 --- /dev/null +++ b/examples/dune @@ -0,0 +1,48 @@ +(executable + (name elf) + (modules Elf) + (libraries bitstring unix) + (preprocess + (pps bitstring.ppx))) + +(executable + (name ext3_superblock) + (modules Ext3_superblock) + (libraries bitstring unix) + (preprocess + (pps bitstring.ppx))) + +(executable + (name gif) + (modules Gif) + (libraries bitstring unix) + (preprocess + (pps bitstring.ppx))) + +(executable + (name ipv4_header) + (modules Ipv4_header) + (libraries bitstring unix) + (preprocess + (pps bitstring.ppx))) + +(executable + (name libpcap) + (modules Libpcap) + (libraries bitstring unix) + (preprocess + (pps bitstring.ppx))) + +(executable + (name make_ipv4_header) + (modules Make_ipv4_header) + (libraries bitstring unix) + (preprocess + (pps bitstring.ppx))) + +(executable + (name ping) + (modules Ping) + (libraries bitstring unix) + (preprocess + (pps bitstring.ppx))) diff --git a/examples/jbuild b/examples/jbuild deleted file mode 100644 index 819b819..0000000 --- a/examples/jbuild +++ /dev/null @@ -1,50 +0,0 @@ -(jbuild_version 1) - -(executable - ((name elf) - (modules (Elf)) - (libraries (bitstring unix)) - (preprocess (pps (bitstring.ppx))) - )) - -(executable - ((name ext3_superblock) - (modules (Ext3_superblock)) - (libraries (bitstring unix)) - (preprocess (pps (bitstring.ppx))) - )) - -(executable - ((name gif) - (modules (Gif)) - (libraries (bitstring unix)) - (preprocess (pps (bitstring.ppx))) - )) - -(executable - ((name ipv4_header) - (modules (Ipv4_header)) - (libraries (bitstring unix)) - (preprocess (pps (bitstring.ppx))) - )) - -(executable - ((name libpcap) - (modules (Libpcap)) - (libraries (bitstring unix)) - (preprocess (pps (bitstring.ppx))) - )) - -(executable - ((name make_ipv4_header) - (modules (Make_ipv4_header)) - (libraries (bitstring unix)) - (preprocess (pps (bitstring.ppx))) - )) - -(executable - ((name ping) - (modules (Ping)) - (libraries (bitstring unix)) - (preprocess (pps (bitstring.ppx))) - )) diff --git a/ppx/dune b/ppx/dune new file mode 100644 index 0000000..1eb515f --- /dev/null +++ b/ppx/dune @@ -0,0 +1,7 @@ +(library + (name ppx_bitstring) + (public_name bitstring.ppx) + (kind ppx_rewriter) + (libraries str compiler-libs ppx_tools_versioned ocaml-migrate-parsetree) + (preprocess + (pps ppx_tools_versioned.metaquot_405))) diff --git a/ppx/jbuild b/ppx/jbuild deleted file mode 100644 index 9f38577..0000000 --- a/ppx/jbuild +++ /dev/null @@ -1,13 +0,0 @@ -(jbuild_version 1) - -(library - ((name ppx_bitstring) - (public_name bitstring.ppx) - (kind ppx_rewriter) - (libraries (str - compiler-libs - ppx_tools_versioned - ocaml-migrate-parsetree - )) - (preprocess (pps (ppx_tools_versioned.metaquot_405))) - )) diff --git a/ppx/ppx_bitstring.ml b/ppx/ppx_bitstring.ml index a17157b..d14db1d 100644 --- a/ppx/ppx_bitstring.ml +++ b/ppx/ppx_bitstring.ml @@ -202,23 +202,23 @@ let option_bind opt f = let rec process_expr_loc ~loc expr = match expr with - | { pexp_desc = Pexp_ident(ident) } -> + | { pexp_desc = Pexp_ident(ident); _ } -> let lident = Location.mkloc ident.txt loc in { expr with pexp_desc = Pexp_ident(lident); pexp_loc = loc } - | { pexp_desc = Pexp_tuple(ops) } -> + | { pexp_desc = Pexp_tuple(ops); _ } -> let fld = List.fold_left (fun acc exp -> acc @ [ process_expr_loc ~loc exp ]) [] ops in { expr with pexp_desc = Pexp_tuple(fld); pexp_loc = loc } - | { pexp_desc = Pexp_construct(ident, ops) } -> + | { pexp_desc = Pexp_construct(ident, ops); _ } -> let lident = Location.mkloc ident.txt loc in let lops = begin match ops with | Some o -> Some (process_expr_loc ~loc o) | None -> None end in { expr with pexp_desc = Pexp_construct(lident, lops); pexp_loc = loc } - | { pexp_desc = Pexp_apply(ident, ops) } -> + | { pexp_desc = Pexp_apply(ident, ops); _ } -> let lident = process_expr_loc ~loc ident in let fld = List.fold_left (fun acc (lbl, exp) -> acc @ [ (lbl, (process_expr_loc ~loc exp)) ]) @@ -227,7 +227,7 @@ let rec process_expr_loc ~loc expr = in { expr with pexp_desc = Pexp_apply(lident, fld); pexp_loc = loc } | { pexp_desc = Pexp_fun(ident, ops, { ppat_desc = Ppat_var(pid); ppat_loc; ppat_attributes }, - exp) } -> + exp); _ } -> let lpid = Location.mkloc pid.txt loc in let lpat = { ppat_desc = Ppat_var lpid; ppat_loc = loc; ppat_attributes } in let lops = begin match ops with @@ -248,9 +248,9 @@ let parse_expr expr = _ -> location_exn ~loc:expr.loc ("Parse expression error: '" ^ expr.txt ^ "'") ;; -let rec process_pat_loc ~loc pat = +let process_pat_loc ~loc pat = match pat with - | { ppat_desc = Ppat_var(ident); ppat_loc; ppat_attributes } -> + | { ppat_desc = Ppat_var(ident); ppat_loc; ppat_attributes; _ } -> let lident = Location.mkloc ident.txt loc in { ppat_desc = Ppat_var(lident); ppat_loc = loc; ppat_attributes } | _ -> @@ -412,13 +412,13 @@ let parse_quals quals = | hd :: tl -> process_quals (process_qual state hd) tl in match expr with (* single named qualifiers *) - | { pexp_desc = Pexp_ident (_) } -> + | { pexp_desc = Pexp_ident (_); _ } -> process_qual Qualifiers.empty expr (* single functional qualifiers *) - | { pexp_desc = Pexp_apply (_, _) } -> + | { pexp_desc = Pexp_apply (_, _); _ } -> process_qual Qualifiers.empty expr (* multiple qualifiers *) - | { pexp_desc = Pexp_tuple (e) } -> + | { pexp_desc = Pexp_tuple (e); _ } -> process_quals Qualifiers.empty e (* Unrecognized expression *) | expr -> @@ -478,7 +478,7 @@ let rec evaluate_expr = function | Some l, Some r -> Some (l mod r) | _ -> None end - | { pexp_desc = Pexp_constant (const) } -> + | { pexp_desc = Pexp_constant (const); _ } -> begin match const with | Pconst_integer(i, _) -> Some (int_of_string i) | _ -> None @@ -764,7 +764,7 @@ and gen_offset ~loc cur nxt fld beh = let open Entity in let open Qualifiers in match fld.MatchField.qls.offset with - | Some ({ pexp_loc } as off) -> + | Some ({ pexp_loc; _ } as off) -> [%expr let [%p nxt.off.pat] = [%e cur.off.exp] + [%e off] in [%e beh]] [@metaloc pexp_loc] @@ -775,7 +775,7 @@ and gen_offset_saver ~loc cur nxt fld beh = let open Entity in let open Qualifiers in match fld.MatchField.qls.save_offset_to with - | Some { pexp_desc = Pexp_ident ({ txt; loc = eloc }) } -> + | Some { pexp_desc = Pexp_ident ({ txt; loc = eloc }); _ } -> let ptxt = pvar ~loc:eloc (Longident.last txt) in [%expr let [%p ptxt] = [%e nxt.off.exp] - [%e cur.off.exp] in [%e beh]] @@ -783,12 +783,10 @@ and gen_offset_saver ~loc cur nxt fld beh = | Some _ | None -> beh and gen_unbound_string ~loc cur nxt fld beh fields = - let open Entity in - let open Context in let p = fld.MatchField.pat in match p with - | { ppat_desc = Ppat_var(_) } -> + | { ppat_desc = Ppat_var(_); _ } -> [%expr let [%p p] = [%e (gen_extractor ~loc nxt fld)] in [%e (gen_next_all ~loc cur nxt beh fields)]] @@ -807,16 +805,16 @@ and gen_bound_bitstring ~loc cur nxt fld beh fields = and (l, _) = fld.MatchField.len in match p with - | { ppat_desc = Ppat_var(_) } -> + | { ppat_desc = Ppat_var(_); _ } -> [%expr - if Pervasives.(>=) [%e nxt.len.exp] [%e l] then + if Stdlib.(>=) [%e nxt.len.exp] [%e l] then let [%p p] = [%e (gen_extractor ~loc nxt fld)] in [%e (gen_next ~loc cur nxt fld beh fields)] else ()] [@metaloc loc] | [%pat? _ ] -> [%expr - if Pervasives.(>=) [%e nxt.len.exp] [%e l] then + if Stdlib.(>=) [%e nxt.len.exp] [%e l] then [%e (gen_next ~loc cur nxt fld beh fields)] else ()] [@metaloc loc] @@ -829,7 +827,7 @@ and gen_bound_string ~loc cur nxt fld beh fields = let (l, _) = fld.MatchField.len in [%expr - if Pervasives.(>=) [%e nxt.len.exp] [%e l] then + if Stdlib.(>=) [%e nxt.len.exp] [%e l] then [%e (gen_match ~loc cur nxt fld beh fields)] else ()] [@metaloc loc] @@ -840,7 +838,7 @@ and gen_bound_int_with_size ~loc cur nxt fld beh fields = let (l, _) = fld.MatchField.len in [%expr - if Pervasives.(>=) [%e nxt.len.exp] [%e l] then + if Stdlib.(>=) [%e nxt.len.exp] [%e l] then [%e (gen_match ~loc cur nxt fld beh fields)] else ()] [@metaloc loc] @@ -851,9 +849,9 @@ and gen_bound_int ~loc cur nxt fld beh fields = let (l, _) = fld.MatchField.len in [%expr - if Pervasives.(>=) [%e l] 1 && - Pervasives.(<=) [%e l] 64 && - Pervasives.(>=) [%e nxt.len.exp] [%e l] then + if Stdlib.(>=) [%e l] 1 && + Stdlib.(<=) [%e l] 64 && + Stdlib.(>=) [%e nxt.len.exp] [%e l] then [%e (gen_match ~loc cur nxt fld beh fields)] else ()] [@metaloc loc] @@ -883,7 +881,6 @@ and gen_fields_with_quals ~loc cur nxt fld beh fields = |> gen_offset ~loc cur nxt fld and gen_fields ~loc cur nxt beh fields = - let open Qualifiers in let (exp, alias) = beh in match fields with @@ -938,7 +935,7 @@ let mark_optimized_fastpath fields = in let check_field off tuple = match tuple with - | { pat; len = (l, Some (v)); qls = { value_type = Some (Type.Int) }; _ } -> + | { pat; len = (l, Some (v)); qls = { value_type = Some (Type.Int); _ }; _ } -> if (off land 7) = 0 && (v = 16 || v = 32 || v = 64) then (Some (off + v), MatchField.Tuple { tuple with opt = true }) else @@ -979,12 +976,11 @@ let gen_case_constant ~loc cur nxt res case value alias = |> gen_fields ~loc cur nxt (beh, alias) let gen_case cur nxt res case = - let open Entity in let loc = case.pc_lhs.ppat_loc in match case.pc_lhs.ppat_desc with | Ppat_constant (Pconst_string (value, _)) -> gen_case_constant ~loc cur nxt res case value None - | Ppat_alias ({ ppat_desc = Ppat_constant (Pconst_string (value, _)) }, { txt = a }) -> + | Ppat_alias ({ ppat_desc = Ppat_constant (Pconst_string (value, _)); _ }, { txt = a; _ }) -> gen_case_constant ~loc cur nxt res case value (Some a) | _ -> location_exn ~loc "Wrong pattern type" @@ -1168,7 +1164,7 @@ let gen_assignment_behavior ~loc sym fields = let post = [%expr let _res = [%e rep] in - if Pervasives.(=) (Bitstring.bitstring_length _res) [%e len] + if Stdlib.(=) (Bitstring.bitstring_length _res) [%e len] then _res else raise Exit] [@metaloc loc] in @@ -1201,7 +1197,7 @@ let transform_single_let ~loc ast expr = match ast.pvb_pat.ppat_desc, ast.pvb_expr.pexp_desc with | Parsetree.Ppat_var (s), Pexp_constant (Pconst_string (value, _)) -> let pat = pvar ~loc s.txt in - let constructor_expr = gen_constructor_expr loc value in + let constructor_expr = gen_constructor_expr ~loc value in [%expr let [%p pat] = [%e constructor_expr] in [%e expr]] | _ -> location_exn ~loc "Invalid pattern type" ;; @@ -1215,7 +1211,7 @@ let extension expr = let loc = expr.pexp_loc in match expr.pexp_desc with | Pexp_constant (Pconst_string (value, (_ : string option))) -> - gen_constructor_expr loc value + gen_constructor_expr ~loc value | Pexp_let (Nonrecursive, bindings, expr) -> List.fold_right (fun binding expr -> transform_single_let ~loc binding expr) diff --git a/src/bitstring.ml b/src/bitstring.ml index 1d0b60b..80b8344 100644 --- a/src/bitstring.ml +++ b/src/bitstring.ml @@ -1293,7 +1293,7 @@ let hexdump_bitstring chan (data, off, len) = if !linelen > 0 then ( let skip = (16 - !linelen) * 3 + if !linelen < 8 then 1 else 0 in - for i = 0 to skip-1 do fprintf chan " " done; + for _ = 0 to skip-1 do fprintf chan " " done; fprintf chan " |%s|\n%!" (Bytes.unsafe_to_string linechars) ) else fprintf chan "\n%!" diff --git a/src/dune b/src/dune new file mode 100644 index 0000000..334ad32 --- /dev/null +++ b/src/dune @@ -0,0 +1,6 @@ +(library + (name bitstring) + (public_name bitstring) + (c_names bitstring_fastpath) + (c_flags -I.) + (libraries str unix stdlib-shims)) diff --git a/src/jbuild b/src/jbuild deleted file mode 100644 index add7852..0000000 --- a/src/jbuild +++ /dev/null @@ -1,9 +0,0 @@ -(jbuild_version 1) - -(library - ((name bitstring) - (public_name bitstring) - (c_names (bitstring_fastpath)) - (c_flags (-I.)) - (libraries (str unix)) - )) diff --git a/tests/dune b/tests/dune new file mode 100644 index 0000000..bc54f42 --- /dev/null +++ b/tests/dune @@ -0,0 +1,12 @@ +(executable + (name bitstring_tests) + (libraries bitstring oUnit) + (preprocess + (pps ppx_bitstring))) + +(alias + (name runtest) + (deps + (:< bitstring_tests.exe)) + (action + (run %{<}))) diff --git a/tests/jbuild b/tests/jbuild deleted file mode 100644 index 5035ce3..0000000 --- a/tests/jbuild +++ /dev/null @@ -1,12 +0,0 @@ -(jbuild_version 1) - -(executable - ((name bitstring_tests) - (libraries (bitstring oUnit)) - (preprocess (pps (ppx_bitstring))) - )) - -(alias - ((name runtest) - (deps (bitstring_tests.exe)) - (action (run ${<})))) |