On 04/06/2012 04:56 PM, Richard W.M. Jones wrote:
On Fri, Apr 06, 2012 at 01:37:33PM +0800, Wanlong Gao wrote:
Hi Rich,
I tried to implement the logging feature, but I can't though compiling with this patch now, could you please give me some comments?
The error message is below, --- ocamlfind ocamlopt -g -warn-error CDEFLMPSUVYZX -package unix -I ../src/.libs -I ../ocaml -c sysprep_operation.ml -o sysprep_operation.cmx File "sysprep_operation.ml", line 1, characters 0-1: Error: The implementation sysprep_operation.ml does not match the interface sysprep_operation.cmi: Type declarations do not match: type operation = { name : string; pod_description : string; extra_args : ((Arg.key * Arg.spec * Arg.doc) * string) list; perform : Guestfs.guestfs -> string -> bool -> flag list; } is not included in type operation = { name : string; pod_description : string; extra_args : ((Arg.key * Arg.spec * Arg.doc) * string) list; perform : Guestfs.guestfs -> string -> flag list; } The types for field perform are not equal.
Indeed they are not! The implementation (*.ml) has changed:
- perform : Guestfs.guestfs -> string -> flag list; + perform : Guestfs.guestfs -> string -> bool -> flag list;
but you must make an equivalent change to the interface (in sysprep_operation.mli) -- adding the extra debug flag.
May I suggest another way to do this which is a bit more natural. Use a function. Declare it as:
type debug_fn = ('a, unit, string, unit) format4 -> 'a type operation = { ... perform : Guestfs.guestfs -> debug:debug_fn -> string -> flag list }
Implementations would just do this:
let foo_perform g ~debug root = debug "I'm calling foo %s" root; ...
The main function does this:
let debug fs = ksprintf (fun str -> if show_log then prerr_endline str) fs
...
Sysprep_operations.perform_operations ?operations ~debug g root
Note that the debug function prints conditionally, based on whether show_log is set or not.
Rich, I defer to your great knowledge on this, then I'll try to do like what you said and if has questions, please don't mind my asking for help again. :-D Thanks, Wanlong Gao
Rich.