From 2a7b2d97171dd39dca7cefb91008a3c84ec003ba Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 26 Nov 2024 08:25:23 +0100 Subject: [PATCH] Improve InitShmemAccess() prototype The code comment said, 'the argument should be declared "PGShmemHeader *seghdr", but we use void to avoid having to include ipc.h in shmem.h.' We can achieve the original goal with a struct forward declaration. (ipc.h was also not the correct header file.) Discussion: https://www.postgresql.org/message-id/flat/cnthxg2eekacrejyeonuhiaezc7vd7o2uowlsbenxqfkjwgvwj@qgzu6eoqrglb --- src/backend/storage/ipc/shmem.c | 13 ++++--------- src/include/storage/shmem.h | 3 ++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index 6d5f0839864..50f987ae240 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -92,18 +92,13 @@ static HTAB *ShmemIndex = NULL; /* primary index hashtable for shmem */ /* * InitShmemAccess() --- set up basic pointers to shared memory. - * - * Note: the argument should be declared "PGShmemHeader *seghdr", - * but we use void to avoid having to include ipc.h in shmem.h. */ void -InitShmemAccess(void *seghdr) +InitShmemAccess(PGShmemHeader *seghdr) { - PGShmemHeader *shmhdr = (PGShmemHeader *) seghdr; - - ShmemSegHdr = shmhdr; - ShmemBase = (void *) shmhdr; - ShmemEnd = (char *) ShmemBase + shmhdr->totalsize; + ShmemSegHdr = seghdr; + ShmemBase = seghdr; + ShmemEnd = (char *) ShmemBase + seghdr->totalsize; } /* diff --git a/src/include/storage/shmem.h b/src/include/storage/shmem.h index 842989111c3..8cdbe7a89c8 100644 --- a/src/include/storage/shmem.h +++ b/src/include/storage/shmem.h @@ -27,7 +27,8 @@ /* shmem.c */ extern PGDLLIMPORT slock_t *ShmemLock; -extern void InitShmemAccess(void *seghdr); +struct PGShmemHeader; /* avoid including storage/pg_shmem.h here */ +extern void InitShmemAccess(struct PGShmemHeader *seghdr); extern void InitShmemAllocation(void); extern void *ShmemAlloc(Size size); extern void *ShmemAllocNoError(Size size); -- 2.30.2