[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 5/5] CODING_STYLE: add .clang-format


  • To: Julien Grall <julien@xxxxxxx>
  • From: Edwin Torok <edvin.torok@xxxxxxxxxx>
  • Date: Thu, 1 Dec 2022 09:21:45 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Wx9YRRqR8NDFoWKn6VBaGrKqmGimLUWd5KB2t2RPG4g=; b=EcLPGWpCEU+M55eLkpWH3vPjch1aDuAUUA5c5BJzaWLwiTMd22DwOzXA470/l128M4cY86AWJjukTaiB0+Vzl7w3AeC3xX9tskfdf6Lt91dGSHxfXtuMD/P9qY0rFufUvC4Bi9QMWWH1zqc6YMwerFNmUHdFzGcopUyuGiNCmKLNcKJRpHRP99kCoTb6Z8W/JXfK3fTIZecfGBhwbiI7YCjQ9AjO3YPxVy+NDtttG3S3//8arLSjVC1+9KfoORPhvfnndlijQVb+FxUaykigMo1TRv/0DLvMSkwnn4cANE9DlhyF1NRFAa52vY0RB073MxT+LjZs94/VVuuxolK0wg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YGrFrR8nqIVXsqezozOZX8P3Q/mdf6W6wOU/2h0Ltq7RwwRxx5I2N6/lOKk4jJ/xR3s+QF4M6RSFojECTI9BC74YubTuacUs6ygTy4N7T40qpZQvUf58NjPVc4As6Tv0n86scR/SCVpzvx3IDDCSnqIBJKsc4G6J0MTzjtbPHdTvvBe4FiFmVr+v4TLtMlJEwMfDH0dlrQTezEFHqHSKME17K6MPSU9ZCPGandF1fhjDt90zNkpeeuLkR2bpDCiC7rs4L6P+R+VNvmQ6xDBojsk8nJ2GFoeUGZN3YP5HnnHq1GjmGLWX+JyjXQ1zcskywVxMxY2ir5pcDw7zYly06w==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Christian Lindig <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Thu, 01 Dec 2022 09:22:02 +0000
  • Ironport-data: A9a23:21i0LaOo07IH4drvrR1qlsFynXyQoLVcMsEvi/4bfWQNrUp31zEBz 2QaCmqAPvbeZWWjftolbo6woBlX75eDy4JnQQto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQA+KmU4YoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGj9SuvzrRC9H5qyo4mpC5gVmP5ingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0usnGnFkx aZbEywmUAyDo/m22u2cVfY506zPLOGzVG8ekldJ6GiDSNwAEdXESaiM4sJE1jAtgMwIBezZe 8cSdTtoalLHfgFLPVAUTpk5mY9EhFGmK2Ee9A3T+PdxujeJpOBy+OGF3N79d9CURMMTgkGCo WHu9GXlGBAKcteYzFJp91r82LOUxnimAer+EpXk/NhpkEGD2FAsKzQHcwq3o+uV01GXDoc3x 0s8v3BGQbIJ3E62StjwWTWorXjCuQQTM/JAHut/5AyTx6785weCGnNCXjNHcMYhtsI9WXotz FDht9/gGzFHqrCeTnOZsLCOoluaJiw9PWIEIygeQmMt+ML/qYs+ihbOSNdLE6OviNDxXzbqz Fi3QDMWgrwSiYsB0fW99FWe2Ta0/MGWFEgy+xndWX+j4kVhfom5aoe06F/dq/FdMIKeSVrHt 38B8ySD0N0z4Vi2vHTlaI0w8HuBvJ5p7BW0bYZTIqQc
  • Ironport-hdrordr: A9a23:fIBLIKzMSNnO2nDM+GHKKrPwFr1zdoMgy1knxilNoHtuHvBw9v rAoB1/73TJYVkqNk3I9ergBEDjewK+yXcF2+ks1N6ZNWGN1VdAR7sSj7cKrQeQfBHWx6pw0r phbrg7KPCYNykdsS8i2njcLz/3+qjizJyV
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZBOHhQzYCKXctsk6F2XwSospvV65YwCGAgAACuQA=
  • Thread-topic: [PATCH v1 5/5] CODING_STYLE: add .clang-format


> On 1 Dec 2022, at 09:11, Julien Grall <julien@xxxxxxx> wrote:
> 
> Hi Edwin,
> 
> The title should have "OCaml" to clarify that .clang-format is not added at 
> the root level.
> 

Sure, I'll update that when I resend.

> On 30/11/2022 17:32, Edwin Török wrote:
>> Add a .clang-format configuration that tries to match CODING_STYLE where
>> possible.
>> I was not able to express the special casing of braces after 'do'
>> though, this can only be controlled generally for all control
>> statements.
>> It is imperfect, but should be better than the existing bindings, which
>> do not follow Xen coding style.
> 
> Right, from previous discussion, I was under the impression that it requires 
> some work to write a clang-format file for Xen.
> 
> I am hopeful that some day we will have a proper one. In fact, we have been 
> discussing about this as part of MISRA (+ Stefano).
> 
>> Add this to tools/ocaml first because:
>> * there are relatively few C files here, and it is a good place to start with
>> * it'd be useful to make these follow Xen's CODING_STYLE
>> (which they currently do not because they use tabs for example)
>> * they change relatively infrequently, so shouldn't cause issues with
>>   backporting security fixes (could either backport the reindentation
>>   patch too, or use git cherry-pick with `-Xignore-space-change`)
>> Once this is used it'll need inserting some '#include <stdint.h>', otherwise 
>> xs_wire.h
>> fails to compile due to the missing uint32_t define.
> 
> At first I was a bit concerned with this paragraph because a coding style 
> should not impact compilation. But I guess that's because the format will 
> convert u32 to uint32_t. Is that correct?
> 
> If so, I would expand the paragraph to explicit say that, per the coding 
> styel, u32 will be converted to uint32_t.


clang-format rearranges the order of '#include' in C files, it shouldn't 
convert types.
But rearranging (sorting) includes can sometimes reveal bugs where the code 
only happened to compile because the includes were done in a certain order
(e.g. we included something that included stdint.h, therefore the next include 
line worked, but if you swap the include order that no longer works), i.e.:

#include "c.h"
#include "b.h"

vs

/* post formatting */
#include "b.h"
#include "c.h"

Where c.h includes a.h, and b.h depends on declarations from a.h, then prior to 
reformat the code compiles, and afterwards it doesn't.

Which can be fixed by adding this to the C file (and then regardless of include 
order of the other 2 it compiles):
#include <a.h>

Or by fixing b.h to include a.h itself it it depends on it.


Perhaps this'd better be fixed in xs_wire.h itself to include all its 
dependencies, but that is a publicly installed header, and there might be a 
reason why it doesn't include stdint.h.
(neither u32, nor uint32_t is standard C, both require a header to be included 
for them to be available)

Best regards,
--Edwin
> 
> Cheers,
> 
> -- 
> Julien Grall


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.