Get rid of anonymous struct
authorJohn Naylor <john.naylor@postgresql.org>
Tue, 9 Apr 2024 09:16:01 +0000 (16:16 +0700)
committerJohn Naylor <john.naylor@postgresql.org>
Tue, 9 Apr 2024 09:16:01 +0000 (16:16 +0700)
This is a C11 feature, and we require C99. While at it, go the further
step and get rid of the surrounding union (with uintptr_t) entirely,
as there is currently no use case for this file to access the header of
BlocktableEntry as a uintptr_t, and there are no additional alignment
requirements. The least invasive way seems to be to transfer the old
union name to this struct.

Reported by Pavel Borisov and Andres Freund, per buildfarm member mylodon
Reviewed by Pavel Borisov

Discussion: https://postgr.es/m/CALT9ZEH11NYV8AOzKb1bWhCf6J0H=H31f0MgT9xX+HdqvcA1rw@mail.gmail.com

src/backend/access/common/tidstore.c

index cddbaf013bcc715a70a3ac2c349457e115f9184e..fb3949d69f69fb1200ddd1d49634457891bcb16f 100644 (file)
  */
 typedef struct BlocktableEntry
 {
-   union
+   struct
    {
-       struct
-       {
 #ifndef WORDS_BIGENDIAN
-           /*
-            * We need to position this member so that the backing radix tree
-            * can use the lowest bit for a pointer tag. In particular, it
-            * must be placed within 'header' so that it corresponds to the
-            * lowest byte in 'ptr'. We position 'nwords' along with it to
-            * avoid struct padding.
-            */
-           uint8       flags;
-
-           int8        nwords;
+       /*
+        * We need to position this member to reserve space for the backing
+        * radix tree to tag the lowest bit when struct 'header' is stored
+        * inside a pointer or DSA pointer.
+        */
+       uint8       flags;
+
+       int8        nwords;
 #endif
 
-           /*
-            * We can store a small number of offsets here to avoid wasting
-            * space with a sparse bitmap.
-            */
-           OffsetNumber full_offsets[NUM_FULL_OFFSETS];
+       /*
+        * We can store a small number of offsets here to avoid wasting space
+        * with a sparse bitmap.
+        */
+       OffsetNumber full_offsets[NUM_FULL_OFFSETS];
 
 #ifdef WORDS_BIGENDIAN
-           int8        nwords;
-           uint8       flags;
+       int8        nwords;
+       uint8       flags;
 #endif
-       };
-       uintptr_t   ptr;
    }           header;
 
+   /*
+    * We don't expect any padding space here, but to be cautious, code
+    * creating new entries should zero out space up to 'words'.
+    */
+
    bitmapword  words[FLEXIBLE_ARRAY_MEMBER];
 } BlocktableEntry;