[{"id":1763305,"web_url":"http://patchwork.ozlabs.org/comment/1763305/","msgid":"<54c80221-aaf8-48c3-d58d-485003f77988@amsat.org>","list_archive_url":null,"date":"2017-09-05T12:41:40","subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","submitter":{"id":70924,"url":"http://patchwork.ozlabs.org/api/people/70924/","name":"Philippe Mathieu-Daudé","email":"f4bug@amsat.org"},"content":"Hi Marc-André,\n\nOn 09/05/2017 09:14 AM, Marc-André Lureau wrote:\n> Hi,\n> \n> I have a series of changes generated with clang-tidy qemu [1] pending\n> for review [2].\n> \n> It translates calloc/*malloc*/*realloc() calls to\n> g_new/g_newa/g_new0/g_renew() where the argument is a sizeof(T) [* N].\n> \n> This is the first commit to give you an idea:\n> \n> diff --git a/hw/timer/arm_timer.c b/hw/timer/arm_timer.c\n> index 98fddd7ac1..75affcb8a6 100644\n> --- a/hw/timer/arm_timer.c\n> +++ b/hw/timer/arm_timer.c\n> @@ -166,7 +166,7 @@ static arm_timer_state *arm_timer_init(uint32_t freq)\n>       arm_timer_state *s;\n>       QEMUBH *bh;\n> \n> -    s = (arm_timer_state *)g_malloc0(sizeof(arm_timer_state));\n> +    s = g_new0(arm_timer_state, 1);\n>       s->freq = freq;\n>       s->control = TIMER_CTRL_IE;\n> \n> g_new() advantages (from glib doc):\n> - the returned pointer is cast to a pointer to the given type.\n> - care is taken to avoid overflow when calculating the size of the\n> allocated block.\n> \n> But it is also shorter&nicer :)\n> \n> I have not included in the first batch the opportunity to also\n> translate: alloc(sizeof(*p) * x) to g_new(typeof(*p), x), since it is\n> arguably not much nicer. But for consistency, I think it would be good\n\n\"avoid overflow when calculating the size\" sounds nicer.\n\n> to use g_new(). What do you think?\n\nDunno if useful, but Juan Quintela had some issue:\n\nhttp://lists.nongnu.org/archive/html/qemu-devel/2017-09/msg00085.html\n\n> \n> I splitted the changes amont the various MAINTAINERS entries, but it\n> is still about 70 patches (without the typeof() changes).\n> \n> \n> [1] https://github.com/elmarco/clang-tools-extra/\n> [2] https://github.com/elmarco/qemu/commits/gnew\n> \n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"M7NaXOeI\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xmmbr4Fswz9sRV\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue,  5 Sep 2017 22:43:36 +1000 (AEST)","from localhost ([::1]:58726 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dpDCY-0007GQ-L6\n\tfor incoming@patchwork.ozlabs.org; Tue, 05 Sep 2017 08:43:34 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:59416)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dpDB1-0006Ps-03\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 08:42:03 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dpDAw-0001ki-4J\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 08:41:59 -0400","from mail-qt0-x231.google.com ([2607:f8b0:400d:c0d::231]:33732)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dpDAm-0001c4-1G; Tue, 05 Sep 2017 08:41:44 -0400","by mail-qt0-x231.google.com with SMTP id i50so11422232qtf.0;\n\tTue, 05 Sep 2017 05:41:43 -0700 (PDT)","from [192.168.1.10] ([181.93.89.178])\n\tby smtp.gmail.com with ESMTPSA id\n\ta50sm185407qtc.93.2017.09.05.05.41.41\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tTue, 05 Sep 2017 05:41:42 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=sender:subject:to:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=39Me8lXIy5VBPit/mrAtHHjFrlqa92uxLxXFfC7V2U4=;\n\tb=M7NaXOeI+STmPpTFY4xOWGR8LBV27kWsG3cfh7sQsEB4WUNHt6q3voIj9iNMPFbM3z\n\tUzPUEccY2UUPgFaMNESjJLBCOMnpPIricFvjCEgBnBavK/lW5F37im8mr9CIhS/BBQA0\n\tf/dCa89pNZtmoqfJoH66BhvU1EnQpViiujqfzBlN8HBzJ8FzZlQVd1npdVhX91745vua\n\tI73I/LiUxWuJSlgLJ41j7oda7obV8sPQAbozsLO4nmkeOexCKz7Isozw6yjY72BHTlvu\n\tsXlOvf5BnID6kjvfIa+QrNaRDfgUALQTCbL9NG4db3RLYwLEOsho6U5tIvUswz5Jx8yN\n\tXVIg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:sender:subject:to:references:from:message-id\n\t:date:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=39Me8lXIy5VBPit/mrAtHHjFrlqa92uxLxXFfC7V2U4=;\n\tb=Hg90hs/rc+Sz+GWucV2eVFdg1UOzFrX9+qBdR4YJ07a/1c7q0T47Y2qrWz+BadR8PY\n\t3IUv/sa0AAkyAYtOq/UNVBaQtHDS4awf2U1HRzdz3iyfDb5Snb7EzA0J8dil44mMqgaS\n\tLACLuSWgjb68WlUf96JT+IMESCPgNqhVg7FOE0zOTlUftkgKhXaFP85hW517w4dPunjm\n\tBQLeqG9wtDJOgmftGEpqnQm9+genfktz2RUs8zlv95Lj3zjNfMxdzvZzkKCtKCQ3NknC\n\thpQCE8/AWbFHXIWnj1g/oTKZfctu7BwddReVNTWvHoxohZcFV2UhpnqRK/MuPD7qRAVx\n\tgsYA==","X-Gm-Message-State":"AHPjjUgPQmXMb30ColOcz78EPN/GrikI67n7QUrAPkK01aj0P9qtB7oH\n\tZAlogxPuuQqKNnqKJtd/lA==","X-Google-Smtp-Source":"ADKCNb5F82+CASvWVFWnrHuTt8um1ymaR6l8Ksqzj6wTF1yUuIZTXLhD3UljVMDXTSO0HTKKDnORIQ==","X-Received":"by 10.200.38.135 with SMTP id 7mr5203725qto.225.1504615303191;\n\tTue, 05 Sep 2017 05:41:43 -0700 (PDT)","To":"=?utf-8?q?Marc-Andr=C3=A9_Lureau?= <marcandre.lureau@gmail.com>,\n\tQEMU <qemu-devel@nongnu.org>, qemu trival <qemu-trivial@nongnu.org>","References":"<CAJ+F1C+mPu9ftXwgs4UrGTQp4f65-thhvmWoB-kuRmu0=vnFFw@mail.gmail.com>","From":"=?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <f4bug@amsat.org>","Message-ID":"<54c80221-aaf8-48c3-d58d-485003f77988@amsat.org>","Date":"Tue, 5 Sep 2017 09:41:40 -0300","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<CAJ+F1C+mPu9ftXwgs4UrGTQp4f65-thhvmWoB-kuRmu0=vnFFw@mail.gmail.com>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Language":"en-US","Content-Transfer-Encoding":"8bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:400d:c0d::231","Subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1763314,"web_url":"http://patchwork.ozlabs.org/comment/1763314/","msgid":"<CAJ+F1C+JR8QqRGXaFizqHNrmWfi7v4ZuFAsOzUeqmXW=rqnFZw@mail.gmail.com>","list_archive_url":null,"date":"2017-09-05T12:48:35","subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","submitter":{"id":6442,"url":"http://patchwork.ozlabs.org/api/people/6442/","name":"Marc-André Lureau","email":"marcandre.lureau@gmail.com"},"content":"On Tue, Sep 5, 2017 at 2:41 PM Philippe Mathieu-Daudé <f4bug@amsat.org>\nwrote:\n\n> Hi Marc-André,\n>\n> On 09/05/2017 09:14 AM, Marc-André Lureau wrote:\n> > Hi,\n> >\n> > I have a series of changes generated with clang-tidy qemu [1] pending\n> > for review [2].\n> >\n> > It translates calloc/*malloc*/*realloc() calls to\n> > g_new/g_newa/g_new0/g_renew() where the argument is a sizeof(T) [* N].\n> >\n> > This is the first commit to give you an idea:\n> >\n> > diff --git a/hw/timer/arm_timer.c b/hw/timer/arm_timer.c\n> > index 98fddd7ac1..75affcb8a6 100644\n> > --- a/hw/timer/arm_timer.c\n> > +++ b/hw/timer/arm_timer.c\n> > @@ -166,7 +166,7 @@ static arm_timer_state *arm_timer_init(uint32_t freq)\n> >       arm_timer_state *s;\n> >       QEMUBH *bh;\n> >\n> > -    s = (arm_timer_state *)g_malloc0(sizeof(arm_timer_state));\n> > +    s = g_new0(arm_timer_state, 1);\n> >       s->freq = freq;\n> >       s->control = TIMER_CTRL_IE;\n> >\n> > g_new() advantages (from glib doc):\n> > - the returned pointer is cast to a pointer to the given type.\n> > - care is taken to avoid overflow when calculating the size of the\n> > allocated block.\n> >\n> > But it is also shorter&nicer :)\n> >\n> > I have not included in the first batch the opportunity to also\n> > translate: alloc(sizeof(*p) * x) to g_new(typeof(*p), x), since it is\n> > arguably not much nicer. But for consistency, I think it would be good\n>\n> \"avoid overflow when calculating the size\" sounds nicer.\n>\n> > to use g_new(). What do you think?\n>\n> Dunno if useful, but Juan Quintela had some issue:\n>\n> http://lists.nongnu.org/archive/html/qemu-devel/2017-09/msg00085.html\n\n\nThanks for pointing this out.\n\nIt looks like the last iteration didn't change it after all:\nhttps://lists.gnu.org/archive/html/qemu-devel/2017-09/msg00076.html\n\n\n>\n> >\n> > I splitted the changes amont the various MAINTAINERS entries, but it\n> > is still about 70 patches (without the typeof() changes).\n> >\n> >\n> > [1] https://github.com/elmarco/clang-tools-extra/\n> > [2] https://github.com/elmarco/qemu/commits/gnew\n> >\n> >\n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"GJd3PAqZ\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xmmkq6zRbz9sRm\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue,  5 Sep 2017 22:49:39 +1000 (AEST)","from localhost ([::1]:58756 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dpDIQ-0003fQ-3m\n\tfor incoming@patchwork.ozlabs.org; Tue, 05 Sep 2017 08:49:38 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:34535)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <marcandre.lureau@gmail.com>) id 1dpDHg-0003Sp-EB\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 08:49:00 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <marcandre.lureau@gmail.com>) id 1dpDHb-0006LG-C7\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 08:48:52 -0400","from mail-oi0-x22c.google.com ([2607:f8b0:4003:c06::22c]:33230)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <marcandre.lureau@gmail.com>)\n\tid 1dpDHb-0006Kq-3o; Tue, 05 Sep 2017 08:48:47 -0400","by mail-oi0-x22c.google.com with SMTP id x184so23881143oia.0;\n\tTue, 05 Sep 2017 05:48:46 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to;\n\tbh=qRpJjd6Ai2dT4y1KebMiUxQL8r8ZhevGZh9McwkCLo8=;\n\tb=GJd3PAqZivNy+KYjWSW01DhDC7Z/mOX29mlXKKsqPXj4viFiQKcfkCHNZsk6sKBb9c\n\tEamqtLO1+y3miQxK9V7ouER42Jf5I7ql5Bg3exo+jPkmwlUKWaBANh94HHkirA8WokOk\n\tMW7DTri4ugPzToGpvWOOfjDpAagx8ddbLSMcnM/pCa6qvnDO2vzyCu6TX9vdJi8l7FVF\n\t5An1Aqr5gbHZhoOu8gtpwJ6eymtuPyfxdFdFd7oBFfRKdh8sP14w0aIQbBQCG7CBIqr0\n\t9CWbGMYTVi/E3YoE8ggJ+QUp+W/9cI9y67k+AVQZ6IQQDvAO3C66S+vyMvIG+54iwSOr\n\tBxlQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to;\n\tbh=qRpJjd6Ai2dT4y1KebMiUxQL8r8ZhevGZh9McwkCLo8=;\n\tb=eOx8vecr1NE7m679g6HxZNRtYsrcQN4StBYHSPsWJVbzrqlQn0DmSFdZt6KVPYRt82\n\tnKc3xau9oNMLaYHHtCAVl1YOIFKKMDRnMQhGzqJgY7IATp9WgJekDE8wgPwwXM2Aid5Q\n\tHDhdHgEoZs7io+Oq5RgkjT9PwUQbXvLGwMQJeeOyyuzPP4CxkPT0NOfah1RMjg5W65A+\n\tAYXhD3JCgcd9LH68mHybOeFEvy/RdDxAmJSOklS8IdxjHBidYSyYfwz+0r9T69fgtDWg\n\t3nS8V5U0WdTSk28xsOmC/mihckHNcEkf1zALKskrkGloLyquqkXjlfntAwlW5uyBswCe\n\t2TVQ==","X-Gm-Message-State":"AHPjjUhSo049Q/DrDk8Mgnt1W2j5R8CVH81WNK9DgGuNH6QWzoP7vJ7R\n\tIRRBHPm8n46E4jFSyDnmIu2n4Yw+JA==","X-Google-Smtp-Source":"ADKCNb5fb0ieaiMsK9FkEi9AB9A8+worq4kbtnYXNAbn03TRp5v3CcnkWQX6/fnO9pzu6WJejZdqyjktTfpzSFr0su4=","X-Received":"by 10.202.81.200 with SMTP id f191mr3587714oib.137.1504615726071;\n\tTue, 05 Sep 2017 05:48:46 -0700 (PDT)","MIME-Version":"1.0","References":"<CAJ+F1C+mPu9ftXwgs4UrGTQp4f65-thhvmWoB-kuRmu0=vnFFw@mail.gmail.com>\n\t<54c80221-aaf8-48c3-d58d-485003f77988@amsat.org>","In-Reply-To":"<54c80221-aaf8-48c3-d58d-485003f77988@amsat.org>","From":"=?utf-8?q?Marc-Andr=C3=A9_Lureau?= <marcandre.lureau@gmail.com>","Date":"Tue, 05 Sep 2017 12:48:35 +0000","Message-ID":"<CAJ+F1C+JR8QqRGXaFizqHNrmWfi7v4ZuFAsOzUeqmXW=rqnFZw@mail.gmail.com>","To":"=?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <f4bug@amsat.org>,\n\tQEMU <qemu-devel@nongnu.org>, qemu trival <qemu-trivial@nongnu.org>, \n\tJuan Quintela <quintela@redhat.com>","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:4003:c06::22c","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-Content-Filtered-By":"Mailman/MimeDel 2.1.21","Subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1763332,"web_url":"http://patchwork.ozlabs.org/comment/1763332/","msgid":"<87zia9palk.fsf@dusky.pond.sub.org>","list_archive_url":null,"date":"2017-09-05T12:56:55","subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","submitter":{"id":2645,"url":"http://patchwork.ozlabs.org/api/people/2645/","name":"Markus Armbruster","email":"armbru@redhat.com"},"content":"Marc-André Lureau <marcandre.lureau@gmail.com> writes:\n\n> Hi,\n>\n> I have a series of changes generated with clang-tidy qemu [1] pending\n> for review [2].\n>\n> It translates calloc/*malloc*/*realloc() calls to\n> g_new/g_newa/g_new0/g_renew() where the argument is a sizeof(T) [* N].\n\nOnly for *type* T, or for arbitrary T?\n\nFor type T, we've done the transformation repeatedly with Coccinelle,\nfirst in commit b45c03f (commit message appended).  Repeatedly, because\nthey creep back in.\n\nHow does your technique compare to this prior one?\n\n> This is the first commit to give you an idea:\n>\n> diff --git a/hw/timer/arm_timer.c b/hw/timer/arm_timer.c\n> index 98fddd7ac1..75affcb8a6 100644\n> --- a/hw/timer/arm_timer.c\n> +++ b/hw/timer/arm_timer.c\n> @@ -166,7 +166,7 @@ static arm_timer_state *arm_timer_init(uint32_t freq)\n>      arm_timer_state *s;\n>      QEMUBH *bh;\n>\n> -    s = (arm_timer_state *)g_malloc0(sizeof(arm_timer_state));\n> +    s = g_new0(arm_timer_state, 1);\n>      s->freq = freq;\n>      s->control = TIMER_CTRL_IE;\n>\n> g_new() advantages (from glib doc):\n> - the returned pointer is cast to a pointer to the given type.\n> - care is taken to avoid overflow when calculating the size of the\n> allocated block.\n>\n> But it is also shorter&nicer :)\n>\n> I have not included in the first batch the opportunity to also\n> translate: alloc(sizeof(*p) * x) to g_new(typeof(*p), x), since it is\n> arguably not much nicer. But for consistency, I think it would be good\n> to use g_new(). What do you think?\n\np = g_malloc(sizeof(*p)) is idiomatic, and not obviously inferior to\np = g_new(T, 1), where T is the type of *p.  Use whatever is easier to\nread, I guess.\n\nBut once you add multiplication, g_new() adds something useful: overflow\nprotection.  Conversion to g_new() might make sense then.\n\n> I splitted the changes amont the various MAINTAINERS entries, but it\n> is still about 70 patches (without the typeof() changes).\n>\n>\n> [1] https://github.com/elmarco/clang-tools-extra/\n> [2] https://github.com/elmarco/qemu/commits/gnew\n\n\ncommit b45c03f585ea9bb1af76c73e82195418c294919d\nAuthor: Markus Armbruster <armbru@redhat.com>\nDate:   Mon Sep 7 10:39:27 2015 +0100\n\n    arm: Use g_new() & friends where that makes obvious sense\n    \n    g_new(T, n) is neater than g_malloc(sizeof(T) * n).  It's also safer,\n    for two reasons.  One, it catches multiplication overflowing size_t.\n    Two, it returns T * rather than void *, which lets the compiler catch\n    more type errors.\n    \n    This commit only touches allocations with size arguments of the form\n    sizeof(T).\n    \n    Coccinelle semantic patch:\n    \n        @@\n        type T;\n        @@\n        -g_malloc(sizeof(T))\n        +g_new(T, 1)\n        @@\n        type T;\n        @@\n        -g_try_malloc(sizeof(T))\n        +g_try_new(T, 1)\n        @@\n        type T;\n        @@\n        -g_malloc0(sizeof(T))\n        +g_new0(T, 1)\n        @@\n        type T;\n        @@\n        -g_try_malloc0(sizeof(T))\n        +g_try_new0(T, 1)\n        @@\n        type T;\n        expression n;\n        @@\n        -g_malloc(sizeof(T) * (n))\n        +g_new(T, n)\n        @@\n        type T;\n        expression n;\n        @@\n        -g_try_malloc(sizeof(T) * (n))\n        +g_try_new(T, n)\n        @@\n        type T;\n        expression n;\n        @@\n        -g_malloc0(sizeof(T) * (n))\n        +g_new0(T, n)\n        @@\n        type T;\n        expression n;\n        @@\n        -g_try_malloc0(sizeof(T) * (n))\n        +g_try_new0(T, n)\n        @@\n        type T;\n        expression p, n;\n        @@\n        -g_realloc(p, sizeof(T) * (n))\n        +g_renew(T, p, n)\n        @@\n        type T;\n        expression p, n;\n        @@\n        -g_try_realloc(p, sizeof(T) * (n))\n        +g_try_renew(T, p, n)\n        @@\n        type T;\n        expression n;\n        @@\n        -(T *)g_new(T, n)\n        +g_new(T, n)\n        @@\n        type T;\n        expression n;\n        @@\n        -(T *)g_new0(T, n)\n        +g_new0(T, n)\n        @@\n        type T;\n        expression p, n;\n        @@\n        -(T *)g_renew(T, p, n)\n        +g_renew(T, p, n)\n    \n    Signed-off-by: Markus Armbruster <armbru@redhat.com>\n    Reviewed-by: Eric Blake <eblake@redhat.com>\n    Message-id: 1440524394-15640-1-git-send-email-armbru@redhat.com\n    Signed-off-by: Peter Maydell <peter.maydell@linaro.org>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx02.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx02.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=armbru@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xmmwD5hkxz9t16\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue,  5 Sep 2017 22:57:48 +1000 (AEST)","from localhost ([::1]:58782 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dpDQI-00074f-Tv\n\tfor incoming@patchwork.ozlabs.org; Tue, 05 Sep 2017 08:57:46 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:37455)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1dpDPb-0006wG-6W\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 08:57:13 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1dpDPW-0004Xe-6z\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 08:57:03 -0400","from mx1.redhat.com ([209.132.183.28]:36182)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <armbru@redhat.com>)\n\tid 1dpDPV-0004WH-UQ; Tue, 05 Sep 2017 08:56:58 -0400","from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id E3CBC67730;\n\tTue,  5 Sep 2017 12:56:56 +0000 (UTC)","from blackfin.pond.sub.org (ovpn-116-75.ams2.redhat.com\n\t[10.36.116.75])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id 87FC56BE7D;\n\tTue,  5 Sep 2017 12:56:56 +0000 (UTC)","by blackfin.pond.sub.org (Postfix, from userid 1000)\n\tid 100561138645; Tue,  5 Sep 2017 14:56:55 +0200 (CEST)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com E3CBC67730","From":"Markus Armbruster <armbru@redhat.com>","To":"=?utf-8?q?Marc-Andr=C3=A9?= Lureau <marcandre.lureau@gmail.com>","References":"<CAJ+F1C+mPu9ftXwgs4UrGTQp4f65-thhvmWoB-kuRmu0=vnFFw@mail.gmail.com>","Date":"Tue, 05 Sep 2017 14:56:55 +0200","In-Reply-To":"<CAJ+F1C+mPu9ftXwgs4UrGTQp4f65-thhvmWoB-kuRmu0=vnFFw@mail.gmail.com>\n\t( =?utf-8?b?Ik1hcmMtQW5kcsOp?= Lureau\"'s message of \"Tue,\n\t5 Sep 2017 \t14:14:42 +0200\")","Message-ID":"<87zia9palk.fsf@dusky.pond.sub.org>","User-Agent":"Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.15","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.26]);\n\tTue, 05 Sep 2017 12:56:57 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"qemu trival <qemu-trivial@nongnu.org>, QEMU <qemu-devel@nongnu.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1763361,"web_url":"http://patchwork.ozlabs.org/comment/1763361/","msgid":"<CAJ+F1CJaxdbHnLQy6H=5=Q3ZMw0w01xsvK3ybhj80=6F9dR6gQ@mail.gmail.com>","list_archive_url":null,"date":"2017-09-05T13:29:48","subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","submitter":{"id":6442,"url":"http://patchwork.ozlabs.org/api/people/6442/","name":"Marc-André Lureau","email":"marcandre.lureau@gmail.com"},"content":"Hi\n\nOn Tue, Sep 5, 2017 at 2:56 PM Markus Armbruster <armbru@redhat.com> wrote:\n\n> Marc-André Lureau <marcandre.lureau@gmail.com> writes:\n>\n> > Hi,\n> >\n> > I have a series of changes generated with clang-tidy qemu [1] pending\n> > for review [2].\n> >\n> > It translates calloc/*malloc*/*realloc() calls to\n> > g_new/g_newa/g_new0/g_renew() where the argument is a sizeof(T) [* N].\n>\n> Only for *type* T, or for arbitrary T?\n>\n>\nIf sizeof() argument is a type:\nhttps://github.com/elmarco/clang-tools-extra/blob/master/clang-tidy/qemu/UseGnewCheck.cpp#L65\n\nFor type T, we've done the transformation repeatedly with Coccinelle,\n> first in commit b45c03f (commit message appended).  Repeatedly, because\n> they creep back in.\n>\n> How does your technique compare to this prior one?\n>\n\nWell, for one, I have a lot of trouble running coccinelle, mostly because\nit is slow and/or eat all my memory. Afaik, coccinelle also has trouble\nparsing the code in various cases. I have also trouble writing coccinelle\nsemantic patch... And, I gave up.\n\nclang-tidy in comparison, is quite fast (it takes a minute to apply on qemu\ncode base). I find it easier to write a tidy check, and more friendly\ncommand line / output etc:\n\n/tmp/test.c:3:17: warning: use g_new() instead [qemu-use-gnew]\n        int *f = (int*)malloc(sizeof(int) * 2);\n                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~\n                 g_new(int, 2)\n\nclang-tidy should also respect clang-format rules when modifying the code\n(see also\nhttps://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg05762.html).\n\nI also imagine it should be possible to integrate to clang warnings in the\nfuture (similar to libreoffice clang plugins for ex). All in all,\ncoccinelle or clang-tidy are probably both capable of doing this job, but\nclang-tidy is snappier and has more potentials for toolchain integration.\n\n> This is the first commit to give you an idea:\n> >\n> > diff --git a/hw/timer/arm_timer.c b/hw/timer/arm_timer.c\n> > index 98fddd7ac1..75affcb8a6 100644\n> > --- a/hw/timer/arm_timer.c\n> > +++ b/hw/timer/arm_timer.c\n> > @@ -166,7 +166,7 @@ static arm_timer_state *arm_timer_init(uint32_t freq)\n> >      arm_timer_state *s;\n> >      QEMUBH *bh;\n> >\n> > -    s = (arm_timer_state *)g_malloc0(sizeof(arm_timer_state));\n> > +    s = g_new0(arm_timer_state, 1);\n> >      s->freq = freq;\n> >      s->control = TIMER_CTRL_IE;\n> >\n> > g_new() advantages (from glib doc):\n> > - the returned pointer is cast to a pointer to the given type.\n> > - care is taken to avoid overflow when calculating the size of the\n> > allocated block.\n> >\n> > But it is also shorter&nicer :)\n> >\n> > I have not included in the first batch the opportunity to also\n> > translate: alloc(sizeof(*p) * x) to g_new(typeof(*p), x), since it is\n> > arguably not much nicer. But for consistency, I think it would be good\n> > to use g_new(). What do you think?\n>\n> p = g_malloc(sizeof(*p)) is idiomatic, and not obviously inferior to\n> p = g_new(T, 1), where T is the type of *p.  Use whatever is easier to\n> read, I guess.\n>\n> But once you add multiplication, g_new() adds something useful: overflow\n> protection.  Conversion to g_new() might make sense then.\n>\n> > I splitted the changes amont the various MAINTAINERS entries, but it\n> > is still about 70 patches (without the typeof() changes).\n> >\n> >\n> > [1] https://github.com/elmarco/clang-tools-extra/\n> > [2] https://github.com/elmarco/qemu/commits/gnew\n>\n>\n> commit b45c03f585ea9bb1af76c73e82195418c294919d\n> Author: Markus Armbruster <armbru@redhat.com>\n> Date:   Mon Sep 7 10:39:27 2015 +0100\n>\n>     arm: Use g_new() & friends where that makes obvious sense\n>\n>     g_new(T, n) is neater than g_malloc(sizeof(T) * n).  It's also safer,\n>     for two reasons.  One, it catches multiplication overflowing size_t.\n>     Two, it returns T * rather than void *, which lets the compiler catch\n>     more type errors.\n>\n>     This commit only touches allocations with size arguments of the form\n>     sizeof(T).\n>\n>     Coccinelle semantic patch:\n>\n>         @@\n>         type T;\n>         @@\n>         -g_malloc(sizeof(T))\n>         +g_new(T, 1)\n>         @@\n>         type T;\n>         @@\n>         -g_try_malloc(sizeof(T))\n>         +g_try_new(T, 1)\n>\n\nthanks, I actually forgot the g_try_new() family (I thought we didn't use\nit!)\n\n        @@\n>         type T;\n>         @@\n>         -g_malloc0(sizeof(T))\n>         +g_new0(T, 1)\n>         @@\n>         type T;\n>         @@\n>         -g_try_malloc0(sizeof(T))\n>         +g_try_new0(T, 1)\n>         @@\n>         type T;\n>         expression n;\n>         @@\n>         -g_malloc(sizeof(T) * (n))\n>         +g_new(T, n)\n>         @@\n>         type T;\n>         expression n;\n>         @@\n>         -g_try_malloc(sizeof(T) * (n))\n>         +g_try_new(T, n)\n>         @@\n>         type T;\n>         expression n;\n>         @@\n>         -g_malloc0(sizeof(T) * (n))\n>         +g_new0(T, n)\n>         @@\n>         type T;\n>         expression n;\n>         @@\n>         -g_try_malloc0(sizeof(T) * (n))\n>         +g_try_new0(T, n)\n>         @@\n>         type T;\n>         expression p, n;\n>         @@\n>         -g_realloc(p, sizeof(T) * (n))\n>         +g_renew(T, p, n)\n>         @@\n>         type T;\n>         expression p, n;\n>         @@\n>         -g_try_realloc(p, sizeof(T) * (n))\n>         +g_try_renew(T, p, n)\n>         @@\n>         type T;\n>         expression n;\n>         @@\n>         -(T *)g_new(T, n)\n>         +g_new(T, n)\n>         @@\n>         type T;\n>         expression n;\n>         @@\n>         -(T *)g_new0(T, n)\n>         +g_new0(T, n)\n>         @@\n>         type T;\n>         expression p, n;\n>         @@\n>         -(T *)g_renew(T, p, n)\n>         +g_renew(T, p, n)\n>\n>     Signed-off-by: Markus Armbruster <armbru@redhat.com>\n>     Reviewed-by: Eric Blake <eblake@redhat.com>\n>     Message-id: 1440524394-15640-1-git-send-email-armbru@redhat.com\n>     Signed-off-by: Peter Maydell <peter.maydell@linaro.org>\n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"ZCteUXCE\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xmnlS4sczz9t2W\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue,  5 Sep 2017 23:35:15 +1000 (AEST)","from localhost ([::1]:58977 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dpE0W-0005DK-UW\n\tfor incoming@patchwork.ozlabs.org; Tue, 05 Sep 2017 09:35:12 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:51469)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <marcandre.lureau@gmail.com>) id 1dpDvZ-0001NX-RT\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 09:30:16 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <marcandre.lureau@gmail.com>) id 1dpDvU-0004G9-7U\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 09:30:05 -0400","from mail-oi0-x242.google.com ([2607:f8b0:4003:c06::242]:33423)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <marcandre.lureau@gmail.com>)\n\tid 1dpDvU-0004Fq-0H; Tue, 05 Sep 2017 09:30:00 -0400","by mail-oi0-x242.google.com with SMTP id k191so2648935oih.0;\n\tTue, 05 Sep 2017 06:29:59 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=cxNcQD6oS2QBoVnmjqCLBPJmbt7PdbeW7QGIIHsQXX0=;\n\tb=ZCteUXCE1JGbI2nGM+z3q+pBX+WU5IVzZtO6kT1psgwAn27ALJPEMmuf+uxiTMjBVN\n\tyqrWaNBazOUe6kmda+puEUwW9XvSGJT22f/Pjtl+nqmN/zGgoD2zHelAdTHgyWSeUAnO\n\talX8Q7GF09Fs59b2HoVJMn/9Qurb6TTGK3c+jdHjPQSg2c3qrXP28nkJP52poLDiyCk8\n\tfI7Su0zGY403/7Jl6OV+DECmDa1mqJCdWbgW7aGaW1b6XTvDyvekYWuE3BROmBV+5Vmj\n\tme4jHFo4sLeiIWPaQW6JJ6atNFM/gqhOPxfiFETnxoccGz+N6fUk+tnfwMe2aERX6s7I\n\teEWw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=cxNcQD6oS2QBoVnmjqCLBPJmbt7PdbeW7QGIIHsQXX0=;\n\tb=IxMg12vr++9d1BVjG/3GoRKKa4QAHDpHp9Mn0bxNfe33eqkkxdtFGGzIfpyaaNgt0g\n\tzvpCN1y/0q3P+/+tGuPjvDhzKhlsyq5zdJXt1qFf+PZkFvb8FrnWv0TvrGw06Qk5QN9A\n\tqGRJFxknfXNfhYQui+xn9/r+Ra+dg1z/LFuAbZVCeAnsFGIIGIj2zrokPNf1yJuydEQ1\n\tHDgOAzL8+V9Oa+0VLX3O3Vkx1aXZxnC19bvZ8aeSfCRQIv/dBKwOtK83CgFZQ4xH89mO\n\tWKxmtqRpiGnmvqPKrJw7uela5WL04TJ2Jm0ojoDlXZSDBd3/5dVXwk23Xol2ZnLoTc27\n\tXvbg==","X-Gm-Message-State":"AHPjjUgzoG94nJm55YeyFerFlALLvT+EM3lfi5xVxO1TaGfGwJYKc2nQ\n\tgbSbfCbkdvaKoFR9eQRwNlWnhekP9w==","X-Google-Smtp-Source":"ADKCNb4Jbb+V9CWpKJpoP77PP7w/lLxbyvmMf0bZdM5GPNoayUhXmjh9YbnWKmSyVSVuvf7iYuSKFYHjs9awexwFjdc=","X-Received":"by 10.202.57.69 with SMTP id g66mr3315924oia.28.1504618199121;\n\tTue, 05 Sep 2017 06:29:59 -0700 (PDT)","MIME-Version":"1.0","References":"<CAJ+F1C+mPu9ftXwgs4UrGTQp4f65-thhvmWoB-kuRmu0=vnFFw@mail.gmail.com>\n\t<87zia9palk.fsf@dusky.pond.sub.org>","In-Reply-To":"<87zia9palk.fsf@dusky.pond.sub.org>","From":"=?utf-8?q?Marc-Andr=C3=A9_Lureau?= <marcandre.lureau@gmail.com>","Date":"Tue, 05 Sep 2017 13:29:48 +0000","Message-ID":"<CAJ+F1CJaxdbHnLQy6H=5=Q3ZMw0w01xsvK3ybhj80=6F9dR6gQ@mail.gmail.com>","To":"Markus Armbruster <armbru@redhat.com>","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:4003:c06::242","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-Content-Filtered-By":"Mailman/MimeDel 2.1.21","Subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"qemu trival <qemu-trivial@nongnu.org>, QEMU <qemu-devel@nongnu.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1763451,"web_url":"http://patchwork.ozlabs.org/comment/1763451/","msgid":"<87fuc1ma7d.fsf@dusky.pond.sub.org>","list_archive_url":null,"date":"2017-09-05T15:33:42","subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","submitter":{"id":2645,"url":"http://patchwork.ozlabs.org/api/people/2645/","name":"Markus Armbruster","email":"armbru@redhat.com"},"content":"Marc-André Lureau <marcandre.lureau@gmail.com> writes:\n\n> Hi\n>\n> On Tue, Sep 5, 2017 at 2:56 PM Markus Armbruster <armbru@redhat.com> wrote:\n>\n>> Marc-André Lureau <marcandre.lureau@gmail.com> writes:\n>>\n>> > Hi,\n>> >\n>> > I have a series of changes generated with clang-tidy qemu [1] pending\n>> > for review [2].\n>> >\n>> > It translates calloc/*malloc*/*realloc() calls to\n>> > g_new/g_newa/g_new0/g_renew() where the argument is a sizeof(T) [* N].\n>>\n>> Only for *type* T, or for arbitrary T?\n>>\n>>\n> If sizeof() argument is a type:\n> https://github.com/elmarco/clang-tools-extra/blob/master/clang-tidy/qemu/UseGnewCheck.cpp#L65\n>\n> For type T, we've done the transformation repeatedly with Coccinelle,\n>> first in commit b45c03f (commit message appended).  Repeatedly, because\n>> they creep back in.\n>>\n>> How does your technique compare to this prior one?\n>>\n>\n> Well, for one, I have a lot of trouble running coccinelle, mostly because\n> it is slow and/or eat all my memory.\n\nIt's a bit of a pig, but it doesn't get anywhere close to prohibitive\neven on my rather modest development box.  Example run with a minor\nvariation of the semantic patch from commit b45c03f:\n\n$ time spatch --in-place --sp-file g_new.cocci --macro-file scripts/cocci-macro-file.h --use-idutils --dir .\n[...]\nreal\t0m42.379s\nuser\t0m38.988s\nsys\t0m2.179s\n$ git-diff --shortstat\n 123 files changed, 211 insertions(+), 216 deletions(-)\n\nNote that \"--use-idutils --dir .\" directs spatch to work only on files\nthat need work.  There's also --use-glimpse.  You can easily do the\ndirecting by hand with a judicious `git-grep ...`.  Your experience can\nbe far worse if you feed it source files indiscriminately.\n\n>                                      Afaik, coccinelle also has trouble\n> parsing the code in various cases.\n\nYes, but anything else that doesn't is almost certainly not tackling the\nfull problem.\n\nPreprocessing C is easy enough.  Parsing preprocessed C is easy enough.\nParsing unpreprocessed C into something that's suitable for transforming\nis darn hard.\n\nDoesn't mean that clang-tidy couldn't be doing a better job for our\ncode.\n\n>                                    I have also trouble writing coccinelle\n> semantic patch...\n\nPoint taken.\n\n>                   And, I gave up.\n\nI've found it frustrating at times, but overall too useful to pass up.\n\nI'd love to buy a well-written book on the thing.\n\n> clang-tidy in comparison, is quite fast (it takes a minute to apply on qemu\n\nSame order of magnitude as my spatch run above.\n\n> code base). I find it easier to write a tidy check, and more friendly\n> command line / output etc:\n>\n> /tmp/test.c:3:17: warning: use g_new() instead [qemu-use-gnew]\n>         int *f = (int*)malloc(sizeof(int) * 2);\n>                  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~\n>                  g_new(int, 2)\n>\n> clang-tidy should also respect clang-format rules when modifying the code\n> (see also\n> https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg05762.html).\n>\n> I also imagine it should be possible to integrate to clang warnings in the\n> future (similar to libreoffice clang plugins for ex). All in all,\n> coccinelle or clang-tidy are probably both capable of doing this job, but\n> clang-tidy is snappier and has more potentials for toolchain integration.\n\nSuggest you show us cool things you can do with clang-tidy that haven't\nbeen done with Coccinelle :)\n\n[...]","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=armbru@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xmrNt6qslz9sRm\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  6 Sep 2017 01:34:22 +1000 (AEST)","from localhost ([::1]:59659 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dpFro-0007e1-AD\n\tfor incoming@patchwork.ozlabs.org; Tue, 05 Sep 2017 11:34:20 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:49824)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1dpFrO-0007cW-KM\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 11:33:59 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1dpFrG-0006AJ-Kj\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 11:33:54 -0400","from mx1.redhat.com ([209.132.183.28]:36418)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <armbru@redhat.com>)\n\tid 1dpFrG-00069p-C4; Tue, 05 Sep 2017 11:33:46 -0400","from smtp.corp.redhat.com\n\t(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 6537F335F;\n\tTue,  5 Sep 2017 15:33:44 +0000 (UTC)","from blackfin.pond.sub.org (ovpn-116-75.ams2.redhat.com\n\t[10.36.116.75])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id E91428E368;\n\tTue,  5 Sep 2017 15:33:43 +0000 (UTC)","by blackfin.pond.sub.org (Postfix, from userid 1000)\n\tid 6C02E1138645; Tue,  5 Sep 2017 17:33:42 +0200 (CEST)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 6537F335F","From":"Markus Armbruster <armbru@redhat.com>","To":"=?utf-8?q?Marc-Andr=C3=A9?= Lureau <marcandre.lureau@gmail.com>","References":"<CAJ+F1C+mPu9ftXwgs4UrGTQp4f65-thhvmWoB-kuRmu0=vnFFw@mail.gmail.com>\n\t<87zia9palk.fsf@dusky.pond.sub.org>\n\t<CAJ+F1CJaxdbHnLQy6H=5=Q3ZMw0w01xsvK3ybhj80=6F9dR6gQ@mail.gmail.com>","Date":"Tue, 05 Sep 2017 17:33:42 +0200","In-Reply-To":"<CAJ+F1CJaxdbHnLQy6H=5=Q3ZMw0w01xsvK3ybhj80=6F9dR6gQ@mail.gmail.com>\n\t( =?utf-8?b?Ik1hcmMtQW5kcsOp?= Lureau\"'s message of \"Tue,\n\t05 Sep 2017 \t13:29:48 +0000\")","Message-ID":"<87fuc1ma7d.fsf@dusky.pond.sub.org>","User-Agent":"Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.12","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.30]);\n\tTue, 05 Sep 2017 15:33:44 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"qemu trival <qemu-trivial@nongnu.org>, QEMU <qemu-devel@nongnu.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1763464,"web_url":"http://patchwork.ozlabs.org/comment/1763464/","msgid":"<CAJ+F1CLAFEHjWpZpJQ_QS2VV=sjYqYpydjSe2ZEdRN-N-bhHzQ@mail.gmail.com>","list_archive_url":null,"date":"2017-09-05T15:55:28","subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","submitter":{"id":6442,"url":"http://patchwork.ozlabs.org/api/people/6442/","name":"Marc-André Lureau","email":"marcandre.lureau@gmail.com"},"content":"Hi\n\n\n> Suggest you show us cool things you can do with clang-tidy that haven't\n> been done with Coccinelle :)\n>\n> Well to do that I would have to have a transformations to do & know the\nlimits/strength of coccinelle & clang-tidy, I am not there yet... Today, I\nprefer invest in clang-tidy for what I need to do.\n\nWe already discussed some of the pros/cons of coccinelle vs tidy her and in\nthe previous round-up series. For ex, clang-tidy is able to evaluate\nconstant expressions, so you can write generic rules that you can't capture\nwith coccinelle yet (A + B-1) / B * B:\nhttps://github.com/elmarco/clang-tools-extra/blob/master/clang-tidy/qemu/RoundCheck.cpp\n.\n\nHowever, I think it is more difficult to write clang-tidy transformation\nthat spans accross various code paths (like adding errors/free/locks etc).\nCoccinelle makes that fairly easily apparently.","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"RjNtVwIJ\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xmrtz2K8kz9sRm\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  6 Sep 2017 01:56:59 +1000 (AEST)","from localhost ([::1]:59793 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dpGDh-0002ZG-Aq\n\tfor incoming@patchwork.ozlabs.org; Tue, 05 Sep 2017 11:56:57 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:60412)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <marcandre.lureau@gmail.com>) id 1dpGCi-0002HM-0h\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 11:56:00 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <marcandre.lureau@gmail.com>) id 1dpGCd-0005c8-8S\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 11:55:56 -0400","from mail-oi0-x241.google.com ([2607:f8b0:4003:c06::241]:33277)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <marcandre.lureau@gmail.com>)\n\tid 1dpGCS-0005VO-JV; Tue, 05 Sep 2017 11:55:40 -0400","by mail-oi0-x241.google.com with SMTP id k191so2929447oih.0;\n\tTue, 05 Sep 2017 08:55:40 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=+L5aZ/QySFPq/8pOAY6bCHffUdUY0G6YppHROyJXcno=;\n\tb=RjNtVwIJSIAY+8cwQmtTPszzekDnx9FBfl5nc+Av9SbKquxBYgbb/qn10ZFgpgLjil\n\tdFe8WRdoaj1ZnAq4Lm4WBwuvAPMmDdG3t+1jLnQr6FaIsKmhEQLOQ/xiHb69OAo1xIlp\n\tdxrIx/Uu8isXUSOtrG/aUkcWDJdzDnIURQt4OSlHvAFmrFhxklyjRS8I+sOv5Ink6uwK\n\tFu3UoyWcvTcA7JKD67V3UHC4SHo+qPVwKG6u9ft5IjAJRMiYtpiJpt1PIhrxG4v3lh+m\n\tT4WXkoaums1OhsPeimgw/8BTeyvm78IMjohMOOrjUG+MMKcEUGJXe1QLOJWxeINSlypd\n\t8E6g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=+L5aZ/QySFPq/8pOAY6bCHffUdUY0G6YppHROyJXcno=;\n\tb=jHJ6DyIfiYQD9orpn9WTcfEwyM/MpO1Z1DR9r+fhcO5lvhoZx3ZEg/TqLwpNgYXwQe\n\tif/u07d7N8JvUWXNdkCQktxY9DUlQG+DUAzN8iFCCwDEgj83uTx5v4cwujypDDVjBB6r\n\tlUdHANC9kc4Z73XvIcIbMUhAtWcb85JYp7ta9hNZvKmOqzFVN0eO2ELLwbXzbMbvPoXG\n\tmdECPHzxDzQLhjqMPFvS1WdRLrshvKZ8TS+VUKY8vXER5WqhdLyMw4T+C+8qYuPRVGdr\n\t89fEq6SIZ5vUyUCXYuvL9HWwCbQVnF5E7XKTcrfGgPsr/iquHHFsgaAH8TCjEYl2gql0\n\tRRAw==","X-Gm-Message-State":"AHPjjUjQ8ELInPIig340am0wM6onSpAXON8v5hA3M1yQ5rQNw8ptpOc5\n\t7DOkkME+T0deaWxvLGXJNC492tiY2Q==","X-Google-Smtp-Source":"ADKCNb6VjksQJpJAAl2Fl1dvT2Po4izfbZgRBsGtxit3sybq3o+IZOZqJY72N6pN9TJBkVY6IAm0wA+S/HsltkuL5pQ=","X-Received":"by 10.202.79.211 with SMTP id d202mr3979601oib.42.1504626939695; \n\tTue, 05 Sep 2017 08:55:39 -0700 (PDT)","MIME-Version":"1.0","References":"<CAJ+F1C+mPu9ftXwgs4UrGTQp4f65-thhvmWoB-kuRmu0=vnFFw@mail.gmail.com>\n\t<87zia9palk.fsf@dusky.pond.sub.org>\n\t<CAJ+F1CJaxdbHnLQy6H=5=Q3ZMw0w01xsvK3ybhj80=6F9dR6gQ@mail.gmail.com>\n\t<87fuc1ma7d.fsf@dusky.pond.sub.org>","In-Reply-To":"<87fuc1ma7d.fsf@dusky.pond.sub.org>","From":"=?utf-8?q?Marc-Andr=C3=A9_Lureau?= <marcandre.lureau@gmail.com>","Date":"Tue, 05 Sep 2017 15:55:28 +0000","Message-ID":"<CAJ+F1CLAFEHjWpZpJQ_QS2VV=sjYqYpydjSe2ZEdRN-N-bhHzQ@mail.gmail.com>","To":"Markus Armbruster <armbru@redhat.com>","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:4003:c06::241","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-Content-Filtered-By":"Mailman/MimeDel 2.1.21","Subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"qemu trival <qemu-trivial@nongnu.org>, QEMU <qemu-devel@nongnu.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1763481,"web_url":"http://patchwork.ozlabs.org/comment/1763481/","msgid":"<8760cxktbg.fsf@dusky.pond.sub.org>","list_archive_url":null,"date":"2017-09-05T16:23:47","subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","submitter":{"id":2645,"url":"http://patchwork.ozlabs.org/api/people/2645/","name":"Markus Armbruster","email":"armbru@redhat.com"},"content":"Marc-André Lureau <marcandre.lureau@gmail.com> writes:\n\n> Hi\n>\n>\n>> Suggest you show us cool things you can do with clang-tidy that haven't\n>> been done with Coccinelle :)\n>>\n> Well to do that I would have to have a transformations to do & know the\n> limits/strength of coccinelle & clang-tidy, I am not there yet... Today, I\n> prefer invest in clang-tidy for what I need to do.\n\nWith any luck, you'll soon enough run into something that hasn't been\ndone with Coccinelle.\n\n> We already discussed some of the pros/cons of coccinelle vs tidy her and in\n> the previous round-up series. For ex, clang-tidy is able to evaluate\n> constant expressions, so you can write generic rules that you can't capture\n> with coccinelle yet (A + B-1) / B * B:\n> https://github.com/elmarco/clang-tools-extra/blob/master/clang-tidy/qemu/RoundCheck.cpp\n> .\n>\n> However, I think it is more difficult to write clang-tidy transformation\n> that spans accross various code paths (like adding errors/free/locks etc).\n> Coccinelle makes that fairly easily apparently.\n\nFortunately, we can use both.\n\nI'm not so fond of doing the same things with both, though :)","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=armbru@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xmsVp5JYVz9s7g\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  6 Sep 2017 02:24:32 +1000 (AEST)","from localhost ([::1]:60082 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dpGeM-0001cK-3o\n\tfor incoming@patchwork.ozlabs.org; Tue, 05 Sep 2017 12:24:30 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:47070)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1dpGdn-0001am-VK\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 12:24:00 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1dpGdi-0002mB-VQ\n\tfor qemu-devel@nongnu.org; Tue, 05 Sep 2017 12:23:55 -0400","from mx1.redhat.com ([209.132.183.28]:43324)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <armbru@redhat.com>)\n\tid 1dpGdi-0002lD-Os; Tue, 05 Sep 2017 12:23:50 -0400","from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 884697538F;\n\tTue,  5 Sep 2017 16:23:49 +0000 (UTC)","from blackfin.pond.sub.org (ovpn-116-75.ams2.redhat.com\n\t[10.36.116.75])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id 5579486B00;\n\tTue,  5 Sep 2017 16:23:49 +0000 (UTC)","by blackfin.pond.sub.org (Postfix, from userid 1000)\n\tid D0C471138645; Tue,  5 Sep 2017 18:23:47 +0200 (CEST)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 884697538F","From":"Markus Armbruster <armbru@redhat.com>","To":"=?utf-8?q?Marc-Andr=C3=A9?= Lureau <marcandre.lureau@gmail.com>","References":"<CAJ+F1C+mPu9ftXwgs4UrGTQp4f65-thhvmWoB-kuRmu0=vnFFw@mail.gmail.com>\n\t<87zia9palk.fsf@dusky.pond.sub.org>\n\t<CAJ+F1CJaxdbHnLQy6H=5=Q3ZMw0w01xsvK3ybhj80=6F9dR6gQ@mail.gmail.com>\n\t<87fuc1ma7d.fsf@dusky.pond.sub.org>\n\t<CAJ+F1CLAFEHjWpZpJQ_QS2VV=sjYqYpydjSe2ZEdRN-N-bhHzQ@mail.gmail.com>","Date":"Tue, 05 Sep 2017 18:23:47 +0200","In-Reply-To":"<CAJ+F1CLAFEHjWpZpJQ_QS2VV=sjYqYpydjSe2ZEdRN-N-bhHzQ@mail.gmail.com>\n\t( =?utf-8?b?Ik1hcmMtQW5kcsOp?= Lureau\"'s message of \"Tue,\n\t05 Sep 2017 \t15:55:28 +0000\")","Message-ID":"<8760cxktbg.fsf@dusky.pond.sub.org>","User-Agent":"Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.15","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.39]);\n\tTue, 05 Sep 2017 16:23:49 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"qemu trival <qemu-trivial@nongnu.org>, QEMU <qemu-devel@nongnu.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1763927,"web_url":"http://patchwork.ozlabs.org/comment/1763927/","msgid":"<20170906085259.GB3753@dhcp-200-186.str.redhat.com>","list_archive_url":null,"date":"2017-09-06T08:52:59","subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","submitter":{"id":2714,"url":"http://patchwork.ozlabs.org/api/people/2714/","name":"Kevin Wolf","email":"kwolf@redhat.com"},"content":"Am 05.09.2017 um 17:33 hat Markus Armbruster geschrieben:\n> Marc-André Lureau <marcandre.lureau@gmail.com> writes:\n> > code base). I find it easier to write a tidy check, and more friendly\n> > command line / output etc:\n> >\n> > /tmp/test.c:3:17: warning: use g_new() instead [qemu-use-gnew]\n> >         int *f = (int*)malloc(sizeof(int) * 2);\n> >                  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~\n> >                  g_new(int, 2)\n> >\n> > clang-tidy should also respect clang-format rules when modifying the code\n> > (see also\n> > https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg05762.html).\n> >\n> > I also imagine it should be possible to integrate to clang warnings in the\n> > future (similar to libreoffice clang plugins for ex). All in all,\n> > coccinelle or clang-tidy are probably both capable of doing this job, but\n> > clang-tidy is snappier and has more potentials for toolchain integration.\n> \n> Suggest you show us cool things you can do with clang-tidy that haven't\n> been done with Coccinelle :)\n\nWell, I don't really know clang-tidy, but if the above is what it does,\nthat _is_ cool. With Coccinelle scripts you run the script from time to\ntime and remove any new offenders. But if clang-tidy allows us to turn\nany new offender into a build error so that they don't even make it into\nmaster, then to me that's way superior.\n\nNot all users are using clang, obviously, so even if we can\nautomatically enable this for clang, not everyone would see the\nwarnings. But if we can make some patchew hosts use it, that would\nalready be enough to catch those things.\n\nUnless I'm misinterpreting what Marc-André is saying and running\nclang-tidy actually requires more than is reasonable for patchew.\n\nKevin","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=kwolf@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnHTM0QZLz9sBZ\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  6 Sep 2017 18:54:47 +1000 (AEST)","from localhost ([::1]:35037 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dpW6f-0008UH-5b\n\tfor incoming@patchwork.ozlabs.org; Wed, 06 Sep 2017 04:54:45 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:55685)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <kwolf@redhat.com>) id 1dpW52-0007gh-8a\n\tfor qemu-devel@nongnu.org; Wed, 06 Sep 2017 04:53:06 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <kwolf@redhat.com>) id 1dpW51-0005on-Ah\n\tfor qemu-devel@nongnu.org; Wed, 06 Sep 2017 04:53:04 -0400","from mx1.redhat.com ([209.132.183.28]:32820)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <kwolf@redhat.com>)\n\tid 1dpW51-0005oO-4g; Wed, 06 Sep 2017 04:53:03 -0400","from smtp.corp.redhat.com\n\t(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 1EC5D5F795;\n\tWed,  6 Sep 2017 08:53:02 +0000 (UTC)","from dhcp-200-186.str.redhat.com (dhcp-200-186.str.redhat.com\n\t[10.33.200.186])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id 342CB80F8E;\n\tWed,  6 Sep 2017 08:53:00 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 1EC5D5F795","Date":"Wed, 6 Sep 2017 10:52:59 +0200","From":"Kevin Wolf <kwolf@redhat.com>","To":"Markus Armbruster <armbru@redhat.com>","Message-ID":"<20170906085259.GB3753@dhcp-200-186.str.redhat.com>","References":"<CAJ+F1C+mPu9ftXwgs4UrGTQp4f65-thhvmWoB-kuRmu0=vnFFw@mail.gmail.com>\n\t<87zia9palk.fsf@dusky.pond.sub.org>\n\t<CAJ+F1CJaxdbHnLQy6H=5=Q3ZMw0w01xsvK3ybhj80=6F9dR6gQ@mail.gmail.com>\n\t<87fuc1ma7d.fsf@dusky.pond.sub.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","In-Reply-To":"<87fuc1ma7d.fsf@dusky.pond.sub.org>","User-Agent":"Mutt/1.8.3 (2017-05-23)","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.12","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.39]);\n\tWed, 06 Sep 2017 08:53:02 +0000 (UTC)","Content-Transfer-Encoding":"quoted-printable","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] clang-tidy: use g_new() family of functions","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"qemu trival <qemu-trivial@nongnu.org>, =?iso-8859-1?q?Marc-Andr=E9?=\n\tLureau <marcandre.lureau@gmail.com>, \tQEMU <qemu-devel@nongnu.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]