From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-6.3 required=3.0 tests=AWL,BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 8A6B61F9AF for ; Mon, 30 Jan 2017 21:10:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754474AbdA3VKb (ORCPT ); Mon, 30 Jan 2017 16:10:31 -0500 Received: from mout.gmx.net ([212.227.17.20]:60891 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752507AbdA3VKa (ORCPT ); Mon, 30 Jan 2017 16:10:30 -0500 Received: from virtualbox ([37.201.192.48]) by mail.gmx.com (mrgmx103 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MYfJW-1d2bZT2Y42-00VMTP; Mon, 30 Jan 2017 22:03:21 +0100 Date: Mon, 30 Jan 2017 22:03:19 +0100 (CET) From: Johannes Schindelin X-X-Sender: virtualbox@virtualbox To: Johannes Sixt cc: =?UTF-8?Q?Ren=C3=A9_Scharfe?= , Git List , Junio C Hamano Subject: Re: [PATCH 1/5] add SWAP macro In-Reply-To: Message-ID: References: <8ef4c833-45bd-6831-0683-6d01f30aa518@web.de> <0bdb58a6-3a7f-2218-4b70-c591ae90e95e@web.de> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-526191596-1485810201=:3469" X-Provags-ID: V03:K0:2qEmpQT8fUtj1wFDyHGmKnR+q9vnWSZo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Sic9TaDsCwdw== Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-526191596-1485810201=:3469 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Hi Hannes, On Mon, 30 Jan 2017, Johannes Sixt wrote: > Am 30.01.2017 um 17:01 schrieb Johannes > Schindelin: > > On Sat, 28 Jan 2017, Ren=C3=A9 Scharfe wrote: > > > diff --git a/git-compat-util.h > > > b/git-compat-util.h > > > index 87237b092b..66cd466eea 100644 > > > --- a/git-compat-util.h > > > +++ b/git-compat-util.h > > > @@ -527,6 +527,16 @@ static inline int > > > @@ ends_with(const char *str, const char > > > @@ *suffix) > > > =09return strip_suffix(str, suffix, &len); > > > } > > > > > > +#define SWAP(a, b) do { > > > \ > > > +=09void *_swap_a_ptr =3D &(a); > > > \ > > > +=09void *_swap_b_ptr =3D &(b); > > > \ > > > +=09unsigned char _swap_buffer[sizeof(a)]; > > > \ > > > +=09memcpy(_swap_buffer, _swap_a_ptr, > > > sizeof(a));=09=09\ > > > +=09memcpy(_swap_a_ptr, _swap_b_ptr, > > > sizeof(a) +=09=09\ > > > +=09 BUILD_ASSERT_OR_ZERO(sizeof(a) > > > =3D=3D sizeof(b)));=09\ > > > +=09memcpy(_swap_b_ptr, _swap_buffer, > > > sizeof(a));=09=09\ > > > +} while (0) > > > + > > > #if defined(NO_MMAP) || > > > defined(USE_WIN32_MMAP) > > > > It may seem as a matter of taste, or maybe > > not: I prefer this without the > > _swap_a_ptr >=20 > The purpose of these pointers is certainly to > avoid that the macro arguments are evaluated > more than once. I mistook "a" being used in sizeof(a) for breaking that assumption, but of course a is *not* evaluated in that case. It is curious, though, that an expression like "sizeof(a++)" would not be rejected. Further, what would SWAP(a++, b) do? Swap a and b, and *then* increment a? Ciao, Johannes --8323329-526191596-1485810201=:3469--