PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

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_combine_function(), advance_transition_function(), advance_windowaggregate(), advance_windowaggregate_base(), array_get_element_expanded(), construct_empty_expanded_array(), datumCopy(), datumEstimateSpace(), DatumGetAnyArrayP(), DatumGetExpandedArray(), DatumGetExpandedArrayX(), datumSerialize(), DeleteExpandedObject(), expand_array(), heap_compute_data_size(), heap_fill_tuple(), heap_tuple_fetch_attr(), MakeExpandedObjectReadOnlyInternal(), 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:104
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:323
#define VARDATA_EXTERNAL(PTR)
Definition: postgres.h:311
#define Assert(condition)
Definition: c.h:681
#define VARATT_IS_EXPANDED_HEADER(PTR)
#define DatumGetPointer(X)
Definition: postgres.h:555
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_combine_function(), advance_transition_function(), advance_windowaggregate(), advance_windowaggregate_base(), and assign_simple_var().

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:200
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
#define Assert(condition)
Definition: c.h:681
#define DatumGetPointer(X)
Definition: postgres.h:555
#define VARATT_IS_EXTERNAL_EXPANDED_RW(PTR)
Definition: postgres.h:321
MemoryContext eoh_context
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(), heap_fill_tuple(), 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
Size EOH_get_flat_size ( ExpandedObjectHeader eohptr)
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 expand_array().

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:104
char eoh_rw_ptr[EXPANDED_POINTER_SIZE]
#define VARDATA_EXTERNAL(PTR)
Definition: postgres.h:311
#define SET_VARTAG_EXTERNAL(PTR, tag)
Definition: postgres.h:332
#define EOH_HEADER_MAGIC
const ExpandedObjectMethods * eoh_methods
char eoh_ro_ptr[EXPANDED_POINTER_SIZE]
MemoryContext eoh_context
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:555
#define VARATT_IS_EXTERNAL_EXPANDED_RW(PTR)
Definition: postgres.h:321
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:317
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
#define Assert(condition)
Definition: c.h:681
#define DatumGetPointer(X)
Definition: postgres.h:555
#define EOHPGetRWDatum(eohptr)
#define VARATT_IS_EXTERNAL_EXPANDED_RW(PTR)
Definition: postgres.h:321
MemoryContext eoh_context