PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
copyfuncs.c File Reference
#include "postgres.h"
#include "miscadmin.h"
#include "utils/datum.h"
#include "copyfuncs.funcs.c"
#include "copyfuncs.switch.c"
Include dependency graph for copyfuncs.c:

Go to the source code of this file.

Macros

#define COPY_SCALAR_FIELD(fldname)    (newnode->fldname = from->fldname)
 
#define COPY_NODE_FIELD(fldname)    (newnode->fldname = copyObjectImpl(from->fldname))
 
#define COPY_BITMAPSET_FIELD(fldname)    (newnode->fldname = bms_copy(from->fldname))
 
#define COPY_STRING_FIELD(fldname)    (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
 
#define COPY_ARRAY_FIELD(fldname)    memcpy(newnode->fldname, from->fldname, sizeof(newnode->fldname))
 
#define COPY_POINTER_FIELD(fldname, sz)
 
#define COPY_LOCATION_FIELD(fldname)    (newnode->fldname = from->fldname)
 

Functions

static Const_copyConst (const Const *from)
 
static A_Const_copyA_Const (const A_Const *from)
 
static ExtensibleNode_copyExtensibleNode (const ExtensibleNode *from)
 
static Bitmapset_copyBitmapset (const Bitmapset *from)
 
void * copyObjectImpl (const void *from)
 

Macro Definition Documentation

◆ COPY_ARRAY_FIELD

#define COPY_ARRAY_FIELD (   fldname)     memcpy(newnode->fldname, from->fldname, sizeof(newnode->fldname))

Definition at line 46 of file copyfuncs.c.

◆ COPY_BITMAPSET_FIELD

#define COPY_BITMAPSET_FIELD (   fldname)     (newnode->fldname = bms_copy(from->fldname))

Definition at line 38 of file copyfuncs.c.

◆ COPY_LOCATION_FIELD

#define COPY_LOCATION_FIELD (   fldname)     (newnode->fldname = from->fldname)

Definition at line 61 of file copyfuncs.c.

◆ COPY_NODE_FIELD

#define COPY_NODE_FIELD (   fldname)     (newnode->fldname = copyObjectImpl(from->fldname))

Definition at line 34 of file copyfuncs.c.

◆ COPY_POINTER_FIELD

#define COPY_POINTER_FIELD (   fldname,
  sz 
)
Value:
do { \
Size _size = (sz); \
if (_size > 0) \
{ \
newnode->fldname = palloc(_size); \
memcpy(newnode->fldname, from->fldname, _size); \
} \
} while (0)
void * palloc(Size size)
Definition: mcxt.c:1317

Definition at line 50 of file copyfuncs.c.

◆ COPY_SCALAR_FIELD

#define COPY_SCALAR_FIELD (   fldname)     (newnode->fldname = from->fldname)

Definition at line 30 of file copyfuncs.c.

◆ COPY_STRING_FIELD

#define COPY_STRING_FIELD (   fldname)     (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)

Definition at line 42 of file copyfuncs.c.

Function Documentation

◆ _copyA_Const()

static A_Const * _copyA_Const ( const A_Const from)
static

Definition at line 108 of file copyfuncs.c.

109{
110 A_Const *newnode = makeNode(A_Const);
111
112 COPY_SCALAR_FIELD(isnull);
113 if (!from->isnull)
114 {
115 /* This part must duplicate other _copy*() functions. */
116 COPY_SCALAR_FIELD(val.node.type);
117 switch (nodeTag(&from->val))
118 {
119 case T_Integer:
120 COPY_SCALAR_FIELD(val.ival.ival);
121 break;
122 case T_Float:
123 COPY_STRING_FIELD(val.fval.fval);
124 break;
125 case T_Boolean:
126 COPY_SCALAR_FIELD(val.boolval.boolval);
127 break;
128 case T_String:
129 COPY_STRING_FIELD(val.sval.sval);
130 break;
131 case T_BitString:
132 COPY_STRING_FIELD(val.bsval.bsval);
133 break;
134 default:
135 elog(ERROR, "unrecognized node type: %d",
136 (int) nodeTag(&from->val));
137 break;
138 }
139 }
140
141 COPY_LOCATION_FIELD(location);
142
143 return newnode;
144}
#define COPY_LOCATION_FIELD(fldname)
Definition: copyfuncs.c:61
#define COPY_STRING_FIELD(fldname)
Definition: copyfuncs.c:42
#define COPY_SCALAR_FIELD(fldname)
Definition: copyfuncs.c:30
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
long val
Definition: informix.c:689
#define nodeTag(nodeptr)
Definition: nodes.h:133
#define makeNode(_type_)
Definition: nodes.h:155
bool isnull
Definition: parsenodes.h:365
union ValUnion val
Definition: parsenodes.h:364

References COPY_LOCATION_FIELD, COPY_SCALAR_FIELD, COPY_STRING_FIELD, elog, ERROR, A_Const::isnull, makeNode, nodeTag, A_Const::val, and val.

◆ _copyBitmapset()

static Bitmapset * _copyBitmapset ( const Bitmapset from)
static

Definition at line 164 of file copyfuncs.c.

165{
166 return bms_copy(from);
167}
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:122

References bms_copy().

◆ _copyConst()

static Const * _copyConst ( const Const from)
static

Definition at line 73 of file copyfuncs.c.

74{
75 Const *newnode = makeNode(Const);
76
77 COPY_SCALAR_FIELD(consttype);
78 COPY_SCALAR_FIELD(consttypmod);
79 COPY_SCALAR_FIELD(constcollid);
80 COPY_SCALAR_FIELD(constlen);
81
82 if (from->constbyval || from->constisnull)
83 {
84 /*
85 * passed by value so just copy the datum. Also, don't try to copy
86 * struct when value is null!
87 */
88 newnode->constvalue = from->constvalue;
89 }
90 else
91 {
92 /*
93 * passed by reference. We need a palloc'd copy.
94 */
95 newnode->constvalue = datumCopy(from->constvalue,
96 from->constbyval,
97 from->constlen);
98 }
99
100 COPY_SCALAR_FIELD(constisnull);
101 COPY_SCALAR_FIELD(constbyval);
102 COPY_LOCATION_FIELD(location);
103
104 return newnode;
105}
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132

References COPY_LOCATION_FIELD, COPY_SCALAR_FIELD, datumCopy(), and makeNode.

◆ _copyExtensibleNode()

static ExtensibleNode * _copyExtensibleNode ( const ExtensibleNode from)
static

Definition at line 147 of file copyfuncs.c.

148{
149 ExtensibleNode *newnode;
150 const ExtensibleNodeMethods *methods;
151
152 methods = GetExtensibleNodeMethods(from->extnodename, false);
153 newnode = (ExtensibleNode *) newNode(methods->node_size,
154 T_ExtensibleNode);
155 COPY_STRING_FIELD(extnodename);
156
157 /* copy the private fields */
158 methods->nodeCopy(newnode, from);
159
160 return newnode;
161}
const ExtensibleNodeMethods * GetExtensibleNodeMethods(const char *extnodename, bool missing_ok)
Definition: extensible.c:125
static Node * newNode(size_t size, NodeTag tag)
Definition: nodes.h:144
void(* nodeCopy)(struct ExtensibleNode *newnode, const struct ExtensibleNode *oldnode)
Definition: extensible.h:66
const char * extnodename
Definition: extensible.h:37

References COPY_STRING_FIELD, ExtensibleNode::extnodename, GetExtensibleNodeMethods(), newNode(), ExtensibleNodeMethods::node_size, and ExtensibleNodeMethods::nodeCopy.

◆ copyObjectImpl()

void * copyObjectImpl ( const void *  from)

Definition at line 177 of file copyfuncs.c.

178{
179 void *retval;
180
181 if (from == NULL)
182 return NULL;
183
184 /* Guard against stack overflow due to overly complex expressions */
186
187 switch (nodeTag(from))
188 {
189#include "copyfuncs.switch.c"
190
191 case T_List:
192 retval = list_copy_deep(from);
193 break;
194
195 /*
196 * Lists of integers, OIDs and XIDs don't need to be deep-copied,
197 * so we perform a shallow copy via list_copy()
198 */
199 case T_IntList:
200 case T_OidList:
201 case T_XidList:
202 retval = list_copy(from);
203 break;
204
205 default:
206 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
207 retval = 0; /* keep compiler quiet */
208 break;
209 }
210
211 return retval;
212}
List * list_copy_deep(const List *oldlist)
Definition: list.c:1639
List * list_copy(const List *oldlist)
Definition: list.c:1573
void check_stack_depth(void)
Definition: stack_depth.c:95

References check_stack_depth(), elog, ERROR, list_copy(), list_copy_deep(), and nodeTag.

Referenced by list_copy_deep().