From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpCkm-00014A-91 for qemu-devel@nongnu.org; Tue, 05 Sep 2017 08:15:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpCke-0006ph-GW for qemu-devel@nongnu.org; Tue, 05 Sep 2017 08:14:52 -0400 MIME-Version: 1.0 From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Tue, 5 Sep 2017 14:14:42 +0200 Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] clang-tidy: use g_new() family of functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 =3D (arm_timer_state *)g_malloc0(sizeof(arm_timer_state)); + s =3D g_new0(arm_timer_state, 1); s->freq =3D freq; s->control =3D 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 --=20 Marc-Andr=C3=A9 Lureau