PostgreSQL Source Code  git master
expandeddatum.c File Reference
#include "postgres.h"
#include "utils/expandeddatum.h"
#include "utils/memutils.h"
Include dependency graph for expandeddatum.c:

Go to the source code of this file.

Functions

ExpandedObjectHeaderDatumGetEOHP (Datum d)
 
void EOH_init_header (ExpandedObjectHeader *eohptr, const ExpandedObjectMethods *methods, MemoryContext obj_context)
 
Size EOH_get_flat_size (ExpandedObjectHeader *eohptr)
 
void EOH_flatten_into (ExpandedObjectHeader *eohptr, void *result, Size allocated_size)
 
Datum MakeExpandedObjectReadOnlyInternal (Datum d)
 
Datum TransferExpandedObject (Datum d, MemoryContext new_parent)
 
void DeleteExpandedObject (Datum d)
 

Function Documentation

◆ DatumGetEOHP()

ExpandedObjectHeader* DatumGetEOHP ( Datum  d)

Definition at line 29 of file expandeddatum.c.

References Assert, DatumGetPointer, varatt_expanded::eohptr, VARATT_IS_EXPANDED_HEADER, VARATT_IS_EXTERNAL_EXPANDED, and VARDATA_EXTERNAL.

Referenced by advance_transition_function(), advance_windowaggregate(), advance_windowaggregate_base(), array_get_element_expanded(), coerce_function_result_tuple(), construct_empty_expanded_array(), datumCopy(), datumEstimateSpace(), DatumGetAnyArrayP(), DatumGetExpandedArray(), DatumGetExpandedArrayX(), DatumGetExpandedRecord(), datumSerialize(), DeleteExpandedObject(), exec_move_row_from_datum(), ExecAggTransReparent(), ExecEvalFieldSelect(), expand_array(), fill_val(), heap_compute_data_size(), heap_tuple_fetch_attr(), MakeExpandedObjectReadOnlyInternal(), plpgsql_exec_trigger(), toast_datum_size(), toast_raw_datum_size(), and TransferExpandedObject().

30 {
32  varatt_expanded ptr;
33 
35  memcpy(&ptr, VARDATA_EXTERNAL(datum), sizeof(ptr));
37  return ptr.eohptr;
38 }
ExpandedObjectHeader * eohptr
Definition: postgres.h:103
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:322
#define VARDATA_EXTERNAL(PTR)
Definition: postgres.h:310
#define Assert(condition)
Definition: c.h:699
#define VARATT_IS_EXPANDED_HEADER(PTR)
#define DatumGetPointer(X)
Definition: postgres.h:534

◆ DeleteExpandedObject()

void DeleteExpandedObject ( Datum  d)

Definition at line 136 of file expandeddatum.c.

References Assert, DatumGetEOHP(), DatumGetPointer, ExpandedObjectHeader::eoh_context, MemoryContextDelete(), and VARATT_IS_EXTERNAL_EXPANDED_RW.

Referenced by advance_transition_function(), advance_windowaggregate(), advance_windowaggregate_base(), assign_record_var(), assign_simple_var(), exec_move_row(), and ExecAggTransReparent().

137 {
138  ExpandedObjectHeader *eohptr = DatumGetEOHP(d);
139 
140  /* Assert caller gave a R/W pointer */
142 
143  /* Kill it */
145 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
#define Assert(condition)
Definition: c.h:699
#define DatumGetPointer(X)
Definition: postgres.h:534
#define VARATT_IS_EXTERNAL_EXPANDED_RW(PTR)
Definition: postgres.h:320
MemoryContext eoh_context

◆ EOH_flatten_into()

void EOH_flatten_into ( ExpandedObjectHeader eohptr,
void *  result,
Size  allocated_size 
)

Definition at line 81 of file expandeddatum.c.

References ExpandedObjectHeader::eoh_methods, and ExpandedObjectMethods::flatten_into.

Referenced by datumCopy(), datumSerialize(), fill_val(), and heap_tuple_fetch_attr().

83 {
84  eohptr->eoh_methods->flatten_into(eohptr, result, allocated_size);
85 }
EOM_flatten_into_method flatten_into
Definition: expandeddatum.h:75
const ExpandedObjectMethods * eoh_methods

◆ EOH_get_flat_size()

Size EOH_get_flat_size ( ExpandedObjectHeader eohptr)

◆ EOH_init_header()

void EOH_init_header ( ExpandedObjectHeader eohptr,
const ExpandedObjectMethods methods,
MemoryContext  obj_context 
)

Definition at line 48 of file expandeddatum.c.

References ExpandedObjectHeader::eoh_context, EOH_HEADER_MAGIC, ExpandedObjectHeader::eoh_methods, ExpandedObjectHeader::eoh_ro_ptr, ExpandedObjectHeader::eoh_rw_ptr, varatt_expanded::eohptr, SET_VARTAG_EXTERNAL, VARDATA_EXTERNAL, VARTAG_EXPANDED_RO, VARTAG_EXPANDED_RW, and ExpandedObjectHeader::vl_len_.

Referenced by build_dummy_expanded_header(), expand_array(), make_expanded_record_from_datum(), make_expanded_record_from_exprecord(), make_expanded_record_from_tupdesc(), and make_expanded_record_from_typeid().

51 {
52  varatt_expanded ptr;
53 
54  eohptr->vl_len_ = EOH_HEADER_MAGIC;
55  eohptr->eoh_methods = methods;
56  eohptr->eoh_context = obj_context;
57 
58  ptr.eohptr = eohptr;
59 
61  memcpy(VARDATA_EXTERNAL(eohptr->eoh_rw_ptr), &ptr, sizeof(ptr));
62 
64  memcpy(VARDATA_EXTERNAL(eohptr->eoh_ro_ptr), &ptr, sizeof(ptr));
65 }
ExpandedObjectHeader * eohptr
Definition: postgres.h:103
char eoh_rw_ptr[EXPANDED_POINTER_SIZE]
#define VARDATA_EXTERNAL(PTR)
Definition: postgres.h:310
#define SET_VARTAG_EXTERNAL(PTR, tag)
Definition: postgres.h:333
#define EOH_HEADER_MAGIC
const ExpandedObjectMethods * eoh_methods
char eoh_ro_ptr[EXPANDED_POINTER_SIZE]
MemoryContext eoh_context

◆ MakeExpandedObjectReadOnlyInternal()

Datum MakeExpandedObjectReadOnlyInternal ( Datum  d)

Definition at line 95 of file expandeddatum.c.

References DatumGetEOHP(), DatumGetPointer, EOHPGetRODatum, and VARATT_IS_EXTERNAL_EXPANDED_RW.

Referenced by ExecInterpExpr().

96 {
97  ExpandedObjectHeader *eohptr;
98 
99  /* Nothing to do if not a read-write expanded-object pointer */
101  return d;
102 
103  /* Now safe to extract the object pointer */
104  eohptr = DatumGetEOHP(d);
105 
106  /* Return the built-in read-only pointer instead of given pointer */
107  return EOHPGetRODatum(eohptr);
108 }
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
#define EOHPGetRODatum(eohptr)
#define DatumGetPointer(X)
Definition: postgres.h:534
#define VARATT_IS_EXTERNAL_EXPANDED_RW(PTR)
Definition: postgres.h:320

◆ TransferExpandedObject()

Datum TransferExpandedObject ( Datum  d,
MemoryContext  new_parent 
)

Definition at line 118 of file expandeddatum.c.

References Assert, DatumGetEOHP(), DatumGetPointer, ExpandedObjectHeader::eoh_context, EOHPGetRWDatum, MemoryContextSetParent(), and VARATT_IS_EXTERNAL_EXPANDED_RW.

Referenced by datumTransfer(), and plpgsql_exec_function().

119 {
120  ExpandedObjectHeader *eohptr = DatumGetEOHP(d);
121 
122  /* Assert caller gave a R/W pointer */
124 
125  /* Transfer ownership */
126  MemoryContextSetParent(eohptr->eoh_context, new_parent);
127 
128  /* Return the object's standard read-write pointer */
129  return EOHPGetRWDatum(eohptr);
130 }
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
Definition: mcxt.c:354
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
#define Assert(condition)
Definition: c.h:699
#define DatumGetPointer(X)
Definition: postgres.h:534
#define EOHPGetRWDatum(eohptr)
#define VARATT_IS_EXTERNAL_EXPANDED_RW(PTR)
Definition: postgres.h:320
MemoryContext eoh_context