All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] clang-tidy: use g_new() family of functions
@ 2017-09-05 12:14 Marc-André Lureau
  2017-09-05 12:41 ` Philippe Mathieu-Daudé
  2017-09-05 12:56 ` Markus Armbruster
  0 siblings, 2 replies; 9+ messages in thread
From: Marc-André Lureau @ 2017-09-05 12:14 UTC (permalink / raw)
  To: QEMU, qemu trival

Hi,

I have a series of changes generated with clang-tidy qemu [1] pending
for review [2].

It translates calloc/*malloc*/*realloc() calls to
g_new/g_newa/g_new0/g_renew() where the argument is a sizeof(T) [* N].

This is the first commit to give you an idea:

diff --git a/hw/timer/arm_timer.c b/hw/timer/arm_timer.c
index 98fddd7ac1..75affcb8a6 100644
--- a/hw/timer/arm_timer.c
+++ b/hw/timer/arm_timer.c
@@ -166,7 +166,7 @@ static arm_timer_state *arm_timer_init(uint32_t freq)
     arm_timer_state *s;
     QEMUBH *bh;

-    s = (arm_timer_state *)g_malloc0(sizeof(arm_timer_state));
+    s = g_new0(arm_timer_state, 1);
     s->freq = freq;
     s->control = TIMER_CTRL_IE;

g_new() advantages (from glib doc):
- the returned pointer is cast to a pointer to the given type.
- care is taken to avoid overflow when calculating the size of the
allocated block.

But it is also shorter&nicer :)

I have not included in the first batch the opportunity to also
translate: alloc(sizeof(*p) * x) to g_new(typeof(*p), x), since it is
arguably not much nicer. But for consistency, I think it would be good
to use g_new(). What do you think?

I splitted the changes amont the various MAINTAINERS entries, but it
is still about 70 patches (without the typeof() changes).


[1] https://github.com/elmarco/clang-tools-extra/
[2] https://github.com/elmarco/qemu/commits/gnew


-- 
Marc-André Lureau

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-09-06  8:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-05 12:14 [Qemu-devel] clang-tidy: use g_new() family of functions Marc-André Lureau
2017-09-05 12:41 ` Philippe Mathieu-Daudé
2017-09-05 12:48   ` Marc-André Lureau
2017-09-05 12:56 ` Markus Armbruster
2017-09-05 13:29   ` Marc-André Lureau
2017-09-05 15:33     ` Markus Armbruster
2017-09-05 15:55       ` Marc-André Lureau
2017-09-05 16:23         ` Markus Armbruster
2017-09-06  8:52       ` Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.