[PATCH 1/2] c: NFC Remove redundant parentheses
--- generator/generator_c.ml | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/generator/generator_c.ml b/generator/generator_c.ml index 4324ec0..9cfb2b7 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -1187,7 +1187,7 @@ trace_send_line (guestfs_h *g) let n = name_of_optargt argt in let uc_shortname = String.uppercase shortname in let uc_n = String.uppercase n in - pr " if ((optargs->bitmask & GUESTFS_%s_%s_BITMASK))\n" + pr " if (optargs->bitmask & GUESTFS_%s_%s_BITMASK)\n" uc_shortname uc_n; (match argt with | OBool n -- 1.7.7.5
Previously, passing NULL optargs to an _argv call resulted in a segfault. This change causes NULL optargs to be interpreted as no optargs, and to be correctly handled accordingly. --- generator/generator_c.ml | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/generator/generator_c.ml b/generator/generator_c.ml index 9cfb2b7..c6962f5 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -994,6 +994,16 @@ trace_send_line (guestfs_h *g) indent shortname (string_of_errcode errcode) in + let handle_null_optargs optargs shortname = + if optargs <> [] then ( + pr " struct guestfs_%s_argv optargs_null;\n" shortname; + pr " if (!optargs) {\n"; + pr " optargs_null.bitmask = 0;\n"; + pr " optargs = &optargs_null;\n"; + pr " }\n\n"; + ) + in + (* For non-daemon functions, generate a wrapper around each function. *) List.iter ( fun (shortname, (ret, _, optargs as style), _, _, _, _, _) -> @@ -1006,6 +1016,9 @@ trace_send_line (guestfs_h *g) ~handle:"g" ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv shortname style; pr "{\n"; + + handle_null_optargs optargs shortname; + pr " int trace_flag = g->trace;\n"; pr " FILE *trace_fp;\n"; (match ret with @@ -1071,6 +1084,8 @@ trace_send_line (guestfs_h *g) pr "{\n"; + handle_null_optargs optargs shortname; + (match args with | [] -> () | _ -> pr " struct %s_args args;\n" name -- 1.7.7.5
On Tue, Jan 17, 2012 at 01:48:48PM +0000, Matthew Booth wrote:
Previously, passing NULL optargs to an _argv call resulted in a segfault. This change causes NULL optargs to be interpreted as no optargs, and to be correctly handled accordingly. --- generator/generator_c.ml | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/generator/generator_c.ml b/generator/generator_c.ml index 9cfb2b7..c6962f5 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -994,6 +994,16 @@ trace_send_line (guestfs_h *g) indent shortname (string_of_errcode errcode) in
+ let handle_null_optargs optargs shortname = + if optargs <> [] then ( + pr " struct guestfs_%s_argv optargs_null;\n" shortname; + pr " if (!optargs) {\n"; + pr " optargs_null.bitmask = 0;\n"; + pr " optargs = &optargs_null;\n"; + pr " }\n\n"; + ) + in + (* For non-daemon functions, generate a wrapper around each function. *) List.iter ( fun (shortname, (ret, _, optargs as style), _, _, _, _, _) -> @@ -1006,6 +1016,9 @@ trace_send_line (guestfs_h *g) ~handle:"g" ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv shortname style; pr "{\n"; + + handle_null_optargs optargs shortname; + pr " int trace_flag = g->trace;\n"; pr " FILE *trace_fp;\n"; (match ret with @@ -1071,6 +1084,8 @@ trace_send_line (guestfs_h *g)
pr "{\n";
+ handle_null_optargs optargs shortname; + (match args with | [] -> () | _ -> pr " struct %s_args args;\n" name -- 1.7.7.5
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs
ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
On Tue, Jan 17, 2012 at 01:48:47PM +0000, Matthew Booth wrote:
--- generator/generator_c.ml | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/generator/generator_c.ml b/generator/generator_c.ml index 4324ec0..9cfb2b7 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -1187,7 +1187,7 @@ trace_send_line (guestfs_h *g) let n = name_of_optargt argt in let uc_shortname = String.uppercase shortname in let uc_n = String.uppercase n in - pr " if ((optargs->bitmask & GUESTFS_%s_%s_BITMASK))\n" + pr " if (optargs->bitmask & GUESTFS_%s_%s_BITMASK)\n" uc_shortname uc_n; (match argt with | OBool n
NACK. I believe this avoids a gcc warning where it's complaining that you've "mistakenly" written if (a & b) instead of if (a && b). Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
On 01/17/2012 02:01 PM, Richard W.M. Jones wrote:
On Tue, Jan 17, 2012 at 01:48:47PM +0000, Matthew Booth wrote:
--- generator/generator_c.ml | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/generator/generator_c.ml b/generator/generator_c.ml index 4324ec0..9cfb2b7 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -1187,7 +1187,7 @@ trace_send_line (guestfs_h *g) let n = name_of_optargt argt in let uc_shortname = String.uppercase shortname in let uc_n = String.uppercase n in - pr " if ((optargs->bitmask& GUESTFS_%s_%s_BITMASK))\n" + pr " if (optargs->bitmask& GUESTFS_%s_%s_BITMASK)\n" uc_shortname uc_n; (match argt with | OBool n
NACK. I believe this avoids a gcc warning where it's complaining that you've "mistakenly" written if (a& b) instead of if (a&& b).
Rich.
I didn't see that warning. Are you sure it's still around? Matt -- Matthew Booth, RHCA, RHCSS Red Hat Engineering, Virtualisation Team GPG ID: D33C3490 GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
On Tue, Jan 17, 2012 at 02:02:29PM +0000, Matthew Booth wrote:
On 01/17/2012 02:01 PM, Richard W.M. Jones wrote:
On Tue, Jan 17, 2012 at 01:48:47PM +0000, Matthew Booth wrote:
--- generator/generator_c.ml | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/generator/generator_c.ml b/generator/generator_c.ml index 4324ec0..9cfb2b7 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -1187,7 +1187,7 @@ trace_send_line (guestfs_h *g) let n = name_of_optargt argt in let uc_shortname = String.uppercase shortname in let uc_n = String.uppercase n in - pr " if ((optargs->bitmask& GUESTFS_%s_%s_BITMASK))\n" + pr " if (optargs->bitmask& GUESTFS_%s_%s_BITMASK)\n" uc_shortname uc_n; (match argt with | OBool n
NACK. I believe this avoids a gcc warning where it's complaining that you've "mistakenly" written if (a& b) instead of if (a&& b).
Rich.
I didn't see that warning. Are you sure it's still around?
Seems to be my imagination, or maybe some old compiler I used, so ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
participants (2)
-
Matthew Booth -
Richard W.M. Jones