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 1w075T-001cwZ-1I for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Mar 2026 00:06:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w075Q-006l4g-0s for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Mar 2026 00:06:04 +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 1w075P-006l4X-3A for pgsql-hackers@lists.postgresql.org; Wed, 11 Mar 2026 00:06:04 +0000 Received: from mail-dy1-x132e.google.com ([2607:f8b0:4864:20::132e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w075O-0000000237H-01Oa for pgsql-hackers@lists.postgresql.org; Wed, 11 Mar 2026 00:06:04 +0000 Received: by mail-dy1-x132e.google.com with SMTP id 5a478bee46e88-2be0f64a05bso576174eec.3 for ; Tue, 10 Mar 2026 17:06:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773187559; cv=none; d=google.com; s=arc-20240605; b=X++y9myLQAkEd6PbDNpiVM33jaiOB2AhVvufn6jilUir5d5Qi8YPRCOF9dfINYUX8/ vGbZBMOuotf/NqsYT/HnJuNnucVNfxN4Iq/Y83dRfXAtqi7KdzBG8ERySA9qbS4npSwY 3bpkbCfpZ5TnYvM+EMpDoyEKkvI2YHUG7xQt4EzqwAs+rPeWyW1B2a/uLbLUJxliG6wB n6k8uxIvBJj9eECdw1gxGz+o7GoE6ToRoup4QeUTTFKu0qftB1jfhVyTlZHJL5XXSkFM PqASxPGR5t7woOSdNA7bnAkBZq+XjbhYo/SdDL+bK2cXFCalZXwq8yY2akYa2sOk3jEq 7J2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=qMyBcjbdDT+ddBMeyeLfAe5xGYumQoVoQ0hMX9gGanU=; fh=+N6pHTXQ7ysfPeo6EEV8iKT0Ru2blLyR87+Wv0CrkR8=; b=BMaUatfApctg546LBHfzZLtIK1UBsYkIBlFomn1wYqeaTZT3PoybjKXtQXlF8ke+qE fcWZGq90PHW0QrgAp5iJJzVLgfiIOd6lA3WrrWL558f7TAfmJzas1Ij25dGh7AbAHE9y HO88ZD06mdVoNRJyjtNSa72fbHJOLBB9ceeAd8YaE3IhKdkqcN8pqk6aTWqjDmi5JO7d c/tv7WA76P9kdpDj9erArnXMLIJ+jIg479jB3YPSOu1nEmaMf5icM6raSXe8MZNW00HZ UXUYSVpoVCnhII5A7chBi6N7mVzS+owOx5jUAJ7PS3NtAzBkv9FPfutVVFfAXJjBB03e ++tw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773187559; x=1773792359; 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=qMyBcjbdDT+ddBMeyeLfAe5xGYumQoVoQ0hMX9gGanU=; b=cetqCsGHv6k/dFTKEItNd4NY3dXJV8Uao0s7tS1xtWkfHzpm31GeTc29AczrDR6MZ9 4c+BKAprs/xEylafg680MtUxZEVmfdlMnl2UGZALxnsEDvK8oYRkkgHpXXIuW1dTM/Th aPFV0xe3E1MrIb6KC3DZf94aiD/MGa53hIFd21wVGQs0AGXtz6dkrrf0ass8U8CdZC3O QzFe8YZCHkN0HM0GZy/337aL5qWHCMadohUipQ9YpKFsbqRd7Z6kytAMh8YwNqD87aSL 4gZMTgKZFsCk4mV2NugX+/BBggpYN+GSqt9u0Ac3wX7Z9Cj0y/pqKSv/3nJQeuzf11MH L6uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773187559; x=1773792359; 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=qMyBcjbdDT+ddBMeyeLfAe5xGYumQoVoQ0hMX9gGanU=; b=q5xbAvHcKJC7696uvaCuG0NUmkJNPsvGGjtvif6uo17YIYg+I9AWDlvh96kzxmEUF7 tSIYGPO+SLohVq9tiAW3uin/sB7yZBa/hubueODxFCGP9lnTmYbYnu7ah47J/h0VcrbN zBQpJEsLjqUeXMbcb7SkzJmp1uDU+1i3gQzrBdp5C9227m0d5vdBNrxvaF5LedmoReQy r5OleORvXpFfCaoThy3/q1SSuD2puba7WqUGk9UCjmzcgQ+xnbB1d4XVDrSF1GS8/MPb Gvvi4AtKPBXp3IqNTWli3EVp0GovTRrutMG8E4QQHQITKdDgRV0QJTfhgj0Q+ITJIIGN Vutg== X-Forwarded-Encrypted: i=1; AJvYcCU1cFaB35/krhU+yD6fdRDO/3uDh6GTVfxeHrKD6FQ+XpUEJHdzY0YSwLFaOWp+EQiIUkuEhJ1pFY6fCvsn@lists.postgresql.org X-Gm-Message-State: AOJu0YwxngOtlsqKtkXfwVtX+8Jypzxcg3xOznFw3/p2IaFU2g4PlzLI FAmDUcLzihihuCGSZoGUjkRooAHOd4DwUkx5Z3qxk51mH6t9PjLSkrcs6Y7mLRYc8rIwFtfr3RO CSjta84twaU9t5TD6v+m7tcbQd9VQ3ONPNZ4q X-Gm-Gg: ATEYQzydZdFqkUyVIcfJr/+NcOzuHr9DQfpRcgsDyANDY7eDd0JXHrMZF28RvEaWuyg 7hfFR3uwoKM4lfbgL3cDnrTSNRZTZpMNIzXZQxa6CkKNGa417Xqvx86ov5dV0fyz8N8ApXOq9Yg bCQn6xQGqaoQlhtQnTNikiL6X+Ulx+LcIAu0y30Sz6JZJsCNdt67RXVtMZysqqUFHRj0p/TLwFT +B5+YUoAO2Mi728qdbO/f6Uytd4wKtzw5U01onlPHdFntA+7YWiCssmUb7zX+0AjZ4AclBk4WEb JU6JjV3JO1i86oDThvFlgmO3Eq8iT45ChGI0U5CXKYYFJF8+qEuXLnajqmVRHcQH3UH5FdEAlCk = X-Received: by 2002:a05:7301:2b06:b0:2be:80c4:2c8d with SMTP id 5a478bee46e88-2be8a1e3372mr172755eec.2.1773187558874; Tue, 10 Mar 2026 17:05:58 -0700 (PDT) MIME-Version: 1.0 References: <854785.1772206539@sss.pgh.pa.us> In-Reply-To: From: Thomas Munro Date: Wed, 11 Mar 2026 13:05:22 +1300 X-Gm-Features: AaiRm51_CgDuAXN3lKvSuoH_EwRJ0ghyk1YiPF_eXutfLQmhi0lbWJsXsjeqsiM Message-ID: Subject: Re: A stack allocation API To: Andres Freund Cc: Tom Lane , PostgreSQL Hackers 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, Feb 28, 2026 at 7:02=E2=80=AFAM Andres Freund = wrote: > I wish msvc implemented something akin to gcc/clang's > attribute(cleanup(cleanup_function)), but it doesn't look like it > does. Obviously it would if we were to compile with C++, but I don't thin= k > anybody has appetite for the work it'd need to get there. Well, it does have __try/__finally, but the future of the idea for C2y looks like Go or Zig: #include p =3D malloc(); defer free(p); It's already available in bleeding edge GCC and Clang 22, based on the TS 25755 draft[1]. Unfortunately for the real world, it's annoyingly difficult to come up with *nice* looking macros that can expand to the dialects we'd need to cover even if we were OK with abandoning the notion of supporting C < 2y compilers other than the 3 we talk about, due to syntactic structure and semantic differences, presumably: 1. C2y defer 2. C++ RAII 3. GCC/Clang cleanup attributes 4. MSVC __try/__finally But with big honking framing macros BEGIN_MAGIC_PIXIE_DUST(), ... pg_defer_pfree(p) (assuming we'd want a style with a pathway to the future standard?); ... END_MAGIC_PIXIE_DUST(), I think it's probably doable... There are lots of people trying to suffer through portable-enough-for-me and just-enough-functionality-for-my-project, maybe some inspiration[2]... [1] https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3734.pdf [2] https://antonz.org/defer-in-c/