summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorBruce Momjian2002-11-10 02:17:25 +0000
committerBruce Momjian2002-11-10 02:17:25 +0000
commit78822b328c2907accf590d5473a0508ea3ee07a5 (patch)
tree69bc6e0445f319311c13b6e8c9865187fbc93d3b /src/include
parent7aeab94adf2a7e1ad0d0a32ee4bdc6b30e1cadeb (diff)
Add palloc0 function to inline MemSet for newNode call.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/nodes/nodes.h25
-rw-r--r--src/include/utils/palloc.h5
2 files changed, 23 insertions, 7 deletions
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h
index aad54a9c26c..cec75309210 100644
--- a/src/include/nodes/nodes.h
+++ b/src/include/nodes/nodes.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: nodes.h,v 1.121 2002/11/06 00:00:44 tgl Exp $
+ * $Id: nodes.h,v 1.122 2002/11/10 02:17:25 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -262,6 +262,24 @@ typedef struct Node
#define nodeTag(nodeptr) (((Node*)(nodeptr))->type)
+/*
+ * There is no way to dereference the palloc'ed pointer to assign the
+ * tag, and return the pointer itself, so we need a holder variable.
+ * Fortunately, this function isn't recursive so we just define
+ * a global variable for this purpose.
+ */
+extern Node *newNodeMacroHolder;
+
+#define newNode(size, tag) \
+( \
+ AssertMacro((size) >= sizeof(Node)), /* need the tag, at least */ \
+\
+ newNodeMacroHolder = (Node *) palloc0(size), \
+ newNodeMacroHolder->type = (tag), \
+ newNodeMacroHolder \
+)
+
+
#define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_))
#define NodeSetTag(nodeptr,t) (((Node*)(nodeptr))->type = (t))
@@ -284,11 +302,6 @@ typedef struct Node
*/
/*
- * nodes/nodes.c
- */
-extern Node *newNode(Size size, NodeTag tag);
-
-/*
* nodes/{outfuncs.c,print.c}
*/
extern char *nodeToString(void *obj);
diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h
index 44adc1ed969..89b5c151a2c 100644
--- a/src/include/utils/palloc.h
+++ b/src/include/utils/palloc.h
@@ -21,7 +21,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: palloc.h,v 1.21 2002/10/11 04:16:44 momjian Exp $
+ * $Id: palloc.h,v 1.22 2002/11/10 02:17:25 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -46,9 +46,12 @@ extern DLLIMPORT MemoryContext CurrentMemoryContext;
* Fundamental memory-allocation operations (more are in utils/memutils.h)
*/
extern void *MemoryContextAlloc(MemoryContext context, Size size);
+extern void *MemoryContextAllocZero(MemoryContext context, Size size);
#define palloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz))
+#define palloc0(sz) MemoryContextAllocZero(CurrentMemoryContext, (sz))
+
extern void pfree(void *pointer);
extern void *repalloc(void *pointer, Size size);