Message ID | 20171006235023.11952-35-f4bug@amsat.org |
---|---|
State | New |
Headers | show |
Series | use g_new() family of functions | expand |
On 10/06/2017 06:49 PM, Philippe Mathieu-Daudé wrote: > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > qapi/opts-visitor.c | 2 +- > qapi/qapi-clone-visitor.c | 2 +- > qapi/qapi-dealloc-visitor.c | 2 +- > qapi/qobject-output-visitor.c | 2 +- > qapi/string-input-visitor.c | 2 +- > qapi/string-output-visitor.c | 2 +- > 6 files changed, 6 insertions(+), 6 deletions(-) > > diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c > index 324b197495..34ac49f3c2 100644 > --- a/qapi/opts-visitor.c > +++ b/qapi/opts-visitor.c > @@ -539,7 +539,7 @@ opts_visitor_new(const QemuOpts *opts) > OptsVisitor *ov; > > assert(opts); > - ov = g_malloc0(sizeof *ov); > + ov = g_new0(OptsVisitor, 1); Transformations like this are harder to justify - you have more typing rather than less, and no change in the amount of type-safety. If we really want to convert LHS = g_malloc0(sizeof(*LHS)), we probably ought to have a stronger justification (consistency might be such an argument, if the entire series is applied and HACKING is updated to mention our new preferred style, and where the checked-in Coccinelle script can be easily re-run in the future to catch regressions). Converting LHS = g_malloc0(sizeof(type)) is a no-brainer, because it DOES add type-safety, and often results in less typing. But I haven't looked at your entire series to see which patches fall in the no-brainer category vs. the weakly-argued consistency category.
diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 324b197495..34ac49f3c2 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -539,7 +539,7 @@ opts_visitor_new(const QemuOpts *opts) OptsVisitor *ov; assert(opts); - ov = g_malloc0(sizeof *ov); + ov = g_new0(OptsVisitor, 1); ov->visitor.type = VISITOR_INPUT; diff --git a/qapi/qapi-clone-visitor.c b/qapi/qapi-clone-visitor.c index d8b62792bc..3d216e5906 100644 --- a/qapi/qapi-clone-visitor.c +++ b/qapi/qapi-clone-visitor.c @@ -145,7 +145,7 @@ static Visitor *qapi_clone_visitor_new(void) { QapiCloneVisitor *v; - v = g_malloc0(sizeof(*v)); + v = g_new0(QapiCloneVisitor, 1); v->visitor.type = VISITOR_CLONE; v->visitor.start_struct = qapi_clone_start_struct; diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index ed70a0158b..ad0d0eb7e4 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -120,7 +120,7 @@ Visitor *qapi_dealloc_visitor_new(void) { QapiDeallocVisitor *v; - v = g_malloc0(sizeof(*v)); + v = g_new0(QapiDeallocVisitor, 1); v->visitor.type = VISITOR_DEALLOC; v->visitor.start_struct = qapi_dealloc_start_struct; diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c index d325163e55..7228986c0c 100644 --- a/qapi/qobject-output-visitor.c +++ b/qapi/qobject-output-visitor.c @@ -229,7 +229,7 @@ Visitor *qobject_output_visitor_new(QObject **result) { QObjectOutputVisitor *v; - v = g_malloc0(sizeof(*v)); + v = g_new0(QObjectOutputVisitor, 1); v->visitor.type = VISITOR_OUTPUT; v->visitor.start_struct = qobject_output_start_struct; diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index 67a0a4a58b..3a2fe58478 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -356,7 +356,7 @@ Visitor *string_input_visitor_new(const char *str) StringInputVisitor *v; assert(str); - v = g_malloc0(sizeof(*v)); + v = g_new0(StringInputVisitor, 1); v->visitor.type = VISITOR_INPUT; v->visitor.type_int64 = parse_type_int64; diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index 7ab64468d9..a7bbbae109 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -341,7 +341,7 @@ Visitor *string_output_visitor_new(bool human, char **result) { StringOutputVisitor *v; - v = g_malloc0(sizeof(*v)); + v = g_new0(StringOutputVisitor, 1); v->string = g_string_new(NULL); v->human = human;
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> --- qapi/opts-visitor.c | 2 +- qapi/qapi-clone-visitor.c | 2 +- qapi/qapi-dealloc-visitor.c | 2 +- qapi/qobject-output-visitor.c | 2 +- qapi/string-input-visitor.c | 2 +- qapi/string-output-visitor.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)