summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-10 10:46:50 +0100
committerRichard Jones <rjones@redhat.com>2009-04-10 10:46:50 +0100
commit3acec39588bd574a616fa0671a29cd1280f356fb (patch)
tree17935cf3020896a9d806e734a8299ca9eae3b6ff
parent469224a9eca9b575063e6a1ca1b1d97adb3448cb (diff)
downloadlibguestfs-3acec39588bd574a616fa0671a29cd1280f356fb.tar.gz
libguestfs-3acec39588bd574a616fa0671a29cd1280f356fb.tar.xz
libguestfs-3acec39588bd574a616fa0671a29cd1280f356fb.zip
Add more function checking.
-rwxr-xr-xsrc/generator.ml59
1 files changed, 55 insertions, 4 deletions
diff --git a/src/generator.ml b/src/generator.ml
index b0a71589..31aa4c13 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -482,6 +482,7 @@ details.");
"\
This is just a shortcut for listing C<guestfs_aug_match>
C<path/*> and sorting the resulting nodes into alphabetical order.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
@@ -624,15 +625,65 @@ let name_of_argt = function String n | OptString n | Bool n | Int n -> n
(* Check function names etc. for consistency. *)
let check_functions () =
+ let contains_uppercase str =
+ let len = String.length str in
+ let rec loop i =
+ if i >= len then false
+ else (
+ let c = str.[i] in
+ if c >= 'A' && c <= 'Z' then true
+ else loop (i+1)
+ )
+ in
+ loop 0
+ in
+
+ (* Check function names. *)
List.iter (
- fun (name, _, _, _, _, longdesc) ->
+ fun (name, _, _, _, _, _) ->
+ if String.length name >= 7 && String.sub name 0 7 = "guestfs" then
+ failwithf "function name %s does not need 'guestfs' prefix" name;
+ if contains_uppercase name then
+ failwithf "function name %s should not contain uppercase chars" name;
if String.contains name '-' then
- failwithf "function name '%s' should not contain '-', use '_' instead."
- name;
+ failwithf "function name %s should not contain '-', use '_' instead."
+ name
+ ) all_functions;
+
+ (* Check function parameter/return names. *)
+ List.iter (
+ fun (name, style, _, _, _, _) ->
+ let check_arg_ret_name n =
+ if contains_uppercase n then
+ failwithf "%s param/ret %s should not contain uppercase chars"
+ name n;
+ if String.contains n '-' || String.contains n '_' then
+ failwithf "%s param/ret %s should not contain '-' or '_'"
+ name n;
+ if n = "value" then
+ failwithf "%s has a param/ret called 'value', which causes conflicts in the OCaml bindings, use something like 'val' or a more descriptive name" n
+ in
+
+ (match fst style with
+ | Err -> ()
+ | RInt n | RBool n | RConstString n | RString n
+ | RStringList n | RPVList n | RVGList n | RLVList n ->
+ check_arg_ret_name n
+ | RIntBool (n,m) ->
+ check_arg_ret_name n;
+ check_arg_ret_name m
+ );
+ List.iter (fun arg -> check_arg_ret_name (name_of_argt arg)) (snd style)
+ ) all_functions;
+
+ (* Check long dscriptions. *)
+ List.iter (
+ fun (name, _, _, _, _, longdesc) ->
if longdesc.[String.length longdesc-1] = '\n' then
failwithf "long description of %s should not end with \\n." name
) all_functions;
+ (* Check proc_nrs. *)
List.iter (
fun (name, _, proc_nr, _, _, _) ->
if proc_nr <= 0 then
@@ -656,7 +707,7 @@ let check_functions () =
| (name1,nr1) :: ((name2,nr2) :: _ as rest) when nr1 < nr2 ->
loop rest
| (name1,nr1) :: (name2,nr2) :: _ ->
- failwithf "'%s' and '%s' have conflicting procedure numbers (%d, %d)"
+ failwithf "%s and %s have conflicting procedure numbers (%d, %d)"
name1 name2 nr1 nr2
in
loop proc_nrs