1/*-------------------------------------------------------------------------
4 * Support functions for "expanded" value representations.
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/utils/adt/expandeddatum.c
13 *-------------------------------------------------------------------------
23 * Given a Datum that is an expanded-object reference, extract the pointer.
25 * This is a bit tedious since the pointer may not be properly aligned;
26 * compare VARATT_EXTERNAL_GET_POINTER().
43 * Initialize the common header of an expanded object.
45 * The main thing this encapsulates is initializing the TOAST pointers.
71 * Convenience functions for invoking the "methods" of an expanded object.
82 void *result,
Size allocated_size)
88 * If the Datum represents a R/W expanded object, change it to R/O.
89 * Otherwise return the original Datum.
91 * Caller must ensure that the datum is a non-null varlena value. Typically
92 * this is invoked via MakeExpandedObjectReadOnly(), which checks that.
99 /* Nothing to do if not a read-write expanded-object pointer */
103 /* Now safe to extract the object pointer */
106 /* Return the built-in read-only pointer instead of given pointer */
111 * Transfer ownership of an expanded object to a new parent memory context.
112 * The object must be referenced by a R/W pointer, and what we return is
113 * always its "standard" R/W pointer, which is certain to have the same
114 * lifespan as the object itself. (The passed-in pointer might not, and
115 * in any case wouldn't provide a unique identifier if it's not that one.)
122 /* Assert caller gave a R/W pointer */
125 /* Transfer ownership */
128 /* Return the object's standard read-write pointer */
133 * Delete an expanded object (must be referenced by a R/W pointer).
140 /* Assert caller gave a R/W pointer */
ExpandedObjectHeader * DatumGetEOHP(Datum d)
void EOH_flatten_into(ExpandedObjectHeader *eohptr, void *result, Size allocated_size)
void EOH_init_header(ExpandedObjectHeader *eohptr, const ExpandedObjectMethods *methods, MemoryContext obj_context)
void DeleteExpandedObject(Datum d)
Datum TransferExpandedObject(Datum d, MemoryContext new_parent)
Datum MakeExpandedObjectReadOnlyInternal(Datum d)
Size EOH_get_flat_size(ExpandedObjectHeader *eohptr)
#define VARATT_IS_EXPANDED_HEADER(PTR)
static Datum EOHPGetRWDatum(const struct ExpandedObjectHeader *eohptr)
static Datum EOHPGetRODatum(const struct ExpandedObjectHeader *eohptr)
Assert(PointerIsAligned(start, uint64))
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
void MemoryContextDelete(MemoryContext context)
static Pointer DatumGetPointer(Datum X)
char eoh_rw_ptr[EXPANDED_POINTER_SIZE]
MemoryContext eoh_context
const ExpandedObjectMethods * eoh_methods
char eoh_ro_ptr[EXPANDED_POINTER_SIZE]
EOM_get_flat_size_method get_flat_size
EOM_flatten_into_method flatten_into
ExpandedObjectHeader * eohptr
static bool VARATT_IS_EXTERNAL_EXPANDED_RW(const void *PTR)
static char * VARDATA_EXTERNAL(const void *PTR)
static void SET_VARTAG_EXTERNAL(void *PTR, vartag_external tag)
static bool VARATT_IS_EXTERNAL_EXPANDED(const void *PTR)