Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/common_401.cppo.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#if OCAML_VERSION >= (4, 03, 0)
external swap16 : int -> int = "%bswap16"
external swap32 : int32 -> int32 = "%bswap_int32"
external swap64 : int64 -> int64 = "%bswap_int64"
external swapnative : nativeint -> nativeint = "%bswap_native"
#else
external swap16 : int -> int = "caml_bswap16"
external swap32 : int32 -> int32 = "caml_int32_bswap"
external swap64 : int64 -> int64 = "caml_int64_bswap"
external swapnative : nativeint -> nativeint = "caml_nativeint_bswap"
#endif

module BigEndian = struct

Expand Down
22 changes: 21 additions & 1 deletion src/endianBigstring.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ let unsafe_set_char (s:bigstring) off v =

#include "common.ml"

#if OCAML_VERSION >= (4, 01, 0)
#if OCAML_VERSION >= (4, 03, 0)

external unsafe_get_16 : bigstring -> int -> int = "%caml_bigstring_get16u"
external unsafe_get_32 : bigstring -> int -> int32 = "%caml_bigstring_get32u"
Expand All @@ -113,6 +113,26 @@ external set_64 : bigstring -> int -> int64 -> unit = "%caml_bigstring_set64"

#include "common_401.ml"

#elif OCAML_VERSION >= (4, 01, 0)

external unsafe_get_16 : bigstring -> int -> int = "caml_ba_uint8_get16"
external unsafe_get_32 : bigstring -> int -> int32 = "caml_ba_uint8_get32"
external unsafe_get_64 : bigstring -> int -> int64 = "caml_ba_uint8_get64"

external unsafe_set_16 : bigstring -> int -> int -> unit = "caml_ba_uint8_set16"
external unsafe_set_32 : bigstring -> int -> int32 -> unit = "caml_ba_uint8_set32"
external unsafe_set_64 : bigstring -> int -> int64 -> unit = "caml_ba_uint8_set64"

external get_16 : bigstring -> int -> int = "caml_ba_uint8_get16"
external get_32 : bigstring -> int -> int32 = "caml_ba_uint8_get32"
external get_64 : bigstring -> int -> int64 = "caml_ba_uint8_get64"

external set_16 : bigstring -> int -> int -> unit = "caml_ba_uint8_set16"
external set_32 : bigstring -> int -> int32 -> unit = "caml_ba_uint8_set32"
external set_64 : bigstring -> int -> int64 -> unit = "caml_ba_uint8_set64"

#include "common_401.ml"

#else

#include "common_400.ml"
Expand Down
22 changes: 21 additions & 1 deletion src/endianBytes.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ let unsafe_set_char (s:Bytes.t) off v =

#include "common.ml"

#if OCAML_VERSION >= (4, 01, 0)
#if OCAML_VERSION >= (4, 03, 0)

external unsafe_get_16 : Bytes.t -> int -> int = "%caml_string_get16u"
external unsafe_get_32 : Bytes.t -> int -> int32 = "%caml_string_get32u"
Expand All @@ -109,6 +109,26 @@ external set_64 : Bytes.t -> int -> int64 -> unit = "%caml_string_set64"

#include "common_401.ml"

#elif OCAML_VERSION >= (4, 01, 0)

external unsafe_get_16 : Bytes.t -> int -> int = "caml_string_get16"
external unsafe_get_32 : Bytes.t -> int -> int32 = "caml_string_get32"
external unsafe_get_64 : Bytes.t -> int -> int64 = "caml_string_get64"

external unsafe_set_16 : Bytes.t -> int -> int -> unit = "caml_string_set16"
external unsafe_set_32 : Bytes.t -> int -> int32 -> unit = "caml_string_set32"
external unsafe_set_64 : Bytes.t -> int -> int64 -> unit = "caml_string_set64"

external get_16 : Bytes.t -> int -> int = "caml_string_get16"
external get_32 : Bytes.t -> int -> int32 = "caml_string_get32"
external get_64 : Bytes.t -> int -> int64 = "caml_string_get64"

external set_16 : Bytes.t -> int -> int -> unit = "caml_string_set16"
external set_32 : Bytes.t -> int -> int32 -> unit = "caml_string_set32"
external set_64 : Bytes.t -> int -> int64 -> unit = "caml_string_set64"

#include "common_401.ml"

#else

#include "common_400.ml"
Expand Down
22 changes: 21 additions & 1 deletion src/endianString.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ let unsafe_set_char (s:Bytes.t) off v =

#include "common.ml"

#if OCAML_VERSION >= (4, 01, 0)
#if OCAML_VERSION >= (4, 03, 0)

external unsafe_get_16 : string -> int -> int = "%caml_string_get16u"
external unsafe_get_32 : string -> int -> int32 = "%caml_string_get32u"
Expand All @@ -105,6 +105,26 @@ external set_64 : Bytes.t -> int -> int64 -> unit = "%caml_string_set64"

#include "common_401.ml"

#elif OCAML_VERSION >= (4, 01, 0)

external unsafe_get_16 : string -> int -> int = "caml_string_get16"
external unsafe_get_32 : string -> int -> int32 = "caml_string_get32"
external unsafe_get_64 : string -> int -> int64 = "caml_string_get64"

external unsafe_set_16 : Bytes.t -> int -> int -> unit = "caml_string_set16"
external unsafe_set_32 : Bytes.t -> int -> int32 -> unit = "caml_string_set32"
external unsafe_set_64 : Bytes.t -> int -> int64 -> unit = "caml_string_set64"

external get_16 : string -> int -> int = "caml_string_get16"
external get_32 : string -> int -> int32 = "caml_string_get32"
external get_64 : string -> int -> int64 = "caml_string_get64"

external set_16 : Bytes.t -> int -> int -> unit = "caml_string_set16"
external set_32 : Bytes.t -> int -> int32 -> unit = "caml_string_set32"
external set_64 : Bytes.t -> int -> int64 -> unit = "caml_string_set64"

#include "common_401.ml"

#else

#include "common_400.ml"
Expand Down
16 changes: 11 additions & 5 deletions tests/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ let allocdiff =
let stat2 = Gc.quick_stat () in
(stat2.Gc.minor_words -. stat1.Gc.minor_words)

let version_over_4_01 =
let version_over req_major req_minor =
try
Scanf.sscanf Sys.ocaml_version "%i.%i.%i"
(fun major minor patch -> major > 4 || (major = 4 && minor >= 1))
(fun major minor patch -> major > req_major || (major = req_major && minor >= req_minor))
with _ -> false

let () =
Expand Down Expand Up @@ -40,6 +40,12 @@ let () =
Printf.printf "bytes: allocated words %f\n%!" alloc3;
(* we cannot ensure that there are no allocations only with the
primives added in 4.01.0 *)
if version_over_4_01 && (alloc1 <> 0. || alloc2 <> 0. || alloc3 <> 0.)
then exit 1
else exit 0
let failure =
if version_over 4 3 then
(alloc1 <> 0. || alloc2 <> 0. || alloc3 <> 0.)
else if version_over 4 1 then
(alloc1 <> 72. || alloc2 <> 72. || alloc3 <> 72.)
else
false
in
exit (if failure then 1 else 0)