[Libguestfs] [PATCH 1/2] gobject: Allow RConstOptString to return an error

Matthew Booth mbooth at redhat.com
Wed Jan 25 17:19:41 UTC 2012


RConstOptString cannot return an error in the C api. This makes it a special
case for the GObject api, as all other return types have a corresponding GError
**err argument to return an error. This change removes this special case, and
includes the possibility of an error return in the API. An error is indicated by
setting *err to a non-NULL value.

This change is in preparation for adding a close api. An attempt to call any
api, even RConstOptString, on a closed handle must return an error.
---
 generator/generator_gobject.ml |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/generator/generator_gobject.ml b/generator/generator_gobject.ml
index 4779f23..2b88274 100644
--- a/generator/generator_gobject.ml
+++ b/generator/generator_gobject.ml
@@ -37,10 +37,6 @@ let camel_of_name flags name =
         a ^ String.uppercase (Str.first_chars b 1) ^ Str.string_after b 1
     ) "" (Str.split (regexp "_") name)
 
-let returns_error = function
-  | RConstOptString _ -> false
-  | _ -> true
-
 let generate_gobject_proto name ?(single_line = true)
                                 (ret, args, optargs) flags =
   let spacer = if single_line then " " else "\n" in
@@ -109,7 +105,7 @@ let generate_gobject_proto name ?(single_line = true)
   | _ -> ());
   if List.exists (function Cancellable -> true | _ -> false) flags then
     pr ", GCancellable *cancellable";
-  if returns_error ret then pr ", GError **err";
+  pr ", GError **err";
   pr ")"
 
 let generate_gobject_header_static () =
@@ -780,7 +776,7 @@ let generate_gobject_c_methods () =
 
       (* Check return, throw error if necessary, marshall return value *)
 
-      if returns_error ret then (
+      if match ret with RConstOptString _ -> false | _ -> true then (
         pr "  if (ret == %s) {\n"
           (match ret with
           | RErr | RInt _ | RInt64 _ | RBool _ ->
-- 
1.7.7.5




More information about the Libguestfs mailing list