PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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) : 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)
 
voidcopyObjectImpl (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.

50 { \
51 Size _size = (sz); \
52 if (_size > 0) \
53 { \
54 newnode->fldname = palloc(_size); \
55 memcpy(newnode->fldname, from->fldname, _size); \
56 } \
57 } while (0)
58
59/* Copy a parse location field (for Copy, this is same as scalar case) */
60#define COPY_LOCATION_FIELD(fldname) \
61 (newnode->fldname = from->fldname)
62
63
64#include "copyfuncs.funcs.c"
65
66
67/*
68 * Support functions for nodes with custom_copy_equal attribute
69 */
70
71static Const *
72_copyConst(const Const *from)
73{
75
76 COPY_SCALAR_FIELD(consttype);
80
81 if (from->constbyval || from->constisnull)
82 {
83 /*
84 * passed by value so just copy the datum. Also, don't try to copy
85 * struct when value is null!
86 */
87 newnode->constvalue = from->constvalue;
88 }
89 else
90 {
91 /*
92 * passed by reference. We need a palloc'd copy.
93 */
94 newnode->constvalue = datumCopy(from->constvalue,
95 from->constbyval,
96 from->constlen);
97 }
98
101 COPY_LOCATION_FIELD(location);
102
103 return newnode;
104}
105
106static A_Const *
107_copyA_Const(const A_Const *from)
108{
110
111 COPY_SCALAR_FIELD(isnull);
112 if (!from->isnull)
113 {
114 /* This part must duplicate other _copy*() functions. */
115 COPY_SCALAR_FIELD(val.node.type);
116 switch (nodeTag(&from->val))
117 {
118 case T_Integer:
119 COPY_SCALAR_FIELD(val.ival.ival);
120 break;
121 case T_Float:
122 COPY_STRING_FIELD(val.fval.fval);
123 break;
124 case T_Boolean:
125 COPY_SCALAR_FIELD(val.boolval.boolval);
126 break;
127 case T_String:
128 COPY_STRING_FIELD(val.sval.sval);
129 break;
130 case T_BitString:
131 COPY_STRING_FIELD(val.bsval.bsval);
132 break;
133 default:
134 elog(ERROR, "unrecognized node type: %d",
135 (int) nodeTag(&from->val));
136 break;
137 }
138 }
139
140 COPY_LOCATION_FIELD(location);
141
142 return newnode;
143}
144
145static ExtensibleNode *
147{
149 const ExtensibleNodeMethods *methods;
150
151 methods = GetExtensibleNodeMethods(from->extnodename, false);
154 COPY_STRING_FIELD(extnodename);
155
156 /* copy the private fields */
157 methods->nodeCopy(newnode, from);
158
159 return newnode;
160}
161
162static Bitmapset *
163_copyBitmapset(const Bitmapset *from)
164{
165 return bms_copy(from);
166}
167
168
169/*
170 * copyObjectImpl -- implementation of copyObject(); see nodes/nodes.h
171 *
172 * Create a copy of a Node tree or list. This is a "deep" copy: all
173 * substructure is copied too, recursively.
174 */
175void *
176copyObjectImpl(const void *from)
177{
178 void *retval;
179
180 if (from == NULL)
181 return NULL;
182
183 /* Guard against stack overflow due to overly complex expressions */
185
186 switch (nodeTag(from))
187 {
188#include "copyfuncs.switch.c"
189
190 case T_List:
191 retval = list_copy_deep(from);
192 break;
193
194 /*
195 * Lists of integers, OIDs and XIDs don't need to be deep-copied,
196 * so we perform a shallow copy via list_copy()
197 */
198 case T_IntList:
199 case T_OidList:
200 case T_XidList:
201 retval = list_copy(from);
202 break;
203
204 default:
205 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
206 retval = NULL; /* keep compiler quiet */
207 break;
208 }
209
210 return retval;
211}
Bitmapset * bms_copy(const Bitmapset *a)
Definition bitmapset.c:122
size_t Size
Definition c.h:619
static Const * _copyConst(const Const *from)
Definition copyfuncs.c:73
static ExtensibleNode * _copyExtensibleNode(const ExtensibleNode *from)
Definition copyfuncs.c:147
#define COPY_LOCATION_FIELD(fldname)
Definition copyfuncs.c:61
void * copyObjectImpl(const void *from)
Definition copyfuncs.c:177
static A_Const * _copyA_Const(const A_Const *from)
Definition copyfuncs.c:108
#define COPY_STRING_FIELD(fldname)
Definition copyfuncs.c:42
static Bitmapset * _copyBitmapset(const Bitmapset *from)
Definition copyfuncs.c:164
#define COPY_SCALAR_FIELD(fldname)
Definition copyfuncs.c:30
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition datum.c:132
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
const ExtensibleNodeMethods * GetExtensibleNodeMethods(const char *extnodename, bool missing_ok)
Definition extensible.c:125
long val
Definition informix.c:689
List * list_copy_deep(const List *oldlist)
Definition list.c:1639
List * list_copy(const List *oldlist)
Definition list.c:1573
void * palloc(Size size)
Definition mcxt.c:1387
#define nodeTag(nodeptr)
Definition nodes.h:139
static Node * newNode(size_t size, NodeTag tag)
Definition nodes.h:150
#define makeNode(_type_)
Definition nodes.h:161
static int fb(int x)
void check_stack_depth(void)
Definition stack_depth.c:95
bool isnull
Definition parsenodes.h:388
union ValUnion val
Definition parsenodes.h:387
void(* nodeCopy)(struct ExtensibleNode *newnode, const struct ExtensibleNode *oldnode)
Definition extensible.h:66
const char * extnodename
Definition extensible.h:37

◆ 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)

Definition at line 50 of file copyfuncs.c.

51 { \
52 Size _size = (sz); \
53 if (_size > 0) \
54 { \
55 newnode->fldname = palloc(_size); \
56 memcpy(newnode->fldname, from->fldname, _size); \
57 } \
58 } while (0)

◆ 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) : NULL)

Definition at line 42 of file copyfuncs.c.

43 : NULL)

Function Documentation

◆ _copyA_Const()

static A_Const * _copyA_Const ( const A_Const from)
static

Definition at line 108 of file copyfuncs.c.

109{
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}

References COPY_LOCATION_FIELD, COPY_SCALAR_FIELD, COPY_STRING_FIELD, elog, ERROR, fb(), 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}

References bms_copy().

◆ _copyConst()

static Const * _copyConst ( const Const from)
static

Definition at line 73 of file copyfuncs.c.

74{
76
77 COPY_SCALAR_FIELD(consttype);
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
102 COPY_LOCATION_FIELD(location);
103
104 return newnode;
105}

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

◆ _copyExtensibleNode()

static ExtensibleNode * _copyExtensibleNode ( const ExtensibleNode from)
static

Definition at line 147 of file copyfuncs.c.

148{
150 const ExtensibleNodeMethods *methods;
151
152 methods = GetExtensibleNodeMethods(from->extnodename, false);
155 COPY_STRING_FIELD(extnodename);
156
157 /* copy the private fields */
158 methods->nodeCopy(newnode, from);
159
160 return newnode;
161}

References COPY_STRING_FIELD, ExtensibleNode::extnodename, fb(), 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 = NULL; /* keep compiler quiet */
208 break;
209 }
210
211 return retval;
212}

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

Referenced by list_copy_deep().