]> granicus.if.org Git - postgresql/commitdiff
Some more FLEXIBLE_ARRAY_MEMBER hacking.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 20 Feb 2015 07:28:03 +0000 (02:28 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 20 Feb 2015 07:28:03 +0000 (02:28 -0500)
src/backend/utils/adt/rowtypes.c

index 3dc9a843bf06d412efa3e5946c99b949b419765f..a65e18d4040b7133fd4e294660f608e9dcd05d0b 100644 (file)
@@ -43,7 +43,7 @@ typedef struct RecordIOData
        Oid                     record_type;
        int32           record_typmod;
        int                     ncolumns;
-       ColumnIOData columns[1];        /* VARIABLE LENGTH ARRAY */
+       ColumnIOData columns[FLEXIBLE_ARRAY_MEMBER];
 } RecordIOData;
 
 /*
@@ -61,7 +61,7 @@ typedef struct RecordCompareData
        int32           record1_typmod;
        Oid                     record2_type;
        int32           record2_typmod;
-       ColumnCompareData columns[1];           /* VARIABLE LENGTH ARRAY */
+       ColumnCompareData columns[FLEXIBLE_ARRAY_MEMBER];
 } RecordCompareData;
 
 
@@ -120,8 +120,8 @@ record_in(PG_FUNCTION_ARGS)
        {
                fcinfo->flinfo->fn_extra =
                        MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
-                                                          sizeof(RecordIOData) - sizeof(ColumnIOData)
-                                                          ncolumns * sizeof(ColumnIOData));
+                                                          offsetof(RecordIOData, columns) +
+                                                          ncolumns * sizeof(ColumnIOData));
                my_extra = (RecordIOData *) fcinfo->flinfo->fn_extra;
                my_extra->record_type = InvalidOid;
                my_extra->record_typmod = 0;
@@ -131,8 +131,8 @@ record_in(PG_FUNCTION_ARGS)
                my_extra->record_typmod != tupTypmod)
        {
                MemSet(my_extra, 0,
-                          sizeof(RecordIOData) - sizeof(ColumnIOData)
-                          ncolumns * sizeof(ColumnIOData));
+                          offsetof(RecordIOData, columns) +
+                          ncolumns * sizeof(ColumnIOData));
                my_extra->record_type = tupType;
                my_extra->record_typmod = tupTypmod;
                my_extra->ncolumns = ncolumns;
@@ -334,8 +334,8 @@ record_out(PG_FUNCTION_ARGS)
        {
                fcinfo->flinfo->fn_extra =
                        MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
-                                                          sizeof(RecordIOData) - sizeof(ColumnIOData)
-                                                          ncolumns * sizeof(ColumnIOData));
+                                                          offsetof(RecordIOData, columns) +
+                                                          ncolumns * sizeof(ColumnIOData));
                my_extra = (RecordIOData *) fcinfo->flinfo->fn_extra;
                my_extra->record_type = InvalidOid;
                my_extra->record_typmod = 0;
@@ -345,8 +345,8 @@ record_out(PG_FUNCTION_ARGS)
                my_extra->record_typmod != tupTypmod)
        {
                MemSet(my_extra, 0,
-                          sizeof(RecordIOData) - sizeof(ColumnIOData)
-                          ncolumns * sizeof(ColumnIOData));
+                          offsetof(RecordIOData, columns) +
+                          ncolumns * sizeof(ColumnIOData));
                my_extra->record_type = tupType;
                my_extra->record_typmod = tupTypmod;
                my_extra->ncolumns = ncolumns;
@@ -489,8 +489,8 @@ record_recv(PG_FUNCTION_ARGS)
        {
                fcinfo->flinfo->fn_extra =
                        MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
-                                                          sizeof(RecordIOData) - sizeof(ColumnIOData)
-                                                          ncolumns * sizeof(ColumnIOData));
+                                                          offsetof(RecordIOData, columns) +
+                                                          ncolumns * sizeof(ColumnIOData));
                my_extra = (RecordIOData *) fcinfo->flinfo->fn_extra;
                my_extra->record_type = InvalidOid;
                my_extra->record_typmod = 0;
@@ -500,8 +500,8 @@ record_recv(PG_FUNCTION_ARGS)
                my_extra->record_typmod != tupTypmod)
        {
                MemSet(my_extra, 0,
-                          sizeof(RecordIOData) - sizeof(ColumnIOData)
-                          ncolumns * sizeof(ColumnIOData));
+                          offsetof(RecordIOData, columns) +
+                          ncolumns * sizeof(ColumnIOData));
                my_extra->record_type = tupType;
                my_extra->record_typmod = tupTypmod;
                my_extra->ncolumns = ncolumns;
@@ -677,8 +677,8 @@ record_send(PG_FUNCTION_ARGS)
        {
                fcinfo->flinfo->fn_extra =
                        MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
-                                                          sizeof(RecordIOData) - sizeof(ColumnIOData)
-                                                          ncolumns * sizeof(ColumnIOData));
+                                                          offsetof(RecordIOData, columns) +
+                                                          ncolumns * sizeof(ColumnIOData));
                my_extra = (RecordIOData *) fcinfo->flinfo->fn_extra;
                my_extra->record_type = InvalidOid;
                my_extra->record_typmod = 0;
@@ -688,8 +688,8 @@ record_send(PG_FUNCTION_ARGS)
                my_extra->record_typmod != tupTypmod)
        {
                MemSet(my_extra, 0,
-                          sizeof(RecordIOData) - sizeof(ColumnIOData)
-                          ncolumns * sizeof(ColumnIOData));
+                          offsetof(RecordIOData, columns) +
+                          ncolumns * sizeof(ColumnIOData));
                my_extra->record_type = tupType;
                my_extra->record_typmod = tupTypmod;
                my_extra->ncolumns = ncolumns;
@@ -829,8 +829,8 @@ record_cmp(FunctionCallInfo fcinfo)
        {
                fcinfo->flinfo->fn_extra =
                        MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
-                                               sizeof(RecordCompareData) - sizeof(ColumnCompareData)
-                                                          ncols * sizeof(ColumnCompareData));
+                                                          offsetof(RecordCompareData, columns) +
+                                                          ncols * sizeof(ColumnCompareData));
                my_extra = (RecordCompareData *) fcinfo->flinfo->fn_extra;
                my_extra->ncolumns = ncols;
                my_extra->record1_type = InvalidOid;
@@ -1065,8 +1065,8 @@ record_eq(PG_FUNCTION_ARGS)
        {
                fcinfo->flinfo->fn_extra =
                        MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
-                                               sizeof(RecordCompareData) - sizeof(ColumnCompareData)
-                                                          ncols * sizeof(ColumnCompareData));
+                                                          offsetof(RecordCompareData, columns) +
+                                                          ncols * sizeof(ColumnCompareData));
                my_extra = (RecordCompareData *) fcinfo->flinfo->fn_extra;
                my_extra->ncolumns = ncols;
                my_extra->record1_type = InvalidOid;
@@ -1324,8 +1324,8 @@ record_image_cmp(FunctionCallInfo fcinfo)
        {
                fcinfo->flinfo->fn_extra =
                        MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
-                                               sizeof(RecordCompareData) - sizeof(ColumnCompareData)
-                                                          ncols * sizeof(ColumnCompareData));
+                                                          offsetof(RecordCompareData, columns) +
+                                                          ncols * sizeof(ColumnCompareData));
                my_extra = (RecordCompareData *) fcinfo->flinfo->fn_extra;
                my_extra->ncolumns = ncols;
                my_extra->record1_type = InvalidOid;
@@ -1601,8 +1601,8 @@ record_image_eq(PG_FUNCTION_ARGS)
        {
                fcinfo->flinfo->fn_extra =
                        MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
-                                               sizeof(RecordCompareData) - sizeof(ColumnCompareData)
-                                                          ncols * sizeof(ColumnCompareData));
+                                                          offsetof(RecordCompareData, columns) +
+                                                          ncols * sizeof(ColumnCompareData));
                my_extra = (RecordCompareData *) fcinfo->flinfo->fn_extra;
                my_extra->ncolumns = ncols;
                my_extra->record1_type = InvalidOid;