Blame SOURCES/0019-Fixes-for-safe-string-in-OCaml-4.06.patch

271612
From 2d8ef8a4ca613ad291bc05a4e5ebdc11c3eae6b9 Mon Sep 17 00:00:00 2001
695b7d
From: "Richard W.M. Jones" <rjones@redhat.com>
695b7d
Date: Sat, 18 Nov 2017 12:01:34 +0000
271612
Subject: [PATCH 19/23] Fixes for -safe-string in OCaml 4.06.
695b7d
695b7d
---
695b7d
 src/top.ml | 13 ++++++++-----
695b7d
 1 file changed, 8 insertions(+), 5 deletions(-)
695b7d
695b7d
diff --git a/src/top.ml b/src/top.ml
695b7d
index e2a93d6..d4f7697 100644
695b7d
--- a/src/top.ml
695b7d
+++ b/src/top.ml
695b7d
@@ -296,17 +296,20 @@ let millisleep n =
695b7d
  *)
695b7d
 let get_string maxlen =
695b7d
   ignore (echo ());
695b7d
-  let str = String.create maxlen in
695b7d
-  let ok = getstr str in (* Safe because binding calls getnstr. *)
695b7d
+  let str = Bytes.create maxlen in
695b7d
+  (* Safe because binding calls getnstr.  However the unsafe cast
695b7d
+   * to string is required because ocaml-curses needs to be fixed.
695b7d
+   *)
695b7d
+  let ok = getstr (Obj.magic str) in
695b7d
   ignore (noecho ());
695b7d
   if not ok then ""
695b7d
   else (
695b7d
     (* Chop at first '\0'. *)
695b7d
     try
695b7d
-      let i = String.index str '\000' in
695b7d
-      String.sub str 0 i
695b7d
+      let i = Bytes.index str '\000' in
695b7d
+      Bytes.sub_string str 0 i
695b7d
     with
695b7d
-      Not_found -> str (* it is full maxlen bytes *)
695b7d
+      Not_found -> Bytes.to_string str (* it is full maxlen bytes *)
695b7d
   )
695b7d
 
695b7d
 (* Main loop. *)
695b7d
-- 
271612
2.31.1
695b7d