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.96) (envelope-from ) id 1vRgeE-002OBQ-1F for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Dec 2025 00:59:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vRgeD-00AZT8-05 for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Dec 2025 00:59:41 +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.96) (envelope-from ) id 1vRgbt-00AWib-1k for pgsql-hackers@lists.postgresql.org; Sat, 06 Dec 2025 00:57:17 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vRgbp-003Myq-2o for pgsql-hackers@lists.postgresql.org; Sat, 06 Dec 2025 00:57:15 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-295351ad2f5so4015475ad.3 for ; Fri, 05 Dec 2025 16:57:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764982629; x=1765587429; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=586snzexZ+ZMsmfS6ULjIbWEsWhNdu86yrcN7s9D5r0=; b=VjWj9j2vcu1HtBdNLcKJ8zA9m4t3sP6z9m+0ZPH3iiR+qtEAmmt/KWR637R2QlYUHH 1d95sh8nyb8itx1gMYOi9DnYhdQ7/Ox1g8+6pFl1sS84TYYrAJXHJGLZUQv37mpFem0M eFKP+MxFbIdqfdh1S8zEvU/ZnpB9y932mHIBrayb8YlArP+vfDVZuifKc+v+VK+FzGdg TUfswHSb2NoIfMas8o7wJAgiCA4zBf/HuF2+pIL/cWgXQhjEbqBI2+fw81boyKnSIWwf gjX/nfIhRrYMInVpQ7Xdzpv+nDOkTZPpMsmpDV+uTpCcqMA9P9okEQFKE5RA+wGjbsS0 AjzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764982629; x=1765587429; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=586snzexZ+ZMsmfS6ULjIbWEsWhNdu86yrcN7s9D5r0=; b=kZqdnpGnCGYtugHJDJu9ZnsWggMi2xCQhZ/WJ+wBAIW6l5ftKiIEeSPKr9oK5akVvl 8Tqd2GQUjb7l6AsuVt5eG+vI+5aF2txAmpRmMMsOg5GpL5KxhV0eMQ7XbupQGXuA7U28 xiziSll74f0rYEQ49MOmpHyj2tRE8RBfzOX/VzBeJZCuYJuFpVnjW4mYvvQd5ud3xRcl 4hqG7pP5/u4V9GlDKy8MQQmnIuSsdgtNASRrGZ/xkiWLtCgGcj2l8qGweI6apt5MDQB7 jTwaQbxiqbHsecjD0a9HbGXdwqw6/5geunAz+0NKGS4eZKvPTEHMGaXIPwz43LYmKhdh bV6Q== X-Forwarded-Encrypted: i=1; AJvYcCWUjgGd3ccD5zXZS489xHYNkodL9ZJBk2bmxLzMwYreyNXluyg8nZ016gAHKcxur+/RrizvFMtlZtVRt9Cg@lists.postgresql.org X-Gm-Message-State: AOJu0YzZ0ZPY/73r5DzueLSI5Vk9ciF8F5gFfh3apgcIH71cerJ9IQc1 XZ4ABlQ8tmwZ1qcH4VJqvv8Jewqjr+k2u6sk5FeLapB6uAoHjl/+Ki4a6MWYSuS79CDDAjQzNGX qjMjz6wUYaJy9wmz6OiU28uzhtrOR2G0= X-Gm-Gg: ASbGnctWz4RGpUt1cKYnsyME/lk5qKPBMddEmbcVV7TEeYXM5QJ/6vsyXefX4k7rFD8 T2WOywwmA6tEJWFCsSdFgzVOR3OHimaJDxpJajEN74XH1hDRdW2eC0TfdgB8MIwQt8XHzlPGaUv 3SLQ2U8XBZkCWmbiMyJSUHTVwD5xH4qRkugqc9vGqvcdzN1NuxEtyjtGnVfkiF6maOa5BpgT63r AHO+yM/sN2dt/Z1xQcADZnxPgzzw2hwcfR19Icgf0yKFsWJSpSB/IcvAlq4CETayIPlMZE/Z0qE Z579snE4yE1ZDHhYralmiqFbQUJ3MNoqilutyX9bMsLoUc2jjrcG X-Google-Smtp-Source: AGHT+IHUr+7B1IcwdOT4PZcKWJWTbxssSSfP6aVq+BNGrnXsuCLIHof4HWdoHKRyx2WrgGcWh3mSgYjW2Y/uS5Myk4w= X-Received: by 2002:a05:7300:c39d:b0:2ab:ca55:b76b with SMTP id 5a478bee46e88-2abca55b835mr64485eec.6.1764982629033; Fri, 05 Dec 2025 16:57:09 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Thomas Munro Date: Sat, 6 Dec 2025 13:56:32 +1300 X-Gm-Features: AQt7F2ptngM-C_yDdeG5UXCssbHo_A7CtxPgz2kQjyTDa3Shb2aDYoXG3MggBm4 Message-ID: Subject: Re: Safer hash table initialization macro To: Jelte Fennema-Nio Cc: Bertrand Drouvot , pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Dec 6, 2025 at 3:32=E2=80=AFAM Jelte Fennema-Nio wrote: > On Fri, 5 Dec 2025 at 02:30, Thomas Munro wrote: > > How much of our header stuff is supposed to work from C++ too? > > I think it's nice if it works, but it doesn't seem the most important. > Especially since C++ has its own hashmaps. And if it really needs to > create a hashmap it's still possible to call the. ... C functions without the helper macros. Yeah. That seems OK to me. > > I suppose you could > > write the typeof-based version you already hinted at, but only use it > > for __cplusplus__ (where typeof exists as decltype). > > I tried to figure something out that would work in C++ (with help of > Claude), but I wasn't able to create a version of the macros without > also needing to add: > > #ifdef __cplusplus > } > #include > extern "C" { > #endif > > It seems quite ugly to escape the extern "C" from the parent like that > and then re-enter it. Overall it doesn't seem worth the hassle to me > to make these macros work in C++. Yeah. I don't think we want that sort of thing all over the place. We could eventually come up with a small set of tools in a central place though, so people can work with this stuff without also known C++ meta-programming voodoo. For example something like (untested, I didn't think about char[size], just spitballing here...): (pg_expr_has_type_p(ptr, char *) || pg_expr_has_type_p(ptr, NameData *)) ... given the definition I posted recently[1]. I take your point that it's not really important for this case though. > > Another consideration is what impact we have on the Rust world, and > > potentially other languages used for extensions that call C via FFI > > etc > > FFI generally cannot call macros anyway, only actual symbols. Sure, I was just thinking about how such cross-language usage would be forced to unpick our macrology and call the underlying C functions without them. Doesn't seem like the end of the world anyway, I was just thinking out loud about the consequences of this phenomenon in headers. [1] https://www.postgresql.org/message-id/CA+hUKGL7trhWiJ4qxpksBztMMTWDyPnP= 1QN+Lq341V7QL775DA@mail.gmail.com