From e2c0bda7e7d6994bf2ca1d414a68e9855d623011 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 22 Sep 2025 14:47:48 +0200 Subject: [PATCH 11/23] C11 anonymous unions [deparse] --- src/backend/commands/event_trigger.c | 64 +++++++++---------- src/include/tcop/deparse_utility.h | 2 +- .../test_ddl_deparse/test_ddl_deparse.c | 4 +- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c index f34868da5ab..ec42d95ce5a 100644 --- a/src/backend/commands/event_trigger.c +++ b/src/backend/commands/event_trigger.c @@ -1731,8 +1731,8 @@ EventTriggerCollectSimpleCommand(ObjectAddress address, command->type = SCT_Simple; command->in_extension = creating_extension; - command->d.simple.address = address; - command->d.simple.secondaryObject = secondaryObject; + command->simple.address = address; + command->simple.secondaryObject = secondaryObject; command->parsetree = copyObject(parsetree); currentEventTriggerState->commandList = lappend(currentEventTriggerState->commandList, @@ -1767,9 +1767,9 @@ EventTriggerAlterTableStart(Node *parsetree) command->type = SCT_AlterTable; command->in_extension = creating_extension; - command->d.alterTable.classId = RelationRelationId; - command->d.alterTable.objectId = InvalidOid; - command->d.alterTable.subcmds = NIL; + command->alterTable.classId = RelationRelationId; + command->alterTable.objectId = InvalidOid; + command->alterTable.subcmds = NIL; command->parsetree = copyObject(parsetree); command->parent = currentEventTriggerState->currentCommand; @@ -1790,7 +1790,7 @@ EventTriggerAlterTableRelid(Oid objectId) currentEventTriggerState->commandCollectionInhibited) return; - currentEventTriggerState->currentCommand->d.alterTable.objectId = objectId; + currentEventTriggerState->currentCommand->alterTable.objectId = objectId; } /* @@ -1814,7 +1814,7 @@ EventTriggerCollectAlterTableSubcmd(Node *subcmd, ObjectAddress address) Assert(IsA(subcmd, AlterTableCmd)); Assert(currentEventTriggerState->currentCommand != NULL); - Assert(OidIsValid(currentEventTriggerState->currentCommand->d.alterTable.objectId)); + Assert(OidIsValid(currentEventTriggerState->currentCommand->alterTable.objectId)); oldcxt = MemoryContextSwitchTo(currentEventTriggerState->cxt); @@ -1822,8 +1822,8 @@ EventTriggerCollectAlterTableSubcmd(Node *subcmd, ObjectAddress address) newsub->address = address; newsub->parsetree = copyObject(subcmd); - currentEventTriggerState->currentCommand->d.alterTable.subcmds = - lappend(currentEventTriggerState->currentCommand->d.alterTable.subcmds, newsub); + currentEventTriggerState->currentCommand->alterTable.subcmds = + lappend(currentEventTriggerState->currentCommand->alterTable.subcmds, newsub); MemoryContextSwitchTo(oldcxt); } @@ -1849,7 +1849,7 @@ EventTriggerAlterTableEnd(void) parent = currentEventTriggerState->currentCommand->parent; /* If no subcommands, don't collect */ - if (currentEventTriggerState->currentCommand->d.alterTable.subcmds != NIL) + if (currentEventTriggerState->currentCommand->alterTable.subcmds != NIL) { MemoryContext oldcxt; @@ -1904,7 +1904,7 @@ EventTriggerCollectGrant(InternalGrant *istmt) command = palloc(sizeof(CollectedCommand)); command->type = SCT_Grant; command->in_extension = creating_extension; - command->d.grant.istmt = icopy; + command->grant.istmt = icopy; command->parsetree = NULL; currentEventTriggerState->commandList = @@ -1935,10 +1935,10 @@ EventTriggerCollectAlterOpFam(AlterOpFamilyStmt *stmt, Oid opfamoid, command = palloc(sizeof(CollectedCommand)); command->type = SCT_AlterOpFamily; command->in_extension = creating_extension; - ObjectAddressSet(command->d.opfam.address, + ObjectAddressSet(command->opfam.address, OperatorFamilyRelationId, opfamoid); - command->d.opfam.operators = operators; - command->d.opfam.procedures = procedures; + command->opfam.operators = operators; + command->opfam.procedures = procedures; command->parsetree = (Node *) copyObject(stmt); currentEventTriggerState->commandList = @@ -1968,10 +1968,10 @@ EventTriggerCollectCreateOpClass(CreateOpClassStmt *stmt, Oid opcoid, command = palloc0(sizeof(CollectedCommand)); command->type = SCT_CreateOpClass; command->in_extension = creating_extension; - ObjectAddressSet(command->d.createopc.address, + ObjectAddressSet(command->createopc.address, OperatorClassRelationId, opcoid); - command->d.createopc.operators = operators; - command->d.createopc.procedures = procedures; + command->createopc.operators = operators; + command->createopc.procedures = procedures; command->parsetree = (Node *) copyObject(stmt); currentEventTriggerState->commandList = @@ -2002,11 +2002,11 @@ EventTriggerCollectAlterTSConfig(AlterTSConfigurationStmt *stmt, Oid cfgId, command = palloc0(sizeof(CollectedCommand)); command->type = SCT_AlterTSConfig; command->in_extension = creating_extension; - ObjectAddressSet(command->d.atscfg.address, + ObjectAddressSet(command->atscfg.address, TSConfigRelationId, cfgId); - command->d.atscfg.dictIds = palloc(sizeof(Oid) * ndicts); - memcpy(command->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts); - command->d.atscfg.ndicts = ndicts; + command->atscfg.dictIds = palloc(sizeof(Oid) * ndicts); + memcpy(command->atscfg.dictIds, dictIds, sizeof(Oid) * ndicts); + command->atscfg.ndicts = ndicts; command->parsetree = (Node *) copyObject(stmt); currentEventTriggerState->commandList = @@ -2035,7 +2035,7 @@ EventTriggerCollectAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt) command = palloc0(sizeof(CollectedCommand)); command->type = SCT_AlterDefaultPrivileges; - command->d.defprivs.objtype = stmt->action->objtype; + command->defprivs.objtype = stmt->action->objtype; command->in_extension = creating_extension; command->parsetree = (Node *) copyObject(stmt); @@ -2085,7 +2085,7 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS) * state anyway. */ if (cmd->type == SCT_Simple && - !OidIsValid(cmd->d.simple.address.objectId)) + !OidIsValid(cmd->simple.address.objectId)) continue; switch (cmd->type) @@ -2101,17 +2101,17 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS) char *schema = NULL; if (cmd->type == SCT_Simple) - addr = cmd->d.simple.address; + addr = cmd->simple.address; else if (cmd->type == SCT_AlterTable) ObjectAddressSet(addr, - cmd->d.alterTable.classId, - cmd->d.alterTable.objectId); + cmd->alterTable.classId, + cmd->alterTable.objectId); else if (cmd->type == SCT_AlterOpFamily) - addr = cmd->d.opfam.address; + addr = cmd->opfam.address; else if (cmd->type == SCT_CreateOpClass) - addr = cmd->d.createopc.address; + addr = cmd->createopc.address; else if (cmd->type == SCT_AlterTSConfig) - addr = cmd->d.atscfg.address; + addr = cmd->atscfg.address; /* * If an object was dropped in the same command we may end @@ -2199,7 +2199,7 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS) /* command tag */ values[i++] = CStringGetTextDatum(CreateCommandName(cmd->parsetree)); /* object_type */ - values[i++] = CStringGetTextDatum(stringify_adefprivs_objtype(cmd->d.defprivs.objtype)); + values[i++] = CStringGetTextDatum(stringify_adefprivs_objtype(cmd->defprivs.objtype)); /* schema */ nulls[i++] = true; /* identity */ @@ -2218,10 +2218,10 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS) /* objsubid */ nulls[i++] = true; /* command tag */ - values[i++] = CStringGetTextDatum(cmd->d.grant.istmt->is_grant ? + values[i++] = CStringGetTextDatum(cmd->grant.istmt->is_grant ? "GRANT" : "REVOKE"); /* object_type */ - values[i++] = CStringGetTextDatum(stringify_grant_objtype(cmd->d.grant.istmt->objtype)); + values[i++] = CStringGetTextDatum(stringify_grant_objtype(cmd->grant.istmt->objtype)); /* schema */ nulls[i++] = true; /* identity */ diff --git a/src/include/tcop/deparse_utility.h b/src/include/tcop/deparse_utility.h index 36510451d83..4ed83315bd9 100644 --- a/src/include/tcop/deparse_utility.h +++ b/src/include/tcop/deparse_utility.h @@ -100,7 +100,7 @@ typedef struct CollectedCommand { ObjectType objtype; } defprivs; - } d; + }; struct CollectedCommand *parent; /* when nested */ } CollectedCommand; diff --git a/src/test/modules/test_ddl_deparse/test_ddl_deparse.c b/src/test/modules/test_ddl_deparse/test_ddl_deparse.c index 193669f2bc1..d002121ada3 100644 --- a/src/test/modules/test_ddl_deparse/test_ddl_deparse.c +++ b/src/test/modules/test_ddl_deparse/test_ddl_deparse.c @@ -94,10 +94,10 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) InitMaterializedSRF(fcinfo, 0); - if (cmd->d.alterTable.subcmds == NIL) + if (cmd->alterTable.subcmds == NIL) elog(ERROR, "empty alter table subcommand list"); - foreach(cell, cmd->d.alterTable.subcmds) + foreach(cell, cmd->alterTable.subcmds) { CollectedATSubcmd *sub = lfirst(cell); AlterTableCmd *subcmd = castNode(AlterTableCmd, sub->parsetree); -- 2.51.0