I got this build failure:
Guestfs.hs:1941:11: parse error on input `module'
where that (generated) file looked like this:
1940 modprobe :: GuestfsH -> String -> IO ()
1941 modprobe h module = do
1942 r <- withCString module $ \module -> withForeignPtr h (\p ->
c_modprobe p module)
1943 if (r == -1)
1944 then do
1945 err <- last_error h
1946 fail err
1947 else return ()
That's because "module" is a reserved word in Haskell.
The following adds a list of nearly all Haskell, OCaml and C
reserved words, and ensures that we don't use them as parameter
or return value names when generating code.
From 9c799cb1a58b46b7d01f3d4862d1b37b8bcf65c1 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Wed, 19 Aug 2009 14:30:02 +0200
Subject: [PATCH libguestfs] avoid build failure due to Haskell keyword clash
* src/generator.ml: Fix this particular problem by
renaming the "module" parameter to "modulename".
Avoid the general problem by ensuring that no parameter name is
in the set of nearly all Haskell, OCaml and C reserved words.
(zfile): Adjust one more offender: s/method/meth/.
---
src/generator.ml | 34 +++++++++++++++++++++++++++++++---
1 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/src/generator.ml b/src/generator.ml
index 230be80..cd19f12 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -2968,7 +2968,7 @@ were rarely if ever used anyway.
See also C<guestfs_sfdisk> and the L<sfdisk(8)> manpage.");
- ("zfile", (RString "description", [String "method";
Pathname "path"]), 140, [DeprecatedBy "file"],
+ ("zfile", (RString "description", [String "meth";
Pathname "path"]), 140, [DeprecatedBy "file"],
[],
"determine file type inside a compressed file",
"\
@@ -3560,7 +3560,7 @@ an external journal on the journal with UUID C<uuid>.
See also C<guestfs_mke2journal_U>.");
- ("modprobe", (RErr, [String "module"]), 194, [],
+ ("modprobe", (RErr, [String "modulename"]), 194, [],
[InitNone, Always, TestRun [["modprobe"; "ext2"]]],
"load a kernel module",
"\
@@ -4050,7 +4050,35 @@ let check_functions () =
if n = "i" || n = "n" then
failwithf "%s has a param/ret called 'i' or 'n', which
will cause some conflicts in the generated code" name;
if n = "argv" || n = "args" then
- failwithf "%s has a param/ret called 'argv' or 'args',
which will cause some conflicts in the generated code" name
+ failwithf "%s has a param/ret called 'argv' or 'args',
which will cause some conflicts in the generated code" name;
+
+ (* List Haskell, OCaml and C keywords here.
+ *
http://www.haskell.org/haskellwiki/Keywords
+ *
http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#operator-char
+ *
http://en.wikipedia.org/wiki/C_syntax#Reserved_keywords
+ * Formatted via: cat c haskell ocaml|sort -u|grep -v _ \
+ * |perl -pe 's/(.*)/"$1";/'|fmt -70
+ * Omitting the OCaml reserved word, "val", is ok,
+ * and saves us from renaming several parameters.
+ *)
+ let reserved = [
+ "and"; "as"; "asr"; "assert";
"auto"; "begin"; "break"; "case";
+ "char"; "class"; "const"; "constraint";
"continue"; "data";
+ "default"; "deriving"; "do"; "done";
"double"; "downto"; "else";
+ "end"; "enum"; "exception"; "extern";
"external"; "false"; "float";
+ "for"; "forall"; "foreign"; "fun";
"function"; "functor"; "goto";
+ "hiding"; "if"; "import"; "in";
"include"; "infix"; "infixl";
+ "infixr"; "inherit"; "initializer";
"inline"; "instance"; "int";
+ "land"; "lazy"; "let"; "long";
"lor"; "lsl"; "lsr"; "lxor";
+ "match"; "mdo"; "method"; "mod";
"module"; "mutable"; "new";
+ "newtype"; "object"; "of"; "open";
"or"; "private"; "qualified";
+ "rec"; "register"; "restrict";
"return"; "short"; "sig"; "signed";
+ "sizeof"; "static"; "struct"; "switch";
"then"; "to"; "true"; "try";
+ "type"; "typedef"; "union"; "unsigned";
"val"; "virtual"; "void";
+ "volatile"; "when"; "where"; "while";
+ ] in
+ if List.mem n reserved then
+ failwithf "%s has param/ret using reserved word %s" name n;
in
(match fst style with
--
1.6.4.378.g88f2f