Improve InitShmemAccess()
authorPeter Eisentraut <[email protected]>
Tue, 26 Nov 2024 07:25:23 +0000 (08:25 +0100)
committerPeter Eisentraut <[email protected]>
Tue, 26 Nov 2024 07:46:22 +0000 (08:46 +0100)
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
src/include/storage/shmem.h

index 6d5f08398641cf0d35256590cb13449c3d1c08dc..50f987ae2404ffcc98f892321e9b250a0e2273aa 100644 (file)
@@ -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;
 }
 
 /*
index 842989111c31a5473ebe57083572125ae3dab201..8cdbe7a89c82d3f8ffd32e35e919d74c0abef2c8 100644 (file)
@@ -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);