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 1t5Qoj-0062T4-MZ for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Oct 2024 14:34:02 +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 1t5Qni-0079Eq-7J for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Oct 2024 14:32:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t5Qnh-0079Eh-TH for pgsql-hackers@lists.postgresql.org; Mon, 28 Oct 2024 14:32:58 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t5Qnf-003Hbr-E3 for pgsql-hackers@lists.postgresql.org; Mon, 28 Oct 2024 14:32:57 +0000 Received: from [192.168.1.110] (dsl-hkibng22-50ddb7-241.dhcp.inet.fi [80.221.183.241]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4XcbTJ3Nhtz49Q16; Mon, 28 Oct 2024 16:32:51 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1730125973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PErFAaaAuonTvu2Z5XBHyqUpOzdu+5+1HKjHsACN4lQ=; b=tH0NT1/Y8y246DkurZNpdACsruGBM4Gv4qA8aEetPuZGdhaQu9pppi0TgwQn6iw2qq2Xyw qXpr759/ddn3tIeEGwBgNByQdZ1XPIPj6rVHiXCPRsYmt6dkxqxbH67PPtglsnNo43X/UT XKIuOxUWFtMRNF/KSP3u3LPSWnB1ABxtXOxudC+UOumvdB/57DYcghnloO59Zr9ls38whq iKCHzT5QbdRGL2r5R3eJwlcG5FT9Jq52FNnMFRWiOuSvGy/HtSPE1uyl04xmrAqJ19poeC V954HffXmuFMLPUMkL3jVvhwpQMkUfdZOYvyZ6M83PCJqrqoBuSgaCyRq+DnKQ== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1730125973; a=rsa-sha256; cv=none; b=JPdHdHOT9CZlxtFgSKiaHNQgTuRaj1RJHRN/FTNb3ZCE+3WR8hBXLRBhvuEvouoVQTud9l gzgyuvdKRk5ckqJa0+guL3M3F/KGdaw4q9+rOQkuJJBkdI9utUd8KQGDfTiqMtUAl3n2na e0aZR71BHb2uHHVRNV4XOynnWdS2Ob1jFK/oxnxAY5I6mQg0an8B904YR9Z0dFh2AuKWOg 90JgTtSlS46v0ENgdbmKqwOkdotOuVstYDNJ15oMbFxX9/hV7vrb5LSQPu1jhQnHRLAof+ gkrWrH0cgTL05ruRjjUnzLjRZjhMAxFCLYVxSlrOiIpp7ApQ7/dr35PLlq2gCA== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1730125973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PErFAaaAuonTvu2Z5XBHyqUpOzdu+5+1HKjHsACN4lQ=; b=pgIM+SN+Wa6PVCxUccGt24k6Mq6KcaPlAE8mkdbaGFOL6f5jeZ+xolK36V67Ob4L931cqG g2K9IA3HwjQ2kagEuUEq4H1VPJLRH1t5wGNbBHdqqVkGabZ9BWUSKLV+470JqVIoFUUmSA d9N+eYJ64kAW1PaQH4WtVKxFN0qHSbV10NiKRscio7PxnchLz70FzbYGx/EHD+KCB7fbAy z85962NtKEVNLdGntBFd2sdUu6t8tR8McaOnXYfLPeix/ZwP2O/FBTPSMRqGVoo6WZhNhx ezPkNDPikik1K7ffsHMrWRT+ZPhxbl47Hqt2i7/JHoE344rgAMdwi5YhoNYDXQ== Message-ID: Date: Mon, 28 Oct 2024 16:32:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: define pg_structiszero(addr, s, r) To: Bertrand Drouvot , Peter Eisentraut Cc: pgsql-hackers@lists.postgresql.org References: <3023d29e-0fe7-4bec-9028-7f3c0102e437@eisentraut.org> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 18/09/2024 21:57, Bertrand Drouvot wrote: > 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) Not new with this patch, but do we guarantee padding bytes to be zeros? How about this instead: static inline bool pg_is_all_zeros(const char *p, size_t len) { for (size_t i = 0; i < len; i++) { if (p[i] != 0) return false; } return true; } Is there's a de facto standard name for that function? I was surprised that I couldn't find one with a quick google search. That seems like the kind of small utility function that every C program needs. How performance sensitive is this? If it's not, then the above seems like the most straightforward way to do this, which is good. If it is performance sensitive, it's still good, because the compiler can optimize that well: https://godbolt.org/z/x9hPWjheq. -- Heikki Linnakangas Neon (https://neon.tech)