From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id 1E15D1F601 for ; Tue, 6 Dec 2022 01:43:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233417AbiLFBny (ORCPT ); Mon, 5 Dec 2022 20:43:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232343AbiLFBnw (ORCPT ); Mon, 5 Dec 2022 20:43:52 -0500 Received: from cloud.peff.net (cloud.peff.net [104.130.231.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0153212D33 for ; Mon, 5 Dec 2022 17:43:51 -0800 (PST) Received: (qmail 11319 invoked by uid 109); 6 Dec 2022 01:43:51 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Tue, 06 Dec 2022 01:43:51 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 16078 invoked by uid 111); 6 Dec 2022 01:43:52 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Mon, 05 Dec 2022 20:43:52 -0500 Authentication-Results: peff.net; auth=none Date: Mon, 5 Dec 2022 20:43:50 -0500 From: Jeff King To: Taylor Blau Cc: =?utf-8?B?UmVuw6k=?= Scharfe , git@vger.kernel.org, Junio C Hamano Subject: Re: [PATCH] git-compat-util.h: introduce CALLOC(x) Message-ID: References: <6694c52b38674859eb0390c7f62da1209a8d8ec3.1670266373.git.me@ttaylorr.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Mon, Dec 05, 2022 at 05:36:25PM -0500, Taylor Blau wrote: > On Mon, Dec 05, 2022 at 10:01:11PM +0100, René Scharfe wrote: > > This rule would turn this code: > > > > struct foo *bar = xcalloc(1, sizeof(*bar)); > > int i; > > > > ... into: > > > > struct foo *bar; > > CALLOC(bar); > > int i; > > > > ... which violates the coding guideline to not mix declarations and > > statements (-Wdeclaration-after-statement). > > Yeah, I was wondering about this myself when I wrote this part of the > Coccinelle patch. > > Is there an intelligent way to tell it to put the first statement after > all declarations? I couldn't find anything after a quick scan of the > documentation nor our own patches. It feels like generating the code as above is not the end of the world. The most valuable thing that coccinelle is doing here is _finding_ the location, and telling you "it's supposed to be like this". It is great when the "this" post-image is perfect and doesn't need further tweaking. But if the compiler then reminds you "hey, you need to go a bit further manually", that doesn't seem so bad. In other words, I would be happy to follow that work flow if I introduced a bare xcalloc(). My only worry is that somebody less experienced with the project (or with C) would get confused. -Peff