From f831322eb38c955f97a3b5c7e4ec0aa1918bc997 Mon Sep 17 00:00:00 2001 From: Stephane Glondu Date: Sat, 4 Dec 2021 17:41:13 +0100 Subject: New upstream version 1.2 --- CHANGES.md | 8 ++++++++ appveyor.yml | 13 +++++++++++++ ocplib-endian.opam | 4 ++-- src/be_ocaml_401.ml | 9 ++++++++- src/common.ml | 16 ++++++++++++---- src/common_float.ml | 8 ++++---- src/endianBigstring.cppo.ml | 4 ++++ src/endianBytes.cppo.ml | 4 ++++ src/endianString.cppo.ml | 11 +++++++++++ src/endianString.cppo.mli | 7 +++++++ src/le_ocaml_401.ml | 9 ++++++++- src/ne_ocaml_401.ml | 9 ++++++++- tests/test_string.cppo.ml | 3 +++ 13 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 appveyor.yml diff --git a/CHANGES.md b/CHANGES.md index bedaa36..eef35a7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,11 @@ +1.2 +--- + +* Fix for js-of-ocaml (@hhugo) +* Bump minimal OCaml version to 4.03.0 +* Add [@@ocaml.inline] annotations where relevant +* Add [@@ocaml.deprecated] annotations on EndianString.set_* functions + 1.1 --- diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..74ee06f --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,13 @@ +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 --git a/ocplib-endian.opam b/ocplib-endian.opam index 642829c..9cbae80 100644 --- a/ocplib-endian.opam +++ b/ocplib-endian.opam @@ -14,9 +14,9 @@ bug-reports: "https://github.com/OCamlPro/ocplib-endian/issues" doc: "https://ocamlpro.github.io/ocplib-endian/ocplib-endian/" depends: [ "base-bytes" - "ocaml" {>= "4.02.3"} + "ocaml" {>= "4.03.0"} "cppo" {>= "1.1.0" & build} - "dune" {build & >= "1.0"} + "dune" {>= "1.0"} ] build: [ ["dune" "build" "-p" name "-j" jobs diff --git a/src/be_ocaml_401.ml b/src/be_ocaml_401.ml index 38de28c..21bba0b 100644 --- a/src/be_ocaml_401.ml +++ b/src/be_ocaml_401.ml @@ -2,31 +2,38 @@ if not Sys.big_endian then swap16 (get_16 s off) else get_16 s off + [@@ocaml.inline] let get_int16 s off = - ((get_uint16 s off) lsl ( Sys.word_size - 17 )) asr ( Sys.word_size - 17 ) + ((get_uint16 s off) lsl ( Sys.int_size - 16 )) asr ( Sys.int_size - 16 ) + [@@ocaml.inline] let get_int32 s off = if not Sys.big_endian then swap32 (get_32 s off) else get_32 s off + [@@ocaml.inline] let get_int64 s off = if not Sys.big_endian then swap64 (get_64 s off) else get_64 s off + [@@ocaml.inline] let set_int16 s off v = if not Sys.big_endian then (set_16 s off (swap16 v)) else set_16 s off v + [@@ocaml.inline] let set_int32 s off v = if not Sys.big_endian then set_32 s off (swap32 v) else set_32 s off v + [@@ocaml.inline] let set_int64 s off v = if not Sys.big_endian then set_64 s off (swap64 v) else set_64 s off v + [@@ocaml.inline] diff --git a/src/common.ml b/src/common.ml index 54df23e..9ef8bc9 100644 --- a/src/common.ml +++ b/src/common.ml @@ -1,24 +1,32 @@ [@@@warning "-32"] let sign8 v = - (v lsl ( Sys.word_size - 9 )) asr ( Sys.word_size - 9 ) + (v lsl ( Sys.int_size - 8 )) asr ( Sys.int_size - 8 ) + [@@ocaml.inline] let sign16 v = - (v lsl ( Sys.word_size - 17 )) asr ( Sys.word_size - 17 ) + (v lsl ( Sys.int_size - 16 )) asr ( Sys.int_size - 16 ) + [@@ocaml.inline] let get_uint8 s off = Char.code (get_char s off) + [@@ocaml.inline] let get_int8 s off = - ((get_uint8 s off) lsl ( Sys.word_size - 9 )) asr ( Sys.word_size - 9 ) + ((get_uint8 s off) lsl ( Sys.int_size - 8 )) asr ( Sys.int_size - 8 ) + [@@ocaml.inline] let set_int8 s off v = (* It is ok to cast using unsafe_chr because both String.set and Bigarray.Array1.set (on bigstrings) use the 'store unsigned int8' primitives that effectively extract the bits before writing *) set_char s off (Char.unsafe_chr v) + [@@ocaml.inline] let unsafe_get_uint8 s off = Char.code (unsafe_get_char s off) + [@@ocaml.inline] let unsafe_get_int8 s off = - ((unsafe_get_uint8 s off) lsl ( Sys.word_size - 9 )) asr ( Sys.word_size - 9 ) + ((unsafe_get_uint8 s off) lsl ( Sys.int_size - 8 )) asr ( Sys.int_size - 8 ) + [@@ocaml.inline] let unsafe_set_int8 s off v = unsafe_set_char s off (Char.unsafe_chr v) + [@@ocaml.inline] diff --git a/src/common_float.ml b/src/common_float.ml index 3d28d2d..d760492 100644 --- a/src/common_float.ml +++ b/src/common_float.ml @@ -1,5 +1,5 @@ -let get_float buff i = Int32.float_of_bits (get_int32 buff i) -let get_double buff i = Int64.float_of_bits (get_int64 buff i) -let set_float buff i v = set_int32 buff i (Int32.bits_of_float v) -let set_double buff i v = set_int64 buff i (Int64.bits_of_float v) +let get_float buff i = Int32.float_of_bits (get_int32 buff i) [@@ocaml.inline] +let get_double buff i = Int64.float_of_bits (get_int64 buff i) [@@ocaml.inline] +let set_float buff i v = set_int32 buff i (Int32.bits_of_float v) [@@ocaml.inline] +let set_double buff i v = set_int64 buff i (Int64.bits_of_float v) [@@ocaml.inline] diff --git a/src/endianBigstring.cppo.ml b/src/endianBigstring.cppo.ml index b7a6aba..907d1ab 100644 --- a/src/endianBigstring.cppo.ml +++ b/src/endianBigstring.cppo.ml @@ -84,12 +84,16 @@ end let get_char (s:bigstring) off = Array1.get s off + [@@ocaml.inline] let set_char (s:bigstring) off v = Array1.set s off v + [@@ocaml.inline] let unsafe_get_char (s:bigstring) off = Array1.unsafe_get s off + [@@ocaml.inline] let unsafe_set_char (s:bigstring) off v = Array1.unsafe_set s off v + [@@ocaml.inline] #include "common.ml" diff --git a/src/endianBytes.cppo.ml b/src/endianBytes.cppo.ml index 419f063..dd5900e 100644 --- a/src/endianBytes.cppo.ml +++ b/src/endianBytes.cppo.ml @@ -80,12 +80,16 @@ end let get_char (s:Bytes.t) off = Bytes.get s off + [@@ocaml.inline] let set_char (s:Bytes.t) off v = Bytes.set s off v + [@@ocaml.inline] let unsafe_get_char (s:Bytes.t) off = Bytes.unsafe_get s off + [@@ocaml.inline] let unsafe_set_char (s:Bytes.t) off v = Bytes.unsafe_set s off v + [@@ocaml.inline] #include "common.ml" diff --git a/src/endianString.cppo.ml b/src/endianString.cppo.ml index df8ccd4..4a2439f 100644 --- a/src/endianString.cppo.ml +++ b/src/endianString.cppo.ml @@ -52,36 +52,47 @@ module type EndianStringSig = sig [Int64.float_of_bits (get_int64 buff i)] *) val set_char : Bytes.t -> int -> char -> unit + [@@ocaml.deprecated "Use EndianBytes.set_char instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_char}. *) val set_int8 : Bytes.t -> int -> int -> unit + [@@ocaml.deprecated "Use EndianBytes.set_int8 instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_int8}. *) val set_int16 : Bytes.t -> int -> int -> unit + [@@ocaml.deprecated "Use EndianBytes.set_int16 instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_int16}. *) val set_int32 : Bytes.t -> int -> int32 -> unit + [@@ocaml.deprecated "Use EndianBytes.set_int13 instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_int32}. *) val set_int64 : Bytes.t -> int -> int64 -> unit + [@@ocaml.deprecated "Use EndianBytes.set_int64 instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_int64}. *) val set_float : Bytes.t -> int -> float -> unit + [@@ocaml.deprecated "Use EndianBytes.set_float instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_float}. *) val set_double : Bytes.t -> int -> float -> unit + [@@ocaml.deprecated "Use EndianBytes.set_double instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_double}. *) end let get_char (s:string) off = String.get s off + [@@ocaml.inline] let set_char (s:Bytes.t) off v = Bytes.set s off v + [@@ocaml.inline] let unsafe_get_char (s:string) off = String.unsafe_get s off + [@@ocaml.inline] let unsafe_set_char (s:Bytes.t) off v = Bytes.unsafe_set s off v + [@@ocaml.inline] #include "common.ml" diff --git a/src/endianString.cppo.mli b/src/endianString.cppo.mli index 2b703d6..32dee4c 100644 --- a/src/endianString.cppo.mli +++ b/src/endianString.cppo.mli @@ -52,24 +52,31 @@ module type EndianStringSig = sig [Int64.float_of_bits (get_int64 buff i)] *) val set_char : Bytes.t -> int -> char -> unit + [@@ocaml.deprecated "Use EndianBytes.set_char instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_char}. *) val set_int8 : Bytes.t -> int -> int -> unit + [@@ocaml.deprecated "Use EndianBytes.set_int8 instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_int8}. *) val set_int16 : Bytes.t -> int -> int -> unit + [@@ocaml.deprecated "Use EndianBytes.set_int16 instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_int16}. *) val set_int32 : Bytes.t -> int -> int32 -> unit + [@@ocaml.deprecated "Use EndianBytes.set_int13 instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_int32}. *) val set_int64 : Bytes.t -> int -> int64 -> unit + [@@ocaml.deprecated "Use EndianBytes.set_int64 instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_int64}. *) val set_float : Bytes.t -> int -> float -> unit + [@@ocaml.deprecated "Use EndianBytes.set_float instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_float}. *) val set_double : Bytes.t -> int -> float -> unit + [@@ocaml.deprecated "Use EndianBytes.set_double instead."] (** @deprecated This is a deprecated alias of {!endianBytes.set_double}. *) end diff --git a/src/le_ocaml_401.ml b/src/le_ocaml_401.ml index b65184c..9708444 100644 --- a/src/le_ocaml_401.ml +++ b/src/le_ocaml_401.ml @@ -2,31 +2,38 @@ if Sys.big_endian then swap16 (get_16 s off) else get_16 s off + [@@ocaml.inline] let get_int16 s off = - ((get_uint16 s off) lsl ( Sys.word_size - 17 )) asr ( Sys.word_size - 17 ) + ((get_uint16 s off) lsl ( Sys.int_size - 16 )) asr ( Sys.int_size - 16 ) + [@@ocaml.inline] let get_int32 s off = if Sys.big_endian then swap32 (get_32 s off) else get_32 s off + [@@ocaml.inline] let get_int64 s off = if Sys.big_endian then swap64 (get_64 s off) else get_64 s off + [@@ocaml.inline] let set_int16 s off v = if Sys.big_endian then (set_16 s off (swap16 v)) else set_16 s off v + [@@ocaml.inline] let set_int32 s off v = if Sys.big_endian then set_32 s off (swap32 v) else set_32 s off v + [@@ocaml.inline] let set_int64 s off v = if Sys.big_endian then set_64 s off (swap64 v) else set_64 s off v + [@@ocaml.inline] diff --git a/src/ne_ocaml_401.ml b/src/ne_ocaml_401.ml index 2348135..1029db8 100644 --- a/src/ne_ocaml_401.ml +++ b/src/ne_ocaml_401.ml @@ -1,20 +1,27 @@ let get_uint16 s off = get_16 s off + [@@ocaml.inline] let get_int16 s off = - ((get_uint16 s off) lsl ( Sys.word_size - 17 )) asr ( Sys.word_size - 17 ) + ((get_uint16 s off) lsl ( Sys.int_size - 16 )) asr ( Sys.int_size - 16 ) + [@@ocaml.inline] let get_int32 s off = get_32 s off + [@@ocaml.inline] let get_int64 s off = get_64 s off + [@@ocaml.inline] let set_int16 s off v = set_16 s off v + [@@ocaml.inline] let set_int32 s off v = set_32 s off v + [@@ocaml.inline] let set_int64 s off v = set_64 s off v + [@@ocaml.inline] diff --git a/tests/test_string.cppo.ml b/tests/test_string.cppo.ml index dec2521..f108e8c 100644 --- a/tests/test_string.cppo.ml +++ b/tests/test_string.cppo.ml @@ -1,6 +1,9 @@ open EndianString [@@@warning "-52"] +(* Allow testing deprecated string_set functions *) +[@@@warning "-3"] + let to_t = Bytes.unsafe_to_string (* do not allocate to avoid breaking tests *) -- cgit v1.2.3