Use FLEXIBLE_ARRAY_MEMBER in struct varlena.

This forces some minor coding adjustments in tuptoaster.c and inv_api.c,
but the new coding there is cleaner anyway.

Michael Paquier
This commit is contained in:
Tom Lane 2015-02-20 16:51:53 -05:00
parent 8902f79264
commit e38b1eb098
3 changed files with 16 additions and 10 deletions

View File

@ -1365,11 +1365,13 @@ toast_save_datum(Relation rel, Datum value,
CommandId mycid = GetCurrentCommandId(true); CommandId mycid = GetCurrentCommandId(true);
struct varlena *result; struct varlena *result;
struct varatt_external toast_pointer; struct varatt_external toast_pointer;
struct union
{ {
struct varlena hdr; struct varlena hdr;
char data[TOAST_MAX_CHUNK_SIZE]; /* make struct big enough */ /* this is to make the union big enough for a chunk: */
int32 align_it; /* ensure struct is aligned well enough */ char data[TOAST_MAX_CHUNK_SIZE + VARHDRSZ];
/* ensure union is aligned well enough: */
int32 align_it;
} chunk_data; } chunk_data;
int32 chunk_size; int32 chunk_size;
int32 chunk_seq = 0; int32 chunk_seq = 0;

View File

@ -562,11 +562,13 @@ inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
bool neednextpage; bool neednextpage;
bytea *datafield; bytea *datafield;
bool pfreeit; bool pfreeit;
struct union
{ {
bytea hdr; bytea hdr;
char data[LOBLKSIZE]; /* make struct big enough */ /* this is to make the union big enough for a LO data chunk: */
int32 align_it; /* ensure struct is aligned well enough */ char data[LOBLKSIZE + VARHDRSZ];
/* ensure union is aligned well enough: */
int32 align_it;
} workbuf; } workbuf;
char *workb = VARDATA(&workbuf.hdr); char *workb = VARDATA(&workbuf.hdr);
HeapTuple newtup; HeapTuple newtup;
@ -748,11 +750,13 @@ inv_truncate(LargeObjectDesc *obj_desc, int64 len)
SysScanDesc sd; SysScanDesc sd;
HeapTuple oldtuple; HeapTuple oldtuple;
Form_pg_largeobject olddata; Form_pg_largeobject olddata;
struct union
{ {
bytea hdr; bytea hdr;
char data[LOBLKSIZE]; /* make struct big enough */ /* this is to make the union big enough for a LO data chunk: */
int32 align_it; /* ensure struct is aligned well enough */ char data[LOBLKSIZE + VARHDRSZ];
/* ensure union is aligned well enough: */
int32 align_it;
} workbuf; } workbuf;
char *workb = VARDATA(&workbuf.hdr); char *workb = VARDATA(&workbuf.hdr);
HeapTuple newtup; HeapTuple newtup;

View File

@ -391,7 +391,7 @@ typedef struct
struct varlena struct varlena
{ {
char vl_len_[4]; /* Do not touch this field directly! */ char vl_len_[4]; /* Do not touch this field directly! */
char vl_dat[1]; char vl_dat[FLEXIBLE_ARRAY_MEMBER]; /* Data content is here */
}; };
#define VARHDRSZ ((int32) sizeof(int32)) #define VARHDRSZ ((int32) sizeof(int32))