Fix string mutability.

This commit is contained in:
Richard W.M. Jones 2017-11-08 18:07:05 +00:00
parent 27831566ef
commit d1ce7c1844
3 changed files with 76 additions and 4 deletions

View File

@ -0,0 +1,37 @@
From 87de49cebbf028ebb0f9950ab9e8fed97807c86e Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 8 Nov 2017 18:04:15 +0000
Subject: [PATCH 1/2] generator: Use Bytes instead of String.
---
generator/generator.ml | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/generator/generator.ml b/generator/generator.ml
index 4125ae7..0401217 100755
--- a/generator/generator.ml
+++ b/generator/generator.ml
@@ -415,15 +415,15 @@ let failwithf fs = ksprintf failwith fs
let unique = let i = ref 0 in fun () -> incr i; !i
let replace_char s c1 c2 =
- let s2 = String.copy s in
+ let s2 = Bytes.of_string s in
let r = ref false in
- for i = 0 to String.length s2 - 1 do
- if String.unsafe_get s2 i = c1 then (
- String.unsafe_set s2 i c2;
+ for i = 0 to String.length s - 1 do
+ if String.unsafe_get s i = c1 then (
+ Bytes.unsafe_set s2 i c2;
r := true
)
done;
- if not !r then s else s2
+ if not !r then s else Bytes.to_string s2
let isspace c =
c = ' '
--
2.13.1

View File

@ -0,0 +1,33 @@
From f45648c58c18f35507475363e12a33589fb6a5f2 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 8 Nov 2017 18:05:31 +0000
Subject: [PATCH 2/2] ocaml/t/hivex_200_write.ml: Use Bytes instead of String.
---
ocaml/t/hivex_200_write.ml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ocaml/t/hivex_200_write.ml b/ocaml/t/hivex_200_write.ml
index f70deee..97d9597 100644
--- a/ocaml/t/hivex_200_write.ml
+++ b/ocaml/t/hivex_200_write.ml
@@ -55,14 +55,14 @@ let () =
and utf16le_of_ascii str =
let len = String.length str in
let len' = len * 2 + 2 in
- let str' = String.create len' in
+ let str' = Bytes.create len' in
for i = 0 to len-1 do
str'.[i*2] <- str.[i];
str'.[i*2+1] <- '\000'
done;
str'.[len'-2] <- '\000';
str'.[len'-1] <- '\000';
- str'
+ Bytes.to_string str'
in
iter 0 0 (Hivex.root h);
--
2.13.1

View File

@ -26,6 +26,10 @@ Source1: http://libguestfs.org/download/hivex/%{name}-%{version}.tar.gz.s
Source2: libguestfs.keyring
%endif
# Upstream patches to fix string mutability.
Patch1: 0001-generator-Use-Bytes-instead-of-String.patch
Patch2: 0002-ocaml-t-hivex_200_write.ml-Use-Bytes-instead-of-Stri.patch
BuildRequires: perl-interpreter
BuildRequires: perl-devel
BuildRequires: perl-generators
@ -194,6 +198,7 @@ tmphome="$(mktemp -d)"
gpgv2 --homedir "$tmphome" --keyring %{SOURCE2} %{SOURCE1} %{SOURCE0}
%endif
%setup -q
%autopatch -p1
# Build Python 3 bindings in a separate subdirectory. We have to
# build everything twice unfortunately.
@ -324,10 +329,7 @@ popd
%changelog
* Wed Nov 08 2017 Richard W.M. Jones <rjones@redhat.com> - 1.3.14-12
- Bump release and rebuild.
* Wed Nov 08 2017 Richard W.M. Jones <rjones@redhat.com> - 1.3.14-11
- Bump release and rebuild.
- Fix string mutability.
* Wed Nov 08 2017 Richard W.M. Jones <rjones@redhat.com> - 1.3.14-10
- OCaml 4.06.0 rebuild.