mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +03:00
Make some use of anonymous unions [DSM registry].
Make some use of anonymous unions, which are allowed as of C11, as examples and encouragement for future code, and to test compilers. This commit changes the DSMRegistryEntry struct. Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://postgr.es/m/aNKsDg0fJwqhZdXX%40nathan
This commit is contained in:
@@ -98,7 +98,7 @@ typedef struct DSMRegistryEntry
|
|||||||
NamedDSMState dsm;
|
NamedDSMState dsm;
|
||||||
NamedDSAState dsa;
|
NamedDSAState dsa;
|
||||||
NamedDSHState dsh;
|
NamedDSHState dsh;
|
||||||
} data;
|
};
|
||||||
} DSMRegistryEntry;
|
} DSMRegistryEntry;
|
||||||
|
|
||||||
static const dshash_parameters dsh_params = {
|
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);
|
entry = dshash_find_or_insert(dsm_registry_table, name, found);
|
||||||
if (!(*found))
|
if (!(*found))
|
||||||
{
|
{
|
||||||
NamedDSMState *state = &entry->data.dsm;
|
NamedDSMState *state = &entry->dsm;
|
||||||
dsm_segment *seg;
|
dsm_segment *seg;
|
||||||
|
|
||||||
entry->type = DSMR_ENTRY_TYPE_DSM;
|
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)
|
else if (entry->type != DSMR_ENTRY_TYPE_DSM)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errmsg("requested DSM segment does not match type of existing entry")));
|
(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,
|
ereport(ERROR,
|
||||||
(errmsg("requested DSM segment size does not match size of existing segment")));
|
(errmsg("requested DSM segment size does not match size of existing segment")));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NamedDSMState *state = &entry->data.dsm;
|
NamedDSMState *state = &entry->dsm;
|
||||||
dsm_segment *seg;
|
dsm_segment *seg;
|
||||||
|
|
||||||
/* If the existing segment is not already attached, attach it now. */
|
/* 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);
|
entry = dshash_find_or_insert(dsm_registry_table, name, found);
|
||||||
if (!(*found))
|
if (!(*found))
|
||||||
{
|
{
|
||||||
NamedDSAState *state = &entry->data.dsa;
|
NamedDSAState *state = &entry->dsa;
|
||||||
|
|
||||||
entry->type = DSMR_ENTRY_TYPE_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")));
|
(errmsg("requested DSA does not match type of existing entry")));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NamedDSAState *state = &entry->data.dsa;
|
NamedDSAState *state = &entry->dsa;
|
||||||
|
|
||||||
if (dsa_is_attached(state->handle))
|
if (dsa_is_attached(state->handle))
|
||||||
ereport(ERROR,
|
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);
|
entry = dshash_find_or_insert(dsm_registry_table, name, found);
|
||||||
if (!(*found))
|
if (!(*found))
|
||||||
{
|
{
|
||||||
NamedDSHState *dsh_state = &entry->data.dsh;
|
NamedDSHState *dsh_state = &entry->dsh;
|
||||||
dshash_parameters params_copy;
|
dshash_parameters params_copy;
|
||||||
dsa_area *dsa;
|
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")));
|
(errmsg("requested DSHash does not match type of existing entry")));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NamedDSHState *dsh_state = &entry->data.dsh;
|
NamedDSHState *dsh_state = &entry->dsh;
|
||||||
dsa_area *dsa;
|
dsa_area *dsa;
|
||||||
|
|
||||||
/* XXX: Should we verify params matches what table was created with? */
|
/* 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.
|
* attaching to them, return NULL for those.
|
||||||
*/
|
*/
|
||||||
if (entry->type == DSMR_ENTRY_TYPE_DSM)
|
if (entry->type == DSMR_ENTRY_TYPE_DSM)
|
||||||
vals[2] = Int64GetDatum(entry->data.dsm.size);
|
vals[2] = Int64GetDatum(entry->dsm.size);
|
||||||
else
|
else
|
||||||
nulls[2] = true;
|
nulls[2] = true;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user