Cleanup gcc trick with varattrib_1b_e in VARATT_EXTERNAL_GET_POINTER() - Mailing list pgsql-hackers

From Michael Paquier
Subject Cleanup gcc trick with varattrib_1b_e in VARATT_EXTERNAL_GET_POINTER()
Date
Msg-id aEaZf_45j-D_HNw5@paquier.xyz
Whole thread Raw
Responses Re: Cleanup gcc trick with varattrib_1b_e in VARATT_EXTERNAL_GET_POINTER()
List pgsql-hackers
Hi,

Back in b89e151054a0, the following macro has been introduced to
retrieve the varatt_external of an on-disk external TOAST Datum, stuff
now in detoast.h:
/*
 * Macro to fetch the possibly-unaligned contents of an EXTERNAL datum
 * into a local "struct varatt_external" toast pointer.  This should be
 * just a memcpy, but some versions of gcc seem to produce broken code
 * that assumes the datum contents are aligned.  Introducing an explicit
 * intermediate "varattrib_1b_e *" variable seems to fix it.
 */
#define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr) \
do { \
    varattrib_1b_e *attre = (varattrib_1b_e *) (attr); \
    Assert(VARATT_IS_EXTERNAL(attre)); \
    Assert(VARSIZE_EXTERNAL(attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL); \
    memcpy(&(toast_pointer), VARDATA_EXTERNAL(attre), sizeof(toast_pointer)); \
} while (0)

I vaguely recall that this has been mentioned during the unconference
session dedicated to TOAST, or perhaps not.  Anyway, I've just bumped
into that again while working on this area, and I am wondering if this
is relevant these days.

varattrib_1b_e should never be referenced directly in the code, so it
would be nice to clean up things like in the attached.  The CI is OK
with that, which is not the buildfarm but it's a start.

Comments or opinions?
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: wenhui qiu
Date:
Subject: Re: [PATCH] Refactor: Extract XLogRecord info
Next
From: Fujii Masao
Date:
Subject: Re: Extend COPY FROM with HEADER to skip multiple lines