[Libguestfs] [PATCH 10/46] resize: Mark isatty function as "noalloc".

Richard W.M. Jones rjones at redhat.com
Sat Aug 24 12:36:46 UTC 2013


From: "Richard W.M. Jones" <rjones at redhat.com>

This turns it into an ordinary C call without the unnecessary [in this
case] GC frame overhead.  See:
http://camltastic.blogspot.co.uk/2008/08/tip-calling-c-functions-directly-with.html

(cherry picked from commit 3d39549ded3e05df929547bb65ce620e6487a81b)
(cherry picked from commit a08b4304d1fc0a02a18daa84d6747f432f495b67)
---
 resize/tTY.ml  |  2 +-
 resize/tty-c.c | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/resize/tTY.ml b/resize/tTY.ml
index 32c1f54..80f0e1e 100644
--- a/resize/tTY.ml
+++ b/resize/tTY.ml
@@ -16,4 +16,4 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-external isatty_stdout : unit -> bool = "virt_resize_isatty_stdout"
+external isatty_stdout : unit -> bool = "virt_resize_isatty_stdout" "noalloc"
diff --git a/resize/tty-c.c b/resize/tty-c.c
index 040a132..64fa884 100644
--- a/resize/tty-c.c
+++ b/resize/tty-c.c
@@ -25,11 +25,14 @@
 #include <caml/memory.h>
 #include <caml/mlvalues.h>
 
-/* RHEL 5-era ocaml didn't have Unix.isatty. */
+/* RHEL 5-era ocaml didn't have Unix.isatty.
+ *
+ * Note this function is marked as "noalloc" so it must not call any
+ * OCaml allocation functions:
+ * http://camltastic.blogspot.co.uk/2008/08/tip-calling-c-functions-directly-with.html
+ */
 value
 virt_resize_isatty_stdout (value unitv)
 {
-  CAMLparam1 (unitv);
-
-  CAMLreturn (isatty (1) ? Val_true : Val_false);
+  return isatty (1) ? Val_true : Val_false;
 }
-- 
1.8.3.1




More information about the Libguestfs mailing list