---
generator/ocaml.ml | 35 +++++++++++++++++++++++------------
ocaml/guestfs-c.c | 15 ++++++++++-----
2 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/generator/ocaml.ml b/generator/ocaml.ml
index 1447bdc..9071eb0 100644
--- a/generator/ocaml.ml
+++ b/generator/ocaml.ml
@@ -592,14 +592,23 @@ copy_table (char * const * argv)
| Key n
| GUID n ->
(* Copy strings in case the GC moves them: RHBZ#604691 *)
- pr " char *%s = guestfs_int_safe_strdup (g, String_val (%sv));\n"
n n
+ pr " char *%s;\n" n;
+ pr " %s = strdup (String_val (%sv));\n" n n;
+ pr " if (%s == NULL) caml_raise_out_of_memory ();\n" n
| OptString n ->
- pr " char *%s =\n" n;
- pr " %sv != Val_int (0) ?\n" n;
- pr " guestfs_int_safe_strdup (g, String_val (Field (%sv, 0))) :
NULL;\n" n
+ pr " char *%s;\n" n;
+ pr " if (%sv == Val_int (0))\n" n;
+ pr " %s = NULL;\n" n;
+ pr " else {\n";
+ pr " %s = strdup (String_val (Field (%sv, 0)));\n" n n;
+ pr " if (%s == NULL) caml_raise_out_of_memory ();\n" n;
+ pr " }\n"
| BufferIn n ->
pr " size_t %s_size = caml_string_length (%sv);\n" n n;
- pr " char *%s = guestfs_int_safe_memdup (g, String_val (%sv),
%s_size);\n" n n n
+ pr " char *%s;\n" n;
+ pr " %s = malloc (%s_size);\n" n n;
+ pr " if (%s == NULL) caml_raise_out_of_memory ();\n" n;
+ pr " memcpy (%s, String_val (%sv), %s_size);\n" n n n
| StringList n | DeviceList n | FilenameList n ->
pr " char **%s = guestfs_int_ocaml_strings_val (g, %sv);\n" n n
| Bool n ->
@@ -622,17 +631,19 @@ copy_table (char * const * argv)
let uc_n = String.uppercase n in
pr " if (%sv != Val_int (0)) {\n" n;
pr " optargs_s.bitmask |= %s_%s_BITMASK;\n" c_optarg_prefix
uc_n;
- pr " optargs_s.%s = " n;
(match argt with
- | OBool _ -> pr "Bool_val (Field (%sv, 0))" n
- | OInt _ -> pr "Int_val (Field (%sv, 0))" n
- | OInt64 _ -> pr "Int64_val (Field (%sv, 0))" n
+ | OBool _ ->
+ pr " optargs_s.%s = Bool_val (Field (%sv, 0));\n" n n
+ | OInt _ ->
+ pr " optargs_s.%s = Int_val (Field (%sv, 0));\n" n n
+ | OInt64 _ ->
+ pr " optargs_s.%s = Int64_val (Field (%sv, 0));\n" n n
| OString _ ->
- pr "guestfs_int_safe_strdup (g, String_val (Field (%sv, 0)))"
n
+ pr " optargs_s.%s = strdup (String_val (Field (%sv,
0)));\n" n n;
+ pr " if (optargs_s.%s == NULL) caml_raise_out_of_memory
();\n" n
| OStringList n ->
- pr "guestfs_int_ocaml_strings_val (g, Field (%sv, 0))\n" n
+ pr " optargs_s.%s = guestfs_int_ocaml_strings_val (g, Field
(%sv, 0));\n" n n
);
- pr ";\n";
pr " }\n";
) optargs
);
diff --git a/ocaml/guestfs-c.c b/ocaml/guestfs-c.c
index 8f74c21..edb4646 100644
--- a/ocaml/guestfs-c.c
+++ b/ocaml/guestfs-c.c
@@ -193,9 +193,12 @@ guestfs_int_ocaml_strings_val (guestfs_h *g, value sv)
char **r;
size_t i;
- r = guestfs_int_safe_malloc (g, sizeof (char *) * (Wosize_val (sv) + 1));
- for (i = 0; i < Wosize_val (sv); ++i)
- r[i] = guestfs_int_safe_strdup (g, String_val (Field (sv, i)));
+ r = malloc (sizeof (char *) * (Wosize_val (sv) + 1));
+ if (r == NULL) caml_raise_out_of_memory ();
+ for (i = 0; i < Wosize_val (sv); ++i) {
+ r[i] = strdup (String_val (Field (sv, i)));
+ if (r[i] == NULL) caml_raise_out_of_memory ();
+ }
r[i] = NULL;
CAMLreturnT (char **, r);
@@ -227,7 +230,8 @@ guestfs_int_ocaml_set_event_callback (value gv, value closure, value
events)
event_bitmask = event_bitmask_of_event_list (events);
- value *root = guestfs_int_safe_malloc (g, sizeof *root);
+ value *root = malloc (sizeof *root);
+ if (root == NULL) caml_raise_out_of_memory ();
*root = closure;
eh = guestfs_set_event_callback (g, event_callback_wrapper,
@@ -307,7 +311,8 @@ get_all_event_callbacks (guestfs_h *g, size_t *len_rtn)
}
/* Copy them into the return array. */
- r = guestfs_int_safe_malloc (g, sizeof (value *) * (*len_rtn));
+ r = malloc (sizeof (value *) * (*len_rtn));
+ if (r == NULL) caml_raise_out_of_memory ();
i = 0;
root = guestfs_first_private (g, &key);
--
2.5.0