summaryrefslogtreecommitdiffstats
path: root/generator/generator_php.ml
diff options
context:
space:
mode:
authorMatthew Booth <mbooth@redhat.com>2012-01-09 10:16:35 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-01-09 13:30:34 +0000
commit0a7b734d2f54d4e98882532da9887feb66c9824a (patch)
tree0f7eb3d9ca6893aa5cb2b66669200a4e500c1701 /generator/generator_php.ml
parente24af214fe8f9dccac39ed520b57ce7d458f9fd1 (diff)
downloadlibguestfs-0a7b734d2f54d4e98882532da9887feb66c9824a.tar.gz
libguestfs-0a7b734d2f54d4e98882532da9887feb66c9824a.tar.xz
libguestfs-0a7b734d2f54d4e98882532da9887feb66c9824a.zip
generator: Create a separate type for optional arguments
Previously, optional arguments had the same type as regular arguments, but were constrained by various runtime tests to be only Bool, Int, Int64 or String. This change makes the type of optional arguments stronger by giving them their own type. A convenience function, optargs_to_args is defined to convert optargs in the few places where they are genuinely treated identically to mandatory arguments. It also allows for future changes to optional arguments which do not affect mandatory arguments. RWMJ: - removed redundant parens - readded the check for > 64 optargs, but changed it to > 63 - changed the new function to args_of_optargs
Diffstat (limited to 'generator/generator_php.ml')
-rw-r--r--generator/generator_php.ml28
1 files changed, 12 insertions, 16 deletions
diff --git a/generator/generator_php.ml b/generator/generator_php.ml
index 4431147f..28bd6683 100644
--- a/generator/generator_php.ml
+++ b/generator/generator_php.ml
@@ -216,12 +216,11 @@ PHP_FUNCTION (guestfs_last_error)
*)
List.iter (
function
- | Bool n -> pr " zend_bool optargs_t_%s = -1;\n" n
- | Int n | Int64 n -> pr " long optargs_t_%s = -1;\n" n
- | String n ->
+ | OBool n -> pr " zend_bool optargs_t_%s = -1;\n" n
+ | OInt n | OInt64 n -> pr " long optargs_t_%s = -1;\n" n
+ | OString n ->
pr " char *optargs_t_%s = NULL;\n" n;
pr " int optargs_t_%s_size = -1;\n" n
- | _ -> assert false
) optargs
);
@@ -246,10 +245,9 @@ PHP_FUNCTION (guestfs_last_error)
String.concat "" (
List.map (
function
- | Bool _ -> "b"
- | Int _ | Int64 _ -> "l"
- | String _ -> "s"
- | _ -> assert false
+ | OBool _ -> "b"
+ | OInt _ | OInt64 _ -> "l"
+ | OString _ -> "s"
) optargs
)
else param_string in
@@ -272,11 +270,10 @@ PHP_FUNCTION (guestfs_last_error)
) args;
List.iter (
function
- | Bool n | Int n | Int64 n ->
+ | OBool n | OInt n | OInt64 n ->
pr ", &optargs_t_%s" n
- | String n ->
+ | OString n ->
pr ", &optargs_t_%s, &optargs_t_%s_size" n n
- | _ -> assert false
) optargs;
pr ") == FAILURE) {\n";
pr " RETURN_FALSE;\n";
@@ -338,14 +335,13 @@ PHP_FUNCTION (guestfs_last_error)
let uc_shortname = String.uppercase shortname in
List.iter (
fun argt ->
- let n = name_of_argt argt in
+ let n = name_of_optargt argt in
let uc_n = String.uppercase n in
pr " if (optargs_t_%s != " n;
(match argt with
- | Bool _ -> pr "((zend_bool)-1)"
- | Int _ | Int64 _ -> pr "-1"
- | String _ -> pr "NULL"
- | _ -> assert false
+ | OBool _ -> pr "((zend_bool)-1)"
+ | OInt _ | OInt64 _ -> pr "-1"
+ | OString _ -> pr "NULL"
);
pr ") {\n";
pr " optargs_s.%s = optargs_t_%s;\n" n n;