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 1v13qB-004Ac9-7t for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Sep 2025 14:17:59 +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 1v13q9-0061iL-TI for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Sep 2025 14:17:57 +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 1v13q9-0061iA-Hj for pgsql-hackers@lists.postgresql.org; Tue, 23 Sep 2025 14:17:57 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v13q5-002O6z-2v for pgsql-hackers@postgresql.org; Tue, 23 Sep 2025 14:17:57 +0000 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-42486ed0706so23693235ab.0 for ; Tue, 23 Sep 2025 07:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758637073; x=1759241873; darn=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=QKS2KJLoS24Ai1p9jFyBLI0zlpi1xucVD1LtZtcFBmY=; b=eFNGxqMyj5BirXEJEqBZ8ZF/EnhFyrNd8qBf6JnpAdwU8giMhiQTRujahVPfHkHPzZ yCJ5/VfFW48kKzNhqvqkF9K4OExpje4H758mE+jtiOmEh61YAowgxefsLggsiMh7VEba K6wIO/sJ2Jp4pqtMj3K/MRGbepSr7imuZLM/VZf1svRxQ9+EzxOwIXQUAiQ1ZODt184L 9Uv2DigqYX9oCjh7DfedtDcU6tDXsC75OjHJ5dJh3QE9rLx9VRK27iMlpy250SHLAcJz Qn0eRGI1iG2Zrke3HJ40NW2kL6dyMfAnVxbxdpMtgCOEjjbkFxxSYANTfk9b9m2t9bxf X8cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758637073; x=1759241873; 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=QKS2KJLoS24Ai1p9jFyBLI0zlpi1xucVD1LtZtcFBmY=; b=EQVSZ38GXzE6NzcceaXnF9fPXGePQ01WRZBl/UjwodZrEgrZwUHmsl3/LvFsWadJQq H3/fi/mQNUKk3w7899RpMYsm9kLnXOUz7nylVZ2zs8Lz8TLridTF2fi5bNen+aQcpyHD ahFrQbt8p/lttOc1GeXIT3MiLCz2A/ykJqrv6y95h9mWACwFOimPGEUMKg2vTlyrttXk nbFeLy55iPXAgG56ME1GaEq8it0ut8HI9E+QNQ1GZYSlngZBgfo/D9wsp3JIotaf4E6s beDsuZaep/MjOikJDjewOPUklFHK+A2L/NhJMWyBlc3EvmC+zKMZqkC0nxgtTP7QQATF C8MQ== X-Gm-Message-State: AOJu0Yye+29PfRk6QLUbwWMh/W0lcSw5+RuOiNjXa8HxTjTUJa1zZbZz 5VZ9Q8S6aZCIjLc0BjywJBJ2f1+9OF84IRCvHUkrlYDbdMAr6BlP+n2g X-Gm-Gg: ASbGncv/kmlFnQ4Wbi6yuN6BhjsirUEHmuiquaNKFqpEYfBiGjQdIze2eHwLQPq/ypU 48Hg7JhU0FVmZ4sre64dv+7rdqcm4VawblNxlskipcKeg0FF5aViv3eeF4TbwAhKkW9E2hZydk7 ch/cZOwuXeB3IY5Gu6YgXrUrH9Mwz6sJzDVqVojiwycZjrBWYH8pR1LDcWN6I4EDkFmMcf/WXIz A1vrrCNF7foayWs4rconGMQoVMwpPqwafIBCNZZplPpgCm59w1OPK/j8hUVlVp3UvuKL+k5G5wi N+qXX/Qie3Tpg7mUjW+WH+/11sIx2Vfol61YmOS+wCkuI28Q8D1GVnQ2nDUdc42TAtd79i72T98 EiOXIlVzTh9KkX02BByhqjnp/tA5VLeVUHRc+IhPmv6/YDRX7wqZE2eqfz0G4tb1fLNg8JOBdiR Xr3iasR43+3gwI X-Google-Smtp-Source: AGHT+IH93zI9YExDE+FeYiTTWmTto8x/Be/ILj84Wzbv14LVYq/DaFmjNV21BSc/Px/axVCslwb5nw== X-Received: by 2002:a05:6e02:1949:b0:407:dc0b:7ba2 with SMTP id e9e14a558f8ab-42581e116a1mr42609955ab.3.1758637072709; Tue, 23 Sep 2025 07:17:52 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-424819d4f74sm62385415ab.34.2025.09.23.07.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Sep 2025 07:17:51 -0700 (PDT) Date: Tue, 23 Sep 2025 09:17:50 -0500 From: Nathan Bossart To: Peter Eisentraut Cc: pgsql-hackers Subject: Re: anonymous unions (C11) Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2SNfCC13RkeYbxv+" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --2SNfCC13RkeYbxv+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Sep 23, 2025 at 11:38:22AM +0200, Peter Eisentraut wrote: > That said, I did go overboard here and converted all the struct/union > combinations I could find, but I'm not necessarily proposing to apply > all of them. I'm proposing patches 0001 through 0004, which are > relatively simple or in areas that have already changed a few times > recently (so backpatching would not be trivial anyway), and/or they > are somewhat close to my heart because they originally motivated this > work a long time ago. But if someone finds among the other patches > one that they particularly like, we could add that one as well. I would have used this in the DSM registry if it was available. Patch attached. -- nathan --2SNfCC13RkeYbxv+ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=0001-C11-anonymous-unions-DSM-registry.patch From 4d28101c17fd94761069009ef04017bc022e1b13 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 23 Sep 2025 09:15:21 -0500 Subject: [PATCH 1/1] C11 anonymous unions [DSM registry] --- src/backend/storage/ipc/dsm_registry.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/backend/storage/ipc/dsm_registry.c b/src/backend/storage/ipc/dsm_registry.c index 97130925106..a926b9c3f32 100644 --- a/src/backend/storage/ipc/dsm_registry.c +++ b/src/backend/storage/ipc/dsm_registry.c @@ -98,7 +98,7 @@ typedef struct DSMRegistryEntry NamedDSMState dsm; NamedDSAState dsa; NamedDSHState dsh; - } data; + }; } DSMRegistryEntry; static const dshash_parameters dsh_params = { @@ -212,7 +212,7 @@ GetNamedDSMSegment(const char *name, size_t size, entry = dshash_find_or_insert(dsm_registry_table, name, found); if (!(*found)) { - NamedDSMState *state = &entry->data.dsm; + NamedDSMState *state = &entry->dsm; dsm_segment *seg; entry->type = DSMR_ENTRY_TYPE_DSM; @@ -232,12 +232,12 @@ GetNamedDSMSegment(const char *name, size_t size, else if (entry->type != DSMR_ENTRY_TYPE_DSM) ereport(ERROR, (errmsg("requested DSM segment does not match type of existing entry"))); - else if (entry->data.dsm.size != size) + else if (entry->dsm.size != size) ereport(ERROR, (errmsg("requested DSM segment size does not match size of existing segment"))); else { - NamedDSMState *state = &entry->data.dsm; + NamedDSMState *state = &entry->dsm; dsm_segment *seg; /* If the existing segment is not already attached, attach it now. */ @@ -294,7 +294,7 @@ GetNamedDSA(const char *name, bool *found) entry = dshash_find_or_insert(dsm_registry_table, name, found); if (!(*found)) { - NamedDSAState *state = &entry->data.dsa; + NamedDSAState *state = &entry->dsa; entry->type = DSMR_ENTRY_TYPE_DSA; @@ -314,7 +314,7 @@ GetNamedDSA(const char *name, bool *found) (errmsg("requested DSA does not match type of existing entry"))); else { - NamedDSAState *state = &entry->data.dsa; + NamedDSAState *state = &entry->dsa; if (dsa_is_attached(state->handle)) ereport(ERROR, @@ -367,7 +367,7 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found) entry = dshash_find_or_insert(dsm_registry_table, name, found); if (!(*found)) { - NamedDSHState *dsh_state = &entry->data.dsh; + NamedDSHState *dsh_state = &entry->dsh; dshash_parameters params_copy; dsa_area *dsa; @@ -395,7 +395,7 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found) (errmsg("requested DSHash does not match type of existing entry"))); else { - NamedDSHState *dsh_state = &entry->data.dsh; + NamedDSHState *dsh_state = &entry->dsh; dsa_area *dsa; /* XXX: Should we verify params matches what table was created with? */ @@ -447,7 +447,7 @@ pg_get_dsm_registry_allocations(PG_FUNCTION_ARGS) * attaching to them, return NULL for those. */ if (entry->type == DSMR_ENTRY_TYPE_DSM) - vals[2] = Int64GetDatum(entry->data.dsm.size); + vals[2] = Int64GetDatum(entry->dsm.size); else nulls[2] = true; -- 2.39.5 (Apple Git-154) --2SNfCC13RkeYbxv+--