List* functions throw exceptions if maxids = 0, so bypass this case.
[ocaml-libvirt.git] / libvirt / generator.pl
index 4fbace6..0995922 100755 (executable)
@@ -620,6 +620,16 @@ sub gen_c_code
   int i = Int_val (iv);
   int ids[i], r;
 
+  /* Some libvirt List* functions still throw exceptions if i == 0,
+   * so catch that and return an empty array directly.  This changes
+   * the semantics slightly (masking other failures) but it's
+   * unlikely anyone will care.  RWMJ 2008/06/10
+   */
+  if (i == 0) {
+    rv = caml_alloc (0, 0);
+    CAMLreturn (rv);
+  }
+
   NONBLOCKING (r = $c_name (conn, ids, i));
   CHECK_ERROR (r == -1, conn, \"$c_name\");
 
@@ -637,6 +647,16 @@ sub gen_c_code
   char *names[i];
   int r;
 
+  /* Some libvirt List* functions still throw exceptions if i == 0,
+   * so catch that and return an empty array directly.  This changes
+   * the semantics slightly (masking other failures) but it's
+   * unlikely anyone will care.  RWMJ 2008/06/10
+   */
+  if (i == 0) {
+    rv = caml_alloc (0, 0);
+    CAMLreturn (rv);
+  }
+
   NONBLOCKING (r = $c_name ($1, names, i));
   CHECK_ERROR (r == -1, conn, \"$c_name\");