Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sqzs6-00EgrT-OY for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Sep 2024 18:57:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sqzs5-00EE1L-9N for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Sep 2024 18:57:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sqzs4-00EE1D-Vg for pgsql-hackers@lists.postgresql.org; Wed, 18 Sep 2024 18:57:48 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sqzry-001rzY-Ei for pgsql-hackers@lists.postgresql.org; Wed, 18 Sep 2024 18:57:48 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42cba8340beso7248865e9.1 for ; Wed, 18 Sep 2024 11:57:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726685861; x=1727290661; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=6F+Hd+X+gaX+2OBnLGwE7bgyt2ROUeLCeUNMWreFH7Q=; b=WKOIqSVSJyVkWfUn6H9zH74HCdDMkw8hR4Z+aGTkGbR3Cb2ODiavN2+17P6MfKncFW SBLU70syWCZVA2eOXLQfI54GS9vYw1St2T3C4sKylxi4c8BrZok1+h6kDsg7SaP9jMHH 0jRdUNzkpcAVd9cA9S2W1pr6mVdj0wD/UO7Iz07k3yjXUFDC5vgOHXwQugo3iA5XjzgF 4uCycN1rR8G0RR+37/r6SBU+7/o41az8EVX2SlXkD0knMHc5CZ2FOSWGoOksm4q+wW6D nc6Ck63iE/JxmSLBGqVo+wtc4DuWtk5NWp5aOAkVfCFU5CCBoeC311RAovep6HQoAXkB A2bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726685861; x=1727290661; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6F+Hd+X+gaX+2OBnLGwE7bgyt2ROUeLCeUNMWreFH7Q=; b=Hwt58KTMltk7MUSeH6Q4JexBcoztRw87X0MYygg4nnNfohkLKYOPixfMxNRk7jR4QG WiRcpx6yH7TbvaAA9uT7EqodnJ/TJ6tRKDKDmJJA85GTOgT3RSOA3nkGpQe3NnBWbNiJ jahI7NqUKE8B0rKWHSu+J0b6PL5Y9RtR9YCeByqDYrXXQQORsXojIH9amiVMM9UYhHTS QxE2aoPpajo4pE+ezZz5PX5VyhT7oDN/ExmumEYPLUaaz5+C5PLORxI1v7jB5vGPkt0B ah8wO0QPpK5bveNbo/3D2U12hpS1iseFPRhMyntkty0rBKjNxzRVJuUElu5O/kdMteAt 3IqQ== X-Gm-Message-State: AOJu0YyMCkJnKdTMY/3gqS6gs12ChBrLHouYiAE1mBXkClgN4YkgNQpw EPJm8iAluiQ/BhiK2S6wIMMb2XiOoIwu9Y8zgoCGRvWjkKa6GxK63DfUGw== X-Google-Smtp-Source: AGHT+IGLkxBkN3oYV3k+4o0o/s52PnoP0dkrWaf86VpShNbK/EtxxTqLaPVa0OBlfrSeIEa61rt6yA== X-Received: by 2002:a05:6000:d4b:b0:374:cd15:c46c with SMTP id ffacd0b85a97d-3799a1dd485mr400559f8f.15.1726685861256; Wed, 18 Sep 2024 11:57:41 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e754c5627sm488065e9.40.2024.09.18.11.57.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 11:57:40 -0700 (PDT) Date: Wed, 18 Sep 2024 18:57:39 +0000 From: Bertrand Drouvot To: Peter Eisentraut Cc: pgsql-hackers@lists.postgresql.org Subject: Re: define pg_structiszero(addr, s, r) Message-ID: References: <3023d29e-0fe7-4bec-9028-7f3c0102e437@eisentraut.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3023d29e-0fe7-4bec-9028-7f3c0102e437@eisentraut.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, Sep 18, 2024 at 10:03:21AM +0200, Peter Eisentraut wrote: > On 18.09.24 06:16, Bertrand Drouvot wrote: > > +#define pg_structiszero(addr, s, r) \ > > + do { \ > > + /* We assume this initializes to zeroes */ \ > > + static const s all_zeroes; \ > > + r = (memcmp(addr, &all_zeroes, sizeof(all_zeroes)) == 0); \ > > + } while (0) > Thanks for the feedback. > This assumption is kind of the problem, isn't it? Because, you can't assume > that. And the existing code is arguably kind of wrong. But moreover, this > macro also assumes that the "addr" argument has no random padding bits. > > In the existing code, you can maybe make a local analysis that the code is > working correctly, although I'm not actually sure. I think it is but will give it a closer look. > But if you are > repackaging this as a general macro under a general-sounding name, then the > requirements should be more stringent. Agree. That said in v2 ([1]), it has been renamed to pgstat_entry_all_zeros(). I think that I will: 1/ take a closer look regarding the existing assumption 2/ if 1/ outcome is fine, then add more detailed comments around pgstat_entry_all_zeros() to make sure it's not used outside of the existing context Sounds good to you? [1]: https://www.postgresql.org/message-id/ZuqHLCdZXtEsbyb/%40ip-10-97-1-34.eu-west-3.compute.internal Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com