Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf90cc26

Browse files
committed
Code beautification for object-access hook machinery.
KaiGai Kohei
1 parentf11af2b commitf90cc26

29 files changed

+123
-119
lines changed

‎src/backend/catalog/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ top_builddir = ../../..
1111
include$(top_builddir)/src/Makefile.global
1212

1313
OBJS = catalog.o dependency.o heap.o index.o indexing.o namespace.o aclchk.o\
14-
objectaddress.o pg_aggregate.o pg_collation.o pg_constraint.o pg_conversion.o\
14+
objectaccess.o objectaddress.o pg_aggregate.o pg_collation.o\
15+
pg_constraint.o pg_conversion.o\
1516
pg_depend.o pg_enum.o pg_inherits.o pg_largeobject.o pg_namespace.o\
1617
pg_operator.o pg_proc.o pg_range.o pg_db_role_setting.o pg_shdepend.o\
1718
pg_type.o storage.o toasting.o

‎src/backend/catalog/dependency.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -997,14 +997,8 @@ deleteOneObject(const ObjectAddress *object, Relation *depRel, int flags)
997997
HeapTupletup;
998998

999999
/* DROP hook of the objects being removed */
1000-
if (object_access_hook)
1001-
{
1002-
ObjectAccessDropdrop_arg;
1003-
1004-
drop_arg.dropflags=flags;
1005-
InvokeObjectAccessHook(OAT_DROP,object->classId,object->objectId,
1006-
object->objectSubId,&drop_arg);
1007-
}
1000+
InvokeObjectDropHookArg(object->classId,object->objectId,
1001+
object->objectSubId,flags);
10081002

10091003
/*
10101004
* Close depRel if we are doing a drop concurrently. The object deletion

‎src/backend/catalog/heap.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,15 +1293,7 @@ heap_create_with_catalog(const char *relname,
12931293
}
12941294

12951295
/* Post creation hook for new relation */
1296-
if (object_access_hook)
1297-
{
1298-
ObjectAccessPostCreatepost_create_args;
1299-
1300-
memset(&post_create_args,0,sizeof(ObjectAccessPostCreate));
1301-
post_create_args.is_internal=is_internal;
1302-
(*object_access_hook)(OAT_POST_CREATE,RelationRelationId,
1303-
relid,0,&post_create_args);
1304-
}
1296+
InvokeObjectPostCreateHookArg(RelationRelationId,relid,0,is_internal);
13051297

13061298
/*
13071299
* Store any supplied constraints and defaults.

‎src/backend/catalog/index.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,15 +1028,8 @@ index_create(Relation heapRelation,
10281028
}
10291029

10301030
/* Post creation hook for new index */
1031-
if (object_access_hook)
1032-
{
1033-
ObjectAccessPostCreatepost_create_args;
1034-
1035-
memset(&post_create_args,0,sizeof(ObjectAccessPostCreate));
1036-
post_create_args.is_internal=is_internal;
1037-
(*object_access_hook)(OAT_POST_CREATE,RelationRelationId,
1038-
indexRelationId,0,&post_create_args);
1039-
}
1031+
InvokeObjectPostCreateHookArg(RelationRelationId,
1032+
indexRelationId,0,is_internal);
10401033

10411034
/*
10421035
* Advance the command counter so that we can see the newly-entered

‎src/backend/catalog/objectaccess.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* -------------------------------------------------------------------------
2+
*
3+
* objectaccess.c
4+
*functions for object_access_hook on various events
5+
*
6+
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
* -------------------------------------------------------------------------
10+
*/
11+
#include"postgres.h"
12+
13+
#include"catalog/objectaccess.h"
14+
15+
/*
16+
* Hook on object accesses. This is intended as infrastructure for security
17+
* and logging plugins.
18+
*/
19+
object_access_hook_typeobject_access_hook=NULL;
20+
21+
/*
22+
* RunObjectPostCreateHook
23+
*
24+
* It is entrypoint of OAT_POST_CREATE event
25+
*/
26+
void
27+
RunObjectPostCreateHook(OidclassId,OidobjectId,intsubId,
28+
boolis_internal)
29+
{
30+
ObjectAccessPostCreatepc_arg;
31+
32+
/* caller should check, but just in case... */
33+
Assert(object_access_hook!=NULL);
34+
35+
memset(&pc_arg,0,sizeof(ObjectAccessPostCreate));
36+
pc_arg.is_internal=is_internal;
37+
38+
(*object_access_hook)(OAT_POST_CREATE,
39+
classId,objectId,subId,
40+
(void*)&pc_arg);
41+
}
42+
43+
/*
44+
* RunObjectDropHook
45+
*
46+
* It is entrypoint of OAT_DROP event
47+
*/
48+
void
49+
RunObjectDropHook(OidclassId,OidobjectId,intsubId,
50+
intdropflags)
51+
{
52+
ObjectAccessDropdrop_arg;
53+
54+
/* caller should check, but just in case... */
55+
Assert(object_access_hook!=NULL);
56+
57+
memset(&drop_arg,0,sizeof(ObjectAccessDrop));
58+
drop_arg.dropflags=dropflags;
59+
60+
(*object_access_hook)(OAT_DROP,
61+
classId,objectId,subId,
62+
(void*)&drop_arg);
63+
}

‎src/backend/catalog/pg_collation.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ CollationCreate(const char *collname, Oid collnamespace,
136136
recordDependencyOnCurrentExtension(&myself, false);
137137

138138
/* Post creation hook for new collation */
139-
InvokeObjectAccessHook(OAT_POST_CREATE,
140-
CollationRelationId,oid,0,NULL);
139+
InvokeObjectPostCreateHook(CollationRelationId,oid,0);
141140

142141
heap_freetuple(tup);
143142
heap_close(rel,RowExclusiveLock);

‎src/backend/catalog/pg_constraint.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ CreateConstraintEntry(const char *constraintName,
367367
}
368368

369369
/* Post creation hook for new constraint */
370-
InvokeObjectAccessHook(OAT_POST_CREATE,
371-
ConstraintRelationId,conOid,0,NULL);
370+
InvokeObjectPostCreateHook(ConstraintRelationId,conOid,0);
372371

373372
returnconOid;
374373
}

‎src/backend/catalog/pg_conversion.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ ConversionCreate(const char *conname, Oid connamespace,
136136
recordDependencyOnCurrentExtension(&myself, false);
137137

138138
/* Post creation hook for new conversion */
139-
InvokeObjectAccessHook(OAT_POST_CREATE,ConversionRelationId,
140-
HeapTupleGetOid(tup),0,NULL);
139+
InvokeObjectPostCreateHook(ConversionRelationId,HeapTupleGetOid(tup),0);
141140

142141
heap_freetuple(tup);
143142
heap_close(rel,RowExclusiveLock);

‎src/backend/catalog/pg_namespace.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp)
9696
recordDependencyOnCurrentExtension(&myself, false);
9797

9898
/* Post creation hook for new schema */
99-
InvokeObjectAccessHook(OAT_POST_CREATE,
100-
NamespaceRelationId,nspoid,0,NULL);
99+
InvokeObjectPostCreateHook(NamespaceRelationId,nspoid,0);
101100

102101
returnnspoid;
103102
}

‎src/backend/catalog/pg_operator.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ OperatorShellMake(const char *operatorName,
275275
heap_freetuple(tup);
276276

277277
/* Post creation hook for new shell operator */
278-
InvokeObjectAccessHook(OAT_POST_CREATE,
279-
OperatorRelationId,operatorObjectId,0,NULL);
278+
InvokeObjectPostCreateHook(OperatorRelationId,operatorObjectId,0);
280279

281280
/*
282281
* Make sure the tuple is visible for subsequent lookups/updates.
@@ -544,8 +543,7 @@ OperatorCreate(const char *operatorName,
544543
makeOperatorDependencies(tup);
545544

546545
/* Post creation hook for new operator */
547-
InvokeObjectAccessHook(OAT_POST_CREATE,
548-
OperatorRelationId,operatorObjectId,0,NULL);
546+
InvokeObjectPostCreateHook(OperatorRelationId,operatorObjectId,0);
549547

550548
heap_close(pg_operator_desc,RowExclusiveLock);
551549

‎src/backend/catalog/pg_proc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,7 @@ ProcedureCreate(const char *procedureName,
661661
heap_freetuple(tup);
662662

663663
/* Post creation hook for new function */
664-
InvokeObjectAccessHook(OAT_POST_CREATE,
665-
ProcedureRelationId,retval,0,NULL);
664+
InvokeObjectPostCreateHook(ProcedureRelationId,retval,0);
666665

667666
heap_close(rel,RowExclusiveLock);
668667

‎src/backend/catalog/pg_type.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
163163
false);
164164

165165
/* Post creation hook for new shell type */
166-
InvokeObjectAccessHook(OAT_POST_CREATE,
167-
TypeRelationId,typoid,0,NULL);
166+
InvokeObjectPostCreateHook(TypeRelationId,typoid,0);
168167

169168
/*
170169
* clean up and return the type-oid
@@ -476,8 +475,7 @@ TypeCreate(Oid newTypeOid,
476475
rebuildDeps);
477476

478477
/* Post creation hook for new type */
479-
InvokeObjectAccessHook(OAT_POST_CREATE,
480-
TypeRelationId,typeObjectId,0,NULL);
478+
InvokeObjectPostCreateHook(TypeRelationId,typeObjectId,0);
481479

482480
/*
483481
* finish up

‎src/backend/commands/aggregatecmds.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include"catalog/pg_aggregate.h"
3030
#include"catalog/pg_proc.h"
3131
#include"catalog/pg_type.h"
32+
#include"commands/alter.h"
3233
#include"commands/defrem.h"
3334
#include"miscadmin.h"
3435
#include"parser/parse_func.h"

‎src/backend/commands/dbcommands.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ createdb(const CreatedbStmt *stmt)
524524
copyTemplateDependencies(src_dboid,dboid);
525525

526526
/* Post creation hook for new database */
527-
InvokeObjectAccessHook(OAT_POST_CREATE,
528-
DatabaseRelationId,dboid,0,NULL);
527+
InvokeObjectPostCreateHook(DatabaseRelationId,dboid,0);
529528

530529
/*
531530
* Force a checkpoint before starting the copy. This will force dirty
@@ -816,14 +815,7 @@ dropdb(const char *dbname, bool missing_ok)
816815
dbname);
817816

818817
/* DROP hook for the database being removed */
819-
if (object_access_hook)
820-
{
821-
ObjectAccessDropdrop_arg;
822-
823-
memset(&drop_arg,0,sizeof(ObjectAccessDrop));
824-
InvokeObjectAccessHook(OAT_DROP,
825-
DatabaseRelationId,db_id,0,&drop_arg);
826-
}
818+
InvokeObjectDropHook(DatabaseRelationId,db_id,0);
827819

828820
/*
829821
* Disallow dropping a DB that is marked istemplate. This is just to

‎src/backend/commands/event_trigger.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ insert_event_trigger_tuple(char *trigname, char *eventname, Oid evtOwner,
310310
recordDependencyOn(&myself,&referenced,DEPENDENCY_NORMAL);
311311

312312
/* Post creation hook for new operator family */
313-
InvokeObjectAccessHook(OAT_POST_CREATE,
314-
EventTriggerRelationId,trigoid,0,NULL);
313+
InvokeObjectPostCreateHook(EventTriggerRelationId,trigoid,0);
315314

316315
/* Close pg_event_trigger. */
317316
heap_close(tgrel,RowExclusiveLock);

‎src/backend/commands/extension.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,7 @@ InsertExtensionTuple(const char *extName, Oid extOwner,
15621562
recordDependencyOn(&myself,&otherext,DEPENDENCY_NORMAL);
15631563
}
15641564
/* Post creation hook for new extension */
1565-
InvokeObjectAccessHook(OAT_POST_CREATE,
1566-
ExtensionRelationId,extensionOid,0,NULL);
1565+
InvokeObjectPostCreateHook(ExtensionRelationId,extensionOid,0);
15671566

15681567
returnextensionOid;
15691568
}

‎src/backend/commands/foreigncmds.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,7 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
599599
recordDependencyOnCurrentExtension(&myself, false);
600600

601601
/* Post creation hook for new foreign data wrapper */
602-
InvokeObjectAccessHook(OAT_POST_CREATE,
603-
ForeignDataWrapperRelationId,fdwId,0,NULL);
602+
InvokeObjectPostCreateHook(ForeignDataWrapperRelationId,fdwId,0);
604603

605604
heap_close(rel,RowExclusiveLock);
606605

@@ -900,8 +899,7 @@ CreateForeignServer(CreateForeignServerStmt *stmt)
900899
recordDependencyOnCurrentExtension(&myself, false);
901900

902901
/* Post creation hook for new foreign server */
903-
InvokeObjectAccessHook(OAT_POST_CREATE,
904-
ForeignServerRelationId,srvId,0,NULL);
902+
InvokeObjectPostCreateHook(ForeignServerRelationId,srvId,0);
905903

906904
heap_close(rel,RowExclusiveLock);
907905

@@ -1145,8 +1143,7 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
11451143
recordDependencyOnCurrentExtension(&myself, false);
11461144

11471145
/* Post creation hook for new user mapping */
1148-
InvokeObjectAccessHook(OAT_POST_CREATE,
1149-
UserMappingRelationId,umId,0,NULL);
1146+
InvokeObjectPostCreateHook(UserMappingRelationId,umId,0);
11501147

11511148
heap_close(rel,RowExclusiveLock);
11521149

‎src/backend/commands/functioncmds.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,8 +1558,7 @@ CreateCast(CreateCastStmt *stmt)
15581558
recordDependencyOnCurrentExtension(&myself, false);
15591559

15601560
/* Post creation hook for new cast */
1561-
InvokeObjectAccessHook(OAT_POST_CREATE,
1562-
CastRelationId,castid,0,NULL);
1561+
InvokeObjectPostCreateHook(CastRelationId,castid,0);
15631562

15641563
heap_freetuple(tuple);
15651564

‎src/backend/commands/opclasscmds.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
309309
recordDependencyOnCurrentExtension(&myself, false);
310310

311311
/* Post creation hook for new operator family */
312-
InvokeObjectAccessHook(OAT_POST_CREATE,
313-
OperatorFamilyRelationId,opfamilyoid,0,NULL);
312+
InvokeObjectPostCreateHook(OperatorFamilyRelationId,opfamilyoid,0);
314313

315314
heap_close(rel,RowExclusiveLock);
316315

@@ -710,8 +709,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
710709
recordDependencyOnCurrentExtension(&myself, false);
711710

712711
/* Post creation hook for new operator class */
713-
InvokeObjectAccessHook(OAT_POST_CREATE,
714-
OperatorClassRelationId,opclassoid,0,NULL);
712+
InvokeObjectPostCreateHook(OperatorClassRelationId,opclassoid,0);
715713

716714
heap_close(rel,RowExclusiveLock);
717715

‎src/backend/commands/proclang.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ create_proc_lang(const char *languageName, bool replace,
429429
}
430430

431431
/* Post creation hook for new procedural language */
432-
InvokeObjectAccessHook(OAT_POST_CREATE,
433-
LanguageRelationId,myself.objectId,0,NULL);
432+
InvokeObjectPostCreateHook(LanguageRelationId,myself.objectId,0);
434433

435434
heap_close(rel,RowExclusiveLock);
436435

‎src/backend/commands/tablecmds.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4514,8 +4514,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
45144514
heap_freetuple(reltup);
45154515

45164516
/* Post creation hook for new attribute */
4517-
InvokeObjectAccessHook(OAT_POST_CREATE,
4518-
RelationRelationId,myrelid,newattnum,NULL);
4517+
InvokeObjectPostCreateHook(RelationRelationId,myrelid,newattnum);
45194518

45204519
heap_close(pgclass,RowExclusiveLock);
45214520

‎src/backend/commands/tablespace.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
331331
recordDependencyOnOwner(TableSpaceRelationId,tablespaceoid,ownerId);
332332

333333
/* Post creation hook for new tablespace */
334-
InvokeObjectAccessHook(OAT_POST_CREATE,
335-
TableSpaceRelationId,tablespaceoid,0,NULL);
334+
InvokeObjectPostCreateHook(TableSpaceRelationId,tablespaceoid,0);
336335

337336
create_tablespace_directories(location,tablespaceoid);
338337

@@ -439,14 +438,7 @@ DropTableSpace(DropTableSpaceStmt *stmt)
439438
tablespacename);
440439

441440
/* DROP hook for the tablespace being removed */
442-
if (object_access_hook)
443-
{
444-
ObjectAccessDropdrop_arg;
445-
446-
memset(&drop_arg,0,sizeof(ObjectAccessDrop));
447-
InvokeObjectAccessHook(OAT_DROP,TableSpaceRelationId,
448-
tablespaceoid,0,&drop_arg);
449-
}
441+
InvokeObjectDropHook(TableSpaceRelationId,tablespaceoid,0);
450442

451443
/*
452444
* Remove the pg_tablespace tuple (this will roll back if we fail below)

‎src/backend/commands/trigger.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
742742
DEPENDENCY_NORMAL);
743743

744744
/* Post creation hook for new trigger */
745-
InvokeObjectAccessHook(OAT_POST_CREATE,
746-
TriggerRelationId,trigoid,0,NULL);
745+
InvokeObjectPostCreateHook(TriggerRelationId,trigoid,0);
747746

748747
/* Keep lock on target rel until end of xact */
749748
heap_close(rel,NoLock);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp