Skip to content

Commit f90cc26

Browse files
committed
Code beautification for object-access hook machinery.
KaiGai Kohei
1 parent f11af2b commit f90cc26

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
HeapTuple tup;
998998

999999
/* DROP hook of the objects being removed */
1000-
if (object_access_hook)
1001-
{
1002-
ObjectAccessDrop drop_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-
ObjectAccessPostCreate post_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-
ObjectAccessPostCreate post_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_type object_access_hook = NULL;
20+
21+
/*
22+
* RunObjectPostCreateHook
23+
*
24+
* It is entrypoint of OAT_POST_CREATE event
25+
*/
26+
void
27+
RunObjectPostCreateHook(Oid classId, Oid objectId, int subId,
28+
bool is_internal)
29+
{
30+
ObjectAccessPostCreate pc_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(Oid classId, Oid objectId, int subId,
50+
int dropflags)
51+
{
52+
ObjectAccessDrop drop_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
return conOid;
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
return nspoid;
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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy