Skip to content

Commit 82d2375

Browse files
committed
apply changes to stdlib and test suite
1 parent 5329853 commit 82d2375

File tree

9 files changed

+70
-67
lines changed

9 files changed

+70
-67
lines changed

stdlib/bytes.ml

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515

1616
(* Byte sequence operations *)
1717

18-
external length : bytes -> int = "%string_length"
18+
external length : bytes -> int = "%bytes_length"
1919
external string_length : string -> int = "%string_length"
20-
external get : bytes -> int -> char = "%string_safe_get"
21-
external set : bytes -> int -> char -> unit = "%string_safe_set"
22-
external create : int -> bytes = "caml_create_string"
23-
external unsafe_get : bytes -> int -> char = "%string_unsafe_get"
24-
external unsafe_set : bytes -> int -> char -> unit = "%string_unsafe_set"
20+
external get : bytes -> int -> char = "%bytes_safe_get"
21+
external set : bytes -> int -> char -> unit = "%bytes_safe_set"
22+
external create : int -> bytes = "caml_create_bytes"
23+
external unsafe_get : bytes -> int -> char = "%bytes_unsafe_get"
24+
external unsafe_set : bytes -> int -> char -> unit = "%bytes_unsafe_set"
2525
external unsafe_fill : bytes -> int -> int -> char -> unit
26-
= "caml_fill_string" [@@noalloc]
27-
external unsafe_to_string : bytes -> string = "%identity"
28-
external unsafe_of_string : string -> bytes = "%identity"
26+
= "caml_fill_bytes" [@@noalloc]
27+
external unsafe_to_string : bytes -> string = "%bytes_to_string"
28+
external unsafe_of_string : string -> bytes = "%bytes_of_string"
2929

3030
external unsafe_blit : bytes -> int -> bytes -> int -> int -> unit
31-
= "caml_blit_string" [@@noalloc]
31+
= "caml_blit_bytes" [@@noalloc]
3232
external unsafe_blit_string : string -> int -> bytes -> int -> int -> unit
3333
= "caml_blit_string" [@@noalloc]
3434

@@ -259,7 +259,7 @@ let rcontains_from s i c =
259259
type t = bytes
260260

261261
let compare (x: t) (y: t) = Pervasives.compare x y
262-
external equal : t -> t -> bool = "caml_string_equal"
262+
external equal : t -> t -> bool = "caml_bytes_equal"
263263

264264
(* Deprecated functions implemented via other deprecated functions *)
265265
[@@@ocaml.warning "-3"]

stdlib/bytes.mli

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@
4242
@since 4.02.0
4343
*)
4444

45-
external length : bytes -> int = "%string_length"
45+
external length : bytes -> int = "%bytes_length"
4646
(** Return the length (number of bytes) of the argument. *)
4747

48-
external get : bytes -> int -> char = "%string_safe_get"
48+
external get : bytes -> int -> char = "%bytes_safe_get"
4949
(** [get s n] returns the byte at index [n] in argument [s].
5050
5151
Raise [Invalid_argument] if [n] not a valid index in [s]. *)
5252

53-
external set : bytes -> int -> char -> unit = "%string_safe_set"
53+
external set : bytes -> int -> char -> unit = "%bytes_safe_set"
5454
(** [set s n c] modifies [s] in place, replacing the byte at index [n]
5555
with [c].
5656
5757
Raise [Invalid_argument] if [n] is not a valid index in [s]. *)
5858

59-
external create : int -> bytes = "caml_create_string"
59+
external create : int -> bytes = "caml_create_bytes"
6060
(** [create n] returns a new byte sequence of length [n]. The
6161
sequence is uninitialized and contains arbitrary bytes.
6262
@@ -424,10 +424,10 @@ let s = Bytes.of_string "hello"
424424

425425
(* The following is for system use only. Do not call directly. *)
426426

427-
external unsafe_get : bytes -> int -> char = "%string_unsafe_get"
428-
external unsafe_set : bytes -> int -> char -> unit = "%string_unsafe_set"
427+
external unsafe_get : bytes -> int -> char = "%bytes_unsafe_get"
428+
external unsafe_set : bytes -> int -> char -> unit = "%bytes_unsafe_set"
429429
external unsafe_blit :
430430
bytes -> int -> bytes -> int -> int -> unit
431-
= "caml_blit_string" [@@noalloc]
431+
= "caml_blit_bytes" [@@noalloc]
432432
external unsafe_fill :
433-
bytes -> int -> int -> char -> unit = "caml_fill_string" [@@noalloc]
433+
bytes -> int -> int -> char -> unit = "caml_fill_bytes" [@@noalloc]

stdlib/bytesLabels.mli

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
@since 4.02.0
1818
*)
1919

20-
external length : bytes -> int = "%string_length"
20+
external length : bytes -> int = "%bytes_length"
2121
(** Return the length (number of bytes) of the argument. *)
2222

23-
external get : bytes -> int -> char = "%string_safe_get"
23+
external get : bytes -> int -> char = "%bytes_safe_get"
2424
(** [get s n] returns the byte at index [n] in argument [s].
2525
2626
Raise [Invalid_argument] if [n] not a valid index in [s]. *)
2727

2828

29-
external set : bytes -> int -> char -> unit = "%string_safe_set"
29+
external set : bytes -> int -> char -> unit = "%bytes_safe_set"
3030
(** [set s n c] modifies [s] in place, replacing the byte at index [n]
3131
with [c].
3232
3333
Raise [Invalid_argument] if [n] is not a valid index in [s]. *)
3434

35-
external create : int -> bytes = "caml_create_string"
35+
external create : int -> bytes = "caml_create_bytes"
3636
(** [create n] returns a new byte sequence of length [n]. The
3737
sequence is uninitialized and contains arbitrary bytes.
3838
@@ -206,12 +206,12 @@ val compare: t -> t -> int
206206

207207
(* The following is for system use only. Do not call directly. *)
208208

209-
external unsafe_get : bytes -> int -> char = "%string_unsafe_get"
210-
external unsafe_set : bytes -> int -> char -> unit = "%string_unsafe_set"
209+
external unsafe_get : bytes -> int -> char = "%bytes_unsafe_get"
210+
external unsafe_set : bytes -> int -> char -> unit = "%bytes_unsafe_set"
211211
external unsafe_blit :
212212
src:bytes -> src_pos:int -> dst:bytes -> dst_pos:int -> len:int ->
213-
unit = "caml_blit_string" [@@noalloc]
213+
unit = "caml_blit_bytes" [@@noalloc]
214214
external unsafe_fill :
215-
bytes -> pos:int -> len:int -> char -> unit = "caml_fill_string" [@@noalloc]
215+
bytes -> pos:int -> len:int -> char -> unit = "caml_fill_bytes" [@@noalloc]
216216
val unsafe_to_string : bytes -> string
217217
val unsafe_of_string : string -> bytes

stdlib/char.ml

+13-12
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ external unsafe_chr: int -> char = "%identity"
2121
let chr n =
2222
if n < 0 || n > 255 then invalid_arg "Char.chr" else unsafe_chr n
2323

24-
external string_create: int -> string = "caml_create_string"
25-
external string_unsafe_set : string -> int -> char -> unit
26-
= "%string_unsafe_set"
24+
external bytes_create: int -> bytes = "caml_create_bytes"
25+
external bytes_unsafe_set : bytes -> int -> char -> unit
26+
= "%bytes_unsafe_set"
27+
external unsafe_to_string : bytes -> string = "%bytes_to_string"
2728

2829
let escaped = function
2930
| '\'' -> "\\'"
@@ -33,17 +34,17 @@ let escaped = function
3334
| '\r' -> "\\r"
3435
| '\b' -> "\\b"
3536
| ' ' .. '~' as c ->
36-
let s = string_create 1 in
37-
string_unsafe_set s 0 c;
38-
s
37+
let s = bytes_create 1 in
38+
bytes_unsafe_set s 0 c;
39+
unsafe_to_string s
3940
| c ->
4041
let n = code c in
41-
let s = string_create 4 in
42-
string_unsafe_set s 0 '\\';
43-
string_unsafe_set s 1 (unsafe_chr (48 + n / 100));
44-
string_unsafe_set s 2 (unsafe_chr (48 + (n / 10) mod 10));
45-
string_unsafe_set s 3 (unsafe_chr (48 + n mod 10));
46-
s
42+
let s = bytes_create 4 in
43+
bytes_unsafe_set s 0 '\\';
44+
bytes_unsafe_set s 1 (unsafe_chr (48 + n / 100));
45+
bytes_unsafe_set s 2 (unsafe_chr (48 + (n / 10) mod 10));
46+
bytes_unsafe_set s 3 (unsafe_chr (48 + n mod 10));
47+
unsafe_to_string s
4748

4849
let lowercase c =
4950
if (c >= 'A' && c <= 'Z')

stdlib/pervasives.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ external classify_float : (float [@unboxed]) -> fpclass =
186186

187187
external string_length : string -> int = "%string_length"
188188
external bytes_length : bytes -> int = "%string_length"
189-
external bytes_create : int -> bytes = "caml_create_string"
189+
external bytes_create : int -> bytes = "caml_create_bytes"
190190
external string_blit : string -> int -> bytes -> int -> int -> unit
191191
= "caml_blit_string" [@@noalloc]
192192
external bytes_blit : bytes -> int -> bytes -> int -> int -> unit
193-
= "caml_blit_string" [@@noalloc]
194-
external bytes_unsafe_to_string : bytes -> string = "%identity"
193+
= "caml_blit_bytes" [@@noalloc]
194+
external bytes_unsafe_to_string : bytes -> string = "%bytes_to_string"
195195

196196
let ( ^ ) s1 s2 =
197197
let l1 = string_length s1 and l2 = string_length s2 in
@@ -317,7 +317,7 @@ let flush_all () =
317317
in iter (out_channels_list ())
318318

319319
external unsafe_output : out_channel -> bytes -> int -> int -> unit
320-
= "caml_ml_output"
320+
= "caml_ml_output_bytes"
321321
external unsafe_output_string : out_channel -> string -> int -> int -> unit
322322
= "caml_ml_output"
323323

stdlib/string.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
external length : string -> int = "%string_length"
1919
external get : string -> int -> char = "%string_safe_get"
20-
external set : bytes -> int -> char -> unit = "%string_safe_set"
21-
external create : int -> bytes = "caml_create_string"
20+
external set : bytes -> int -> char -> unit = "%bytes_safe_set"
21+
external create : int -> bytes = "caml_create_bytes"
2222
external unsafe_get : string -> int -> char = "%string_unsafe_get"
23-
external unsafe_set : bytes -> int -> char -> unit = "%string_unsafe_set"
23+
external unsafe_set : bytes -> int -> char -> unit = "%bytes_unsafe_set"
2424
external unsafe_blit : string -> int -> bytes -> int -> int -> unit
2525
= "caml_blit_string" [@@noalloc]
2626
external unsafe_fill : bytes -> int -> int -> char -> unit
27-
= "caml_fill_string" [@@noalloc]
27+
= "caml_fill_bytes" [@@noalloc]
2828

2929
module B = Bytes
3030

stdlib/string.mli

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ external get : string -> int -> char = "%string_safe_get"
5858
Raise [Invalid_argument] if [n] not a valid index in [s]. *)
5959

6060

61-
external set : bytes -> int -> char -> unit = "%string_safe_set"
61+
external set : bytes -> int -> char -> unit = "%bytes_safe_set"
6262
[@@ocaml.deprecated "Use Bytes.set instead."]
6363
(** [String.set s n c] modifies byte sequence [s] in place,
6464
replacing the byte at index [n] with [c].
@@ -68,7 +68,7 @@ external set : bytes -> int -> char -> unit = "%string_safe_set"
6868
6969
@deprecated This is a deprecated alias of {!Bytes.set}.[ ] *)
7070

71-
external create : int -> bytes = "caml_create_string"
71+
external create : int -> bytes = "caml_create_bytes"
7272
[@@ocaml.deprecated "Use Bytes.create instead."]
7373
(** [String.create n] returns a fresh byte sequence of length [n].
7474
The sequence is uninitialized and contains arbitrary bytes.
@@ -302,11 +302,11 @@ val split_on_char: char -> string -> string list
302302
(* The following is for system use only. Do not call directly. *)
303303

304304
external unsafe_get : string -> int -> char = "%string_unsafe_get"
305-
external unsafe_set : bytes -> int -> char -> unit = "%string_unsafe_set"
305+
external unsafe_set : bytes -> int -> char -> unit = "%bytes_unsafe_set"
306306
[@@ocaml.deprecated]
307307
external unsafe_blit :
308308
string -> int -> bytes -> int -> int -> unit
309309
= "caml_blit_string" [@@noalloc]
310310
external unsafe_fill :
311-
bytes -> int -> int -> char -> unit = "caml_fill_string" [@@noalloc]
311+
bytes -> int -> int -> char -> unit = "caml_fill_bytes" [@@noalloc]
312312
[@@ocaml.deprecated]

stdlib/stringLabels.mli

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ external get : string -> int -> char = "%string_safe_get"
2424
2525
Raise [Invalid_argument] if [n] not a valid index in [s]. *)
2626

27-
external set : bytes -> int -> char -> unit = "%string_safe_set"
27+
external set : bytes -> int -> char -> unit = "%bytes_safe_set"
2828
[@@ocaml.deprecated "Use BytesLabels.set instead."]
2929
(** [String.set s n c] modifies byte sequence [s] in place,
3030
replacing the byte at index [n] with [c].
@@ -34,7 +34,7 @@ external set : bytes -> int -> char -> unit = "%string_safe_set"
3434
3535
@deprecated This is a deprecated alias of {!BytesLabels.set}. *)
3636

37-
external create : int -> bytes = "caml_create_string"
37+
external create : int -> bytes = "caml_create_bytes"
3838
[@@ocaml.deprecated "Use BytesLabels.create instead."]
3939
(** [String.create n] returns a fresh byte sequence of length [n].
4040
The sequence is uninitialized and contains arbitrary bytes.
@@ -207,11 +207,11 @@ val compare: t -> t -> int
207207
(* The following is for system use only. Do not call directly. *)
208208

209209
external unsafe_get : string -> int -> char = "%string_unsafe_get"
210-
external unsafe_set : bytes -> int -> char -> unit = "%string_unsafe_set"
210+
external unsafe_set : bytes -> int -> char -> unit = "%bytes_unsafe_set"
211211
[@@ocaml.deprecated]
212212
external unsafe_blit :
213213
src:string -> src_pos:int -> dst:bytes -> dst_pos:int -> len:int ->
214214
unit = "caml_blit_string" [@@noalloc]
215215
external unsafe_fill :
216-
bytes -> pos:int -> len:int -> char -> unit = "caml_fill_string" [@@noalloc]
216+
bytes -> pos:int -> len:int -> char -> unit = "caml_fill_bytes" [@@noalloc]
217217
[@@ocaml.deprecated]

testsuite/tests/basic/patmatch.ml

+14-12
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ let l = function
5151

5252
open Printf
5353

54-
external string_create: int -> string = "caml_create_string"
54+
external bytes_create: int -> bytes = "caml_create_bytes"
5555
external unsafe_chr: int -> char = "%identity"
56-
external string_unsafe_set : string -> int -> char -> unit
57-
= "%string_unsafe_set"
56+
external bytes_unsafe_set : bytes -> int -> char -> unit
57+
= "%bytes_unsafe_set"
58+
59+
external unsafe_to_string : bytes -> string = "%bytes_to_string"
5860

5961
(* The following function is roughly equivalent to Char.escaped,
6062
except that it is locale-independent. *)
@@ -67,17 +69,17 @@ let escaped = function
6769
| '\b' -> "\\b"
6870
| c ->
6971
if ((k c) <> "othr") && ((Char.code c) <= 191) then begin
70-
let s = string_create 1 in
71-
string_unsafe_set s 0 c;
72-
s
72+
let s = bytes_create 1 in
73+
bytes_unsafe_set s 0 c;
74+
unsafe_to_string s
7375
end else begin
7476
let n = Char.code c in
75-
let s = string_create 4 in
76-
string_unsafe_set s 0 '\\';
77-
string_unsafe_set s 1 (unsafe_chr (48 + n / 100));
78-
string_unsafe_set s 2 (unsafe_chr (48 + (n / 10) mod 10));
79-
string_unsafe_set s 3 (unsafe_chr (48 + n mod 10));
80-
s
77+
let s = bytes_create 4 in
78+
bytes_unsafe_set s 0 '\\';
79+
bytes_unsafe_set s 1 (unsafe_chr (48 + n / 100));
80+
bytes_unsafe_set s 2 (unsafe_chr (48 + (n / 10) mod 10));
81+
bytes_unsafe_set s 3 (unsafe_chr (48 + n mod 10));
82+
unsafe_to_string s
8183
end
8284

8385
let _ =

0 commit comments

Comments
 (0)