Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package ocaml-integers for openSUSE:Factory checked in at 2021-09-29 20:18:29 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ocaml-integers (Old) and /work/SRC/openSUSE:Factory/.ocaml-integers.new.1899 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ocaml-integers" Wed Sep 29 20:18:29 2021 rev:2 rq:921269 version:0.5.1 Changes: -------- --- /work/SRC/openSUSE:Factory/ocaml-integers/ocaml-integers.changes 2021-04-29 01:38:19.334571791 +0200 +++ /work/SRC/openSUSE:Factory/.ocaml-integers.new.1899/ocaml-integers.changes 2021-09-29 20:19:34.167045459 +0200 @@ -1,0 +2,6 @@ +Sat Sep 11 12:34:56 UTC 2021 - oher...@suse.de + +- Update to version 0.5.1 + see included CHANGES for details + +------------------------------------------------------------------- Old: ---- ocaml-integers-0.4.0.tar.xz New: ---- ocaml-integers-0.5.1.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ocaml-integers.spec ++++++ --- /var/tmp/diff_new_pack.P52vEM/_old 2021-09-29 20:19:34.631046132 +0200 +++ /var/tmp/diff_new_pack.P52vEM/_new 2021-09-29 20:19:34.635046138 +0200 @@ -16,7 +16,7 @@ # Name: ocaml-integers -Version: 0.4.0 +Version: 0.5.1 Release: 0 %{?ocaml_preserve_bytecode} Summary: Various signed and unsigned integer types for OCaml @@ -28,7 +28,7 @@ BuildRequires: ocaml BuildRequires: ocaml-dune -BuildRequires: ocaml-rpm-macros >= 20210121 +BuildRequires: ocaml-rpm-macros >= 20210911 %description The ocaml-integers library provides a number of 8-, 16-, 32- and 64-bit ++++++ _service ++++++ --- /var/tmp/diff_new_pack.P52vEM/_old 2021-09-29 20:19:34.667046184 +0200 +++ /var/tmp/diff_new_pack.P52vEM/_new 2021-09-29 20:19:34.667046184 +0200 @@ -1,7 +1,7 @@ <services> <service name="tar_scm" mode="disabled"> <param name="filename">ocaml-integers</param> - <param name="revision">48522592d7493fb00f3919b881f331f18e2cb463</param> + <param name="revision">ba8a0d6996c4ba92214f1f185e014e7afc94ed0a</param> <param name="scm">git</param> <param name="submodules">disable</param> <param name="url">https://github.com/ocamllabs/ocaml-integers.git</param> ++++++ ocaml-integers-0.4.0.tar.xz -> ocaml-integers-0.5.1.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/.github/workflows/test.yml new/ocaml-integers-0.5.1/.github/workflows/test.yml --- old/ocaml-integers-0.4.0/.github/workflows/test.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/ocaml-integers-0.5.1/.github/workflows/test.yml 2021-08-12 12:28:19.000000000 +0200 @@ -0,0 +1,60 @@ +name: Main workflow + +on: + pull_request: + push: + schedule: + # Prime the caches every Monday + - cron: 0 1 * * MON + +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + ocaml-compiler: 4.03.x + - os: ubuntu-latest + ocaml-compiler: 4.04.x + - os: ubuntu-latest + ocaml-compiler: 4.05.x + - os: ubuntu-latest + ocaml-compiler: 4.06.x + - os: ubuntu-latest + ocaml-compiler: 4.07.x + - os: ubuntu-latest + ocaml-compiler: 4.08.x + - os: ubuntu-latest + ocaml-compiler: 4.09.x + - os: ubuntu-latest + ocaml-compiler: 4.10.x + - os: ubuntu-latest + ocaml-compiler: 4.11.x + - os: ubuntu-latest + ocaml-compiler: 4.12.x + - os: windows-latest + ocaml-compiler: 4.11.x + - os: windows-latest + ocaml-compiler: 4.12.x + - os: macos-latest + ocaml-compiler: 4.11.1 + - os: macos-latest + ocaml-compiler: 4.12.x + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Use OCaml ${{ matrix.ocaml-compiler }} + uses: ocaml/setup-ocaml@v2 + with: + ocaml-compiler: ${{ matrix.ocaml-compiler }} + + - run: opam install . --deps-only --with-test + + - run: opam exec -- dune build + + - run: opam exec -- dune runtest diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/.gitignore new/ocaml-integers-0.5.1/.gitignore --- old/ocaml-integers-0.4.0/.gitignore 1970-01-01 01:00:00.000000000 +0100 +++ new/ocaml-integers-0.5.1/.gitignore 2021-08-12 12:28:19.000000000 +0200 @@ -0,0 +1,4 @@ +*~ +_build +integers.install +.merlin diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/CHANGES.md new/ocaml-integers-0.5.1/CHANGES.md --- old/ocaml-integers-0.4.0/CHANGES.md 2020-05-01 10:55:11.000000000 +0200 +++ new/ocaml-integers-0.5.1/CHANGES.md 2021-08-12 12:28:19.000000000 +0200 @@ -1,3 +1,13 @@ +v0.5.1 2021-08-12 +----------------- + +* Restore support for pre-4.05 OCaml versions (@yallop, #37) + +v0.5.0 2021-07-31 +----------------- +* Hex printing, and option-based parsing (@raphael-proust, #34) +* Add stdlib-compatible string parsing (@mrmr1993, #32) + v0.4.0 2020-05-01 ----------------- * Expose Signed.S.Infix.(asr) (@dra27, #30) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/README.md new/ocaml-integers-0.5.1/README.md --- old/ocaml-integers-0.4.0/README.md 2020-05-01 10:55:11.000000000 +0200 +++ new/ocaml-integers-0.5.1/README.md 2021-08-12 12:28:19.000000000 +0200 @@ -46,11 +46,17 @@ - : int = 1000 ``` -[](https://travis-ci.org/ocamllabs/ocaml-integers) [](https://ci.appveyor.com/project/yallop/ocaml-integers/branch/master) +### Using `integers` with js_of_ocaml + +The [`integers_stubs_js`][integers_stubs_js] package provides JavaScript stubs that make it possible to use this library with [`js_of_ocaml`][js_of_ocaml] [API documentation][doc] +[](https://github.com/ocamllabs/ocaml-integers/actions/workflows/test.yml) + [int32]: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Int32.html [int64]: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Int64.html [nativeint]: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Nativeint.html [doc]: https://ocamllabs.github.io/ocaml-integers/api.docdir/ +[integers_stubs_js]: https://github.com/o1-labs/integers_stubs_js +[js_of_ocaml]: https://github.com/ocsigen/js_of_ocaml diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/appveyor.yml new/ocaml-integers-0.5.1/appveyor.yml --- old/ocaml-integers-0.4.0/appveyor.yml 2020-05-01 10:55:11.000000000 +0200 +++ new/ocaml-integers-0.5.1/appveyor.yml 1970-01-01 01:00:00.000000000 +0100 @@ -1,13 +0,0 @@ -platform: - - x86 - -environment: - FORK_USER: ocaml - FORK_BRANCH: master - CYG_ROOT: C:\cygwin64 - -install: - - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/$env:FORK_USER/ocaml-ci-scripts/$env:FORK_BRANCH/appveyor-install.ps1")) - -build_script: - - call %CYG_ROOT%\bin\bash.exe -l %APPVEYOR_BUILD_FOLDER%\appveyor-opam.sh diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/src/signed.ml new/ocaml-integers-0.5.1/src/signed.ml --- old/ocaml-integers-0.4.0/src/signed.ml 2020-05-01 10:55:11.000000000 +0200 +++ new/ocaml-integers-0.5.1/src/signed.ml 2021-08-12 12:28:19.000000000 +0200 @@ -1,5 +1,6 @@ (* * Copyright (c) 2013 Jeremy Yallop. + * Copyright (c) 2021 Nomadic Labs * * This file is distributed under the terms of the MIT License. * See the file LICENSE for details. @@ -63,6 +64,8 @@ let (asr) = shift_right end +external format_int : string -> int -> string = "caml_format_int" + module Int = struct module Basics = @@ -84,7 +87,9 @@ let of_int x = x let to_int x = x let of_string = int_of_string + let of_string_opt s = try Some (of_string s) with Failure _ -> None let to_string = string_of_int + let to_hexstring = format_int "%x" let zero = 0 let one = 1 let minus_one = -1 @@ -105,12 +110,16 @@ let abs = Pervasives.abs let neg x = -x let pp fmt n = Format.fprintf fmt "%d" n + let pp_hex fmt n = Format.fprintf fmt "%x" n end module Int32 = struct + [@@@ocaml.warning "-32"] (* Int32.equal was introduced in OCaml 4.03.0 *) - let equal (x:int32) (y:int32) = x = y [@@ocaml.warning "-32"] + let equal (x:int32) (y:int32) = x = y + (* Int32.of_string_opt was introduced in OCaml 4.5b0.0 *) + let of_string_opt s = try Some (Int32.of_string s) with Failure _ -> None include Int32 module Infix = MakeInfix(Int32) let of_nativeint = Nativeint.to_int32 @@ -120,12 +129,17 @@ let max = Pervasives.max let min = Pervasives.min let pp fmt n = Format.fprintf fmt "%ld" n + let pp_hex fmt n = Format.fprintf fmt "%lx" n + let to_hexstring n = Format.asprintf "%lx" n end module Int64 = struct + [@@@ocaml.warning "-32"] (* Int64.equal was introduced in OCaml 4.03.0 *) - let equal (x:int64) (y:int64) = x = y [@@ocaml.warning "-32"] + let equal (x:int64) (y:int64) = x = y + (* Int32.of_string_opt was introduced in OCaml 4.5b0.0 *) + let of_string_opt s = try Some (Int64.of_string s) with Failure _ -> None include Int64 module Infix = MakeInfix(Int64) let of_int64 x = x @@ -133,6 +147,8 @@ let max = Pervasives.max let min = Pervasives.min let pp fmt n = Format.fprintf fmt "%Ld" n + let pp_hex fmt n = Format.fprintf fmt "%Lx" n + let to_hexstring n = Format.asprintf "%Lx" n end (* C guarantees that sizeof(t) == sizeof(unsigned t) *) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/src/signed.mli new/ocaml-integers-0.5.1/src/signed.mli --- old/ocaml-integers-0.4.0/src/signed.mli 2020-05-01 10:55:11.000000000 +0200 +++ new/ocaml-integers-0.5.1/src/signed.mli 2021-08-12 12:28:19.000000000 +0200 @@ -1,5 +1,6 @@ (* * Copyright (c) 2013 Jeremy Yallop. + * Copyright (c) 2021 Nomadic Labs * * This file is distributed under the terms of the MIT License. * See the file LICENSE for details. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/src/unsigned.ml new/ocaml-integers-0.5.1/src/unsigned.ml --- old/ocaml-integers-0.4.0/src/unsigned.ml 2020-05-01 10:55:11.000000000 +0200 +++ new/ocaml-integers-0.5.1/src/unsigned.ml 2021-08-12 12:28:19.000000000 +0200 @@ -1,5 +1,6 @@ (* * Copyright (c) 2013 Jeremy Yallop. + * Copyright (c) 2021 Nomadic Labs * * This file is distributed under the terms of the MIT License. * See the file LICENSE for details. @@ -31,6 +32,7 @@ val to_int64 : t -> int64 val of_string : string -> t val to_string : t -> string + val to_hexstring : t -> string end @@ -46,7 +48,9 @@ val equal : t -> t -> bool val max : t -> t -> t val min : t -> t -> t + val of_string_opt : string -> t option val pp : Format.formatter -> t -> unit + val pp_hex : Format.formatter -> t -> unit end @@ -101,9 +105,12 @@ let equal (x : t) (y : t) = Pervasives.(=) x y let max (x : t) (y : t) = Pervasives.max x y let min (x : t) (y : t) = Pervasives.min x y + let of_string_opt (s : string) = try Some (of_string s) with Failure _ -> None let pp fmt x = Format.fprintf fmt "%s" (to_string x) + let pp_hex fmt x = Format.fprintf fmt "%s" (to_hexstring x) end +external format_int : string -> int -> string = "caml_format_int" module UInt8 : S with type t = private int = struct @@ -129,6 +136,7 @@ let to_int64 : t -> int64 = fun x -> Int64.of_int (to_int x) external of_string : string -> t = "integers_uint8_of_string" let to_string : t -> string = string_of_int + let to_hexstring : t -> string = format_int "%x" end include B include Extras(B) @@ -160,6 +168,7 @@ let to_int64 : t -> int64 = fun x -> to_int x |> Int64.of_int external of_string : string -> t = "integers_uint16_of_string" let to_string : t -> string = string_of_int + let to_hexstring : t -> string = format_int "%x" end include B include Extras(B) @@ -169,9 +178,9 @@ module UInt32 : sig include S - external of_int32 : int32 -> t = "integers_uint32_of_int32" - external to_int32 : t -> int32 = "integers_int32_of_uint32" -end = + val of_int32 : int32 -> t + val to_int32 : t -> int32 +end = struct module B = struct @@ -186,27 +195,42 @@ external logxor : t -> t -> t = "integers_uint32_logxor" external shift_left : t -> int -> t = "integers_uint32_shift_left" external shift_right : t -> int -> t = "integers_uint32_shift_right" + external of_string : string -> t = "integers_uint32_of_string" + external to_string : t -> string = "integers_uint32_to_string" + external to_hexstring : t -> string = "integers_uint32_to_hexstring" external of_int : int -> t = "integers_uint32_of_int" external to_int : t -> int = "integers_uint32_to_int" + + external of_int32 : int32 -> t = "integers_uint32_of_int32" + let half_max_plus_two = of_string "0x80000001" + let half_max_minus_one_signed = 0x7fffffffl + let of_int32 i32 = + if i32 >= 0l then + of_int32 i32 + else + add half_max_plus_two (of_int32 (Int32.add i32 half_max_minus_one_signed)) + + external to_int32 : t -> int32 = "integers_int32_of_uint32" + let max_signed = of_int32 Int32.max_int + let to_int32 u32 = + if Pervasives.compare u32 max_signed <= 0 then + to_int32 u32 + else + Int32.sub (to_int32 (sub u32 half_max_plus_two)) half_max_minus_one_signed + external of_int64 : int64 -> t = "integers_uint32_of_int64" external to_int64 : t -> int64 = "integers_uint32_to_int64" - external of_string : string -> t = "integers_uint32_of_string" - external to_string : t -> string = "integers_uint32_to_string" external _max_int : unit -> t = "integers_uint32_max" let max_int = _max_int () end include B include Extras(B) module Infix = MakeInfix(B) - external of_int32 : int32 -> t = "integers_uint32_of_int32" - external to_int32 : t -> int32 = "integers_int32_of_uint32" end module UInt64 : sig include S - external of_int64 : int64 -> t = "integers_uint64_of_int64" - external to_int64 : t -> int64 = "integers_uint64_to_int64" external of_uint32 : UInt32.t -> t = "integers_uint64_of_uint32" external to_uint32 : t -> UInt32.t = "integers_uint32_of_uint64" end = @@ -226,12 +250,29 @@ external shift_right : t -> int -> t = "integers_uint64_shift_right" external of_int : int -> t = "integers_uint64_of_int" external to_int : t -> int = "integers_uint64_to_int" + external of_string : string -> t = "integers_uint64_of_string" + external to_string : t -> string = "integers_uint64_to_string" + external to_hexstring : t -> string = "integers_uint64_to_hexstring" + external of_int64 : int64 -> t = "integers_uint64_of_int64" + let half_max_plus_two = of_string "0x8000000000000001" + let half_max_minus_one_signed = 0x7fffffffffffffffL + let of_int64 i64 = + if i64 >= 0L then + of_int64 i64 + else + add half_max_plus_two (of_int64 (Int64.add i64 half_max_minus_one_signed)) + external to_int64 : t -> int64 = "integers_uint64_to_int64" + let max_signed = of_int64 Int64.max_int + let to_int64 u64 = + if Pervasives.compare u64 max_signed <= 0 then + to_int64 u64 + else + Int64.sub (to_int64 (sub u64 half_max_plus_two)) half_max_minus_one_signed + external of_uint32 : UInt32.t -> t = "integers_uint64_of_uint32" external to_uint32 : t -> UInt32.t = "integers_uint32_of_uint64" - external of_string : string -> t = "integers_uint64_of_string" - external to_string : t -> string = "integers_uint64_to_string" external _max_int : unit -> t = "integers_uint64_max" let max_int = _max_int () end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/src/unsigned.mli new/ocaml-integers-0.5.1/src/unsigned.mli --- old/ocaml-integers-0.4.0/src/unsigned.mli 2020-05-01 10:55:11.000000000 +0200 +++ new/ocaml-integers-0.5.1/src/unsigned.mli 2021-08-12 12:28:19.000000000 +0200 @@ -1,5 +1,6 @@ (* * Copyright (c) 2013 Jeremy Yallop. + * Copyright (c) 2021 Nomadic Labs * * This file is distributed under the terms of the MIT License. * See the file LICENSE for details. @@ -94,12 +95,15 @@ val of_string : string -> t (** Convert the given string to an unsigned integer. Raise {!Failure} - ["int_of_string"] if the given string is not a valid representation of - an unsigned integer. *) + if the given string is not a valid representation of an unsigned + integer. *) val to_string : t -> string (** Return the string representation of its argument. *) + val to_hexstring : t -> string + (** Return the hexadecimal string representation of its argument. *) + val zero : t (** The integer 0. *) @@ -128,9 +132,16 @@ val min : t -> t -> t (** [min x y] is the lesser of [x] and [y] *) + val of_string_opt : string -> t option + (** Convert the given string to an unsigned integer. Returns [None] if the + given string is not a valid representation of an unsigned integer. *) + val pp : Format.formatter -> t -> unit (** Output the result of {!to_string} on a formatter. *) + val pp_hex : Format.formatter -> t -> unit + (** Output the result of {!to_hexstring} on a formatter. *) + module Infix : Infix with type t := t end (** Unsigned integer operations. *) @@ -147,14 +158,53 @@ module UInt32 : sig include S val of_int32 : int32 -> t + (** Convert the given 32-bit signed integer to an unsigned 32-bit integer. + + If the signed integer fits within the unsigned range (in other words, if + the signed integer is positive) then the numerical values represented by + the signed and unsigned integers are the same. + + Whether the signed integer fits or not, the function [of_int32] is always + the inverse of the function {!to_int32}. In other words, + [to_int32 (of_int32 x) = x] holds for all [x : int32]. *) + val to_int32 : t -> int32 + (** Convert the given 32-bit unsigned integer to a signed 32-bit integer. + + If the unsigned integer fits within the signed range (in other words, if + the unsigned integer is less than {!Int32.max_int}) then the numerical + values represented by unsigned and signed integers are the same. + + Whether the unsigned integer fits or not, the function [to_int32] is + always the inverse of the function {!of_int32}. In other words, + [of_int32 (to_int32 x) = x] holds for all [x : t]. *) end (** Unsigned 32-bit integer type and operations. *) module UInt64 : sig include S + val of_int64 : int64 -> t + (** Convert the given 64-bit signed integer to an unsigned 64-bit integer. + + If the signed integer fits within the unsigned range (in other words, if + the signed integer is positive) then the numerical values represented by + the signed and unsigned integers are the same. + + Whether the signed integer fits or not, the function [of_int64] is always + the inverse of the function {!to_int64}. In other words, + [to_int64 (of_int64 x) = x] holds for all [x : int64]. *) + val to_int64 : t -> int64 + (** Convert the given 64-bit unsigned integer to a signed 64-bit integer. + + If the unsigned integer fits within the signed range (in other words, if + the unsigned integer is less than {!Int64.max_int}) then the numerical + values represented by unsigned and signed integers are the same. + + Whether the unsigned integer fits or not, the function [to_int64] is + always the inverse of the function {!of_int64}. In other words, + [of_int64 (to_int64 x) = x] holds for all [x : t]. *) val of_uint32 : UInt32.t -> t (** Convert the given 32-bit unsigned integer to a 64-bit unsigned diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/src/unsigned_stubs.c new/ocaml-integers-0.5.1/src/unsigned_stubs.c --- old/ocaml-integers-0.4.0/src/unsigned_stubs.c 2020-05-01 10:55:11.000000000 +0200 +++ new/ocaml-integers-0.5.1/src/unsigned_stubs.c 2021-08-12 12:28:19.000000000 +0200 @@ -22,6 +22,18 @@ #include "ocaml_integers.h" +static int parse_digit(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + else if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + else if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + else + return -1; +} + #define Uint_custom_val(SIZE, V) Uint_custom_val_(SIZE, V) #define Uint_custom_val_(SIZE, V) \ (*(uint ## SIZE ## _t *)(Data_custom_val(V))) @@ -37,6 +49,56 @@ OP Uint_custom_val(SIZE, b)); \ } +#define UINT_OF_STRING(BITS, COPY) \ + value integers_uint ## BITS ## _of_string(value a) \ + { \ + TYPE(BITS) u, max_prefix; \ + const char *pos = String_val(a); \ + int base = 10, d; \ + \ + /* Strip a leading + sign, if given */ \ + if (*pos == '+') pos++; \ + if (*pos == '0') { \ + switch (pos[1]) { \ + case 'x': case 'X': \ + base = 16; pos += 2; break; \ + case 'o': case 'O': \ + base = 8; pos += 2; break; \ + case 'b': case 'B': \ + base = 2; pos += 2; break; \ + case 'u': case 'U': /* Unsigned prefix. No-op for unsigned types */ \ + pos += 2; break; \ + } \ + } \ + \ + max_prefix = ((TYPE(BITS)) -1) / base; \ + \ + d = parse_digit(*pos); \ + if (d < 0 || d >= base) { \ + caml_failwith("UInt"#BITS".of_string"); \ + } \ + u = (TYPE(BITS)) d; \ + pos++; \ + \ + for (;; pos++) { \ + if (*pos == '_') continue; \ + d = parse_digit(*pos); \ + /* Halt if the digit isn't valid (or this is the string terminator) */ \ + if (d < 0 || d >= base) break; \ + /* Check that we can add another digit */ \ + if (u > max_prefix) break; \ + u = d + u * base; \ + /* Check for overflow */ \ + if (u < (TYPE(BITS)) d) break; \ + } \ + \ + if (pos != String_val(a) + caml_string_length(a)){ \ + caml_failwith("UInt"#BITS".of_string"); \ + } \ + \ + return COPY(u); \ + } \ + #define UINT_DEFS(BITS, BYTES) \ static int uint ## BITS ## _cmp(value v1, value v2) \ { \ @@ -146,21 +208,24 @@ } \ \ /* of_string : string -> t */ \ - value integers_uint ## BITS ## _of_string(value a) \ - { \ - TYPE(BITS) u; \ - if (sscanf(String_val(a), "%" SCNu ## BITS , &u) != 1) \ - caml_failwith("int_of_string"); \ - else \ - return integers_copy_uint ## BITS (u); \ - } \ + UINT_OF_STRING(BITS, integers_copy_uint ## BITS) \ \ /* to_string : t -> string */ \ value integers_uint ## BITS ## _to_string(value a) \ { \ char buf[BUF_SIZE(TYPE(BITS))]; \ if (sprintf(buf, "%" PRIu ## BITS , Uint_custom_val(BITS, a)) < 0) \ - caml_failwith("string_of_int"); \ + caml_failwith("UInt ## BITS ## .to_string"); \ + else \ + return caml_copy_string(buf); \ + } \ + \ + /* to_hexstring : t -> string */ \ + value integers_uint ## BITS ## _to_hexstring(value a) \ + { \ + char buf[BUF_SIZE(TYPE(BITS))]; \ + if (sprintf(buf, "%" PRIx ## BITS , Uint_custom_val(BITS, a)) < 0) \ + caml_failwith("UInt ## BITS ## .to_hexstring"); \ else \ return caml_copy_string(buf); \ } \ @@ -173,21 +238,24 @@ #define UINT_SMALL_DEFS(BITS, BYTES) \ /* of_string : string -> t */ \ - value integers_uint ## BITS ## _of_string(value a) \ - { \ - TYPE(BITS) u; \ - if (sscanf(String_val(a), "%" SCNu ## BITS , &u) != 1) \ - caml_failwith("int_of_string"); \ - else \ - return Integers_val_uint ## BITS(u); \ - } \ + UINT_OF_STRING(BITS, Integers_val_uint ## BITS) \ \ /* to_string : t -> string */ \ value integers_uint ## BITS ## _to_string(value a) \ { \ char buf[BUF_SIZE(TYPE(BITS))]; \ if (sprintf(buf, "%" PRIu ## BITS , Uint ## BITS ##_val(a)) < 0) \ - caml_failwith("string_of_int"); \ + caml_failwith("UInt ## BITS ## .to_string"); \ + else \ + return caml_copy_string(buf); \ + } \ + \ + /* to_hexstring : t -> string */ \ + value integers_uint ## BITS ## _to_hexstring(value a) \ + { \ + char buf[BUF_SIZE(TYPE(BITS))]; \ + if (sprintf(buf, "%" PRIx ## BITS , Uint ## BITS ##_val(a)) < 0) \ + caml_failwith("UInt ## BITS ## .to_hexstring"); \ else \ return caml_copy_string(buf); \ } \ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/test/dune new/ocaml-integers-0.5.1/test/dune --- old/ocaml-integers-0.4.0/test/dune 1970-01-01 01:00:00.000000000 +0100 +++ new/ocaml-integers-0.5.1/test/dune 2021-08-12 12:28:19.000000000 +0200 @@ -0,0 +1,5 @@ +(tests + (package integers) + (libraries integers) + (names hexprinting uint64conversions uint32conversions)) + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/test/hexprinting.ml new/ocaml-integers-0.5.1/test/hexprinting.ml --- old/ocaml-integers-0.4.0/test/hexprinting.ml 1970-01-01 01:00:00.000000000 +0100 +++ new/ocaml-integers-0.5.1/test/hexprinting.ml 2021-08-12 12:28:19.000000000 +0200 @@ -0,0 +1,37 @@ +(* + * Copyright (c) 2021 Nomadic Labs + * + * This file is distributed under the terms of the MIT License. + * See the file LICENSE for details. + *) + +let () = print_endline "Hexstring test: ?" + +let () = + assert Signed.Int.(to_hexstring (of_string "0x23") = "23"); + assert Signed.Int32.(to_hexstring (of_string "0x23") = "23"); + assert Signed.Int64.(to_hexstring (of_string "0x23") = "23"); + assert Unsigned.UInt8.(to_hexstring (of_string "0x23") = "23"); + assert Unsigned.UInt16.(to_hexstring (of_string "0x23") = "23"); + assert Unsigned.UInt32.(to_hexstring (of_string "0x23") = "23"); + assert Unsigned.UInt64.(to_hexstring (of_string "0x23") = "23"); + () + +let () = + assert Signed.Int32.(to_hexstring (of_string "0xDeadBeef") = "deadbeef"); + assert Signed.Int64.(to_hexstring (of_string "0xDeadBeef") = "deadbeef"); + assert Unsigned.UInt32.(to_hexstring (of_string "0xDeadBeef") = "deadbeef"); + assert Unsigned.UInt64.(to_hexstring (of_string "0xDeadBeef") = "deadbeef"); + () + +let () = + assert Signed.Int.(to_hexstring (of_string "0x0") = "0"); + assert Signed.Int32.(to_hexstring (of_string "0x0") = "0"); + assert Signed.Int64.(to_hexstring (of_string "0x0") = "0"); + assert Unsigned.UInt8.(to_hexstring (of_string "0x0") = "0"); + assert Unsigned.UInt16.(to_hexstring (of_string "0x0") = "0"); + assert Unsigned.UInt32.(to_hexstring (of_string "0x0") = "0"); + assert Unsigned.UInt64.(to_hexstring (of_string "0x0") = "0"); + () + +let () = print_endline "Hexstring test: ???" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/test/uint32conversions.ml new/ocaml-integers-0.5.1/test/uint32conversions.ml --- old/ocaml-integers-0.4.0/test/uint32conversions.ml 1970-01-01 01:00:00.000000000 +0100 +++ new/ocaml-integers-0.5.1/test/uint32conversions.ml 2021-08-12 12:28:19.000000000 +0200 @@ -0,0 +1,55 @@ +(* + * Copyright (c) 2021 Nomadic Labs + * + * This file is distributed under the terms of the MIT License. + * See the file LICENSE for details. + *) + +let () = print_endline "UInt32-Int32 conversion test: ?" + +(* Asserting that signed->unsigned conversion is trivial when within range *) +let () = + let check i32 = + let s32 = Int32.to_string i32 in + Unsigned.UInt32.(equal (of_int32 i32) (of_string s32)) + in + assert (check 0l); + assert (check 1l); + assert (check 23l); + assert (check 112783646l); + assert (check Int32.max_int) + +(* Asserting that unsinged->signed conversion is trivial when within range *) +let () = + let check u32 = + let s32 = Unsigned.UInt32.to_string u32 in + Int32.equal (Unsigned.UInt32.to_int32 u32) (Int32.of_string s32) + in + assert (check Unsigned.UInt32.zero); + assert (check Unsigned.UInt32.one); + assert (check (Unsigned.UInt32.of_string "23")); + assert (check (Unsigned.UInt32.of_string "112783646")); + assert (check (Unsigned.UInt32.of_string "2147483647")); + () + +(* Asserting that signed->unsigned->signed roundtrips *) +let () = + assert Unsigned.UInt32.(to_int32 (of_int32 23l) = 23l); + assert Unsigned.UInt32.(to_int32 (of_int32 0l) = 0l); + assert Unsigned.UInt32.(to_int32 (of_int32 (-1l)) = -1l); + assert Unsigned.UInt32.(to_int32 (of_int32 (-23l)) = -23l); + assert Unsigned.UInt32.(to_int32 (of_int32 Int32.max_int) = Int32.max_int); + assert Unsigned.UInt32.(to_int32 (of_int32 Int32.min_int) = Int32.min_int); + () + +(* Asserting that unsigned->signed->unsigned roundtrips *) +let () = + assert Unsigned.UInt32.(equal (of_int32 (to_int32 (of_string "0"))) (of_string "0")); + assert Unsigned.UInt32.(equal (of_int32 (to_int32 (of_string "23"))) (of_string "23")); + assert Unsigned.UInt32.(equal (of_int32 (to_int32 (of_string "2147483647"))) (of_string "2147483647")); + assert Unsigned.UInt32.(equal (of_int32 (to_int32 (of_string "2147483648"))) (of_string "2147483648")); + assert Unsigned.UInt32.(equal (of_int32 (to_int32 (of_string "2147493648"))) (of_string "2147493648")); + assert Unsigned.UInt32.(equal (of_int32 (to_int32 max_int)) max_int); + () + +let () = print_endline "UInt32-Int32 conversion test: ???" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ocaml-integers-0.4.0/test/uint64conversions.ml new/ocaml-integers-0.5.1/test/uint64conversions.ml --- old/ocaml-integers-0.4.0/test/uint64conversions.ml 1970-01-01 01:00:00.000000000 +0100 +++ new/ocaml-integers-0.5.1/test/uint64conversions.ml 2021-08-12 12:28:19.000000000 +0200 @@ -0,0 +1,55 @@ +(* + * Copyright (c) 2021 Nomadic Labs + * + * This file is distributed under the terms of the MIT License. + * See the file LICENSE for details. + *) + +let () = print_endline "UInt64-Int64 conversion test: ?" + +(* Asserting that signed->unsigned conversion is trivial when within range *) +let () = + let check i64 = + let s64 = Int64.to_string i64 in + Unsigned.UInt64.(equal (of_int64 i64) (of_string s64)) + in + assert (check 0L); + assert (check 1L); + assert (check 23L); + assert (check 709182743098L); + assert (check Int64.max_int) + +(* Asserting that unsinged->signed conversion is trivial when within range *) +let () = + let check u64 = + let s64 = Unsigned.UInt64.to_string u64 in + Int64.equal (Unsigned.UInt64.to_int64 u64) (Int64.of_string s64) + in + assert (check Unsigned.UInt64.zero); + assert (check Unsigned.UInt64.one); + assert (check (Unsigned.UInt64.of_string "23")); + assert (check (Unsigned.UInt64.of_string "709182743098")); + assert (check (Unsigned.UInt64.of_string "9223372036854775807")); + () + +(* Asserting that signed->unsigned->signed roundtrips *) +let () = + assert Unsigned.UInt64.(to_int64 (of_int64 23L) = 23L); + assert Unsigned.UInt64.(to_int64 (of_int64 0L) = 0L); + assert Unsigned.UInt64.(to_int64 (of_int64 (-1L)) = -1L); + assert Unsigned.UInt64.(to_int64 (of_int64 (-23L)) = -23L); + assert Unsigned.UInt64.(to_int64 (of_int64 Int64.max_int) = Int64.max_int); + assert Unsigned.UInt64.(to_int64 (of_int64 Int64.min_int) = Int64.min_int); + () + +(* Asserting that unsigned->signed->unsigned roundtrips *) +let () = + assert Unsigned.UInt64.(equal (of_int64 (to_int64 (of_string "0"))) (of_string "0")); + assert Unsigned.UInt64.(equal (of_int64 (to_int64 (of_string "23"))) (of_string "23")); + assert Unsigned.UInt64.(equal (of_int64 (to_int64 (of_string "9223372036854775807"))) (of_string "9223372036854775807")); + assert Unsigned.UInt64.(equal (of_int64 (to_int64 (of_string "9223372036854775808"))) (of_string "9223372036854775808")); + assert Unsigned.UInt64.(equal (of_int64 (to_int64 (of_string "9223372036954775808"))) (of_string "9223372036954775808")); + assert Unsigned.UInt64.(equal (of_int64 (to_int64 max_int)) max_int); + () + +let () = print_endline "UInt64-Int64 conversion test: ???"